Title: [199695] trunk/Source/WebKit2
Revision
199695
Author
[email protected]
Date
2016-04-18 16:00:29 -0700 (Mon, 18 Apr 2016)

Log Message

Swipe view gesture should be reversed in right-to-left contexts
https://bugs.webkit.org/show_bug.cgi?id=156714

Reviewed by Anders Carlsson.

* UIProcess/API/gtk/PageClientImpl.h:
* UIProcess/PageClient.h:
* UIProcess/UserInterfaceLayoutDirection.h: Added.
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::userInterfaceLayoutDirection):
* UIProcess/WebPageProxy.h:
* UIProcess/ios/PageClientImplIOS.h:
* UIProcess/ios/PageClientImplIOS.mm:
(WebKit::PageClientImpl::userInterfaceLayoutDirection):
* UIProcess/mac/PageClientImpl.h:
* UIProcess/mac/PageClientImpl.mm:
(WebKit::PageClientImpl::userInterfaceLayoutDirection):
Plumb RTL-ness through to WebPageProxy.
We look at the WK(Web)View's UI layout direction.
For other platforms, we just assume LTR.

* UIProcess/mac/ViewGestureController.h:
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanBecomeSwipe):
Decide which way to swipe (and which way to look for back-forward items)
based on the WebPageProxy's reported RTLness.

(WebKit::ViewGestureController::isPhysicallySwipingLeft):
"Back" means "swiping left" in LTR and "swiping right" in RTL.

(WebKit::ViewGestureController::trackSwipeGesture):
(WebKit::ViewGestureController::determineLayerAdjacentToSnapshotForParent):
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::handleSwipeGesture):
Make things that were equating "back" with "left" instead check isPhysicallySwipingLeft.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (199694 => 199695)


--- trunk/Source/WebKit2/ChangeLog	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/ChangeLog	2016-04-18 23:00:29 UTC (rev 199695)
@@ -1,3 +1,41 @@
+2016-04-18  Tim Horton  <[email protected]>
+
+        Swipe view gesture should be reversed in right-to-left contexts
+        https://bugs.webkit.org/show_bug.cgi?id=156714
+
+        Reviewed by Anders Carlsson.
+
+        * UIProcess/API/gtk/PageClientImpl.h:
+        * UIProcess/PageClient.h:
+        * UIProcess/UserInterfaceLayoutDirection.h: Added.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::userInterfaceLayoutDirection):
+        * UIProcess/WebPageProxy.h:
+        * UIProcess/ios/PageClientImplIOS.h:
+        * UIProcess/ios/PageClientImplIOS.mm:
+        (WebKit::PageClientImpl::userInterfaceLayoutDirection):
+        * UIProcess/mac/PageClientImpl.h:
+        * UIProcess/mac/PageClientImpl.mm:
+        (WebKit::PageClientImpl::userInterfaceLayoutDirection):
+        Plumb RTL-ness through to WebPageProxy.
+        We look at the WK(Web)View's UI layout direction.
+        For other platforms, we just assume LTR.
+
+        * UIProcess/mac/ViewGestureController.h:
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanBecomeSwipe):
+        Decide which way to swipe (and which way to look for back-forward items)
+        based on the WebPageProxy's reported RTLness.
+
+        (WebKit::ViewGestureController::isPhysicallySwipingLeft):
+        "Back" means "swiping left" in LTR and "swiping right" in RTL.
+
+        (WebKit::ViewGestureController::trackSwipeGesture):
+        (WebKit::ViewGestureController::determineLayerAdjacentToSnapshotForParent):
+        (WebKit::ViewGestureController::beginSwipeGesture):
+        (WebKit::ViewGestureController::handleSwipeGesture):
+        Make things that were equating "back" with "left" instead check isPhysicallySwipingLeft.
+
 2016-04-18  Anders Carlsson  <[email protected]>
 
         Fix build with newer versions of clang.

Modified: trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/API/gtk/PageClientImpl.h	2016-04-18 23:00:29 UTC (rev 199695)
@@ -142,6 +142,8 @@
     bool decidePolicyForInstallMissingMediaPluginsPermissionRequest(InstallMissingMediaPluginsPermissionRequest&) override;
 #endif
 
+    UserInterfaceLayoutDirection userInterfaceLayoutDirection() override { return UserInterfaceLayoutDirection::LTR; }
+
     // Members of PageClientImpl class
     GtkWidget* m_viewWidget;
     DefaultUndoController m_undoController;

