1 /* function for finding the absolute bounds of a node (both inline and block) */
2 function findAbsoluteBounds(node)
4 var bounds = node.getBoundingClientRect();
8 width: bounds.right - bounds.left,
9 height: bounds.bottom - bounds.top
13 function nodeToString(node)
15 if (node === undefined)
21 if (node.nodeType == 3)
22 return "'"+node.nodeValue+"'";
23 return node.nodeName + (node.id ? ('#' + node.id) : '');
26 function boundsToString(bounds)
28 return "("+bounds.left+","+bounds.top+")x("+bounds.width+","+bounds.height+")";
31 function pointToString(point)
33 return "("+point.x+","+point.y+")";
37 function shouldBeNode(adjustedNode, targetNode) {
38 if (typeof targetNode == "string") {
39 var adjustedNodeString = nodeToString(adjustedNode);
40 if (targetNode == adjustedNodeString) {
41 testPassed("adjusted node was " + targetNode + ".");
44 testFailed("adjusted node should be " + targetNode + ". Was " + adjustedNodeString + ".");
48 if (targetNode == adjustedNode) {
49 testPassed("adjusted node was " + nodeToString(targetNode) + ".");
52 testFailed("adjusted node should be " + nodeToString(targetNode) + ". Was " + nodeToString(adjustedNode) + ".");
56 function shouldBeWithin(adjustedPoint, targetArea) {
57 if (adjustedPoint.x >= targetArea.left && adjustedPoint.y >= targetArea.top
58 && adjustedPoint.x <= (targetArea.left + targetArea.width)
59 && adjustedPoint.y <= (targetArea.top + targetArea.height)) {
60 testPassed("adjusted point was within " + boundsToString(targetArea));
62 testFailed("adjusted node should be within " + boundsToString(targetArea) + ". Was " + pointToString(adjustedPoint));
66 function shadowHost(node)
68 for (; node != null; node = node.parentNode) {
75 function testTouchPoint(touchpoint, targetNode, allowTextNodes, disallowShadowDOM)
77 var adjustedNode = internals.touchNodeAdjustedToBestClickableNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document);
78 if (!allowTextNodes && adjustedNode && adjustedNode.nodeType == 3)
79 adjustedNode = adjustedNode.parentNode;
80 if (disallowShadowDOM && adjustedNode && adjustedNode.nodeType == 1) {
81 while (shadowHost(adjustedNode))
82 adjustedNode = shadowHost(adjustedNode);
84 shouldBeNode(adjustedNode, targetNode);
87 function testTouchPointContextMenu(touchpoint, targetNode, allowTextNodes)
89 var adjustedNode = internals.touchNodeAdjustedToBestContextMenuNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document);
90 if (!allowTextNodes && adjustedNode && adjustedNode.nodeType == 3)
91 adjustedNode = adjustedNode.parentNode;
92 shouldBeNode(adjustedNode, targetNode);
95 function adjustTouchPoint(touchpoint)
97 var adjustedPoint = internals.touchPositionAdjustedToBestClickableNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document);
101 function adjustTouchPointContextMenu(touchpoint)
103 var adjustedPoint = internals.touchPositionAdjustedToBestContextMenuNode(touchpoint.left, touchpoint.top, touchpoint.width, touchpoint.height, document);
104 return adjustedPoint;
107 function touchPoint(x, y, radiusX, radiusY)
117 get x() { return this.left + this.width/2; },
118 get y() { return this.top + this.height/2; }
122 function offsetTouchPoint(bounds, relativePosition, touchOffset, touchRadiusX, touchRadiusY)
125 touchRadiusY = touchRadiusX;
127 // Start with the center of the touch at the top-left of the bounds.
128 var touchpoint = touchPoint(bounds.left, bounds.top, touchRadiusX, touchRadiusY);
130 // Adjust the touch point as requested.
131 switch (relativePosition) {
133 touchpoint.left += bounds.width / 2;
134 touchpoint.top += bounds.height / 2;
137 touchpoint.left -= touchOffset;
138 touchpoint.top += bounds.height / 2;
141 touchpoint.left += bounds.width + touchOffset;
142 touchpoint.top += bounds.height / 2;
145 touchpoint.left -= touchOffset;
146 touchpoint.top -= touchOffset;
149 touchpoint.left += bounds.width + touchOffset;
150 touchpoint.top -= touchOffset;
153 touchpoint.left -= touchOffset;
154 touchpoint.top += bounds.height + touchOffset;
157 touchpoint.left += bounds.width + touchOffset;
158 touchpoint.top += bounds.height + touchOffset;
161 touchpoint.left += bounds.width / 2;
162 touchpoint.top -= touchOffset;
165 touchpoint.left += bounds.width / 2;
166 touchpoint.top += bounds.height + touchOffset;