Title: [206986] trunk/Source/WebKit2
Revision
206986
Author
timothy_hor...@apple.com
Date
2016-10-10 00:13:32 -0700 (Mon, 10 Oct 2016)

Log Message

Share more code between iOS and macOS ViewGestureController
https://bugs.webkit.org/show_bug.cgi?id=163158

Reviewed by Simon Fraser.

Share canSwipeInDirection() and the (unused on Mac) alternate back-forward list mechanism.
Make ViewGestureController operate in terms of WebPageProxy, not WKWebView,
because it shouldn't know anything about WKWebView.
Refactor scrollEventCanBecomeSwipe a bit to be less repetitive.

* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView setAllowsBackForwardNavigationGestures:]):
* UIProcess/Cocoa/ViewGestureController.cpp:
(WebKit::ViewGestureController::ViewGestureController):
(WebKit::ViewGestureController::setAlternateBackForwardListSourcePage):
(WebKit::ViewGestureController::canSwipeInDirection):
(WebKit::ViewGestureController::gestureControllerForPage): Deleted.
* UIProcess/Cocoa/ViewGestureController.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::createWeakPtr):
* UIProcess/ios/ViewGestureControllerIOS.mm:
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::setAlternateBackForwardListSourceView): Deleted.
(WebKit::ViewGestureController::canSwipeInDirection): Deleted.
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::PendingSwipeTracker::PendingSwipeTracker):
(WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanBecomeSwipe):
(WebKit::ViewGestureController::PendingSwipeTracker::tryToStartSwipe):

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (206985 => 206986)


--- trunk/Source/WebKit2/ChangeLog	2016-10-10 07:12:35 UTC (rev 206985)
+++ trunk/Source/WebKit2/ChangeLog	2016-10-10 07:13:32 UTC (rev 206986)
@@ -1,3 +1,36 @@
+2016-10-10  Tim Horton  <timothy_hor...@apple.com>
+
+        Share more code between iOS and macOS ViewGestureController
+        https://bugs.webkit.org/show_bug.cgi?id=163158
+
+        Reviewed by Simon Fraser.
+
+        Share canSwipeInDirection() and the (unused on Mac) alternate back-forward list mechanism.
+        Make ViewGestureController operate in terms of WebPageProxy, not WKWebView,
+        because it shouldn't know anything about WKWebView.
+        Refactor scrollEventCanBecomeSwipe a bit to be less repetitive.
+
+        * UIProcess/API/Cocoa/WKWebView.mm:
+        (-[WKWebView setAllowsBackForwardNavigationGestures:]):
+        * UIProcess/Cocoa/ViewGestureController.cpp:
+        (WebKit::ViewGestureController::ViewGestureController):
+        (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage):
+        (WebKit::ViewGestureController::canSwipeInDirection):
+        (WebKit::ViewGestureController::gestureControllerForPage): Deleted.
+        * UIProcess/Cocoa/ViewGestureController.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::WebPageProxy):
+        * UIProcess/WebPageProxy.h:
+        (WebKit::WebPageProxy::createWeakPtr):
+        * UIProcess/ios/ViewGestureControllerIOS.mm:
+        (WebKit::ViewGestureController::beginSwipeGesture):
+        (WebKit::ViewGestureController::setAlternateBackForwardListSourceView): Deleted.
+        (WebKit::ViewGestureController::canSwipeInDirection): Deleted.
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::PendingSwipeTracker::PendingSwipeTracker):
+        (WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanBecomeSwipe):
+        (WebKit::ViewGestureController::PendingSwipeTracker::tryToStartSwipe):
+
 2016-10-10  Tomas Popela  <tpop...@redhat.com>
 
         [GTK] UIProcess crashes when using Japanese IM

Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (206985 => 206986)


--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-10-10 07:12:35 UTC (rev 206985)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm	2016-10-10 07:13:32 UTC (rev 206986)
@@ -2198,7 +2198,8 @@
         if (!_gestureController) {
             _gestureController = std::make_unique<WebKit::ViewGestureController>(*_page);
             _gestureController->installSwipeHandler(self, [self scrollView]);
-            _gestureController->setAlternateBackForwardListSourceView([_configuration _alternateWebViewForNavigationGestures]);
+            if (WKWebView *alternateWebView = [_configuration _alternateWebViewForNavigationGestures])
+                _gestureController->setAlternateBackForwardListSourcePage(alternateWebView->_page.get());
         }
     } else
         _gestureController = nullptr;

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.cpp (206985 => 206986)


--- trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.cpp	2016-10-10 07:12:35 UTC (rev 206985)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.cpp	2016-10-10 07:13:32 UTC (rev 206986)
@@ -29,6 +29,7 @@
 #import "Logging.h"
 #import "RemoteLayerTreeDrawingAreaProxy.h"
 #import "ViewGestureControllerMessages.h"
+#import "WebBackForwardList.h"
 #import "WebPageProxy.h"
 #import "WebProcessProxy.h"
 #import <wtf/MathExtras.h>
@@ -59,7 +60,7 @@
     : m_webPageProxy(webPageProxy)
     , m_swipeActiveLoadMonitoringTimer(RunLoop::main(), this, &ViewGestureController::checkForActiveLoads)
 #if PLATFORM(MAC)
-    , m_pendingSwipeTracker(webPageProxy, std::bind(&ViewGestureController::trackSwipeGesture, this, std::placeholders::_1, std::placeholders::_2))
+    , m_pendingSwipeTracker(webPageProxy, *this)
 #endif
 {
     m_webPageProxy.process().addMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID(), *this);
@@ -83,7 +84,25 @@
         return nullptr;
     return gestureControllerIter->value;
 }
+    
+void ViewGestureController::setAlternateBackForwardListSourcePage(WebPageProxy* page)
+{
+    if (page)
+        m_alternateBackForwardListSourcePage = page->createWeakPtr();
+    else
+        m_alternateBackForwardListSourcePage.clear();
+}
+    
+bool ViewGestureController::canSwipeInDirection(SwipeDirection direction) const
+{
+    RefPtr<WebPageProxy> alternateBackForwardListSourcePage = m_alternateBackForwardListSourcePage.get();
+    auto& backForwardList = alternateBackForwardListSourcePage ? alternateBackForwardListSourcePage->backForwardList() : m_webPageProxy.backForwardList();
+    if (direction == SwipeDirection::Back)
+        return !!backForwardList.backItem();
+    return !!backForwardList.forwardItem();
+}
 
+
 void ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame()
 {
     if (!m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::VisuallyNonEmptyLayout))

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.h (206985 => 206986)


--- trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.h	2016-10-10 07:12:35 UTC (rev 206985)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.h	2016-10-10 07:13:32 UTC (rev 206986)
@@ -28,7 +28,6 @@
 
 #include "MessageReceiver.h"
 #include "SameDocumentNavigationType.h"
-#include "WeakObjCPtr.h"
 #include <WebCore/Color.h>
 #include <WebCore/FloatRect.h>
 #include <chrono>
@@ -35,15 +34,13 @@
 #include <wtf/BlockPtr.h>
 #include <wtf/RetainPtr.h>
 #include <wtf/RunLoop.h>
+#include <wtf/WeakPtr.h>
 
-// FIXME: Move this file out of the mac/ subdirectory.
-
 OBJC_CLASS CALayer;
 
 #if PLATFORM(IOS)
 OBJC_CLASS UIView;
 OBJC_CLASS WKSwipeTransitionController;
-OBJC_CLASS WKWebView;
 OBJC_CLASS _UINavigationInteractiveTransitionBase;
 OBJC_CLASS _UIViewControllerOneToOneTransitionContext;
 OBJC_CLASS _UIViewControllerTransitionContext;
@@ -109,13 +106,15 @@
     bool isPhysicallySwipingLeft(SwipeDirection) const;
 #else
     void installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView);
-    void setAlternateBackForwardListSourceView(WKWebView *);
-    bool canSwipeInDirection(SwipeDirection);
     void beginSwipeGesture(_UINavigationInteractiveTransitionBase *, SwipeDirection);
     void endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *, bool cancelled);
     void willCommitPostSwipeTransitionLayerTree(bool);
     void setRenderTreeSize(uint64_t);
 #endif
+    
+    void setAlternateBackForwardListSourcePage(WebPageProxy*);
+    
+    bool canSwipeInDirection(SwipeDirection) const;
 
     WebCore::Color backgroundColorForCurrentSnapshot() const { return m_backgroundColorForCurrentSnapshot; }
 