Modified: trunk/Source/WebKit2/UIProcess/PageClient.h (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/PageClient.h	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/PageClient.h	2016-04-18 23:00:29 UTC (rev 199695)
@@ -27,6 +27,7 @@
 #define PageClient_h
 
 #include "ShareableBitmap.h"
+#include "UserInterfaceLayoutDirection.h"
 #include "WebColorPicker.h"
 #include "WebPageProxy.h"
 #include "WebPopupMenuProxy.h"
@@ -363,6 +364,8 @@
     virtual void didRestoreScrollPosition() = 0;
 
     virtual bool windowIsFrontWindowUnderMouse(const NativeWebMouseEvent&) { return false; }
+
+    virtual UserInterfaceLayoutDirection userInterfaceLayoutDirection() = 0;
 };
 
 } // namespace WebKit

Added: trunk/Source/WebKit2/UIProcess/UserInterfaceLayoutDirection.h (0 => 199695)


--- trunk/Source/WebKit2/UIProcess/UserInterfaceLayoutDirection.h	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/UserInterfaceLayoutDirection.h	2016-04-18 23:00:29 UTC (rev 199695)
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UserInterfaceLayoutDirection_h
+#define UserInterfaceLayoutDirection_h
+
+namespace WebKit {
+
+enum class UserInterfaceLayoutDirection { LTR, RTL };
+
+} // namespace WebKit
+
+#endif // UserInterfaceLayoutDirection_h

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-04-18 23:00:29 UTC (rev 199695)
@@ -6275,4 +6275,9 @@
     m_process->send(Messages::WebPage::SetResourceCachingDisabled(disabled), m_pageID);
 }
 
+UserInterfaceLayoutDirection WebPageProxy::userInterfaceLayoutDirection()
+{
+    return m_pageClient.userInterfaceLayoutDirection();
+}
+
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-04-18 23:00:29 UTC (rev 199695)
@@ -45,6 +45,7 @@
 #include "ProcessThrottler.h"
 #include "SandboxExtension.h"
 #include "ShareableBitmap.h"
+#include "UserInterfaceLayoutDirection.h"
 #include "UserMediaPermissionRequestManagerProxy.h"
 #include "VisibleContentRectUpdateInfo.h"
 #include "WKBase.h"
@@ -1104,6 +1105,8 @@
     bool isResourceCachingDisabled() const { return m_isResourceCachingDisabled; }
     void setResourceCachingDisabled(bool);
 
+    UserInterfaceLayoutDirection userInterfaceLayoutDirection();
+
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
     void platformInitialize();

Modified: trunk/Source/WebKit2/UIProcess/efl/WebView.h (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/efl/WebView.h	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/efl/WebView.h	2016-04-18 23:00:29 UTC (rev 199695)
@@ -261,6 +261,8 @@
     void beganExitFullScreen(const WebCore::IntRect&, const WebCore::IntRect&) override { }
 #endif
 
+    UserInterfaceLayoutDirection userInterfaceLayoutDirection() override { return UserInterfaceLayoutDirection::LTR; }
+
     EwkView* m_ewkView;
 
     WebViewClient m_client;

Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.h	2016-04-18 23:00:29 UTC (rev 199695)
@@ -193,6 +193,8 @@
 
     void didRestoreScrollPosition() override;
 
+    UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
+
     WKContentView *m_contentView;
     WKWebView *m_webView;
     RetainPtr<WKEditorUndoTargetObjC> m_undoTarget;

Modified: trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/ios/PageClientImplIOS.mm	2016-04-18 23:00:29 UTC (rev 199695)
@@ -747,6 +747,13 @@
 {
 }
 
+UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
+{
+    if (!m_webView)
+        return UserInterfaceLayoutDirection::LTR;
+    return ([UIView userInterfaceLayoutDirectionForSemanticContentAttribute:[m_webView semanticContentAttribute]] == UIUserInterfaceLayoutDirectionLeftToRight) ? UserInterfaceLayoutDirection::LTR : UserInterfaceLayoutDirection::RTL;
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(IOS)

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.h	2016-04-18 23:00:29 UTC (rev 199695)
@@ -220,6 +220,8 @@
     void startWindowDrag() override;
     NSWindow *platformWindow() override;
 
+    UserInterfaceLayoutDirection userInterfaceLayoutDirection() override;
+
 #if WK_API_ENABLED
     NSView *inspectorAttachmentView() override;
     _WKRemoteObjectRegistry *remoteObjectRegistry() override;

Modified: trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/mac/PageClientImpl.mm	2016-04-18 23:00:29 UTC (rev 199695)
@@ -840,6 +840,13 @@
     return m_impl->windowIsFrontWindowUnderMouse(event.nativeEvent());
 }
 
+UserInterfaceLayoutDirection PageClientImpl::userInterfaceLayoutDirection()
+{
+    if (!m_view)
+        return UserInterfaceLayoutDirection::LTR;
+    return (m_view.userInterfaceLayoutDirection == NSUserInterfaceLayoutDirectionLeftToRight) ? UserInterfaceLayoutDirection::LTR : UserInterfaceLayoutDirection::RTL;
+}
+
 } // namespace WebKit
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h	2016-04-18 23:00:29 UTC (rev 199695)
@@ -109,6 +109,8 @@
 
     bool shouldIgnorePinnedState() { return m_pendingSwipeTracker.shouldIgnorePinnedState(); }
     void setShouldIgnorePinnedState(bool ignore) { m_pendingSwipeTracker.setShouldIgnorePinnedState(ignore); }
