From d58c80db76ec5e1549f8e8a90f59c8f7bf92b4ed Mon Sep 17 00:00:00 2001 From: alschmiedt Date: Mon, 15 Mar 2021 12:37:23 -0700 Subject: [PATCH] Refactor flyout and toolbox metrics (#4648) --- core/flyout_horizontal.js | 2 +- core/flyout_vertical.js | 2 +- core/toolbox/toolbox.js | 3 +++ tests/mocha/toolbox_test.js | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/core/flyout_horizontal.js b/core/flyout_horizontal.js index acdbc7479..07d9803db 100644 --- a/core/flyout_horizontal.js +++ b/core/flyout_horizontal.js @@ -96,7 +96,7 @@ Blockly.HorizontalFlyout.prototype.getY = function() { // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. - if (toolboxMetrics.height) { + if (this.targetWorkspace.getToolbox()) { if (atTop) { y = toolboxMetrics.height; } else { diff --git a/core/flyout_vertical.js b/core/flyout_vertical.js index 399fd2b5a..66f754107 100644 --- a/core/flyout_vertical.js +++ b/core/flyout_vertical.js @@ -89,7 +89,7 @@ Blockly.VerticalFlyout.prototype.getX = function() { // If this flyout is not the trashcan flyout (e.g. toolbox or mutator). if (this.targetWorkspace.toolboxPosition == this.toolboxPosition_) { // If there is a category toolbox. - if (toolboxMetrics.width) { + if (this.targetWorkspace.getToolbox()) { if (this.toolboxPosition_ == Blockly.utils.toolbox.Position.LEFT) { x = toolboxMetrics.width; } else { diff --git a/core/toolbox/toolbox.js b/core/toolbox/toolbox.js index 995541455..fce49de23 100644 --- a/core/toolbox/toolbox.js +++ b/core/toolbox/toolbox.js @@ -600,6 +600,7 @@ Blockly.Toolbox.prototype.isHorizontal = function() { * @public */ Blockly.Toolbox.prototype.position = function() { + var workspaceMetrics = this.workspace_.getMetrics(); var toolboxDiv = this.HtmlDiv; if (!toolboxDiv) { // Not initialized yet. @@ -611,6 +612,7 @@ Blockly.Toolbox.prototype.position = function() { toolboxDiv.style.height = 'auto'; toolboxDiv.style.width = '100%'; this.height_ = toolboxDiv.offsetHeight; + this.width_ = workspaceMetrics.viewWidth; if (this.toolboxPosition == Blockly.utils.toolbox.Position.TOP) { toolboxDiv.style.top = '0'; } else { // Bottom @@ -624,6 +626,7 @@ Blockly.Toolbox.prototype.position = function() { } toolboxDiv.style.height = '100%'; this.width_ = toolboxDiv.offsetWidth; + this.height_ = workspaceMetrics.viewHeight; } this.flyout_.position(); }; diff --git a/tests/mocha/toolbox_test.js b/tests/mocha/toolbox_test.js index 42c2085ac..19d88e4ab 100644 --- a/tests/mocha/toolbox_test.js +++ b/tests/mocha/toolbox_test.js @@ -423,6 +423,8 @@ suite('Toolbox', function() { suite('position', function() { setup(function() { this.toolbox = getBasicToolbox(); + var metricsStub = sinon.stub(this.toolbox.workspace_, 'getMetrics'); + metricsStub.returns({}); }); function checkHorizontalToolbox(toolbox) {