Bug 133112

Summary: Touch-action css property support
Product: WebKit Reporter: Jorik Tangelder <j.tangelder>
Component: UI EventsAssignee: Antoine Quint <graouts>
Status: RESOLVED CONFIGURATION CHANGED    
Severity: Normal CC: 50167214, andrew, benjamin, contact, dino, eoconnor, froodian, graouts, gtjrossi, huijing, jared, jouni, jrossi, j.tangelder, marco.lazzeri, marsjaninzmarsa, michael.herzog, mjs, orzage, plummer.andrew, rbyers, redux, rich.g.cook, shmdhussain12, simon.fraser, tobi, webkit-bug-importer, webkit, wenson_hsieh
Priority: P2 Keywords: FromImplementor, InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=175869
https://bugs.webkit.org/show_bug.cgi?id=193447
Bug Depends on: 149854    
Bug Blocks:    
Attachments:
Description Flags
Patch dino: review+

Description Jorik Tangelder 2014-05-20 01:54:04 PDT
What about supporting the touch-action property of the pointer events specification? IE, Blink already support this, and Mozilla is busy implementing it.
https://dvcs.w3.org/hg/pointerevents/raw-file/tip/pointerEvents.html#the-touch-action-css-property

Even when pointer events are not implemented, this css property would really improve the support for touch gestures in webpages. Now we're stuck with only calling preventDefault, and often makes elements blocking the scrolling of a page when not needed...

