Fix bugs with apply colour (#3483)

This commit is contained in:
Sam El-Husseini
2019-12-03 13:22:41 -08:00
committed by GitHub
parent 8017382742
commit 917f58ab0f
4 changed files with 31 additions and 49 deletions

View File

@@ -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();

View File

@@ -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,

View File

@@ -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');

View File

@@ -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);