Remove borderRect_, clean up, and fix RTL

This commit is contained in:
Tim Mickel 2016-04-05 12:19:01 -04:00
parent 46ed2fa129
commit e413d47f4d
3 changed files with 21 additions and 20 deletions

View file

@ -63,6 +63,13 @@ Blockly.BlockSvg.FIELD_HEIGHT = 8 * Blockly.BlockSvg.GRID_UNIT;
* @const
*/
Blockly.BlockSvg.FIELD_WIDTH = 12 * Blockly.BlockSvg.GRID_UNIT;
/**
* Top padding of user inputs
* @const
*/
Blockly.BlockSvg.FIELD_TOP_PADDING = 1.5 * Blockly.BlockSvg.GRID_UNIT;
/**
* Corner radius of number inputs
* @const

View file

@ -134,18 +134,13 @@ Blockly.Field.prototype.init = function(block) {
if (!this.visible_) {
this.fieldGroup_.style.display = 'none';
}
this.borderRect_ = Blockly.createSvgElement('rect',
{'rx': 4,
'ry': 4,
'x': -Blockly.BlockSvg.SEP_SPACE_X / 2,
'y': 0,
'height': Blockly.BlockSvg.FIELD_HEIGHT}, this.fieldGroup_, this.sourceBlock_.workspace);
// Adjust X to be flipped for RTL. Position is relative to horizontal start of source block.
var fieldX = (this.sourceBlock_.RTL) ? -this.size_.width / 2 : this.size_.width / 2;
/** @type {!Element} */
this.textElement_ = Blockly.createSvgElement('text',
{'class': 'blocklyText',
'y': this.size_.height/2 + 6.25,
'x': Blockly.BlockSvg.FIELD_WIDTH / 2,
'width': Blockly.BlockSvg.FIELD_WIDTH - Blockly.BlockSvg.SEP_SPACE_X,
'x': fieldX,
'y': this.size_.height / 2 + Blockly.BlockSvg.FIELD_TOP_PADDING,
'text-anchor': 'middle'},
this.fieldGroup_);
@ -174,7 +169,6 @@ Blockly.Field.prototype.dispose = function() {
goog.dom.removeNode(this.fieldGroup_);
this.fieldGroup_ = null;
this.textElement_ = null;
this.borderRect_ = null;
this.validator_ = null;
};
@ -264,10 +258,6 @@ Blockly.Field.prototype.render_ = function() {
Blockly.Field.cacheWidths_[key] = width;
}
}
if (this.borderRect_) {
this.borderRect_.setAttribute('width',
width + Blockly.BlockSvg.SEP_SPACE_X);
}
} else {
var width = 0;
}
@ -314,10 +304,9 @@ Blockly.Field.prototype.getSize = function() {
* @private
*/
Blockly.Field.prototype.getScaledBBox_ = function() {
var bBox = this.borderRect_.getBBox();
// Create new object, as getBBox can return an uneditable SVGRect in IE.
return new goog.math.Size(bBox.width * this.sourceBlock_.workspace.scale,
bBox.height * this.sourceBlock_.workspace.scale);
var size = this.getSize();
return new goog.math.Size(size.width * this.sourceBlock_.workspace.scale,
size.height * this.sourceBlock_.workspace.scale);
};
/**
@ -479,5 +468,5 @@ Blockly.Field.prototype.getClickTarget_ = function() {
* @private
*/
Blockly.Field.prototype.getAbsoluteXY_ = function() {
return goog.style.getPageOffset(this.borderRect_);
return goog.style.getPageOffset(this.getClickTarget_());
};

View file

@ -70,7 +70,12 @@ Blockly.FieldColour.prototype.columns_ = 0;
*/
Blockly.FieldColour.prototype.init = function(block) {
Blockly.FieldColour.superClass_.init.call(this, block);
this.borderRect_.style['fillOpacity'] = 1;
// XXX: borderRect_ has been removed from the field.
// When fixing field_colour, we should re-color the shadow block instead,
// or re-implement a rectangle in the field.
if (this.borderRect_) {
this.borderRect_.style['fillOpacity'] = 1;
}
this.setValue(this.getValue());
};