-
Notifications
You must be signed in to change notification settings - Fork 160
Touch: Use touch-action and passive event listeners if supported #309
Conversation
I looked some more into the relation between I made a little example: http://bethge.github.io/touch-action/wall-scroll.html with passive event listeners:
Iiuc, Chrome always fires Also, |
@RByers Can you comment on the |
You're saying that trying to scroll an element that's already at it's scroll extent will not fire
That is correct. Think of it this way, there are two separate stages: generating a gesture event and that gesture event having an action.
Yes this is correct and it is indeed inconsistent. It boils down to a limitation we have in chromium that effectively means that A TouchEvent is cancelable in chromium unless:
So you can't infer too much about the exact scenario your in from the If I understand your issue correctly, you're just trying to decide when to fire the Computing whether a gesture is allowed by touch-action is non-trivial. To handle all cases (where a developer may have arbitrary complex style rules) you need to implement the touch-action processing model in the spec where you walk up the DOM, getting the computed style and intersecting all the touch-action values. Perhaps something simpler would be good enough though? Also note that while Safari now supports passive touch listeners and the |
As discussed in today's PEP meeting, we'll not further pursue using passive event listeners in combination with touch-action, if the browser supports it. Chrome is getting ever closer to supporting pointer events natively, and no other browser supports or in the near future plans to support passive event listeners as well as touch-action. |
This PR aims at using native
touch-action
and passive event listeners (#278), if the browser supports them.If
touch-action
is supported, we can apply the matchingtouch-action
style to the elements with thetouch-action
attribute. We would also no longer need topreventDefault()
any touch events, since we only had to do it to mimic the behaviour oftouch-action
.Iiuc, with touch-action and passive event listener support we can use the code originally meant for
touch-action-delay
(https://github.com/jquery/PEP/blob/master/src/touch.js#L17-L22). In https://crbug.com/347272touch-action-delay
has been dropped in favour of passive event listeners.With touch-action and passive event listeners supported, the touch event listener can attach to
document
, since performance should no longer be an issue (not yet tested), andinstaller.js
with theMutationObserver
won't be needed anymore. We still need to be able to detect if at any point during a touch gesture some default user agent behaviour takes over (I hope I got this part correct). Once default UA behaviour takes over, we need to fire apointercancel
and ignore subsequenttouchmove
events.To detect default UA behaviour, I check if
touchmove
iscancelable
. If it is cancelable, no default UA behaviour is taking place and apointermove
should fire. If it is not cancelable, some default UA behaviour is taking over (passive event listeners disallow canceling default UA behaviour, settingcancelable
tofalse
).Using native
touch-action
will change some of the behaviour of PEP.E.g. the behaviour of nested elements with different
touch-action
properties will be different. PEP allows an element withtouch-action: auto
to scroll, even if it is a child of an element withtouch-action: none
. Using nativetouch-action
no scrolling would be possible, see: http://bethge.github.io/touch-action/pep-touch-action.htmlAlso, with native touch action support, an element with
touch-action: auto
may still fire pointer events, e.g. if the user "scrolls against the wall".I haven't checked any corner cases at this point. Just want to make sure I got in principle the expected behaviour and whether we are o.k. with different behaviours across browsers.