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

Commit

Permalink
Make buttons follow DOM3 spec
Browse files Browse the repository at this point in the history
Related #62 tap doesn't work in Firefox and IE11
  • Loading branch information
dfreedm committed Sep 26, 2014
1 parent 39d8ed9 commit 82a3b23
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/mouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

var WHICH_TO_BUTTONS = [0, 1, 4, 2];

var CURRENT_BUTTONS = 0;
var HAS_BUTTONS = false;
try {
HAS_BUTTONS = new MouseEvent('test', {buttons: 1}).buttons === 1;
Expand Down Expand Up @@ -62,8 +63,12 @@
e.isPrimary = true;
e.pointerType = this.POINTER_TYPE;
e._source = 'mouse';
if (!HAS_BUTTONS || (inEvent.type === 'mouseup' && inEvent.buttons === 0)) {
e.buttons = WHICH_TO_BUTTONS[e.which] || 0;
if (!HAS_BUTTONS) {
var type = inEvent.type;
if (type !== 'mousemove') {
CURRENT_BUTTONS ^= (WHICH_TO_BUTTONS[e.which] || 0);
}
e.buttons = CURRENT_BUTTONS;
}
return e;
},
Expand Down
2 changes: 1 addition & 1 deletion src/tap.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
shouldTap: function(e, downState) {
if (e.pointerType === 'mouse') {
// only allow left click to tap for mouse
return e.buttons === 1 && downState.buttons === 1;
return (e.buttons ^ 1) && (downState.buttons & 1);
}
return !e.tapPrevented;
},
Expand Down
2 changes: 1 addition & 1 deletion test/js/fake.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
cancelable: true,
clientX: x,
clientY: y,
buttons: 1,
buttons: type === 'up' ? 0 : 1,
pointerId: 1,
isPrimary: true,
pointerType: 'mouse'
Expand Down
2 changes: 1 addition & 1 deletion test/js/gestures.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ suite('Platform Events', function() {
function test(ev) {
PolymerGestures.removeEventListener(document, 'up', test);
assert.isTrue(ev.isPrimary);
assert.propertyVal(ev, 'buttons', 1);
assert.propertyVal(ev, 'buttons', 0);
assert.propertyVal(ev, 'pointerId', 1);
assert.property(ev, '_source');
assert.property(ev, 'x');
Expand Down

0 comments on commit 82a3b23

Please sign in to comment.