Skip to content
This repository was archived by the owner on Feb 11, 2021. It is now read-only.

Commit f075fb7

Browse files
committed
Dispatcher: Handle nested pointerenter/leave
Fixes gh-197 Closes gh-274
1 parent 3d1060f commit f075fb7

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

src/dispatcher.js

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,11 @@ var dispatcher = {
197197
},
198198
leaveOut: function(event) {
199199
this.out(event);
200-
if (!this.contains(event.target, event.relatedTarget)) {
201-
this.leave(event);
202-
}
200+
this.propagate(event, this.leave, false);
203201
},
204202
enterOver: function(event) {
205203
this.over(event);
206-
if (!this.contains(event.target, event.relatedTarget)) {
207-
this.enter(event);
208-
}
204+
this.propagate(event, this.enter, true);
209205
},
210206

211207
// LISTENER LOGIC
@@ -314,6 +310,21 @@ var dispatcher = {
314310
return capture;
315311
}
316312
},
313+
propagate: function(event, fn, propagateDown) {
314+
var target = event.target;
315+
var targets = [];
316+
while (!target.contains(event.relatedTarget) && target !== document) {
317+
targets.push(target);
318+
target = target.parentNode;
319+
}
320+
if (propagateDown) {
321+
targets.reverse();
322+
}
323+
targets.forEach(function(target) {
324+
event.target = target;
325+
fn.call(this, event);
326+
}, this);
327+
},
317328
setCapture: function(inPointerId, inTarget) {
318329
if (this.captureInfo[inPointerId]) {
319330
this.releaseCapture(inPointerId);

src/touch.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,7 @@ var touchEvents = {
265265
out: inPointer,
266266
outTarget: inPointer.target
267267
});
268-
dispatcher.over(inPointer);
269-
dispatcher.enter(inPointer);
268+
dispatcher.enterOver(inPointer);
270269
dispatcher.down(inPointer);
271270
},
272271
touchmove: function(inEvent) {
@@ -318,8 +317,7 @@ var touchEvents = {
318317
upOut: function(inPointer) {
319318
if (!this.scrolling) {
320319
dispatcher.up(inPointer);
321-
dispatcher.out(inPointer);
322-
dispatcher.leave(inPointer);
320+
dispatcher.leaveOut(inPointer);
323321
}
324322
this.cleanUpPointer(inPointer);
325323
},
@@ -328,8 +326,7 @@ var touchEvents = {
328326
},
329327
cancelOut: function(inPointer) {
330328
dispatcher.cancel(inPointer);
331-
dispatcher.out(inPointer);
332-
dispatcher.leave(inPointer);
329+
dispatcher.leaveOut(inPointer);
333330
this.cleanUpPointer(inPointer);
334331
},
335332
cleanUpPointer: function(inPointer) {

tests/functional/pointerevent_pointerleave_descendants-manual.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ define(function(require) {
99
main: function() {
1010
return w3cTest(this.remote, name + '.html')
1111
.findById('target0')
12-
.moveMouseTo(50, 8)
12+
.moveMouseTo(200, 10)
1313
.end()
14-
.findByTagName('body')
15-
.moveMouseTo(50, 30)
14+
.findByCssSelector('#target0 div')
15+
.moveMouseTo(200, 10)
16+
.moveMouseTo(200, 150)
1617
.end()
1718
.checkResults();
1819
}

0 commit comments

Comments
 (0)