Skip to content

Commit 947172f

Browse files
committed
Use document-wide passive touch listener to update ghostclick blocker target
Fixes #4128
1 parent 1a9c5c8 commit 947172f

1 file changed

Lines changed: 20 additions & 7 deletions

File tree

‎src/standard/gestures.html‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@
3838
}
3939
})();
4040

41+
// check for passive event listeners
42+
var SUPPORTS_PASSIVE = (function() {
43+
var sp = false;
44+
try {
45+
var opts = Object.defineProperty({}, 'passive', {get: function() {sp = true;}})
46+
window.addEventListener('test', null, opts);
47+
window.removeEventListener('test', null, opts);
48+
return sp;
49+
} catch(e) {}
50+
})();
51+
4152
// Check for touch-only devices
4253
var IS_TOUCH_ONLY = navigator.userAgent.match(/iP(?:[oa]d|hone)|Android/);
4354

@@ -82,7 +93,7 @@
8293
}
8394
}
8495

85-
function ignoreMouse() {
96+
function ignoreMouse(ev) {
8697
if (!POINTERSTATE.mouse.mouseIgnoreJob) {
8798
setupTeardownMouseCanceller(true);
8899
}
@@ -91,6 +102,7 @@
91102
POINTERSTATE.mouse.target = null;
92103
POINTERSTATE.mouse.mouseIgnoreJob = null;
93104
};
105+
POINTERSTATE.mouse.target = Polymer.dom(ev).rootTarget;
94106
POINTERSTATE.mouse.mouseIgnoreJob =
95107
Polymer.Debounce(POINTERSTATE.mouse.mouseIgnoreJob, unset, MOUSE_TIMEOUT);
96108
}
@@ -178,6 +190,10 @@
178190
stateObj.upfn = null;
179191
}
180192

193+
if (HAS_NATIVE_TA) {
194+
document.addEventListener('touchend', ignoreMouse, SUPPORTS_PASSIVE ? {passive: true} : false);
195+
}
196+
181197
var Gestures = {
182198
gestures: {},
183199
recognizers: [],
@@ -234,14 +250,11 @@
234250
if (!HAS_NATIVE_TA) {
235251
if (type === 'touchstart' || type === 'touchmove') {
236252
Gestures.handleTouchAction(ev);
253+
} else if (type === 'touchend') {
254+
// ignore syntethic mouse events after a touch
255+
ignoreMouse(ev);
237256
}
238257
}
239-
// disable synth mouse events, unless this event is itself simulated
240-
if (type === 'touchend') {
241-
POINTERSTATE.mouse.target = Polymer.dom(ev).rootTarget;
242-
// ignore syntethic mouse events after a touch
243-
ignoreMouse();
244-
}
245258
}
246259
}
247260
handled = ev[HANDLED_OBJ];

0 commit comments

Comments
 (0)