Permalink
Browse files
Always trigger tap for synthetic click events
- Loading branch information...
Showing
with
30 additions
and 1 deletion.
-
+20
−1
src/standard/gestures.html
-
+10
−0
test/unit/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', {
|
|
|
|
|
|
@@ -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