Swipes occur in the wrong direction in RTL
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2015 23:38:49 +0000 (23:38 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 31 Mar 2015 23:38:49 +0000 (23:38 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143257
<rdar://problem/20300862>

Reviewed by Simon Fraser.

* UIProcess/ios/ViewGestureControllerIOS.mm:
(-[WKSwipeTransitionController gestureRecognizerForInteractiveTransition:WithTarget:action:]):
When choosing which edge to attach our gesture recognizers to,
flip them in RTL.

(-[WKSwipeTransitionController directionForTransition:]):
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::canSwipeInDirection):
* UIProcess/mac/ViewGestureController.h:
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::scrollEventCanBecomeSwipe):
(WebKit::ViewGestureController::trackSwipeGesture):
(WebKit::ViewGestureController::determineLayerAdjacentToSnapshotForParent):
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::handleSwipeGesture):
Adjust SwipeDirection to be in logical back-forward list direction
instead of physical edge direction.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182214 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm
Source/WebKit2/UIProcess/mac/ViewGestureController.h
Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm

index c653bae..a8e7e2b 100644 (file)
@@ -1,3 +1,29 @@
+2015-03-31  Timothy Horton  <timothy_horton@apple.com>
+
+        Swipes occur in the wrong direction in RTL
+        https://bugs.webkit.org/show_bug.cgi?id=143257
+        <rdar://problem/20300862>
+
+        Reviewed by Simon Fraser.
+
+        * UIProcess/ios/ViewGestureControllerIOS.mm:
+        (-[WKSwipeTransitionController gestureRecognizerForInteractiveTransition:WithTarget:action:]):
+        When choosing which edge to attach our gesture recognizers to,
+        flip them in RTL.
+
+        (-[WKSwipeTransitionController directionForTransition:]):
+        (WebKit::ViewGestureController::beginSwipeGesture):
+        (WebKit::ViewGestureController::canSwipeInDirection):
+        * UIProcess/mac/ViewGestureController.h:
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::scrollEventCanBecomeSwipe):
+        (WebKit::ViewGestureController::trackSwipeGesture):
+        (WebKit::ViewGestureController::determineLayerAdjacentToSnapshotForParent):
+        (WebKit::ViewGestureController::beginSwipeGesture):
+        (WebKit::ViewGestureController::handleSwipeGesture):
+        Adjust SwipeDirection to be in logical back-forward list direction
+        instead of physical edge direction.
+
 2015-03-31  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Move ExpansionBehaviorFlags and TextDirection to their own file
index 6ad9046..592a600 100644 (file)
@@ -60,6 +60,7 @@ using namespace WebCore;
     WebKit::ViewGestureController *_gestureController;
     RetainPtr<_UINavigationInteractiveTransitionBase> _backTransitionController;
     RetainPtr<_UINavigationInteractiveTransitionBase> _forwardTransitionController;
+    WebKit::WeakObjCPtr<UIView> _gestureRecognizerView;
 }
 
 static const float swipeSnapshotRemovalRenderTreeSizeTargetFraction = 0.5;
