|
38 | 38 | } |
39 | 39 | })(); |
40 | 40 |
|
| 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 | + |
41 | 52 | // Check for touch-only devices |
42 | 53 | var IS_TOUCH_ONLY = navigator.userAgent.match(/iP(?:[oa]d|hone)|Android/); |
43 | 54 |
|
|
82 | 93 | } |
83 | 94 | } |
84 | 95 |
|
85 | | - function ignoreMouse() { |
| 96 | + function ignoreMouse(ev) { |
86 | 97 | if (!POINTERSTATE.mouse.mouseIgnoreJob) { |
87 | 98 | setupTeardownMouseCanceller(true); |
88 | 99 | } |
|
91 | 102 | POINTERSTATE.mouse.target = null; |
92 | 103 | POINTERSTATE.mouse.mouseIgnoreJob = null; |
93 | 104 | }; |
| 105 | + POINTERSTATE.mouse.target = Polymer.dom(ev).rootTarget; |
94 | 106 | POINTERSTATE.mouse.mouseIgnoreJob = |
95 | 107 | Polymer.Debounce(POINTERSTATE.mouse.mouseIgnoreJob, unset, MOUSE_TIMEOUT); |
96 | 108 | } |
|
178 | 190 | stateObj.upfn = null; |
179 | 191 | } |
180 | 192 |
|
| 193 | + if (HAS_NATIVE_TA) { |
| 194 | + document.addEventListener('touchend', ignoreMouse, SUPPORTS_PASSIVE ? {passive: true} : false); |
| 195 | + } |
| 196 | + |
181 | 197 | var Gestures = { |
182 | 198 | gestures: {}, |
183 | 199 | recognizers: [], |
|
234 | 250 | if (!HAS_NATIVE_TA) { |
235 | 251 | if (type === 'touchstart' || type === 'touchmove') { |
236 | 252 | Gestures.handleTouchAction(ev); |
| 253 | + } else if (type === 'touchend') { |
| 254 | + // ignore syntethic mouse events after a touch |
| 255 | + ignoreMouse(ev); |
237 | 256 | } |
238 | 257 | } |
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 | | - } |
245 | 258 | } |
246 | 259 | } |
247 | 260 | handled = ev[HANDLED_OBJ]; |
|
0 commit comments