+
+    bool isPhysicallySwipingLeft(SwipeDirection) const;
 #else
     void installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView);
     void setAlternateBackForwardListSourceView(WKWebView *);

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm (199694 => 199695)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2016-04-18 22:59:31 UTC (rev 199694)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2016-04-18 23:00:29 UTC (rev 199695)
@@ -31,6 +31,7 @@
 #import "FrameLoadState.h"
 #import "Logging.h"
 #import "NativeWebWheelEvent.h"
+#import "UserInterfaceLayoutDirection.h"
 #import "ViewGestureControllerMessages.h"
 #import "ViewGestureGeometryCollectorMessages.h"
 #import "ViewSnapshotStore.h"
@@ -297,12 +298,19 @@
     bool isPinnedToLeft = m_shouldIgnorePinnedState || m_webPageProxy.isPinnedToLeftSide();
     bool isPinnedToRight = m_shouldIgnorePinnedState || m_webPageProxy.isPinnedToRightSide();
 
-    bool willSwipeLeft = event.scrollingDeltaX > 0 && isPinnedToLeft && m_webPageProxy.backForwardList().backItem();
-    bool willSwipeRight = event.scrollingDeltaX < 0 && isPinnedToRight && m_webPageProxy.backForwardList().forwardItem();
-    if (!willSwipeLeft && !willSwipeRight)
+    bool willSwipeBack = false;
+    bool willSwipeForward = false;
+    if (m_webPageProxy.userInterfaceLayoutDirection() == UserInterfaceLayoutDirection::LTR) {
+        willSwipeBack = event.scrollingDeltaX > 0 && isPinnedToLeft && m_webPageProxy.backForwardList().backItem();
+        willSwipeForward = event.scrollingDeltaX < 0 && isPinnedToRight && m_webPageProxy.backForwardList().forwardItem();
+    } else {
+        willSwipeBack = event.scrollingDeltaX < 0 && isPinnedToRight && m_webPageProxy.backForwardList().backItem();
+        willSwipeForward = event.scrollingDeltaX > 0 && isPinnedToLeft && m_webPageProxy.backForwardList().forwardItem();
+    }
+    if (!willSwipeBack && !willSwipeForward)
         return false;
 
-    potentialSwipeDirection = willSwipeLeft ? ViewGestureController::SwipeDirection::Back : ViewGestureController::SwipeDirection::Forward;
+    potentialSwipeDirection = willSwipeBack ? ViewGestureController::SwipeDirection::Back : ViewGestureController::SwipeDirection::Forward;
 
     return true;
 }
@@ -394,8 +402,9 @@
 
     m_webPageProxy.recordNavigationSnapshot();
 
-    CGFloat maxProgress = (direction == SwipeDirection::Back) ? 1 : 0;
-    CGFloat minProgress = (direction == SwipeDirection::Forward) ? -1 : 0;
+    BOOL swipingLeft = isPhysicallySwipingLeft(direction);
+    CGFloat maxProgress = swipingLeft ? 1 : 0;
+    CGFloat minProgress = !swipingLeft ? -1 : 0;
     RefPtr<WebBackForwardListItem> targetItem = (direction == SwipeDirection::Back) ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem();
     if (!targetItem)
         return;