@@ -202,7 +201,7 @@
 
     class PendingSwipeTracker {
     public:
-        PendingSwipeTracker(WebPageProxy&, std::function<void(NSEvent *, SwipeDirection)> trackSwipeCallback);
+        PendingSwipeTracker(WebPageProxy&, ViewGestureController&);
         bool handleEvent(NSEvent *);
         void eventWasNotHandledByWebCore(NSEvent *);
 
@@ -227,7 +226,7 @@
 
         bool m_shouldIgnorePinnedState { false };
 
-        std::function<void(NSEvent *, SwipeDirection)> m_trackSwipeCallback;
+        ViewGestureController& m_viewGestureController;
         WebPageProxy& m_webPageProxy;
     };
 #endif
@@ -238,6 +237,9 @@
     RunLoop::Timer<ViewGestureController> m_swipeActiveLoadMonitoringTimer;
 
     WebCore::Color m_backgroundColorForCurrentSnapshot;
+    
+    WeakPtr<WebPageProxy> m_alternateBackForwardListSourcePage;
+    RefPtr<WebPageProxy> m_webPageProxyForBackForwardListForCurrentSwipe;
 
 #if PLATFORM(MAC)
     RefPtr<ViewSnapshot> m_currentSwipeSnapshot;
@@ -277,8 +279,6 @@
     RetainPtr<WKSwipeTransitionController> m_swipeInteractiveTransitionDelegate;
     RetainPtr<_UIViewControllerOneToOneTransitionContext> m_swipeTransitionContext;
     uint64_t m_snapshotRemovalTargetRenderTreeSize { 0 };
-    WeakObjCPtr<WKWebView> m_alternateBackForwardListSourceView;
-    RefPtr<WebPageProxy> m_webPageProxyForBackForwardListForCurrentSwipe;
     uint64_t m_gesturePendingSnapshotRemoval { 0 };
 #endif
 

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (206985 => 206986)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-10-10 07:12:35 UTC (rev 206985)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp	2016-10-10 07:13:32 UTC (rev 206986)
@@ -450,6 +450,7 @@
     , m_configurationPreferenceValues(m_configuration->preferenceValues())
     , m_potentiallyChangedViewStateFlags(ViewState::NoFlags)
     , m_viewStateChangeWantsSynchronousReply(false)
+    , m_weakPtrFactory(this)
 {
     m_webProcessLifetimeTracker.addObserver(m_visitedLinkStore);
     m_webProcessLifetimeTracker.addObserver(m_websiteDataStore);

Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (206985 => 206986)


--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-10-10 07:12:35 UTC (rev 206985)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h	2016-10-10 07:13:32 UTC (rev 206986)
@@ -1129,6 +1129,8 @@
 #if ENABLE(GAMEPAD)
     void gamepadActivity(const Vector<GamepadData>&);
 #endif
+        
+    WeakPtr<WebPageProxy> createWeakPtr() const { return m_weakPtrFactory.createWeakPtr(); }
 
 private:
     WebPageProxy(PageClient&, WebProcessProxy&, uint64_t pageID, Ref<API::PageConfiguration>&&);
@@ -1889,6 +1891,8 @@
 #if ENABLE(DOWNLOAD_ATTRIBUTE)
     bool m_syncNavigationActionHasDownloadAttribute { false };
 #endif
+        
+    WeakPtrFactory<WebPageProxy> m_weakPtrFactory;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm (206985 => 206986)


--- trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm	2016-10-10 07:12:35 UTC (rev 206985)
+++ trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm	2016-10-10 07:13:32 UTC (rev 206986)
@@ -34,6 +34,7 @@
 #import "ViewSnapshotStore.h"
 #import "WKBackForwardListItemInternal.h"
 #import "WKWebViewInternal.h"
+#import "WeakObjCPtr.h"
 #import "WebBackForwardList.h"
 #import "WebPageGroup.h"
 #import "WebPageMessages.h"
@@ -140,11 +141,6 @@
     [m_swipeInteractiveTransitionDelegate invalidate];
 }
 
