Title: [250183] trunk
Revision
250183
Author
[email protected]
Date
2019-09-21 09:08:34 -0700 (Sat, 21 Sep 2019)

Log Message

[Pointer Events] touch-action set to pan-x or pan-y alone should disable scrolling altogether if the intial gesture is in the disallowed direction
https://bugs.webkit.org/show_bug.cgi?id=202053
<rdar://problem/54542190>

Reviewed by Tim Horton.

Source/WebKit:

Although the Pointer Events specification does not specify this clearly (see https://github.com/w3c/pointerevents/issues/303), setting "touch-action" to a value
that only allows scrolling a specific direction ("pan-x" or "pan-y") should disable scrolling in the specified direction if the panning gesture initially is directed
in the opposite direction. In practice, this means that setting "touch-action: pan-y" on an element should disable scrolling if the user initially pans horizontally,
even if later on in the gesture the user pans vertically. This allows for sites that want to offer a programmatic horizontal scroller to disable vertical scrolling
if the user pans horizontally.

In order to support this, we add four UISwipeGestureRecognizers, one for each direction, and we selectively allows touches to be recognizer for them based on the
"touch-action" value specified at the initial touch location for a given gesture. In the case of "touch-action: pan-y" we only allow the left and right swipe recognizers
to be enabled, and in the case of "touch-action: pan-x" we only allow the up and down swipe recognizers to be enabled. If any of those gesture recognizers is recognized,
scrolling will be disabled for the duration of this gesture. If a UIScrollView panning gesture recognizer is recognized prior to a swipe, they won't have a chance to be
recognized.

* UIProcess/ios/WKContentViewInteraction.h:
* UIProcess/ios/WKContentViewInteraction.mm:
(-[WKContentView setupInteraction]):
(-[WKContentView cleanupInteraction]):
(-[WKContentView _removeDefaultGestureRecognizers]):
(-[WKContentView _addDefaultGestureRecognizers]):
(-[WKContentView gestureRecognizer:shouldReceiveTouch:]):

LayoutTests:

Add new tests checking that setting "touch-action: pan-y" on an element and initiating a horizontal panning gesture will disallow scrolling vertically
if a vertical scrolling gesture follows. We test both the case where scrolling would apply to the whole page and the case where scrolling would apply
to an "overflow: scroll" element.

* pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling-expected.txt: Added.
* pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling.html: Added.
* pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling-expected.txt: Added.
* pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (250182 => 250183)


--- trunk/LayoutTests/ChangeLog	2019-09-21 15:34:43 UTC (rev 250182)
+++ trunk/LayoutTests/ChangeLog	2019-09-21 16:08:34 UTC (rev 250183)
@@ -1,3 +1,20 @@
+2019-09-21  Antoine Quint  <[email protected]>
+
+        [Pointer Events] touch-action set to pan-x or pan-y alone should disable scrolling altogether if the intial gesture is in the disallowed direction
+        https://bugs.webkit.org/show_bug.cgi?id=202053
+        <rdar://problem/54542190>
+
+        Reviewed by Tim Horton.
+
+        Add new tests checking that setting "touch-action: pan-y" on an element and initiating a horizontal panning gesture will disallow scrolling vertically
+        if a vertical scrolling gesture follows. We test both the case where scrolling would apply to the whole page and the case where scrolling would apply
+        to an "overflow: scroll" element.
+
+        * pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling-expected.txt: Added.
+        * pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling.html: Added.
+        * pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling-expected.txt: Added.
+        * pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling.html: Added.
+
 2019-09-20  Antoine Quint  <[email protected]>
 
         releasePointerCapture() not working for implicit capture; can't opt-in to pointerenter/leave for touches

Added: trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling-expected.txt (0 => 250183)


--- trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling-expected.txt	2019-09-21 16:08:34 UTC (rev 250183)
@@ -0,0 +1,3 @@
+
+PASS Testing that panning in the x-axis first on an element with touch-action: pan-y prevents future vertical scrolling. 
+

Added: trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling.html (0 => 250183)


--- trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling.html	                        (rev 0)
+++ trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-horizontal-gesture-prevents-vertical-scrolling.html	2019-09-21 16:08:34 UTC (rev 250183)
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset=utf-8>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+</head>
+<body>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script>
+
+'use strict';
+
+target_test({ width: "200px", height: "200px" }, (target, test) => {
+    document.body.style.height = "2000px";
+
+    target.style.touchAction = "pan-y";
+    target.style.backgroundColor = "blue";
+
+    const eventTracker = new EventTracker(target, ["pointerdown", "pointerup", "pointercancel"]);
+
+    touchAndDragFromPointToPoint(150, 100, 50, 100)
+    .then(() => touchAndDragFromPointToPoint(50, 100, 50, 50))
+    .then(() => liftUpAtPoint(50, 50))
+    .then(() => {
+        assert_equals(window.pageYOffset, 0, "The page was not scrolled vertically.");
+        eventTracker.assertMatchesEvents([
+            { type: "pointerdown" },
+            { type: "pointerup" }
+        ]);
+        test.done();
+    });
+}, "Testing that panning in the x-axis first on an element with touch-action: pan-y prevents future vertical scrolling.");
+
+</script>
+</body>
+</html>
\ No newline at end of file

Added: trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling-expected.txt (0 => 250183)


--- trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling-expected.txt	2019-09-21 16:08:34 UTC (rev 250183)
@@ -0,0 +1,3 @@
+
+PASS Testing that panning in the x-axis first on an element with touch-action: pan-y prevents future vertical scrolling within an 'overflow: scroll' element. 
+

Added: trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling.html (0 => 250183)


--- trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling.html	                        (rev 0)
+++ trunk/LayoutTests/pointerevents/ios/touch-action-pan-y-in-overflow-scroll-horizontal-gesture-prevents-vertical-scrolling.html	2019-09-21 16:08:34 UTC (rev 250183)
@@ -0,0 +1,55 @@
+<!DOCTYPE html> <!-- webkit-test-runner [ internal:AsyncOverflowScrollingEnabled=true internal:LegacyOverflowScrollingTouchEnabled=false ] -->
+<html>
+<head>
+<meta charset=utf-8>
+<meta name="viewport" content="width=device-width, initial-scale=1">
+<style>
+
+#scrollable {
+    position: absolute;
+    left: 0;
+    top: 0;
+    width: 200px;
+    height: 200px;
+
+    overflow: scroll;
+    background-color: green;
+}
+
+</style>
+</head>
+<body>
+<div id="scrollable"></div>
+<script src=""
+<script src=""
+<script src=""
+<script src=""
+<script>
+
+'use strict';
+
+target_test({ width: "200px", height: "2000px" }, (target, test) => {
+    const scrollable = document.querySelector("#scrollable");
+    scrollable.appendChild(target);
+
+    target.style.touchAction = "pan-y";
+    target.style.backgroundColor = "blue";
+
+    const eventTracker = new EventTracker(target, ["pointerdown", "pointerup", "pointercancel"]);
+
+    touchAndDragFromPointToPoint(150, 100, 50, 100)
+    .then(() => touchAndDragFromPointToPoint(50, 100, 50, 50))
+    .then(() => liftUpAtPoint(50, 50))
+    .then(() => {
+        assert_equals(scrollable.scrollTop, 0, "The page was not scrolled vertically.");
+        eventTracker.assertMatchesEvents([
+            { type: "pointerdown" },
+            { type: "pointerup" }
+        ]);
+        test.done();
+    });
+}, "Testing that panning in the x-axis first on an element with touch-action: pan-y prevents future vertical scrolling within an 'overflow: scroll' element.");
+
+</script>
+</body>
+</html>
\ No newline at end of file

