mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
Remove goog.math.Rect dependency
This commit is contained in:
@@ -30,8 +30,7 @@ goog.require('Blockly.Block');
|
||||
goog.require('Blockly.Flyout');
|
||||
goog.require('Blockly.FlyoutButton');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Rect');
|
||||
goog.require('Blockly.utils.Rect');
|
||||
|
||||
|
||||
/**
|
||||
@@ -336,7 +335,7 @@ Blockly.HorizontalFlyout.prototype.isDragTowardWorkspace = function(
|
||||
|
||||
/**
|
||||
* Return the deletion rectangle for this flyout in viewport coordinates.
|
||||
* @return {goog.math.Rect} Rectangle in which to delete.
|
||||
* @return {Blockly.utils.Rect} Rectangle in which to delete.
|
||||
*/
|
||||
Blockly.HorizontalFlyout.prototype.getClientRect = function() {
|
||||
if (!this.svgGroup_) {
|
||||
@@ -352,10 +351,10 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() {
|
||||
var height = flyoutRect.height;
|
||||
|
||||
if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_TOP) {
|
||||
return new goog.math.Rect(-BIG_NUM, y - BIG_NUM, BIG_NUM * 2,
|
||||
return new Blockly.utils.Rect(-BIG_NUM, y - BIG_NUM, BIG_NUM * 2,
|
||||
BIG_NUM + height);
|
||||
} else if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_BOTTOM) {
|
||||
return new goog.math.Rect(-BIG_NUM, y, BIG_NUM * 2,
|
||||
return new Blockly.utils.Rect(-BIG_NUM, y, BIG_NUM * 2,
|
||||
BIG_NUM + height);
|
||||
}
|
||||
// TODO: Else throw error (should never happen).
|
||||
|
||||
@@ -31,8 +31,7 @@ goog.require('Blockly.Flyout');
|
||||
goog.require('Blockly.FlyoutButton');
|
||||
goog.require('Blockly.userAgent');
|
||||
goog.require('Blockly.utils');
|
||||
|
||||
goog.require('goog.math.Rect');
|
||||
goog.require('Blockly.utils.Rect');
|
||||
|
||||
|
||||
/**
|
||||
@@ -314,7 +313,7 @@ Blockly.VerticalFlyout.prototype.isDragTowardWorkspace = function(
|
||||
|
||||
/**
|
||||
* Return the deletion rectangle for this flyout in viewport coordinates.
|
||||
* @return {goog.math.Rect} Rectangle in which to delete.
|
||||
* @return {Blockly.utils.Rect} Rectangle in which to delete.
|
||||
*/
|
||||
Blockly.VerticalFlyout.prototype.getClientRect = function() {
|
||||
if (!this.svgGroup_) {
|
||||
@@ -330,7 +329,7 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() {
|
||||
var width = flyoutRect.width;
|
||||
|
||||
if (this.toolboxPosition_ == Blockly.TOOLBOX_AT_LEFT) {
|
||||
return new goog.math.Rect(x - BIG_NUM, -BIG_NUM, BIG_NUM + width,
|
||||
return new Blockly.utils.Rect(x - BIG_NUM, -BIG_NUM, BIG_NUM + width,
|
||||
BIG_NUM * 2);
|
||||
} else { // Right
|
||||
// Firefox sometimes reports the wrong value for the client rect.
|
||||
@@ -357,7 +356,7 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() {
|
||||
x = x + this.leftEdge_ * scale;
|
||||
}
|
||||
}
|
||||
return new goog.math.Rect(x, -BIG_NUM, BIG_NUM + width, BIG_NUM * 2);
|
||||
return new Blockly.utils.Rect(x, -BIG_NUM, BIG_NUM + width, BIG_NUM * 2);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -32,12 +32,12 @@ goog.require('Blockly.Flyout');
|
||||
goog.require('Blockly.HorizontalFlyout');
|
||||
goog.require('Blockly.Touch');
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.Rect');
|
||||
goog.require('Blockly.VerticalFlyout');
|
||||
|
||||
goog.require('goog.events');
|
||||
goog.require('goog.events.EventType');
|
||||
goog.require('goog.html.SafeHtml');
|
||||
goog.require('goog.math.Rect');
|
||||
goog.require('goog.ui.tree.BaseNode');
|
||||
goog.require('goog.ui.tree.TreeControl');
|
||||
goog.require('goog.ui.tree.TreeNode');
|
||||
@@ -530,7 +530,7 @@ Blockly.Toolbox.prototype.removeStyle = function(style) {
|
||||
|
||||
/**
|
||||
* Return the deletion rectangle for this toolbox.
|
||||
* @return {goog.math.Rect} Rectangle in which to delete.
|
||||
* @return {Blockly.utils.Rect} Rectangle in which to delete.
|
||||
*/
|
||||
Blockly.Toolbox.prototype.getClientRect = function() {
|
||||
if (!this.HtmlDiv) {
|
||||
@@ -551,15 +551,15 @@ Blockly.Toolbox.prototype.getClientRect = function() {
|
||||
// Assumes that the toolbox is on the SVG edge. If this changes
|
||||
// (e.g. toolboxes in mutators) then this code will need to be more complex.
|
||||
if (this.toolboxPosition == Blockly.TOOLBOX_AT_LEFT) {
|
||||
return new goog.math.Rect(-BIG_NUM, -BIG_NUM, BIG_NUM + x + width,
|
||||
return new Blockly.utils.Rect(-BIG_NUM, -BIG_NUM, BIG_NUM + x + width,
|
||||
2 * BIG_NUM);
|
||||
} else if (this.toolboxPosition == Blockly.TOOLBOX_AT_RIGHT) {
|
||||
return new goog.math.Rect(x, -BIG_NUM, BIG_NUM + width, 2 * BIG_NUM);
|
||||
return new Blockly.utils.Rect(x, -BIG_NUM, BIG_NUM + width, 2 * BIG_NUM);
|
||||
} else if (this.toolboxPosition == Blockly.TOOLBOX_AT_TOP) {
|
||||
return new goog.math.Rect(-BIG_NUM, -BIG_NUM, 2 * BIG_NUM,
|
||||
return new Blockly.utils.Rect(-BIG_NUM, -BIG_NUM, 2 * BIG_NUM,
|
||||
BIG_NUM + y + height);
|
||||
} else { // Bottom
|
||||
return new goog.math.Rect(0, y, 2 * BIG_NUM, BIG_NUM + width);
|
||||
return new Blockly.utils.Rect(0, y, 2 * BIG_NUM, BIG_NUM + width);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -27,10 +27,9 @@
|
||||
goog.provide('Blockly.Trashcan');
|
||||
|
||||
goog.require('Blockly.utils');
|
||||
goog.require('Blockly.utils.Rect');
|
||||
goog.require('Blockly.Xml');
|
||||
|
||||
goog.require('goog.math.Rect');
|
||||
|
||||
|
||||
/**
|
||||
* Class for a trash can.
|
||||
@@ -354,7 +353,7 @@ Blockly.Trashcan.prototype.position = function() {
|
||||
|
||||
/**
|
||||
* Return the deletion rectangle for this trash can.
|
||||
* @return {goog.math.Rect} Rectangle in which to delete.
|
||||
* @return {Blockly.utils.Rect} Rectangle in which to delete.
|
||||
*/
|
||||
Blockly.Trashcan.prototype.getClientRect = function() {
|
||||
if (!this.svgGroup_) {
|
||||
@@ -366,8 +365,7 @@ Blockly.Trashcan.prototype.getClientRect = function() {
|
||||
var top = trashRect.top + this.SPRITE_TOP_ - this.MARGIN_HOTSPOT_;
|
||||
var width = this.WIDTH_ + 2 * this.MARGIN_HOTSPOT_;
|
||||
var height = this.LID_HEIGHT_ + this.BODY_HEIGHT_ + 2 * this.MARGIN_HOTSPOT_;
|
||||
return new goog.math.Rect(left, top, width, height);
|
||||
|
||||
return new Blockly.utils.Rect(left, top, width, height);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
71
core/utils_rect.js
Normal file
71
core/utils_rect.js
Normal file
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* @license
|
||||
* Visual Blocks Editor
|
||||
*
|
||||
* Copyright 2019 Google Inc.
|
||||
* https://developers.google.com/blockly/
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @fileoverview Utility methods for rectangle manipulation.
|
||||
* These methods are not specific to Blockly, and could be factored out into
|
||||
* a JavaScript framework such as Closure.
|
||||
* @author fraser@google.com (Neil Fraser)
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @name Blockly.utils.Rect
|
||||
* @namespace
|
||||
*/
|
||||
goog.provide('Blockly.utils.Rect');
|
||||
|
||||
|
||||
/**
|
||||
* Class for representing rectangular regions.
|
||||
* @param {number} x Left.
|
||||
* @param {number} y Top.
|
||||
* @param {number} w Width.
|
||||
* @param {number} h Height.
|
||||
* @struct
|
||||
* @constructor
|
||||
* @implements {goog.math.IRect}
|
||||
*/
|
||||
Blockly.utils.Rect = function(x, y, w, h) {
|
||||
/** @type {number} */
|
||||
this.left = x;
|
||||
|
||||
/** @type {number} */
|
||||
this.top = y;
|
||||
|
||||
/** @type {number} */
|
||||
this.width = w;
|
||||
|
||||
/** @type {number} */
|
||||
this.height = h;
|
||||
};
|
||||
|
||||
/**
|
||||
* Tests whether this rectangle entirely contains another rectangle or
|
||||
* coordinate.
|
||||
*
|
||||
* @param {number} x The x coordinate to test for containment.
|
||||
* @param {number} y The y coordinate to test for containment.
|
||||
* @return {boolean} Whether this rectangle contains given coordinate.
|
||||
*/
|
||||
Blockly.utils.Rect.prototype.contains = function(x, y) {
|
||||
return x >= this.left && x <= this.left + this.width &&
|
||||
y >= this.top && y <= this.top + this.height;
|
||||
};
|
||||
@@ -1201,11 +1201,12 @@ Blockly.WorkspaceSvg.prototype.recordDeleteAreas = function() {
|
||||
* which delete area the event is over.
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.isDeleteArea = function(e) {
|
||||
var xy = new goog.math.Coordinate(e.clientX, e.clientY);
|
||||
if (this.deleteAreaTrash_ && this.deleteAreaTrash_.contains(xy)) {
|
||||
if (this.deleteAreaTrash_ &&
|
||||
this.deleteAreaTrash_.contains(e.clientX, e.clientY)) {
|
||||
return Blockly.DELETE_AREA_TRASH;
|
||||
}
|
||||
if (this.deleteAreaToolbox_ && this.deleteAreaToolbox_.contains(xy)) {
|
||||
if (this.deleteAreaToolbox_ &&
|
||||
this.deleteAreaToolbox_.contains(e.clientX, e.clientY)) {
|
||||
return Blockly.DELETE_AREA_TOOLBOX;
|
||||
}
|
||||
return Blockly.DELETE_AREA_NONE;
|
||||
|
||||
Reference in New Issue
Block a user