Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* function for finding the absolute bounds of a node (both inline and block) */ | 1 /* function for finding the absolute bounds of a node (both inline and block) */ |
| 2 function findAbsoluteBounds(node) | 2 function findAbsoluteBounds(node) |
| 3 { | 3 { |
| 4 var bounds = node.getBoundingClientRect(); | 4 var bounds = node.getBoundingClientRect(); |
| 5 return { | 5 return { |
| 6 left: bounds.left, | 6 left: bounds.left, |
| 7 top: bounds.top, | 7 top: bounds.top, |
| 8 width: bounds.right - bounds.left, | 8 width: bounds.right - bounds.left, |
| 9 height: bounds.bottom - bounds.top | 9 height: bounds.bottom - bounds.top |
| 10 }; | 10 }; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 function shouldBeWithin(adjustedPoint, targetArea) { | 56 function shouldBeWithin(adjustedPoint, targetArea) { |
| 57 if (adjustedPoint.x >= targetArea.left && adjustedPoint.y >= targetArea.top | 57 if (adjustedPoint.x >= targetArea.left && adjustedPoint.y >= targetArea.top |
| 58 && adjustedPoint.x <= (targetArea.left + targetArea.width) | 58 && adjustedPoint.x <= (targetArea.left + targetArea.width) |
| 59 && adjustedPoint.y <= (targetArea.top + targetArea.height)) { | 59 && adjustedPoint.y <= (targetArea.top + targetArea.height)) { |
| 60 testPassed("adjusted point was within " + boundsToString(targetArea)); | 60 testPassed("adjusted point was within " + boundsToString(targetArea)); |
| 61 } else { | 61 } else { |
| 62 testFailed("adjusted node should be within " + boundsToString(targetArea ) + ". Was " + pointToString(adjustedPoint)); | 62 testFailed("adjusted node should be within " + boundsToString(targetArea ) + ". Was " + pointToString(adjustedPoint)); |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 function testTouchPoint(touchpoint, targetNode, allowTextNodes) | 66 function shadowHost(node) |
| 67 { | 67 { |
| 68 var adjustedNode = internals.touchNodeAdjustedToBestClickableNode(touchpoint .left, touchpoint.top, touchpoint.width, touchpoint.height, document); | 68 while (node != null) { |
| 69 // Not exactly the best method of detecting shadow root as other things can have a document fragment too. | |
|
Rick Byers
2014/07/10 20:09:10
You could just look for the presence of the 'host'
Zeeshan Qureshi
2014/07/10 20:46:16
Done.
| |
| 70 if (node.nodeType == 11) | |
| 71 return node.host; | |
| 72 node = node.parentNode; | |
| 73 } | |
| 74 return node; | |
| 75 } | |
| 76 | |
| 77 function touchNodeAdjustedToBestClickableNode(left, top, width, height, doc, dis allowShadowDOM) | |
|
Rick Byers
2014/07/10 20:09:10
nit: rather than add this new function, might as w
Zeeshan Qureshi
2014/07/10 20:46:16
The only reason to keep that was because nested-sh
| |
| 78 { | |
| 79 var adjustedNode = internals.touchNodeAdjustedToBestClickableNode(left, top, width, height, doc); | |
| 80 if (disallowShadowDOM && adjustedNode && adjustedNode.nodeType == 1) { | |
| 81 while (shadowHost(adjustedNode)) | |
| 82 adjustedNode = shadowHost(adjustedNode); | |
| 83 } | |
| 84 return adjustedNode; | |
| 85 } | |
| 86 | |
| 87 function testTouchPoint(touchpoint, targetNode, allowTextNodes, disallowShadowDO M) | |
| 88 { | |
| 89 var adjustedNode = touchNodeAdjustedToBestClickableNode(touchpoint.left, tou chpoint.top, touchpoint.width, touchpoint.height, document, disallowShadowDOM); | |
| 69 if (!allowTextNodes && adjustedNode && adjustedNode.nodeType == 3) | 90 if (!allowTextNodes && adjustedNode && adjustedNode.nodeType == 3) |
| 70 adjustedNode = adjustedNode.parentNode; | 91 adjustedNode = adjustedNode.parentNode; |
| 71 shouldBeNode(adjustedNode, targetNode); | 92 shouldBeNode(adjustedNode, targetNode); |
| 72 } | 93 } |
| 73 | 94 |
| 74 function testTouchPointContextMenu(touchpoint, targetNode, allowTextNodes) | 95 function testTouchPointContextMenu(touchpoint, targetNode, allowTextNodes) |
| 75 { | 96 { |
| 76 var adjustedNode = internals.touchNodeAdjustedToBestContextMenuNode(touchpoi nt.left, touchpoint.top, touchpoint.width, touchpoint.height, document); | 97 var adjustedNode = internals.touchNodeAdjustedToBestContextMenuNode(touchpoi nt.left, touchpoint.top, touchpoint.width, touchpoint.height, document); |
| 77 if (!allowTextNodes && adjustedNode && adjustedNode.nodeType == 3) | 98 if (!allowTextNodes && adjustedNode && adjustedNode.nodeType == 3) |
| 78 adjustedNode = adjustedNode.parentNode; | 99 adjustedNode = adjustedNode.parentNode; |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 touchpoint.left += bounds.width / 2; | 169 touchpoint.left += bounds.width / 2; |
| 149 touchpoint.top -= touchOffset; | 170 touchpoint.top -= touchOffset; |
| 150 break; | 171 break; |
| 151 case 'bottom': | 172 case 'bottom': |
| 152 touchpoint.left += bounds.width / 2; | 173 touchpoint.left += bounds.width / 2; |
| 153 touchpoint.top += bounds.height + touchOffset; | 174 touchpoint.top += bounds.height + touchOffset; |
| 154 } | 175 } |
| 155 | 176 |
| 156 return touchpoint; | 177 return touchpoint; |
| 157 } | 178 } |
| OLD | NEW |