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

Commit

Permalink
Dispatcher: Handle nested pointerenter/leave
Browse files Browse the repository at this point in the history
Fixes gh-197
Closes gh-274
  • Loading branch information
bethge committed Apr 21, 2016
1 parent 3d1060f commit f075fb7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
23 changes: 17 additions & 6 deletions src/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,11 @@ var dispatcher = {
},
leaveOut: function(event) {
this.out(event);
if (!this.contains(event.target, event.relatedTarget)) {
this.leave(event);
}
this.propagate(event, this.leave, false);
},
enterOver: function(event) {
this.over(event);
if (!this.contains(event.target, event.relatedTarget)) {
this.enter(event);
}
this.propagate(event, this.enter, true);
},

// LISTENER LOGIC
Expand Down Expand Up @@ -314,6 +310,21 @@ var dispatcher = {
return capture;
}
},
propagate: function(event, fn, propagateDown) {
var target = event.target;
var targets = [];
while (!target.contains(event.relatedTarget) && target !== document) {
targets.push(target);
target = target.parentNode;
}
if (propagateDown) {
targets.reverse();
}
targets.forEach(function(target) {
event.target = target;
fn.call(this, event);
}, this);
},
setCapture: function(inPointerId, inTarget) {
if (this.captureInfo[inPointerId]) {
this.releaseCapture(inPointerId);
Expand Down
9 changes: 3 additions & 6 deletions src/touch.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@ var touchEvents = {
out: inPointer,
outTarget: inPointer.target
});
dispatcher.over(inPointer);
dispatcher.enter(inPointer);
dispatcher.enterOver(inPointer);
dispatcher.down(inPointer);
},
touchmove: function(inEvent) {
Expand Down Expand Up @@ -318,8 +317,7 @@ var touchEvents = {
upOut: function(inPointer) {
if (!this.scrolling) {
dispatcher.up(inPointer);
dispatcher.out(inPointer);
dispatcher.leave(inPointer);
dispatcher.leaveOut(inPointer);
}
this.cleanUpPointer(inPointer);
},
Expand All @@ -328,8 +326,7 @@ var touchEvents = {
},
cancelOut: function(inPointer) {
dispatcher.cancel(inPointer);
dispatcher.out(inPointer);
dispatcher.leave(inPointer);
dispatcher.leaveOut(inPointer);
this.cleanUpPointer(inPointer);
},
cleanUpPointer: function(inPointer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ define(function(require) {
main: function() {
return w3cTest(this.remote, name + '.html')
.findById('target0')
.moveMouseTo(50, 8)
.moveMouseTo(200, 10)
.end()
.findByTagName('body')
.moveMouseTo(50, 30)
.findByCssSelector('#target0 div')
.moveMouseTo(200, 10)
.moveMouseTo(200, 150)
.end()
.checkResults();
}
Expand Down

0 comments on commit f075fb7

Please sign in to comment.