diff --git a/core/block_svg.js b/core/block_svg.js index 347a56be7..c340576be 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -40,6 +40,7 @@ goog.require('Blockly.Touch'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); +goog.require('Blockly.utils.Rect'); /** @@ -469,8 +470,7 @@ Blockly.BlockSvg.prototype.snapToGrid = function() { * Returns the coordinates of a bounding box describing the dimensions of this * block and any blocks stacked below it. * Coordinate system: workspace coordinates. - * @return {!{top: number, bottom: number, left: number, right: number}} - * Object with top, bottom, left, and right coordinates of the bounding box. + * @return {!Blockly.utils.Rect} Object with coordinates of the bounding box. */ Blockly.BlockSvg.prototype.getBoundingRectangle = function() { var blockXY = this.getRelativeToSurfaceXY(this); @@ -492,7 +492,7 @@ Blockly.BlockSvg.prototype.getBoundingRectangle = function() { // Width has the tab built into it already so subtract it here. right = blockXY.x + blockBounds.width - tab; } - return {top: top, bottom: bottom, left: left, right: right}; + return new Blockly.utils.Rect(top, bottom, left, right); }; /** diff --git a/core/inject.js b/core/inject.js index e40d110e5..5d4aa5545 100644 --- a/core/inject.js +++ b/core/inject.js @@ -312,8 +312,7 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, } // Bump any object that's below the bottom back inside. - var overflowBottom = - metrics.viewBottom - objectMetrics.bottom; + var overflowBottom = metrics.viewBottom - objectMetrics.bottom; if (overflowBottom < 0) { object.moveBy(0, overflowBottom); } diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 3469c1deb..b93331c6a 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -34,6 +34,7 @@ goog.require('Blockly.Events.Ui'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); +goog.require('Blockly.utils.Rect'); goog.require('Blockly.WorkspaceComment'); @@ -419,8 +420,7 @@ Blockly.WorkspaceCommentSvg.prototype.clearTransformAttributes_ = function() { * Returns the coordinates of a bounding box describing the dimensions of this * comment. * Coordinate system: workspace coordinates. - * @return {!{top: number, bottom: number, left: number, right: number}} - * Object with top, bottom, left, and right coordinates of the bounding box. + * @return {!Blockly.utils.Rect} Object with coordinates of the bounding box. * @package */ Blockly.WorkspaceCommentSvg.prototype.getBoundingRectangle = function() { @@ -440,7 +440,7 @@ Blockly.WorkspaceCommentSvg.prototype.getBoundingRectangle = function() { left = blockXY.x; right = blockXY.x + commentBounds.width; } - return {top: top, bottom: bottom, left: left, right: right}; + return new Blockly.utils.Rect(top, bottom, left, right); }; /** diff --git a/core/workspace_svg.js b/core/workspace_svg.js index bcbe72918..7cedea7ee 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -43,6 +43,7 @@ goog.require('Blockly.Trashcan'); goog.require('Blockly.utils'); goog.require('Blockly.utils.Coordinate'); goog.require('Blockly.utils.dom'); +goog.require('Blockly.utils.Rect'); goog.require('Blockly.VariablesDynamic'); goog.require('Blockly.Workspace'); goog.require('Blockly.WorkspaceAudio'); @@ -1352,8 +1353,8 @@ Blockly.WorkspaceSvg.prototype.onMouseWheel_ = function(e) { * Calculate the bounding box for the blocks on the workspace. * Coordinate system: workspace coordinates. * - * @return {Object} Contains the position and size of the bounding box - * containing the blocks on the workspace. + * @return {!Blockly.utils.Rect} Contains the position and size of the + * bounding box containing the blocks on the workspace. */ Blockly.WorkspaceSvg.prototype.getBlocksBoundingBox = function() { var topBlocks = this.getTopBlocks(false); @@ -1361,7 +1362,7 @@ Blockly.WorkspaceSvg.prototype.getBlocksBoundingBox = function() { var topElements = topBlocks.concat(topComments); // There are no blocks, return empty rectangle. if (!topElements.length) { - return {top: 0, bottom: 0, left: 0, right: 0}; + return new Blockly.utils.Rect(0, 0, 0, 0); } // Initialize boundary using the first block. @@ -1370,18 +1371,18 @@ Blockly.WorkspaceSvg.prototype.getBlocksBoundingBox = function() { // Start at 1 since the 0th block was used for initialization. for (var i = 1; i < topElements.length; i++) { var blockBoundary = topElements[i].getBoundingRectangle(); - if (blockBoundary.left < boundary.left) { - boundary.left = blockBoundary.left; - } - if (blockBoundary.right > boundary.right) { - boundary.right = blockBoundary.right; - } if (blockBoundary.top < boundary.top) { boundary.top = blockBoundary.top; } if (blockBoundary.bottom > boundary.bottom) { boundary.bottom = blockBoundary.bottom; } + if (blockBoundary.left < boundary.left) { + boundary.left = blockBoundary.left; + } + if (blockBoundary.right > boundary.right) { + boundary.right = blockBoundary.right; + } } return boundary; };