mirror of
https://github.com/google/blockly.git
synced 2026-01-15 21:07:14 +01:00
Clean getSvgXY_.
No functional change.
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user