Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Keep better tally of "buttons" bitmask
Browse files Browse the repository at this point in the history
Fixes #67 track stops working after right-mouse click
  • Loading branch information
dfreedm committed Oct 7, 2014
1 parent 82a3b23 commit 7f69799
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
16 changes: 9 additions & 7 deletions src/dispatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,15 @@
for (var i = 0, e, rg; i < this.gestureQueue.length; i++) {
e = this.gestureQueue[i];
rg = e._requiredGestures;
for (var j = 0, g, fn; j < this.gestures.length; j++) {
// only run recognizer if an element in the source event's path is listening for those gestures
if (rg[j]) {
g = this.gestures[j];
fn = g[e.type];
if (fn) {
fn.call(g, e);
if (rg) {
for (var j = 0, g, fn; j < this.gestures.length; j++) {
// only run recognizer if an element in the source event's path is listening for those gestures
if (rg[j]) {
g = this.gestures[j];
fn = g[e.type];
if (fn) {
fn.call(g, e);
}
}
}
}
Expand Down
27 changes: 15 additions & 12 deletions src/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@
e._source = 'mouse';
if (!HAS_BUTTONS) {
var type = inEvent.type;
if (type !== 'mousemove') {
CURRENT_BUTTONS ^= (WHICH_TO_BUTTONS[e.which] || 0);
var bit = WHICH_TO_BUTTONS[inEvent.which] || 0;
if (type === 'mousedown') {
CURRENT_BUTTONS |= bit;
} else if (type === 'mouseup') {
CURRENT_BUTTONS &= ~bit;
}
e.buttons = CURRENT_BUTTONS;
}
Expand All @@ -75,11 +78,6 @@
mousedown: function(inEvent) {
if (!this.isEventSimulatedFromTouch(inEvent)) {
var p = pointermap.has(this.POINTER_ID);
// TODO(dfreedman) workaround for some elements not sending mouseup
// http://crbug/149091
if (p) {
this.mouseup(inEvent);
}
var e = this.prepareEvent(inEvent);
e.target = scope.findTarget(inEvent);
pointermap.set(this.POINTER_ID, e.target);
Expand All @@ -93,9 +91,12 @@
var e = this.prepareEvent(inEvent);
e.target = target;
// handle case where we missed a mouseup
if (e.buttons === 0) {
if ((HAS_BUTTONS ? e.buttons : e.which) === 0) {
if (!HAS_BUTTONS) {
CURRENT_BUTTONS = e.buttons = 0;
}
dispatcher.cancel(e);
this.cleanupMouse();
this.cleanupMouse(e.buttons);
} else {
dispatcher.move(e);
}
Expand All @@ -108,11 +109,13 @@
e.relatedTarget = scope.findTarget(inEvent);
e.target = pointermap.get(this.POINTER_ID);
dispatcher.up(e);
this.cleanupMouse();
this.cleanupMouse(e.buttons);
}
},
cleanupMouse: function() {
pointermap['delete'](this.POINTER_ID);
cleanupMouse: function(buttons) {
if (buttons === 0) {
pointermap.delete(this.POINTER_ID);
}
}
};

Expand Down
5 changes: 3 additions & 2 deletions src/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@
}
},
shouldTap: function(e, downState) {
var tap = true;
if (e.pointerType === 'mouse') {
// only allow left click to tap for mouse
return (e.buttons ^ 1) && (downState.buttons & 1);
tap = (e.buttons ^ 1) && (downState.buttons & 1);
}
return !e.tapPrevented;
return tap && !e.tapPrevented;
},
up: function(inEvent) {
var start = pointermap.get(inEvent.pointerId);
Expand Down

0 comments on commit 7f69799

Please sign in to comment.