Skip to content

Commit

Permalink
Use document-wide passive touch listener to update ghostclick blocker…
Browse files Browse the repository at this point in the history
… target

Fixes #4128
  • Loading branch information
dfreedm committed Nov 4, 2016
1 parent 1a9c5c8 commit 947172f
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/standard/gestures.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
}
})();

// check for passive event listeners
var SUPPORTS_PASSIVE = (function() {
var sp = false;
try {
var opts = Object.defineProperty({}, 'passive', {get: function() {sp = true;}})
window.addEventListener('test', null, opts);
window.removeEventListener('test', null, opts);
return sp;
} catch(e) {}
})();

// Check for touch-only devices
var IS_TOUCH_ONLY = navigator.userAgent.match(/iP(?:[oa]d|hone)|Android/);

Expand Down Expand Up @@ -82,7 +93,7 @@
}
}

function ignoreMouse() {
function ignoreMouse(ev) {
if (!POINTERSTATE.mouse.mouseIgnoreJob) {
setupTeardownMouseCanceller(true);
}
Expand All @@ -91,6 +102,7 @@
POINTERSTATE.mouse.target = null;
POINTERSTATE.mouse.mouseIgnoreJob = null;
};
POINTERSTATE.mouse.target = Polymer.dom(ev).rootTarget;
POINTERSTATE.mouse.mouseIgnoreJob =
Polymer.Debounce(POINTERSTATE.mouse.mouseIgnoreJob, unset, MOUSE_TIMEOUT);
}
Expand Down Expand Up @@ -178,6 +190,10 @@
stateObj.upfn = null;
}

if (HAS_NATIVE_TA) {
document.addEventListener('touchend', ignoreMouse, SUPPORTS_PASSIVE ? {passive: true} : false);
}

var Gestures = {
gestures: {},
recognizers: [],
Expand Down Expand Up @@ -234,14 +250,11 @@
if (!HAS_NATIVE_TA) {
if (type === 'touchstart' || type === 'touchmove') {
Gestures.handleTouchAction(ev);
} else if (type === 'touchend') {
// ignore syntethic mouse events after a touch
ignoreMouse(ev);
}
}
// disable synth mouse events, unless this event is itself simulated
if (type === 'touchend') {
POINTERSTATE.mouse.target = Polymer.dom(ev).rootTarget;
// ignore syntethic mouse events after a touch
ignoreMouse();
}
}
}
handled = ev[HANDLED_OBJ];
Expand Down

0 comments on commit 947172f

Please sign in to comment.