Skip to content
Browse files

Always trigger tap for synthetic click events

Fixes #2212
  • Loading branch information...
1 parent eafa3e5 commit 1eef1a78cd101e0ae103fae861272b956de3c88c @azakus azakus committed
Showing with 30 additions and 1 deletion.
  1. +20 −1 src/standard/gestures.html
  2. +10 −0 test/unit/gestures.html
View
21 src/standard/gestures.html
@@ -111,6 +111,25 @@
}
}
+ function isSyntheticClick(ev) {
+ if (ev.type === 'click') {
+ // ev.detail is 0 for HTMLElement.click in most browsers
+ if (ev.detail === 0) {
+ return true;
+ }
+ // in the worst case, check that the x/y position of the click is within
+ // the bounding box of the target of the event
+ // Thanks IE 10 >:(
+ var t = Gestures.findOriginalTarget(ev);
+ var bcr = t.getBoundingClientRect();
+ // use page x/y to account for scrolling
+ var x = ev.pageX, y = ev.pageY;
+ return (x >= bcr.left && x <= bcr.right) &&
+ (y >= bcr.top && y <= bcr.bottom);
+ }
+ return false;
+ }
+
var POINTERSTATE = {
mouse: {
target: null,
@@ -624,7 +643,7 @@
var dy = Math.abs(e.clientY - this.info.y);
var t = Gestures.findOriginalTarget(e);
// dx,dy can be NaN if `click` has been simulated and there was no `down` for `start`
- if (isNaN(dx) || isNaN(dy) || (dx <= TAP_DISTANCE && dy <= TAP_DISTANCE)) {
+ if (isNaN(dx) || isNaN(dy) || (dx <= TAP_DISTANCE && dy <= TAP_DISTANCE) || isSyntheticClick(e)) {
// prevent taps from being generated if an event has canceled them
if (!this.info.prevent) {
Gestures.fire(t, 'tap', {
View
10 test/unit/gestures.html
@@ -53,6 +53,16 @@
assert.equal(foo._testRootTarget, div, 'foo root target');
});
+ test('HTMLElement.click triggers tap', function() {
+ // make a mousedown *very* far away to tickle the distance check
+ var ev = new CustomEvent('mousedown');
+ ev.clientX = 1e8;
+ ev.clientY = 1e8;
+ app.dispatchEvent(ev);
+ app.click();
+ assert.equal(app._testLocalTarget, app, 'app local target');
+ assert.equal(app._testRootTarget, app, 'app root target');
+ });
});
suite('Event Setup and Teardown', function() {

0 comments on commit 1eef1a7

Please sign in to comment.
Something went wrong with that request. Please try again.