@@ -476,7 +485,7 @@
 CALayer *ViewGestureController::determineLayerAdjacentToSnapshotForParent(SwipeDirection direction, CALayer *snapshotLayerParent) const
 {
     // If we have custom swiping views, we assume that the views were passed to us in back-to-front z-order.
-    CALayer *layerAdjacentToSnapshot = direction == SwipeDirection::Back ? m_currentSwipeLiveLayers.first().get() : m_currentSwipeLiveLayers.last().get();
+    CALayer *layerAdjacentToSnapshot = isPhysicallySwipingLeft(direction) ? m_currentSwipeLiveLayers.first().get() : m_currentSwipeLiveLayers.last().get();
 
     if (m_currentSwipeLiveLayers.size() == 1)
         return layerAdjacentToSnapshot;
@@ -593,7 +602,8 @@
         applyDebuggingPropertiesToSwipeViews();
 
     CALayer *layerAdjacentToSnapshot = determineLayerAdjacentToSnapshotForParent(direction, snapshotLayerParent);
-    if (direction == SwipeDirection::Back)
+    BOOL swipingLeft = isPhysicallySwipingLeft(direction);
+    if (swipingLeft)
         [snapshotLayerParent insertSublayer:m_swipeLayer.get() below:layerAdjacentToSnapshot];
     else
         [snapshotLayerParent insertSublayer:m_swipeLayer.get() above:layerAdjacentToSnapshot];
@@ -657,7 +667,7 @@
         [m_swipeShadowLayer setGeometryFlipped:geometryIsFlippedToRoot];
         [m_swipeShadowLayer setDelegate:[WebActionDisablingCALayerDelegate shared]];
 
-        if (direction == SwipeDirection::Back)
+        if (swipingLeft)
             [snapshotLayerParent insertSublayer:m_swipeDimmingLayer.get() above:m_swipeLayer.get()];
         else
             [snapshotLayerParent insertSublayer:m_swipeDimmingLayer.get() below:m_swipeLayer.get()];
@@ -666,10 +676,19 @@
     }
 }
 
+bool ViewGestureController::isPhysicallySwipingLeft(SwipeDirection direction) const
+{
+    bool isLTR = m_webPageProxy.userInterfaceLayoutDirection() == UserInterfaceLayoutDirection::LTR;
+    bool isSwipingForward = direction == SwipeDirection::Forward;
+    return isLTR != isSwipingForward;
+}
+
 void ViewGestureController::handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, SwipeDirection direction)
 {
     ASSERT(m_activeGestureType == ViewGestureType::Swipe);
 
+    bool swipingLeft = isPhysicallySwipingLeft(direction);
+
     if (!m_webPageProxy.drawingArea())
         return;
 
@@ -681,7 +700,7 @@
 
     double swipingLayerOffset = floor(width * progress);
 
-    double dimmingProgress = (direction == SwipeDirection::Back) ? 1 - progress : -progress;
+    double dimmingProgress = swipingLeft ? 1 - progress : -progress;
     dimmingProgress = std::min(1., std::max(dimmingProgress, 0.));
     [m_swipeDimmingLayer setOpacity:dimmingProgress * swipeOverlayDimmingOpacity];
 
@@ -694,19 +713,19 @@
         [m_swipeShadowLayer setOpacity:swipeOverlayShadowOpacity];
 
     if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap)
-        [m_swipeShadowLayer setTransform:CATransform3DMakeTranslation((direction == SwipeDirection::Back ? 0 : width) + swipingLayerOffset, 0, 0)];
+        [m_swipeShadowLayer setTransform:CATransform3DMakeTranslation((swipingLeft ? 0 : width) + swipingLayerOffset, 0, 0)];
 
     if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap) {
-        if (direction == SwipeDirection::Forward) {
+        if (!swipingLeft) {
             [m_swipeLayer setTransform:CATransform3DMakeTranslation(width + swipingLayerOffset, 0, 0)];
             didMoveSwipeSnapshotLayer();
         }
     } else if (m_swipeTransitionStyle == SwipeTransitionStyle::Push)
-        [m_swipeLayer setTransform:CATransform3DMakeTranslation((direction == SwipeDirection::Back ? -width : width) + swipingLayerOffset, 0, 0)];
+        [m_swipeLayer setTransform:CATransform3DMakeTranslation((swipingLeft ? -width : width) + swipingLayerOffset, 0, 0)];
 
     for (const auto& layer : m_currentSwipeLiveLayers) {
         if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap) {
-            if (direction == SwipeDirection::Back)
+            if (swipingLeft)
                 [layer setTransform:CATransform3DMakeTranslation(swipingLayerOffset, 0, 0)];
         } else if (m_swipeTransitionStyle == SwipeTransitionStyle::Push)
             [layer setTransform:CATransform3DMakeTranslation(swipingLayerOffset, 0, 0)];
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to