diff --git a/core/field.js b/core/field.js index e0d20035e..e6b24207d 100644 --- a/core/field.js +++ b/core/field.js @@ -644,6 +644,15 @@ Blockly.Field.prototype.getSize = function() { return this.size_; }; +/** + * Get the size of the visible field, as used in new rendering. + * @return {!goog.math.Size} The size of the visible field. + * @package + */ +Blockly.Field.prototype.getCorrectedSize = function() { + return this.getSize(); +}; + /** * Returns the bounding box of the rendered field, accounting for workspace * scaling. diff --git a/core/field_checkbox.js b/core/field_checkbox.js index 82f281cad..f82a718c2 100644 --- a/core/field_checkbox.js +++ b/core/field_checkbox.js @@ -209,4 +209,16 @@ Blockly.FieldCheckbox.prototype.convertValueToBool_ = function(value) { } }; +/** + * Get the size of the visible field, as used in new rendering. + * The checkbox field fills the entire border rect, rather than just using the + * text element. + * @return {!goog.math.Size} The size of the visible field. + * @package + */ +Blockly.FieldCheckbox.prototype.getCorrectedSize = function() { + this.getSize(); + return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, + Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT); +}; Blockly.Field.register('field_checkbox', Blockly.FieldCheckbox); diff --git a/core/field_colour.js b/core/field_colour.js index 5f26899ad..7835822be 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -340,4 +340,20 @@ Blockly.FieldColour.prototype.dropdownDispose_ = function() { Blockly.unbindEvent_(this.onUpWrapper_); }; +/** + * Get the size of the visible field, as used in new rendering. + * The colour field fills the bounding box with colour and takes up the full + * space of the bounding box. + * @return {!goog.math.Size} The size of the visible field. + * @package + */ +Blockly.FieldColour.prototype.getCorrectedSize = function() { + // getSize also renders and updates the size if needed. Rather than duplicate + // the logic to figure out whether to rerender, just call getSize. + this.getSize(); + return new goog.math.Size( + this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, + Blockly.Field.BORDER_RECT_DEFAULT_HEIGHT - 1); +}; + Blockly.Field.register('field_colour', Blockly.FieldColour); diff --git a/core/field_dropdown.js b/core/field_dropdown.js index 7d070cfe0..46144acc4 100644 --- a/core/field_dropdown.js +++ b/core/field_dropdown.js @@ -547,4 +547,17 @@ Blockly.FieldDropdown.validateOptions_ = function(options) { } }; +/** + * Get the size of the visible field, as used in new rendering. + * @return {!goog.math.Size} The size of the visible field. + * @package + */ +Blockly.FieldDropdown.prototype.getCorrectedSize = function() { + // getSize also renders and updates the size if needed. Rather than duplicate + // the logic to figure out whether to rerender, just call getSize. + this.getSize(); + return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, + this.size_.height - 9); +}; + Blockly.Field.register('field_dropdown', Blockly.FieldDropdown); diff --git a/core/field_image.js b/core/field_image.js index bd5a56ae1..615de00f3 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -189,4 +189,20 @@ Blockly.FieldImage.prototype.showEditor_ = function() { } }; +/** + * Get the size of the visible field, as used in new rendering. + * @return {!goog.math.Size} The size of the visible field. + * @package + */ +Blockly.FieldImage.prototype.getCorrectedSize = function() { + // getSize also renders and updates the size if needed. Rather than duplicate + // the logic to figure out whether to rerender, just call getSize. + this.getSize(); + // Old rendering adds an extra pixel under the image. We include this in the + // height of the image in new rendering, rather than having the spacer below + // know that there was an image in the previous row. + // TODO: Remove. + return new goog.math.Size(this.size_.width, this.height_ + 1); +}; + Blockly.Field.register('field_image', Blockly.FieldImage); diff --git a/core/field_label.js b/core/field_label.js index efeeb1e6c..6cab5af77 100644 --- a/core/field_label.js +++ b/core/field_label.js @@ -100,4 +100,16 @@ Blockly.FieldLabel.prototype.doClassValidation_ = function(newValue) { return String(newValue); }; +/** + * Get the size of the visible field, as used in new rendering. + * @return {!goog.math.Size} The size of the visible field. + * @package + */ +Blockly.FieldLabel.prototype.getCorrectedSize = function() { + // getSize also renders and updates the size if needed. Rather than duplicate + // the logic to figure out whether to rerender, just call getSize. + this.getSize(); + return new goog.math.Size(this.size_.width, this.size_.height - 5); +}; + Blockly.Field.register('field_label', Blockly.FieldLabel); diff --git a/core/field_textinput.js b/core/field_textinput.js index c525b5c9c..f00ec6d01 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -432,4 +432,16 @@ Blockly.FieldTextInput.nonnegativeIntegerValidator = function(text) { return n; }; +/** + * Get the size of the visible field, as used in new rendering. + * @return {!goog.math.Size} The size of the visible field. + * @package + */ +Blockly.FieldTextInput.prototype.getCorrectedSize = function() { + // getSize also renders and updates the size if needed. Rather than duplicate + // the logic to figure out whether to rerender, just call getSize. + this.getSize(); + return new goog.math.Size(this.size_.width + Blockly.BlockSvg.SEP_SPACE_X, 16); +}; + Blockly.Field.register('field_input', Blockly.FieldTextInput); diff --git a/core/icon.js b/core/icon.js index 73f3df609..39e6accc1 100644 --- a/core/icon.js +++ b/core/icon.js @@ -205,3 +205,15 @@ Blockly.Icon.prototype.computeIconLocation = function() { Blockly.Icon.prototype.getIconLocation = function() { return this.iconXY_; }; + +/** + * Get the size of the icon as used for rendering. + * This differs from the actual size of the icon, because it bulges slightly + * out of its row rather than increasing the height of its row. + * TODO (#2562): Remove getCorrectedSize. + * @return {!goog.math.Size} Height and width. + */ +Blockly.Icon.prototype.getCorrectedSize = function() { + return new goog.math.Size( + Blockly.Icon.prototype.SIZE, Blockly.Icon.prototype.SIZE - 2); +};