-void ViewGestureController::setAlternateBackForwardListSourceView(WKWebView *view)
-{
-    m_alternateBackForwardListSourceView = view;
-}
-
 void ViewGestureController::installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView)
 {
     ASSERT(!m_swipeInteractiveTransitionDelegate);
@@ -159,7 +155,9 @@
 
     m_webPageProxy.recordAutomaticNavigationSnapshot();
 
-    m_webPageProxyForBackForwardListForCurrentSwipe = m_alternateBackForwardListSourceView.get() ? m_alternateBackForwardListSourceView.get()->_page : &m_webPageProxy;
+    RefPtr<WebPageProxy> alternateBackForwardListSourcePage = m_alternateBackForwardListSourcePage.get();
+    m_webPageProxyForBackForwardListForCurrentSwipe = alternateBackForwardListSourcePage ? alternateBackForwardListSourcePage.get() : &m_webPageProxy;
+
     m_webPageProxyForBackForwardListForCurrentSwipe->navigationGestureDidBegin();
     if (&m_webPageProxy != m_webPageProxyForBackForwardListForCurrentSwipe)
         m_webPageProxy.navigationGestureDidBegin();
@@ -239,14 +237,6 @@
     m_activeGestureType = ViewGestureType::Swipe;
 }
 
-bool ViewGestureController::canSwipeInDirection(SwipeDirection direction)
-{
-    auto& backForwardList = m_alternateBackForwardListSourceView.get() ? m_alternateBackForwardListSourceView.get()->_page->backForwardList() : m_webPageProxy.backForwardList();
-    if (direction == SwipeDirection::Back)
-        return !!backForwardList.backItem();
-    return !!backForwardList.forwardItem();
-}
-
 void ViewGestureController::endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *context, bool cancelled)
 {
     [context _setTransitionIsInFlight:NO];

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm (206985 => 206986)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2016-10-10 07:12:35 UTC (rev 206985)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2016-10-10 07:13:32 UTC (rev 206986)
@@ -272,8 +272,8 @@
     return std::abs(y) >= std::abs(x) * minimumScrollEventRatioForSwipe;
 }
 
-ViewGestureController::PendingSwipeTracker::PendingSwipeTracker(WebPageProxy& webPageProxy, std::function<void(NSEvent *, SwipeDirection)> trackSwipeCallback)
-    : m_trackSwipeCallback(WTFMove(trackSwipeCallback))
+ViewGestureController::PendingSwipeTracker::PendingSwipeTracker(WebPageProxy& webPageProxy, ViewGestureController& viewGestureController)
+    : m_viewGestureController(viewGestureController)
     , m_webPageProxy(webPageProxy)
 {
 }
@@ -292,21 +292,16 @@
     bool isPinnedToLeft = m_shouldIgnorePinnedState || m_webPageProxy.isPinnedToLeftSide();
     bool isPinnedToRight = m_shouldIgnorePinnedState || m_webPageProxy.isPinnedToRightSide();
 
-    bool willSwipeBack = false;
-    bool willSwipeForward = false;
-    if (m_webPageProxy.userInterfaceLayoutDirection() == WebCore::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)
+    bool tryingToSwipeBack = event.scrollingDeltaX > 0 && isPinnedToLeft;
+    bool tryingToSwipeForward = event.scrollingDeltaX < 0 && isPinnedToRight;
+    if (m_webPageProxy.userInterfaceLayoutDirection() != WebCore::UserInterfaceLayoutDirection::LTR)
+        std::swap(tryingToSwipeBack, tryingToSwipeForward);
+    
+    if (!tryingToSwipeBack && !tryingToSwipeForward)
         return false;
 
-    potentialSwipeDirection = willSwipeBack ? ViewGestureController::SwipeDirection::Back : ViewGestureController::SwipeDirection::Forward;
-
-    return true;
+    potentialSwipeDirection = tryingToSwipeBack ? SwipeDirection::Back : SwipeDirection::Forward;
+    return m_viewGestureController.canSwipeInDirection(potentialSwipeDirection);
 }
 
 bool ViewGestureController::handleScrollWheelEvent(NSEvent *event)
@@ -372,7 +367,7 @@
     }
 
     if (std::abs(m_cumulativeDelta.width()) >= minimumHorizontalSwipeDistance)
-        m_trackSwipeCallback(event, m_direction);
+        m_viewGestureController.trackSwipeGesture(event, m_direction);
     else
         m_state = State::InsufficientMagnitude;
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to