Skip to content

Commit 1eef1a7

Browse files
committedAug 5, 2015
Always trigger tap for synthetic click events
Fixes #2212
1 parent eafa3e5 commit 1eef1a7

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
 

‎src/standard/gestures.html

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,25 @@
111111
}
112112
}
113113

114+
function isSyntheticClick(ev) {
115+
if (ev.type === 'click') {
116+
// ev.detail is 0 for HTMLElement.click in most browsers
117+
if (ev.detail === 0) {
118+
return true;
119+
}
120+
// in the worst case, check that the x/y position of the click is within
121+
// the bounding box of the target of the event
122+
// Thanks IE 10 >:(
123+
var t = Gestures.findOriginalTarget(ev);
124+
var bcr = t.getBoundingClientRect();
125+
// use page x/y to account for scrolling
126+
var x = ev.pageX, y = ev.pageY;
127+
return (x >= bcr.left && x <= bcr.right) &&
128+
(y >= bcr.top && y <= bcr.bottom);
129+
}
130+
return false;
131+
}
132+
114133
var POINTERSTATE = {
115134
mouse: {
116135
target: null,
@@ -624,7 +643,7 @@
624643
var dy = Math.abs(e.clientY - this.info.y);
625644
var t = Gestures.findOriginalTarget(e);
626645
// dx,dy can be NaN if `click` has been simulated and there was no `down` for `start`
627-
if (isNaN(dx) || isNaN(dy) || (dx <= TAP_DISTANCE && dy <= TAP_DISTANCE)) {
646+
if (isNaN(dx) || isNaN(dy) || (dx <= TAP_DISTANCE && dy <= TAP_DISTANCE) || isSyntheticClick(e)) {
628647
// prevent taps from being generated if an event has canceled them
629648
if (!this.info.prevent) {
630649
Gestures.fire(t, 'tap', {

‎test/unit/gestures.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@
5353
assert.equal(foo._testRootTarget, div, 'foo root target');
5454
});
5555

56+
test('HTMLElement.click triggers tap', function() {
57+
// make a mousedown *very* far away to tickle the distance check
58+
var ev = new CustomEvent('mousedown');
59+
ev.clientX = 1e8;
60+
ev.clientY = 1e8;
61+
app.dispatchEvent(ev);
62+
app.click();
63+
assert.equal(app._testLocalTarget, app, 'app local target');
64+
assert.equal(app._testRootTarget, app, 'app root target');
65+
});
5666
});
5767

5868
suite('Event Setup and Teardown', function() {

0 commit comments

Comments
 (0)
Please sign in to comment.