From 29571e91e25248dfb854203d5cb4c50ef82c2f0a Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 11 Apr 2018 16:17:06 -0700 Subject: [PATCH 1/4] Work around a problem with RTL mutators --- core/flyout_vertical.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 968d01c78..74567a8df 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -155,8 +155,13 @@ Blockly.VerticalFlyout.prototype.position = function() { var x = targetWorkspaceMetrics.absoluteLeft; if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_RIGHT) { x += (targetWorkspaceMetrics.viewWidth - this.width_); + // Save the location of the left edge of the flyout, for use when firefox + // gets the bounding client rect wrong. + this.leftEdge_ = x; } this.positionAt_(this.width_, this.height_, x, y); + + }; /** @@ -315,6 +320,18 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { return new goog.math.Rect(x - BIG_NUM, -BIG_NUM, BIG_NUM + width, BIG_NUM * 2); } else { // Right + // Firefox sometimes reports the wrong value for the client rect. + // See https://github.com/google/blockly/issues/1425 and + // https://bugzilla.mozilla.org/show_bug.cgi?id=1066435 + if (goog.userAgent.GECKO && + this.targetWorkspace_ && this.targetWorkspace_.isMutator) { + // If we're in a mutator, its scale is always 1, purely because of some + // oddities in our rendering optimizations. The actual scale is the same + // as the scale on the parent workspace. + var scale = this.targetWorkspace_.options.parentWorkspace.scale; + x += this.leftEdge_ * scale; + + } return new goog.math.Rect(x, -BIG_NUM, BIG_NUM + width, BIG_NUM * 2); } }; From 40e74d4d65f8bd452958806157d427886c44afc8 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 11 Apr 2018 17:00:39 -0700 Subject: [PATCH 2/4] Check if the browser's value was plausible, and use it if so. --- core/flyout_vertical.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 74567a8df..9768d7549 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -329,8 +329,12 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { // oddities in our rendering optimizations. The actual scale is the same // as the scale on the parent workspace. var scale = this.targetWorkspace_.options.parentWorkspace.scale; - x += this.leftEdge_ * scale; - + var altX = x + this.leftEdge_ * scale; + // If the browser was obviously wrong, use the calculated value. If the + // browser's value was plausible, trust it. + if (Math.abs(altX - x) > 10) { + x = altX; + } } return new goog.math.Rect(x, -BIG_NUM, BIG_NUM + width, BIG_NUM * 2); } From 6606c7c6fc3e4460a0a52d0884a749f1e7fb0c66 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 11 Apr 2018 17:08:18 -0700 Subject: [PATCH 3/4] Fix excess newlines --- core/flyout_vertical.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 9768d7549..78130057d 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -160,8 +160,6 @@ Blockly.VerticalFlyout.prototype.position = function() { this.leftEdge_ = x; } this.positionAt_(this.width_, this.height_, x, y); - - }; /** From 01e48608fbae7861e1cc917a060abd95d3b567d9 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Wed, 11 Apr 2018 18:08:49 -0700 Subject: [PATCH 4/4] Fix my definition of plausible --- core/flyout_vertical.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 78130057d..c95de2607 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -155,7 +155,7 @@ Blockly.VerticalFlyout.prototype.position = function() { var x = targetWorkspaceMetrics.absoluteLeft; if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_RIGHT) { x += (targetWorkspaceMetrics.viewWidth - this.width_); - // Save the location of the left edge of the flyout, for use when firefox + // Save the location of the left edge of the flyout, for use when Firefox // gets the bounding client rect wrong. this.leftEdge_ = x; } @@ -323,15 +323,23 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() { // https://bugzilla.mozilla.org/show_bug.cgi?id=1066435 if (goog.userAgent.GECKO && this.targetWorkspace_ && this.targetWorkspace_.isMutator) { - // If we're in a mutator, its scale is always 1, purely because of some - // oddities in our rendering optimizations. The actual scale is the same - // as the scale on the parent workspace. - var scale = this.targetWorkspace_.options.parentWorkspace.scale; - var altX = x + this.leftEdge_ * scale; - // If the browser was obviously wrong, use the calculated value. If the - // browser's value was plausible, trust it. - if (Math.abs(altX - x) > 10) { - x = altX; + // The position of the left side of the mutator workspace in pixels + // relative to the window origin. + var targetWsLeftPixels = + this.targetWorkspace_.svgGroup_.getBoundingClientRect().x; + // The client rect is in pixels relative to the window origin. When the + // browser gets the wrong value it reports that the flyout left is the + // same as the mutator workspace left. + // We know that in a mutator workspace with the flyout on the right, the + // visible area of the workspace should be more than ten pixels wide. If + // the browser reports that the flyout is within ten pixels of the left + // side of the workspace, ignore it and manually calculate the value. + if (Math.abs(targetWsLeftPixels - x) < 10) { + // If we're in a mutator, its scale is always 1, purely because of some + // oddities in our rendering optimizations. The actual scale is the + // same as the scale on the parent workspace. + var scale = this.targetWorkspace_.options.parentWorkspace.scale; + x = x + this.leftEdge_ * scale; } } return new goog.math.Rect(x, -BIG_NUM, BIG_NUM + width, BIG_NUM * 2);