Modified: trunk/Source/WebKit/ChangeLog (250182 => 250183)


--- trunk/Source/WebKit/ChangeLog	2019-09-21 15:34:43 UTC (rev 250182)
+++ trunk/Source/WebKit/ChangeLog	2019-09-21 16:08:34 UTC (rev 250183)
@@ -1,3 +1,31 @@
+2019-09-21  Antoine Quint  <[email protected]>
+
+        [Pointer Events] touch-action set to pan-x or pan-y alone should disable scrolling altogether if the intial gesture is in the disallowed direction
+        https://bugs.webkit.org/show_bug.cgi?id=202053
+        <rdar://problem/54542190>
+
+        Reviewed by Tim Horton.
+
+        Although the Pointer Events specification does not specify this clearly (see https://github.com/w3c/pointerevents/issues/303), setting "touch-action" to a value
+        that only allows scrolling a specific direction ("pan-x" or "pan-y") should disable scrolling in the specified direction if the panning gesture initially is directed
+        in the opposite direction. In practice, this means that setting "touch-action: pan-y" on an element should disable scrolling if the user initially pans horizontally,
+        even if later on in the gesture the user pans vertically. This allows for sites that want to offer a programmatic horizontal scroller to disable vertical scrolling
+        if the user pans horizontally.
+
+        In order to support this, we add four UISwipeGestureRecognizers, one for each direction, and we selectively allows touches to be recognizer for them based on the
+        "touch-action" value specified at the initial touch location for a given gesture. In the case of "touch-action: pan-y" we only allow the left and right swipe recognizers
+        to be enabled, and in the case of "touch-action: pan-x" we only allow the up and down swipe recognizers to be enabled. If any of those gesture recognizers is recognized,
+        scrolling will be disabled for the duration of this gesture. If a UIScrollView panning gesture recognizer is recognized prior to a swipe, they won't have a chance to be
+        recognized.
+
+        * UIProcess/ios/WKContentViewInteraction.h:
+        * UIProcess/ios/WKContentViewInteraction.mm:
+        (-[WKContentView setupInteraction]):
+        (-[WKContentView cleanupInteraction]):
+        (-[WKContentView _removeDefaultGestureRecognizers]):
+        (-[WKContentView _addDefaultGestureRecognizers]):
+        (-[WKContentView gestureRecognizer:shouldReceiveTouch:]):
+
 2019-09-19  Andy Estes  <[email protected]>
 
         [Apple Pay] Clean up handling of summary items and payment method updates

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h (250182 => 250183)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-09-21 15:34:43 UTC (rev 250182)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.h	2019-09-21 16:08:34 UTC (rev 250183)
@@ -225,6 +225,10 @@
 
 #if ENABLE(POINTER_EVENTS)
     RetainPtr<WKTouchActionGestureRecognizer> _touchActionGestureRecognizer;
+    RetainPtr<UISwipeGestureRecognizer> _touchActionLeftSwipeGestureRecognizer;
+    RetainPtr<UISwipeGestureRecognizer> _touchActionRightSwipeGestureRecognizer;
+    RetainPtr<UISwipeGestureRecognizer> _touchActionUpSwipeGestureRecognizer;
+    RetainPtr<UISwipeGestureRecognizer> _touchActionDownSwipeGestureRecognizer;
 #endif
 
 #if PLATFORM(MACCATALYST)

Modified: trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm (250182 => 250183)


--- trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-09-21 15:34:43 UTC (rev 250182)
+++ trunk/Source/WebKit/UIProcess/ios/WKContentViewInteraction.mm	2019-09-21 16:08:34 UTC (rev 250183)
@@ -716,6 +716,28 @@
 
     [self.layer addObserver:self forKeyPath:@"transform" options:NSKeyValueObservingOptionInitial context:nil];
 
+#if ENABLE(POINTER_EVENTS)
+    _touchActionLeftSwipeGestureRecognizer = adoptNS([[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil]);
+    [_touchActionLeftSwipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionLeft];
+    [_touchActionLeftSwipeGestureRecognizer setDelegate:self];
+    [self addGestureRecognizer:_touchActionLeftSwipeGestureRecognizer.get()];
+
+    _touchActionRightSwipeGestureRecognizer = adoptNS([[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil]);
+    [_touchActionRightSwipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
+    [_touchActionRightSwipeGestureRecognizer setDelegate:self];
+    [self addGestureRecognizer:_touchActionRightSwipeGestureRecognizer.get()];
+
+    _touchActionUpSwipeGestureRecognizer = adoptNS([[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil]);
+    [_touchActionUpSwipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionUp];
+    [_touchActionUpSwipeGestureRecognizer setDelegate:self];
+    [self addGestureRecognizer:_touchActionUpSwipeGestureRecognizer.get()];
+
+    _touchActionDownSwipeGestureRecognizer = adoptNS([[UISwipeGestureRecognizer alloc] initWithTarget:nil action:nil]);
+    [_touchActionDownSwipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionDown];
+    [_touchActionDownSwipeGestureRecognizer setDelegate:self];
+    [self addGestureRecognizer:_touchActionDownSwipeGestureRecognizer.get()];
+#endif
+
     _touchEventGestureRecognizer = adoptNS([[UIWebTouchEventsGestureRecognizer alloc] initWithTarget:self action:@selector(_webTouchEventsRecognized:) touchDelegate:self]);
     [_touchEventGestureRecognizer setDelegate:self];
     [self addGestureRecognizer:_touchEventGestureRecognizer.get()];
@@ -916,6 +938,10 @@
 
 #if ENABLE(POINTER_EVENTS)
     [self removeGestureRecognizer:_touchActionGestureRecognizer.get()];
+    [self removeGestureRecognizer:_touchActionLeftSwipeGestureRecognizer.get()];
+    [self removeGestureRecognizer:_touchActionRightSwipeGestureRecognizer.get()];
+    [self removeGestureRecognizer:_touchActionUpSwipeGestureRecognizer.get()];
+    [self removeGestureRecognizer:_touchActionDownSwipeGestureRecognizer.get()];
 #endif
 
     _layerTreeTransactionIdAtLastTouchStart = { };
@@ -993,6 +1019,10 @@
 #endif
 #if ENABLE(POINTER_EVENTS)
     [self removeGestureRecognizer:_touchActionGestureRecognizer.get()];
+    [self removeGestureRecognizer:_touchActionLeftSwipeGestureRecognizer.get()];
+    [self removeGestureRecognizer:_touchActionRightSwipeGestureRecognizer.get()];
+    [self removeGestureRecognizer:_touchActionUpSwipeGestureRecognizer.get()];
+    [self removeGestureRecognizer:_touchActionDownSwipeGestureRecognizer.get()];
 #endif
 }
 
@@ -1015,6 +1045,10 @@
 #endif
 #if ENABLE(POINTER_EVENTS)
     [self addGestureRecognizer:_touchActionGestureRecognizer.get()];
+    [self addGestureRecognizer:_touchActionLeftSwipeGestureRecognizer.get()];
+    [self addGestureRecognizer:_touchActionRightSwipeGestureRecognizer.get()];
+    [self addGestureRecognizer:_touchActionUpSwipeGestureRecognizer.get()];
+    [self addGestureRecognizer:_touchActionDownSwipeGestureRecognizer.get()];
 #endif
 }
 
@@ -1409,6 +1443,22 @@
         }
     }
 }
+
+- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
+{
+    if (gestureRecognizer != _touchActionLeftSwipeGestureRecognizer && gestureRecognizer != _touchActionRightSwipeGestureRecognizer && gestureRecognizer != _touchActionUpSwipeGestureRecognizer && gestureRecognizer != _touchActionDownSwipeGestureRecognizer)
+        return true;
+
+    // We update the enabled state of the various swipe gesture recognizers such that if we have a unidirectional touch-action
+    // specified (only pan-x or only pan-y) we enable the two recognizers in the opposite axis to prevent scrolling from starting
+    // if the initial gesture is such a swipe. Since the recognizers are specified to use a single finger for recognition, we don't
+    // need to worry about the case where there may be more than a single touch for a given UIScrollView.
+    auto touchActions = WebKit::touchActionsForPoint(self, WebCore::roundedIntPoint([touch locationInView:self]));
+    if (gestureRecognizer == _touchActionLeftSwipeGestureRecognizer || gestureRecognizer == _touchActionRightSwipeGestureRecognizer)
+        return touchActions == WebCore::TouchAction::PanY;
+    return touchActions == WebCore::TouchAction::PanX;
+}
+
 #endif
 
 #pragma mark - WKTouchActionGestureRecognizerDelegate implementation
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to