Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright 2008 The Closure Library Authors. All Rights Reserved.
//
// 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.
goog.provide('goog.fx.AbstractDragDropTest');
goog.setTestOnly('goog.fx.AbstractDragDropTest');
goog.require('goog.array');
goog.require('goog.dom.TagName');
goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('goog.functions');
goog.require('goog.fx.AbstractDragDrop');
goog.require('goog.fx.DragDropItem');
goog.require('goog.math.Box');
goog.require('goog.math.Coordinate');
goog.require('goog.style');
goog.require('goog.testing.events');
goog.require('goog.testing.events.Event');
goog.require('goog.testing.jsunit');
var targets = [
{box_: new goog.math.Box(0, 3, 1, 1)}, {box_: new goog.math.Box(0, 7, 2, 6)},
{box_: new goog.math.Box(2, 2, 3, 1)}, {box_: new goog.math.Box(4, 1, 6, 1)},
{box_: new goog.math.Box(4, 9, 7, 6)},
{box_: new goog.math.Box(9, 9, 10, 1)}
];
var targets2 = [
{box_: new goog.math.Box(10, 50, 20, 10)},
{box_: new goog.math.Box(20, 50, 30, 10)},
{box_: new goog.math.Box(60, 50, 70, 10)},
{box_: new goog.math.Box(70, 50, 80, 10)}
];
var targets3 = [
{box_: new goog.math.Box(0, 4, 1, 1)}, {box_: new goog.math.Box(1, 6, 4, 5)},
{box_: new goog.math.Box(5, 5, 6, 2)}, {box_: new goog.math.Box(2, 1, 5, 0)}
];
/**
* Test the utility function which tells how two one dimensional ranges
* overlap.
*/
function testRangeOverlap() {
assertEquals(RangeOverlap.LEFT, rangeOverlap(1, 2, 3, 4));
assertEquals(RangeOverlap.LEFT, rangeOverlap(2, 3, 3, 4));
assertEquals(RangeOverlap.LEFT_IN, rangeOverlap(1, 3, 2, 4));
assertEquals(RangeOverlap.IN, rangeOverlap(1, 3, 1, 4));
assertEquals(RangeOverlap.IN, rangeOverlap(2, 3, 1, 4));
assertEquals(RangeOverlap.IN, rangeOverlap(3, 4, 1, 4));
assertEquals(RangeOverlap.RIGHT_IN, rangeOverlap(2, 4, 1, 3));
assertEquals(RangeOverlap.RIGHT, rangeOverlap(2, 3, 1, 2));
assertEquals(RangeOverlap.RIGHT, rangeOverlap(3, 4, 1, 2));
assertEquals(RangeOverlap.CONTAINS, rangeOverlap(1, 4, 2, 3));
}
/**
* An enum describing how two ranges overlap (non-symmetrical relation).
* @enum {number}
*/
RangeOverlap = {
LEFT: 1, // First range is placed to the left of the second.
LEFT_IN: 2, // First range overlaps on the left side of the second.
IN: 3, // First range is completely contained in the second.
RIGHT_IN: 4, // First range overlaps on the right side of the second.
RIGHT: 5, // First range is placed to the right side of the second.
CONTAINS: 6 // First range contains the second.
};
/**
* Computes how two one dimensional ranges overlap.
*
* @param {number} left1 Left inclusive bound of the first range.
* @param {number} right1 Right exclusive bound of the first range.
* @param {number} left2 Left inclusive bound of the second range.
* @param {number} right2 Right exclusive bound of the second range.
* @return {RangeOverlap} The enum value describing the type of the overlap.
*/
function rangeOverlap(left1, right1, left2, right2) {
if (right1 <= left2) return RangeOverlap.LEFT;
if (left1 >= right2) return RangeOverlap.RIGHT;
var leftIn = left1 >= left2;
var rightIn = right1 <= right2;
if (leftIn && rightIn) return RangeOverlap.IN;
if (leftIn) return RangeOverlap.RIGHT_IN;
if (rightIn) return RangeOverlap.LEFT_IN;
return RangeOverlap.CONTAINS;
}
/**
* Tells whether two boxes overlap.
*
* @param {goog.math.Box} box1 First box in question.
* @param {goog.math.Box} box2 Second box in question.
* @return {boolean} Whether boxes overlap in any way.
*/
function boxOverlaps(box1, box2) {
var horizontalOverlap =
rangeOverlap(box1.left, box1.right, box2.left, box2.right);
var verticalOverlap =
rangeOverlap(box1.top, box1.bottom, box2.top, box2.bottom);
return horizontalOverlap != RangeOverlap.LEFT &&
horizontalOverlap != RangeOverlap.RIGHT &&
verticalOverlap != RangeOverlap.LEFT &&
verticalOverlap != RangeOverlap.RIGHT;
}
/**
* Tests if the utility function to compute box overlapping functions properly.
*/
function testBoxOverlaps() {
// Overlapping tests.
var box2 = new goog.math.Box(1, 4, 4, 1);
// Corner overlaps.
assertTrue('NW overlap', boxOverlaps(new goog.math.Box(0, 2, 2, 0), box2));
assertTrue('NE overlap', boxOverlaps(new goog.math.Box(0, 5, 2, 3), box2));
assertTrue('SE overlap', boxOverlaps(new goog.math.Box(3, 5, 5, 3), box2));
assertTrue('SW overlap', boxOverlaps(new goog.math.Box(3, 2, 5, 0), box2));
// Inside.
assertTrue(
'Inside overlap', boxOverlaps(new goog.math.Box(2, 3, 3, 2), box2));
// Around.
assertTrue(
'Outside overlap', boxOverlaps(new goog.math.Box(0, 5, 5, 0), box2));
// Edge overlaps.
assertTrue('N overlap', boxOverlaps(new goog.math.Box(0, 3, 2, 2), box2));
assertTrue('E overlap', boxOverlaps(new goog.math.Box(2, 5, 3, 3), box2));
assertTrue('S overlap', boxOverlaps(new goog.math.Box(3, 3, 5, 2), box2));
assertTrue('W overlap', boxOverlaps(new goog.math.Box(2, 2, 3, 0), box2));
assertTrue('N-in overlap', boxOverlaps(new goog.math.Box(0, 5, 2, 0), box2));
assertTrue('E-in overlap', boxOverlaps(new goog.math.Box(0, 5, 5, 3), box2));
assertTrue('S-in overlap', boxOverlaps(new goog.math.Box(3, 5, 5, 0), box2));
assertTrue('W-in overlap', boxOverlaps(new goog.math.Box(0, 2, 5, 0), box2));
// Does not overlap.
var box2 = new goog.math.Box(3, 6, 6, 3);
// Along the edge - shorter.
assertFalse(
'N-in no overlap', boxOverlaps(new goog.math.Box(1, 5, 2, 4), box2));
assertFalse(
'E-in no overlap', boxOverlaps(new goog.math.Box(4, 8, 5, 7), box2));
assertFalse(
'S-in no overlap', boxOverlaps(new goog.math.Box(7, 5, 8, 4), box2));
assertFalse(
'N-in no overlap', boxOverlaps(new goog.math.Box(4, 2, 5, 1), box2));
// By the corner.
assertFalse(
'NE no overlap', boxOverlaps(new goog.math.Box(1, 8, 2, 7), box2));
assertFalse(
'SE no overlap', boxOverlaps(new goog.math.Box(7, 8, 8, 7), box2));
assertFalse(
'SW no overlap', boxOverlaps(new goog.math.Box(7, 2, 8, 1), box2));
assertFalse(
'NW no overlap', boxOverlaps(new goog.math.Box(1, 2, 2, 1), box2));
// Perpendicular to an edge.
assertFalse(
'NNE no overlap', boxOverlaps(new goog.math.Box(1, 7, 2, 5), box2));
assertFalse(
'NEE no overlap', boxOverlaps(new goog.math.Box(2, 8, 4, 7), box2));
assertFalse(
'SEE no overlap', boxOverlaps(new goog.math.Box(5, 8, 7, 7), box2));
assertFalse(
'SSE no overlap', boxOverlaps(new goog.math.Box(7, 7, 8, 5), box2));
assertFalse(
'SSW no overlap', boxOverlaps(new goog.math.Box(7, 4, 8, 2), box2));
assertFalse(
'SWW no overlap', boxOverlaps(new goog.math.Box(5, 2, 7, 1), box2));
assertFalse(
'NWW no overlap', boxOverlaps(new goog.math.Box(2, 2, 4, 1), box2));
assertFalse(
'NNW no overlap', boxOverlaps(new goog.math.Box(1, 4, 2, 2), box2));
// Along the edge - longer.
assertFalse('N no overlap', boxOverlaps(new goog.math.Box(0, 7, 1, 2), box2));
assertFalse('E no overlap', boxOverlaps(new goog.math.Box(2, 9, 7, 8), box2));
assertFalse('S no overlap', boxOverlaps(new goog.math.Box(8, 7, 9, 2), box2));
assertFalse('W no overlap', boxOverlaps(new goog.math.Box(2, 1, 7, 0), box2));
}
/**
* Checks whether a given box overlaps any of given DnD target boxes.
*
* @param {goog.math.Box} box The box to check.
* @param {Array