From 8f73c6b04262bc3fc36b1698880d7bd6594c9573 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Tue, 1 Sep 2015 12:22:50 +0100 Subject: [PATCH] Clean getSvgXY_. No functional change. --- core/utils.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/core/utils.js b/core/utils.js index bc59cfc2b..f81026695 100644 --- a/core/utils.js +++ b/core/utils.js @@ -28,9 +28,10 @@ goog.provide('Blockly.utils'); -goog.require('goog.events.BrowserFeature'); -goog.require('goog.userAgent'); goog.require('goog.dom'); +goog.require('goog.events.BrowserFeature'); +goog.require('goog.math.Coordinate'); +goog.require('goog.userAgent'); /** @@ -294,33 +295,33 @@ Blockly.getRelativeXY_.XY_REGEXP_ = * The origin (0,0) is the top-left corner of the Blockly SVG. * @param {!Element} element Element to find the coordinates of. * @param {!Blockly.Workspace} workspace Element must be in this workspace. - * @return {!Object} Object with .x and .y properties. + * @return {!goog.math.Coordinate} Object with .x and .y properties. * @private */ Blockly.getSvgXY_ = function(element, workspace) { var x = 0; var y = 0; // Evaluate if element isn't child of a canvas. - var canvasFlag = !goog.dom.contains(workspace.getCanvas(), element) && - !goog.dom.contains(workspace.getBubbleCanvas(), element); + var inCanvas = goog.dom.contains(workspace.getCanvas(), element) || + goog.dom.contains(workspace.getBubbleCanvas(), element); do { // Loop through this block and every parent. var xy = Blockly.getRelativeXY_(element); if (element == workspace.getCanvas() || element == workspace.getBubbleCanvas()) { - canvasFlag = true; + inCanvas = false; } // Before the SVG canvas scale the coordinates. - if (canvasFlag) { - x += xy.x; - y += xy.y; - } else { + if (inCanvas) { x += xy.x * workspace.scale; y += xy.y * workspace.scale; + } else { + x += xy.x; + y += xy.y; } element = element.parentNode; } while (element && element != workspace.options.svg); - return {x: x, y: y}; + return new goog.math.Coordinate(x, y); }; /**