diff --git a/core/inject.js b/core/inject.js index 93b1277fc..e68ec6e7a 100644 --- a/core/inject.js +++ b/core/inject.js @@ -257,12 +257,10 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, if (mainWorkspace.isContentBounded()) { // Already in workspace units, no need to divide by scale. var blocksBoundingBox = mainWorkspace.getBlocksBoundingBox(); - workspaceMetrics.contentLeft = blocksBoundingBox.x; - workspaceMetrics.contentTop = blocksBoundingBox.y; - workspaceMetrics.contentRight = - blocksBoundingBox.x + blocksBoundingBox.width; - workspaceMetrics.contentBottom = - blocksBoundingBox.y + blocksBoundingBox.height; + workspaceMetrics.contentLeft = blocksBoundingBox.left; + workspaceMetrics.contentTop = blocksBoundingBox.top; + workspaceMetrics.contentRight = blocksBoundingBox.right; + workspaceMetrics.contentBottom = blocksBoundingBox.bottom; } else { workspaceMetrics.contentLeft = defaultMetrics.contentLeft / scale; workspaceMetrics.contentTop = defaultMetrics.contentTop / scale; diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 08d2b3c26..59e28d8e7 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -430,7 +430,7 @@ Blockly.WorkspaceCommentSvg.prototype.getBoundingRectangle = function() { var bottom = blockXY.y + commentBounds.height; var left, right; if (this.RTL) { - left = blockXY.x - (commentBounds.width); + left = blockXY.x - commentBounds.width; // Add the width of the tab/puzzle piece knob to the x coordinate // since X is the corner of the rectangle, not the whole puzzle piece. right = blockXY.x; diff --git a/core/workspace_svg.js b/core/workspace_svg.js index eb7ec7666..9498a6f85 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1361,7 +1361,7 @@ Blockly.WorkspaceSvg.prototype.getBlocksBoundingBox = function() { var topElements = topBlocks.concat(topComments); // There are no blocks, return empty rectangle. if (!topElements.length) { - return {x: 0, y: 0, width: 0, height: 0}; + return {top: 0, bottom: 0, left: 0, right: 0}; } // Initialize boundary using the first block. @@ -1383,12 +1383,7 @@ Blockly.WorkspaceSvg.prototype.getBlocksBoundingBox = function() { boundary.bottom = blockBoundary.bottom; } } - return { - x: boundary.left, - y: boundary.top, - width: boundary.right - boundary.left, - height: boundary.bottom - boundary.top - }; + return boundary; }; /** @@ -1726,8 +1721,8 @@ Blockly.WorkspaceSvg.prototype.zoomToFit = function() { var workspaceWidth = metrics.viewWidth; var workspaceHeight = metrics.viewHeight; var blocksBox = this.getBlocksBoundingBox(); - var blocksWidth = blocksBox.width; - var blocksHeight = blocksBox.height; + var blocksWidth = blocksBox.right - blocksBox.left; + var blocksHeight = blocksBox.bottom - blocksBox.top; if (!blocksWidth) { return; // Prevents zooming to infinity. } @@ -2018,18 +2013,18 @@ Blockly.WorkspaceSvg.getContentDimensionsExact_ = function(ws) { var scale = ws.scale; // Convert to pixels. - var width = blockBox.width * scale; - var height = blockBox.height * scale; - var left = blockBox.x * scale; - var top = blockBox.y * scale; + var top = blockBox.top * scale; + var bottom = blockBox.bottom * scale; + var left = blockBox.left * scale; + var right = blockBox.right * scale; return { - left: left, top: top, - right: left + width, - bottom: top + height, - width: width, - height: height + bottom: bottom, + left: left, + right: right, + width: right - left, + height: bottom - top }; }; diff --git a/core/xml.js b/core/xml.js index a0fe66b73..c8fb003e5 100644 --- a/core/xml.js +++ b/core/xml.js @@ -461,11 +461,11 @@ Blockly.Xml.appendDomToWorkspace = function(xml, workspace) { } // Load the new blocks into the workspace and get the IDs of the new blocks. var newBlockIds = Blockly.Xml.domToWorkspace(xml,workspace); - if (bbox && bbox.height) { // check if any previous block + if (bbox && bbox.top != bbox.bottom) { // check if any previous block var offsetY = 0; // offset to add to y of the new block var offsetX = 0; - var farY = bbox.y + bbox.height; // bottom position - var topX = bbox.x; // x of bounding box + var farY = bbox.bottom; // bottom position + var topX = bbox.left; // x of bounding box // Check position of the new blocks. var newX = Infinity; // x of top corner var newY = Infinity; // y of top corner diff --git a/tests/jsunit/metrics_test.js b/tests/jsunit/metrics_test.js index 30cd11af3..fb9ca4d37 100644 --- a/tests/jsunit/metrics_test.js +++ b/tests/jsunit/metrics_test.js @@ -34,10 +34,10 @@ function makeMockWs(scale, x, y, width, height) { return { getBlocksBoundingBox: function() { return { - width: width, - height: height, - x: x, - y: y + top: y, + bottom: y + height, + left: x, + right: x + width } }, scale: scale