From 917f58ab0feab1d0e0ba092fc3a129c199287aa8 Mon Sep 17 00:00:00 2001 From: Sam El-Husseini Date: Tue, 3 Dec 2019 13:22:41 -0800 Subject: [PATCH] Fix bugs with apply colour (#3483) --- core/block_svg.js | 4 ---- core/field.js | 32 ++++++++++++++++++++++++++++---- core/field_colour.js | 4 +++- core/field_textinput.js | 40 ---------------------------------------- 4 files changed, 31 insertions(+), 49 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 86059140f..4697f7405 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -972,10 +972,6 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { * @package */ Blockly.BlockSvg.prototype.applyColour = function() { - if (!this.rendered) { - // Non-rendered blocks don't have colour. - return; - } this.pathObject.applyColour(this); var icons = this.getIcons(); diff --git a/core/field.js b/core/field.js index e14e0255b..3dc95a483 100644 --- a/core/field.js +++ b/core/field.js @@ -673,10 +673,34 @@ Blockly.Field.prototype.getSize = function() { * @package */ Blockly.Field.prototype.getScaledBBox = function() { - var bBox = this.borderRect_.getBBox(); - var xy = this.getAbsoluteXY_(); - var scaledWidth = bBox.width * this.sourceBlock_.workspace.scale; - var scaledHeight = bBox.height * this.sourceBlock_.workspace.scale; + if (!this.borderRect_) { + // Browsers are inconsistent in what they return for a bounding box. + // - Webkit / Blink: fill-box / object bounding box + // - Gecko / Triden / EdgeHTML: stroke-box + var bBox = this.sourceBlock_.getHeightWidth(); + var scale = this.sourceBlock_.workspace.scale; + var xy = this.getAbsoluteXY_(); + var scaledWidth = bBox.width * scale; + var scaledHeight = bBox.height * scale; + + if (Blockly.utils.userAgent.GECKO) { + xy.x += 1.5 * scale; + xy.y += 1.5 * scale; + scaledWidth += 1 * scale; + scaledHeight += 1 * scale; + } else { + if (!Blockly.utils.userAgent.EDGE && !Blockly.utils.userAgent.IE) { + xy.x -= 0.5 * scale; + xy.y -= 0.5 * scale; + } + scaledWidth += 1 * scale; + scaledHeight += 1 * scale; + } + } else { + var xy = this.borderRect_.getBoundingClientRect(); + var scaledWidth = xy.width; + var scaledHeight = xy.height; + } return { top: xy.y, bottom: xy.y + scaledHeight, diff --git a/core/field_colour.js b/core/field_colour.js index 10b4879a0..1909f874c 100644 --- a/core/field_colour.js +++ b/core/field_colour.js @@ -199,7 +199,9 @@ Blockly.FieldColour.prototype.initView = function() { */ Blockly.FieldColour.prototype.applyColour = function() { if (!this.constants_.FIELD_COLOUR_FULL_BLOCK) { - this.borderRect_.style.fill = this.getValue(); + if (this.borderRect_) { + this.borderRect_.style.fill = this.getValue(); + } } else { this.sourceBlock_.pathObject.svgPath.setAttribute('fill', this.getValue()); this.sourceBlock_.pathObject.svgPath.setAttribute('stroke', '#fff'); diff --git a/core/field_textinput.js b/core/field_textinput.js index 19127c14f..a38b418ed 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -635,44 +635,4 @@ Blockly.FieldTextInput.prototype.getValueFromEditorText_ = function(text) { return text; }; -/** - * @override - */ -Blockly.FieldTextInput.prototype.getScaledBBox = function() { - if (!this.borderRect_) { - // Browsers are inconsistent in what they return for a bounding box. - // - Webkit / Blink: fill-box / object bounding box - // - Gecko / Triden / EdgeHTML: stroke-box - var bBox = this.sourceBlock_.getHeightWidth(); - var scale = this.sourceBlock_.workspace.scale; - var xy = this.getAbsoluteXY_(); - var scaledWidth = bBox.width * scale; - var scaledHeight = bBox.height * scale; - - if (Blockly.utils.userAgent.GECKO) { - xy.x += 1.5 * scale; - xy.y += 1.5 * scale; - scaledWidth += 1 * scale; - scaledHeight += 1 * scale; - } else { - if (!Blockly.utils.userAgent.EDGE && !Blockly.utils.userAgent.IE) { - xy.x -= 0.5 * scale; - xy.y -= 0.5 * scale; - } - scaledWidth += 1 * scale; - scaledHeight += 1 * scale; - } - } else { - var xy = this.borderRect_.getBoundingClientRect(); - var scaledWidth = xy.width; - var scaledHeight = xy.height; - } - return { - top: xy.y, - bottom: xy.y + scaledHeight, - left: xy.x, - right: xy.x + scaledWidth - }; -}; - Blockly.fieldRegistry.register('field_input', Blockly.FieldTextInput);