(copied from https://bugs.webkit.org/show_bug.cgi?id=105463#c35)
Comment 1 Patrick H. Lauke 2014-05-20 02:53:32 PDT
hah, seems Jorik beat me to it. feel free to de-dup between this and https://bugs.webkit.org/show_bug.cgi?id=133114
Comment 2 Rick Byers 2014-05-20 07:21:05 PDT
FYI there are several reasons we decided to add touch-action to blink.  Eg. from https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/sc5lHnlcLvM/ntJWuKKHUqYJ: 

 1. Provides precise control over the dreaded 300ms click delay on mobile
 2. Reliably enables side-swipe UIs (frees libraries from having to predict when exactly scrolling may start on different browsers)
 3. Enables high-fidelity polyfills of pointer events (eg. as in Polymer)
 4. Provides a declarative signal to blink (and potentially the compositor) about the developers intent wrt. touch input - eg. providing a potential solution the touchstart ACK timeout problem
 5. Reducing confusion around the highly-overloaded response to preventDefault on touch events
 6. A prerequisite for future optimizations to enable scrolling and zooming that never block on the main thread

It's #5 that seems to resonate most with typical web developers.  In particular I continue to see developers struggle with implementing side-swipe UIs (#2), and I believe mobile safari requires them to reverse-engineer a magic distance threshold number (which then imposes a compat burden on the web no to change that magic value).
Comment 3 Benjamin Poulain 2014-05-20 09:59:24 PDT
*** Bug 133114 has been marked as a duplicate of this bug. ***
Comment 4 Patrick H. Lauke 2014-05-20 10:28:42 PDT
Adding this from https://bugs.webkit.org/show_bug.cgi?id=133114 here:

Although there seems to be no immediate desire to implement the full Pointer Events specification (see https://bugs.webkit.org/show_bug.cgi?id=105463), it may be worth considering at least supporting the touch-action:manipulation CSS property/value. 
This recent addition (the "manipulation" value) to the Pointer Events specification is used - in essence - to allow developers to suppress the classic 300ms delay present on touchscreen devices that by default allows for "double-tap to zoom", while retaining other abilities such as scrolling and pinch-to-zoom. It offers a compromise to the often drastic preventDefault() commonly used in touch-optimised applications (which does remove the 300ms delay, but also kills any other default interactions).

touch-action:manipulation is on track to be rolled out in both Firefox and Chrome - see

"Bug 979345 - Implement "touch-action: manipulation" CSS value for Pointer Events" https://bugzilla.mozilla.org/show_bug.cgi?id=979345
"Issue 349016:    Add support for touch-action: manipulation" https://code.google.com/p/chromium/issues/detail?id=349016
Comment 5 Benjamin Poulain 2014-05-20 13:20:21 PDT
Some context: I do not have time to experiment with touch-action at the moment. If someone is interested in contributing patches to WebKit, I would be happy to provide guidance and reviews.

Rick: some questions about the spec:
-At the moment, pan-x and pan-y are pretty much useless for every use case we have. We would need the touch action to have the direction, eg. pan-positive-y/pan-negative-y or pan-y-downard/pan-y-upward. Is there anything like that in the work?
-Is it specified in what coordinates system are the x/y for pan-x/pan-y? Is it in the block coordinates? Its containing block? The whole frame? The main frame?

Patrick: touch-action:manipulation is basically just as bad as preventDefault() for the click delay. Touch events have raw position, mouse/click events are adjusted based on the device DPI, scale factor, finger surface, etc. For tap/click, the right thing to expose is the adjusted value, not the raw touch. The problem is touch-action:manipulation defines touch behavior, not synthetic events.
The synthetic mouse events are superior to touch events for tap/click. I still welcome a real proposal to that issue (IIRC, you had opened a bug for that?).
Comment 6 Patrick H. Lauke 2014-05-20 13:43:13 PDT
"Patrick: touch-action:manipulation is basically just as bad as preventDefault() for the click delay. Touch events have raw position, mouse/click events are adjusted based on the device DPI, scale factor, finger surface, etc. For tap/click, the right thing to expose is the adjusted value, not the raw touch. The problem is touch-action:manipulation defines touch behavior, not synthetic events."

Unless I'm missing something, all that touch-action:manipulation in the context of touch events would do (and I believe that's what Chrome and Mozilla are implementing/have implemented so far) is a rather fancy way of saying "don't wait 300ms for the second tap of a double-tap action". Nothing about affecting raw vs adjusted position values as far as I know.
Comment 7 Patrick H. Lauke 2014-05-20 13:51:02 PDT
"The synthetic mouse events are superior to touch events for tap/click. I still welcome a real proposal to that issue (IIRC, you had opened a bug for that?)"

Yes, it's https://bugs.webkit.org/show_bug.cgi?id=122212 (where we got a bit sidetracked by the fantastic hidden feature is iOS that not even power users know about that is double-tap-to-scroll ;) )
Comment 8 Jacob Rossi [MSFT] 2014-05-20 16:50:50 PDT
Just a couple additional thoughts/responses:

Definitely agree that "synthetic" events (esp. click) are far superior for activation behaviors. Other goodness here too like better accessibility.
     * Note that IE11 now uses the PointerEvent interface for click and will even fire it for multi-touch provided you aren't zooming. So we don't really consider it a "synthetic" event in this regard.

Like Patrick says, touch-action doesn't affect whether you a browser alters coordinate accuracy (in fact, such adjustment is out of scope for our working group)

touch-action: manipulation is about restricting touch behaviors to "scrolling and continuous zooming" aka, disabling features like double-tap-to-zoom
     * This in turn enables browsers to optimize out the 300ms delay for synthetic events like click, but isn't technically a required feature of the API

pan-x/pan-y work well for many common "native" experiences like carousel photo galleries, swiping pagination, etc.
     * The working group has discussed additional values like pan-positive-y/pan-negative-y. It's not in the spec or implementations, but we'd love to have you participate in the WG discussion and discuss use cases we should be solving. I'm thinking we'll tackle this in Pointer Events V2, which is on the near horizon.
Comment 9 Benjamin Poulain 2014-05-20 17:17:09 PDT
(In reply to comment #8)
> Just a couple additional thoughts/responses:

Thanks for participating.

> touch-action: manipulation is about restricting touch behaviors to "scrolling and continuous zooming" aka, disabling features like double-tap-to-zoom
>      * This in turn enables browsers to optimize out the 300ms delay for synthetic events like click, but isn't technically a required feature of the API

I disagree, but that's a completely different problem. Please have a look at https://bugs.webkit.org/show_bug.cgi?id=133112.

> pan-x/pan-y work well for many common "native" experiences like carousel photo galleries, swiping pagination, etc.
>      * The working group has discussed additional values like pan-positive-y/pan-negative-y. It's not in the spec or implementations, but we'd love to have you participate in the WG discussion and discuss use cases we should be solving. I'm thinking we'll tackle this in Pointer Events V2, which is on the near horizon.

On OS X or iOS, we fully support scrollview-inside-scrollview.
Comment 10 Jacob Rossi [MSFT] 2014-05-20 18:29:24 PDT
>> pan-x/pan-y work well for many common "native" experiences like carousel photo galleries, swiping pagination, etc.
>>      * The working group has discussed additional values like pan-positive-y/pan-negative-y. It's not in the spec or implementations, but we'd love to have you participate in the WG discussion and discuss use cases we should be solving. I'm thinking we'll tackle this in Pointer Events V2, which is on the near horizon.

>On OS X or iOS, we fully support scrollview-inside-scrollview.

Not sure I follow how that relates to touch-action. IE (and Chrome/Firefox I think) supports this too. Can you explain further?
Comment 11 Benjamin Poulain 2014-05-20 18:50:11 PDT
(In reply to comment #10)
> >> pan-x/pan-y work well for many common "native" experiences like carousel photo galleries, swiping pagination, etc.
> >>      * The working group has discussed additional values like pan-positive-y/pan-negative-y. It's not in the spec or implementations, but we'd love to have you participate in the WG discussion and discuss use cases we should be solving. I'm thinking we'll tackle this in Pointer Events V2, which is on the near horizon.
> 
> >On OS X or iOS, we fully support scrollview-inside-scrollview.
> 
> Not sure I follow how that relates to touch-action. IE (and Chrome/Firefox I think) supports this too. Can you explain further?

Let's say we would want to change all the carousels to touchAction instead of gesture recognition from touch events.

Let's say the carousel start in the middle.
-In that first state, only pan-y is enabled, pan-x is handled through the touch events.
-You pan to the right edge.
-You rubberband or stop at the edge, but either way, the last position is maxX.
-Now we have two cases:
    -If you continue panning to the right, the superview should take the gesture and track it from there.
    -If you start panning in the other direction, then view takes the touch events and tracks the input.

If you can specify the direction, you change change the touch-action based on the internal state of the carousel.
Comment 12 Jacob Rossi [MSFT] 2014-05-21 12:36:53 PDT
Ah, makes sense. When I use "carousel" I usually mean the ones that wrap around like the kids' ride. They're usually moving things from the beginning to the end of the scroller or vice-versa to create the illusion of a full carousel loop. So you never hit this issue and pan-x/pan-y work just fine.

But, not all work this way and I agree the positive/negative values would improve the experience. Though I like a solution like CSS Scroll Snap Points to enable this to be built with native scrolling instead.

"Pull to refresh" was another scenario we had in mind for positive/negative pan values (so you could enable touch events when pulling down at the top of a scroller, to animate the refresh icon or something; but then still have native scrolling for the rest of the scroller).

Though I understand there may be some complicated issues for Apple to work through to join, it'd really be great if we could continue the positive/negative discussion over in the working group (I don't think we really want to design the API here in the webkit bug).
Comment 13 Benjamin Poulain 2014-05-21 14:32:54 PDT
(In reply to comment #12)
> Ah, makes sense. When I use "carousel" I usually mean the ones that wrap around like the kids' ride. They're usually moving things from the beginning to the end of the scroller or vice-versa to create the illusion of a full carousel loop. So you never hit this issue and pan-x/pan-y work just fine.
> 
> But, not all work this way and I agree the positive/negative values would improve the experience. Though I like a solution like CSS Scroll Snap Points to enable this to be built with native scrolling instead.

Snap points is a good idea to investigate regardless.

There will still be cases when people want full control with JavaScript. With iOS, we try to give as much power as possible to the web page. Generic solutions to provide a near native experience for a large variety of use cases are very useful to have. I can see touch-action being useful there.

> "Pull to refresh" was another scenario we had in mind for positive/negative pan values (so you could enable touch events when pulling down at the top of a scroller, to animate the refresh icon or something; but then still have native scrolling for the rest of the scroller).
> 
> Though I understand there may be some complicated issues for Apple to work through to join, it'd really be great if we could continue the positive/negative discussion over in the working group (I don't think we really want to design the API here in the webkit bug).

I really doubt that is gonna happen. I don't think I will have useful comments before prototyping anyway.
Comment 14 Chris Rebert 2015-10-06 16:20:38 PDT
This bug depends on https://bugs.webkit.org/show_bug.cgi?id=149854
Comment 15 yisibl 2015-12-16 04:17:06 PST
Implement touch-action: manipulation; for iOS
https://bugs.webkit.org/show_bug.cgi?id=149854
Comment 16 Jacob Rossi [MSFT] 2015-12-17 15:53:07 PST
This tracks support for the auto and manipulation values: https://bugs.webkit.org/show_bug.cgi?id=149854

Are there plans to implement none as well? 

Besides the performance optimizations this could enable, support for parsing none will help libraries like: https://github.com/jquery/PEP/issues/250
Comment 17 Rick Byers 2017-03-28 07:51:43 PDT
Note: some discussion of the need for more touch-action values (like pan-y) in order to be able to opt-in to passive event listeners: https://github.com/WICG/EventListenerOptions/issues/56
Comment 18 Radar WebKit Bug Importer 2017-03-28 11:32:08 PDT
<rdar://problem/31302639>
Comment 19 Chen Hui Jing 2017-04-06 02:47:34 PDT
What is the status of touch-action on Desktop Safari 10 onwards? According to caniuse.com, auto and manipulation are supported but using feature queries as the test yields a negative result (i.e. none of the touch-action values are supported). Tested on Safari 10.1 and Safari TP 27.
Link to test page: https://www.chenhuijing.com/touch-action
Comment 20 Ben Frain 2017-04-27 02:41:18 PDT
`touch-action: none` would enable a very elegant solution to the diabolical situation of trying to manage pop-ups with scrolling areas on iOS. See: https://benfrain.com/preventing-body-scroll-for-modals-in-ios/ for examples.

The solution outside of iOS/Safari is to use `touch-action: none`; simple and effective. There seems no clean solution to the issue on iOS outside of WebKit implementing `touch-action: none` but I would welcome any evidence to the contrary?
Comment 21 Richard Cook 2017-09-27 07:45:46 PDT
It would appear that pointer-events: none doesn't work in iOS 11.0.0 – anyone else having this issue?
Comment 22 Patrick H. Lauke 2017-09-27 07:49:35 PDT
(In reply to Richard Cook from comment #21)
> It would appear that pointer-events: none doesn't work in iOS 11.0.0 –
> anyone else having this issue?

assuming you mean touch-action:none, that never worked in iOS. touch-action:manipulation does, however. see https://patrickhlauke.github.io/touch/tests/results/#suppressing-300ms-delay
Comment 23 Richard Cook 2017-09-27 07:52:53 PDT
(In reply to Patrick H. Lauke from comment #22)
> (In reply to Richard Cook from comment #21)
> > It would appear that pointer-events: none doesn't work in iOS 11.0.0 –
> > anyone else having this issue?
> 
> assuming you mean touch-action:none, that never worked in iOS.
> touch-action:manipulation does, however. see
> https://patrickhlauke.github.io/touch/tests/results/#suppressing-300ms-delay

I have only just realised this but it worked in iOS 10 to prevent the clicking of an element that was set on a higher z-index but opacity: 0 and pointer-events: none. But in iOS 11... nope.
Comment 24 Patrick H. Lauke 2017-09-27 07:59:44 PDT
(In reply to Richard Cook from comment #23)

> I have only just realised this but it worked in iOS 10 to prevent the
> clicking of an element that was set on a higher z-index but opacity: 0 and
> pointer-events: none. But in iOS 11... nope.

I'd suggest opening a new bug then, as this bug is about touch-action, not pointer-events
Comment 25 Michael Herzog 2018-07-19 14:35:11 PDT
Any updates on this issue? According to "Can I use" (https://caniuse.com/#feat=css-touch-action) Safari still does not support the CSS touch-action property. I'm working on the three.js project and it would be really great for 3D controls development to have this feature available in all major browsers.
Comment 26 Andrew 2018-09-06 15:21:20 PDT
Any plans to add touch-action: none?
Comment 27 Andrew Plummer 2018-11-19 23:13:13 PST
Would love to see this implemented as well...
Comment 28 Mohamed Hussain S H 2019-01-15 23:09:46 PST
touch-action: none,  will prevent the body scrolling when the Modal div is open?

>>> that is when the fixed pos modal div is open, I will set the touch-action: none to the <body> element and will add the touch-action: automatic to the modal <div> in that case i will prevent the touch action on body so that i will stop scrolling the body  when the user comes to the end of the modal window.

Like to have the touch-action:none in IOS Safari.
Comment 29 Mohamed Hussain S H 2019-01-15 23:10:28 PST
(In reply to Mohamed Hussain S H from comment #28)
> touch-action: none,  will prevent the body scrolling when the Modal div is
> open?
> 
> >>> that is when the fixed pos modal div is open, I will set the touch-action: none to the <body> element and will add the touch-action: automatic to the modal <div> in that case i will prevent the touch action on body so that i will stop scrolling the body  when the user comes to the end of the modal window.
> 
> Like to have the touch-action:none in IOS Safari.

Reference : https://benfrain.com/preventing-body-scroll-for-modals-in-ios/
Comment 30 Jouni Koivuviita 2019-01-29 01:40:17 PST
Having some easy method of preventing unwanted scrolling of the body element would be great, when implementing custom modal dialogs/overlays. 

Either this, or then overscroll-behavior would be very much appreciated!
Comment 31 Antoine Quint 2019-02-13 23:53:13 PST
An implementation of touch-action when in r240579 for https://bugs.webkit.org/show_bug.cgi?id=193447. I'll be working on a macOS implementation in the next couple of months as well.
Comment 32 Michael Herzog 2019-02-14 02:41:37 PST
Sounds great! Please notify us when it's possible to test this with build.
Comment 33 Antoine Quint 2019-02-23 03:40:18 PST
For macOS all we need to do is decide whether to expose the property since it's effectively only relevant with a touch-capable display. Chrome and Firefox on macOS expose the property, but I'm not sure it's right to expose it. Anyone here have thoughts on the topic?
Comment 34 Patrick H. Lauke 2019-02-23 06:58:19 PST
any particular reason NOT to expose it? are there similar situations where a property is only exposed when particular hardware/environment is present? (thinking ahead, would like to avoid naive "test for the presence of this property to determine if it's a touch device" type detects, as they're not recommended/are usually abused)
Comment 35 Maciej Stachowiak 2019-02-26 22:57:32 PST
(In reply to Patrick H. Lauke from comment #34)
> any particular reason NOT to expose it? are there similar situations where a
> property is only exposed when particular hardware/environment is present?
> (thinking ahead, would like to avoid naive "test for the presence of this
> property to determine if it's a touch device" type detects, as they're not
> recommended/are usually abused)

I agree with this. We should always expose the property, even if it may have no effect on some devices. It's what other browsers do and it seems consistent with other "hint" type properties.
Comment 36 Antoine Quint 2019-02-27 00:09:40 PST
OK, the touch-action property will be exposed on macOS.
Comment 37 Antoine Quint 2019-02-28 02:01:03 PST
Created attachment 363213 [details]
Patch
Comment 38 Simon Fraser (smfr) 2019-02-28 11:20:33 PST
Comment on attachment 363213 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=363213&action=review

> LayoutTests/ChangeLog:3
> +        Touch-action css property support

You need a title that is specific to this commit, which seems to be about enabling tests.
Comment 39 Dean Jackson 2019-02-28 14:35:38 PST
Comment on attachment 363213 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=363213&action=review

>> LayoutTests/ChangeLog:3
>> +        Touch-action css property support
> 
> You need a title that is specific to this commit, which seems to be about enabling tests.

Agreed.
Comment 40 Antoine Quint 2019-02-28 23:36:19 PST
The final step to enable the WPT tests is tracked by 195204. This is all done.
Comment 41 Tobi Reif 2019-10-03 07:56:25 PDT
Will touch-action: pan-y be supported? (by mobile Safari)
Comment 42 Antoine Quint 2019-10-03 08:01:51 PDT
(In reply to Tobi Reif from comment #41)
> Will touch-action: pan-y be supported? (by mobile Safari)

`touch-action: pan-y` is supported in Safari on iOS 13. If you find a situation where it does not work as expected, please file a bug.
Comment 43 Tobi Reif 2019-10-03 09:29:57 PDT
> `touch-action: pan-y` is supported in Safari on iOS 13.
> If you find a situation where it does not work as expected,
> please file a bug.

It's a bit complicated, and I unfortunately don't have the time to provide a reduced test-case.

The issue is this:

When I load https://tobireif.com/posts/layout_fun_with_css_grid/ eg on a Galaxy phone (eg in Chrome), and drag the "resize"-bar (below "Another demo"), and over-drag, the handle stops moving. So I add touch-action: pan-y – now when I over-drag, the handle follows. And when I drag the grid demo itself, I get normal y-axis scrolling of the page.

When I load this in the iPhone simulator app (iOS 13 iPhone 8), and over-drag the resize-bar, it (sometimes) doesn't follow. For example: drag-resize the in-page demo to narrow, over-drag, then go back all the way. Do this once or eg twice -> the drag-handle stops following.

So I added this hack:

(function() {

  isMobileSafari = /iP(ad|hone|od)/i.test(navigator.userAgent);
  if (isMobileSafari) {
    demo.style.touchAction = "none";
  }

})();

Now there's no issue with the drag-handle (it always follows), but I don't get any scrolling (the page doesn't move when I try to drag the demo itself up/down). But page-scrolling is very important :/

I hope that you can reproduce all this (probably by toggling stuff via the dev-tools), and that the issue(s) can get fixed soon. Then I can remove the iPhone hack. In Chrome (eg on a Galaxy phone) everything works beautifully.
Comment 44 Tobi Reif 2019-10-03 09:33:58 PDT
Reported (as requested) as a separate bug:
https://bugs.webkit.org/show_bug.cgi?id=202531