Skip to content

Commit e3d8ce8

Browse files
committed
Use more resiliant shadowroot checking
Also avoid cases where shadowRoot.elementFromPoint returns null Fixes #1574 [0.9] Gesture event throws exception when dragged outside document
1 parent a43eb0f commit e3d8ce8

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/standard/gestures.html

+11-11
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,18 @@
9797
return ta;
9898
}
9999

100-
function deepTargetFind(x, y) {
101-
var node = document.elementFromPoint(x, y);
102-
// this code path is only taken when native ShadowDOM is used
103-
var next = node.shadowRoot;
104-
while(next) {
105-
next = next.elementFromPoint(x, y);
106-
if (next) {
107-
node = next;
108-
next = next.shadowRoot;
109-
}
100+
function deepTargetFind(x, y, root) {
101+
root = root || document;
102+
var node = root.elementFromPoint(x, y);
103+
var sr;
104+
if (node) {
105+
sr = node.shadowRoot;
110106
}
111-
return node;
107+
// if there is not a shadowroot, we are done
108+
// if there is a shadowroot, it may have a node at x/y
109+
// if there is a node at x/y in the shadowroot, return it
110+
// otherwise, return this node
111+
return sr ? (deepTargetFind(x, y, sr) || node) : node;
112112
}
113113

114114
var Gestures = {

0 commit comments

Comments
 (0)