@@ -78,6 +79,7 @@ static HashMap<uint64_t, WebKit::ViewGestureController*>& viewGestureControllers
     self = [super init];
     if (self) {
         _gestureController = gestureController;
+        _gestureRecognizerView = gestureRecognizerView;
 
         _backTransitionController = adoptNS([_UINavigationInteractiveTransitionBase alloc]);
         _backTransitionController = [_backTransitionController initWithGestureRecognizerView:gestureRecognizerView animator:nil delegate:self];
@@ -96,7 +98,7 @@ static HashMap<uint64_t, WebKit::ViewGestureController*>& viewGestureControllers
 
 - (WebKit::ViewGestureController::SwipeDirection)directionForTransition:(_UINavigationInteractiveTransitionBase *)transition
 {
-    return transition == _backTransitionController ? WebKit::ViewGestureController::SwipeDirection::Left : WebKit::ViewGestureController::SwipeDirection::Right;
+    return transition == _backTransitionController ? WebKit::ViewGestureController::SwipeDirection::Back : WebKit::ViewGestureController::SwipeDirection::Forward;
 }
 
 - (void)startInteractiveTransition:(_UINavigationInteractiveTransitionBase *)transition
@@ -122,12 +124,19 @@ static HashMap<uint64_t, WebKit::ViewGestureController*>& viewGestureControllers
 - (UIPanGestureRecognizer *)gestureRecognizerForInteractiveTransition:(_UINavigationInteractiveTransitionBase *)transition WithTarget:(id)target action:(SEL)action
 {
     UIScreenEdgePanGestureRecognizer *recognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:target action:action];
+
+#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 90000
+    bool isLTR = [UIView userInterfaceLayoutDirectionForSemanticContentAttribute:[_gestureRecognizerView.get() semanticContentAttribute]] == UIUserInterfaceLayoutDirectionLeftToRight;
+#else
+    bool isLTR = true;
+#endif
+
     switch ([self directionForTransition:transition]) {
-    case WebKit::ViewGestureController::SwipeDirection::Left:
-        [recognizer setEdges:UIRectEdgeLeft];
+    case WebKit::ViewGestureController::SwipeDirection::Back:
+        [recognizer setEdges:isLTR ? UIRectEdgeLeft : UIRectEdgeRight];
         break;
-    case WebKit::ViewGestureController::SwipeDirection::Right:
-        [recognizer setEdges:UIRectEdgeRight];
+    case WebKit::ViewGestureController::SwipeDirection::Forward:
+        [recognizer setEdges:isLTR ? UIRectEdgeRight : UIRectEdgeLeft];
         break;
     }
     return [recognizer autorelease];
@@ -183,7 +192,7 @@ void ViewGestureController::beginSwipeGesture(_UINavigationInteractiveTransition
     if (m_webPageProxyForBackForwardListForCurrentSwipe != &m_webPageProxy)
         backForwardList.currentItem()->setSnapshot(m_webPageProxy.backForwardList().currentItem()->snapshot());
 
-    RefPtr<WebBackForwardListItem> targetItem = direction == SwipeDirection::Left ? backForwardList.backItem() : backForwardList.forwardItem();
+    RefPtr<WebBackForwardListItem> targetItem = direction == SwipeDirection::Back ? backForwardList.backItem() : backForwardList.forwardItem();
 
     CGRect liveSwipeViewFrame = [m_liveSwipeView frame];
 
@@ -218,7 +227,7 @@ void ViewGestureController::beginSwipeGesture(_UINavigationInteractiveTransition
     RetainPtr<UIViewController> targettedViewController = adoptNS([[UIViewController alloc] init]);
     [targettedViewController setView:m_liveSwipeViewClippingView.get()];
 
-    UINavigationControllerOperation transitionOperation = direction == SwipeDirection::Left ? UINavigationControllerOperationPop : UINavigationControllerOperationPush;
+    UINavigationControllerOperation transitionOperation = direction == SwipeDirection::Back ? UINavigationControllerOperationPop : UINavigationControllerOperationPush;
     RetainPtr<_UINavigationParallaxTransition> animationController = adoptNS([[_UINavigationParallaxTransition alloc] initWithCurrentOperation:transitionOperation]);
 
     m_swipeTransitionContext = adoptNS([[_UIViewControllerOneToOneTransitionContext alloc] init]);
@@ -253,7 +262,7 @@ void ViewGestureController::beginSwipeGesture(_UINavigationInteractiveTransition
 bool ViewGestureController::canSwipeInDirection(SwipeDirection direction)
 {
     auto& backForwardList = m_alternateBackForwardListSourceView.get() ? m_alternateBackForwardListSourceView.get()->_page->backForwardList() : m_webPageProxy.backForwardList();
-    if (direction == SwipeDirection::Left)
+    if (direction == SwipeDirection::Back)
         return !!backForwardList.backItem();
     return !!backForwardList.forwardItem();
 }
index 17b9499..64d8c48 100644 (file)
@@ -80,8 +80,8 @@ public:
     };
     
     enum class SwipeDirection {
-        Left,
-        Right
+        Back,
+        Forward
     };
 
     enum class PendingSwipeReason {
index fc43051..0b373e9 100644 (file)
@@ -275,7 +275,7 @@ bool ViewGestureController::scrollEventCanBecomeSwipe(NSEvent *event, ViewGestur
     if (!willSwipeLeft && !willSwipeRight)
         return false;
 
-    potentialSwipeDirection = willSwipeLeft ? ViewGestureController::SwipeDirection::Left : ViewGestureController::SwipeDirection::Right;
+    potentialSwipeDirection = willSwipeLeft ? ViewGestureController::SwipeDirection::Back : ViewGestureController::SwipeDirection::Forward;
 
     return true;
 }
@@ -371,9 +371,9 @@ void ViewGestureController::trackSwipeGesture(NSEvent *event, SwipeDirection dir
 
     m_webPageProxy.recordNavigationSnapshot();
 
-    CGFloat maxProgress = (direction == SwipeDirection::Left) ? 1 : 0;
-    CGFloat minProgress = (direction == SwipeDirection::Right) ? -1 : 0;
-    RefPtr<WebBackForwardListItem> targetItem = (direction == SwipeDirection::Left) ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem();
+    CGFloat maxProgress = (direction == SwipeDirection::Back) ? 1 : 0;
+    CGFloat minProgress = (direction == SwipeDirection::Forward) ? -1 : 0;
+    RefPtr<WebBackForwardListItem> targetItem = (direction == SwipeDirection::Back) ? m_webPageProxy.backForwardList().backItem() : m_webPageProxy.backForwardList().forwardItem();
     if (!targetItem)
         return;
     
@@ -446,7 +446,7 @@ CALayer *ViewGestureController::determineSnapshotLayerParent() const
 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::Left ? m_currentSwipeLiveLayers.first().get() : m_currentSwipeLiveLayers.last().get();
+    CALayer *layerAdjacentToSnapshot = direction == SwipeDirection::Back ? m_currentSwipeLiveLayers.first().get() : m_currentSwipeLiveLayers.last().get();
 
     if (m_currentSwipeLiveLayers.size() == 1)
         return layerAdjacentToSnapshot;
@@ -566,7 +566,7 @@ void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem
 
     // We don't know enough about the custom views' hierarchy to apply a shadow.
     if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap && m_customSwipeViews.isEmpty()) {
-        if (direction == SwipeDirection::Left) {
+        if (direction == SwipeDirection::Back) {
             float topContentInset = m_webPageProxy.topContentInset();
             FloatRect shadowRect(FloatPoint(0, topContentInset), m_webPageProxy.viewSize() - FloatSize(0, topContentInset));
             RetainPtr<CGPathRef> shadowPath = adoptCF(CGPathCreateWithRect(shadowRect, 0));
@@ -584,7 +584,7 @@ void ViewGestureController::beginSwipeGesture(WebBackForwardListItem* targetItem
     }
 
     CALayer *layerAdjacentToSnapshot = determineLayerAdjacentToSnapshotForParent(direction, snapshotLayerParent);
-    if (direction == SwipeDirection::Left)
+    if (direction == SwipeDirection::Back)
         [snapshotLayerParent insertSublayer:m_swipeLayer.get() below:layerAdjacentToSnapshot];
     else
         [snapshotLayerParent insertSublayer:m_swipeLayer.get() above:layerAdjacentToSnapshot];
@@ -606,16 +606,16 @@ void ViewGestureController::handleSwipeGesture(WebBackForwardListItem* targetIte
     double swipingLayerOffset = floor(width * progress);
 
     if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap) {
-        if (direction == SwipeDirection::Right) {
+        if (direction == SwipeDirection::Forward) {
             [m_swipeLayer setTransform:CATransform3DMakeTranslation(width + swipingLayerOffset, 0, 0)];
             didMoveSwipeSnapshotLayer();
         }
     } else if (m_swipeTransitionStyle == SwipeTransitionStyle::Push)
-        [m_swipeLayer setTransform:CATransform3DMakeTranslation((direction == SwipeDirection::Left ? -width : width) + swipingLayerOffset, 0, 0)];
+        [m_swipeLayer setTransform:CATransform3DMakeTranslation((direction == SwipeDirection::Back ? -width : width) + swipingLayerOffset, 0, 0)];
 
     for (const auto& layer : m_currentSwipeLiveLayers) {
         if (m_swipeTransitionStyle == SwipeTransitionStyle::Overlap) {
-            if (direction == SwipeDirection::Left)
+            if (direction == SwipeDirection::Back)
                 [layer setTransform:CATransform3DMakeTranslation(swipingLayerOffset, 0, 0)];
         } else if (m_swipeTransitionStyle == SwipeTransitionStyle::Push)
             [layer setTransform:CATransform3DMakeTranslation(swipingLayerOffset, 0, 0)];