From 49954e0cec8d9cd5bd7363820d8d5c1e90ebf63e Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Wed, 15 May 2019 15:01:44 -0700 Subject: [PATCH] Remove calls to goog.dom.getViewportSize MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit document.documentElement.clientWidth/clientHeight seems to work everywhere Blockly works. Closure’s functions are mind-numbingly complex due to IE5, old WebKit, Opera 8, and others. --- core/dropdowndiv.js | 2 +- core/tooltip.js | 11 +++++------ core/utils.js | 7 ++----- core/workspace_svg.js | 3 +-- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/core/dropdowndiv.js b/core/dropdowndiv.js index 1836214dc..cdcb14388 100644 --- a/core/dropdowndiv.js +++ b/core/dropdowndiv.js @@ -30,9 +30,9 @@ goog.provide('Blockly.DropDownDiv'); goog.require('Blockly.utils'); -goog.require('goog.dom'); goog.require('goog.style'); + /** * Class for drop-down div. * @constructor diff --git a/core/tooltip.js b/core/tooltip.js index 3abf7787f..a423f31dc 100644 --- a/core/tooltip.js +++ b/core/tooltip.js @@ -37,8 +37,6 @@ goog.provide('Blockly.Tooltip'); goog.require('Blockly.utils'); -goog.require('goog.dom'); - /** * Is a tooltip currently showing? @@ -303,7 +301,8 @@ Blockly.Tooltip.show_ = function() { Blockly.Tooltip.DIV.appendChild(div); } var rtl = Blockly.Tooltip.element_.RTL; - var windowSize = goog.dom.getViewportSize(); + var windowWidth = document.documentElement.clientWidth; + var windowHeight = document.documentElement.clientHeight; // Display the tooltip. Blockly.Tooltip.DIV.style.direction = rtl ? 'rtl' : 'ltr'; Blockly.Tooltip.DIV.style.display = 'block'; @@ -318,7 +317,7 @@ Blockly.Tooltip.show_ = function() { var anchorY = Blockly.Tooltip.lastY_ + Blockly.Tooltip.OFFSET_Y; if (anchorY + Blockly.Tooltip.DIV.offsetHeight > - windowSize.height + window.scrollY) { + windowHeight + window.scrollY) { // Falling off the bottom of the screen; shift the tooltip up. anchorY -= Blockly.Tooltip.DIV.offsetHeight + 2 * Blockly.Tooltip.OFFSET_Y; } @@ -327,10 +326,10 @@ Blockly.Tooltip.show_ = function() { anchorX = Math.max(Blockly.Tooltip.MARGINS - window.scrollX, anchorX); } else { if (anchorX + Blockly.Tooltip.DIV.offsetWidth > - windowSize.width + window.scrollX - 2 * Blockly.Tooltip.MARGINS) { + windowWidth + window.scrollX - 2 * Blockly.Tooltip.MARGINS) { // Falling off the right edge of the screen; // clamp the tooltip on the edge. - anchorX = windowSize.width - Blockly.Tooltip.DIV.offsetWidth - + anchorX = windowWidth - Blockly.Tooltip.DIV.offsetWidth - 2 * Blockly.Tooltip.MARGINS; } } diff --git a/core/utils.js b/core/utils.js index 9c08ee8cc..292a76a59 100644 --- a/core/utils.js +++ b/core/utils.js @@ -34,7 +34,6 @@ goog.provide('Blockly.utils'); goog.require('Blockly.userAgent'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); @@ -909,13 +908,11 @@ Blockly.utils.setCssTransform = function(node, transform) { * @package */ Blockly.utils.getViewportBBox = function() { - // Pixels. - var windowSize = goog.dom.getViewportSize(); // Pixels, in window coordinates. var scrollOffset = goog.style.getViewportPageOffset(document); return { - right: windowSize.width + scrollOffset.x, - bottom: windowSize.height + scrollOffset.y, + right: document.documentElement.clientWidth + scrollOffset.x, + bottom: document.documentElement.clientHeight + scrollOffset.y, top: scrollOffset.y, left: scrollOffset.x }; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 74896cbac..7f20dca13 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -767,8 +767,7 @@ Blockly.WorkspaceSvg.prototype.updateScreenCalculationsIfScrolled = function() { /* eslint-disable indent */ var currScroll = goog.dom.getDocumentScroll(); - if (!goog.math.Coordinate.equals(this.lastRecordedPageScroll_, - currScroll)) { + if (!goog.math.Coordinate.equals(this.lastRecordedPageScroll_, currScroll)) { this.lastRecordedPageScroll_ = currScroll; this.updateScreenCalculations_(); }