Changeset 206950 in webkit


Ignore:
Timestamp:
Oct 8, 2016 1:31:00 AM (8 years ago)
Author:
timothy_horton@apple.com
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):

Location:
trunk/Source/WebKit2
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit2/ChangeLog

    r206937 r206950  
     12016-10-08  Tim Horton  <timothy_horton@apple.com>
     2
     3        Share more code between iOS and macOS ViewGestureController
     4        https://bugs.webkit.org/show_bug.cgi?id=163158
     5
     6        Reviewed by Simon Fraser.
     7
     8        Share canSwipeInDirection() and the (unused on Mac) alternate back-forward list mechanism.
     9        Make ViewGestureController operate in terms of WebPageProxy, not WKWebView,
     10        because it shouldn't know anything about WKWebView.
     11        Refactor scrollEventCanBecomeSwipe a bit to be less repetitive.
     12
     13        * UIProcess/API/Cocoa/WKWebView.mm:
     14        (-[WKWebView setAllowsBackForwardNavigationGestures:]):
     15        * UIProcess/Cocoa/ViewGestureController.cpp:
     16        (WebKit::ViewGestureController::ViewGestureController):
     17        (WebKit::ViewGestureController::setAlternateBackForwardListSourcePage):
     18        (WebKit::ViewGestureController::canSwipeInDirection):
     19        (WebKit::ViewGestureController::gestureControllerForPage): Deleted.
     20        * UIProcess/Cocoa/ViewGestureController.h:
     21        * UIProcess/WebPageProxy.cpp:
     22        (WebKit::WebPageProxy::WebPageProxy):
     23        * UIProcess/WebPageProxy.h:
     24        (WebKit::WebPageProxy::createWeakPtr):
     25        * UIProcess/ios/ViewGestureControllerIOS.mm:
     26        (WebKit::ViewGestureController::beginSwipeGesture):
     27        (WebKit::ViewGestureController::setAlternateBackForwardListSourceView): Deleted.
     28        (WebKit::ViewGestureController::canSwipeInDirection): Deleted.
     29        * UIProcess/mac/ViewGestureControllerMac.mm:
     30        (WebKit::ViewGestureController::PendingSwipeTracker::PendingSwipeTracker):
     31        (WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanBecomeSwipe):
     32        (WebKit::ViewGestureController::PendingSwipeTracker::tryToStartSwipe):
     33
    1342016-10-07  Anders Carlsson  <andersca@apple.com>
    235
  • trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm

    r206829 r206950  
    21992199            _gestureController = std::make_unique<WebKit::ViewGestureController>(*_page);
    22002200            _gestureController->installSwipeHandler(self, [self scrollView]);
    2201             _gestureController->setAlternateBackForwardListSourceView([_configuration _alternateWebViewForNavigationGestures]);
     2201            _gestureController->setAlternateBackForwardListSourcePage([_configuration _alternateWebViewForNavigationGestures]->_page.get());
    22022202        }
    22032203    } else
  • trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.cpp

    r206936 r206950  
    3030#import "RemoteLayerTreeDrawingAreaProxy.h"
    3131#import "ViewGestureControllerMessages.h"
     32#import "WebBackForwardList.h"
    3233#import "WebPageProxy.h"
    3334#import "WebProcessProxy.h"
     
    6061    , m_swipeActiveLoadMonitoringTimer(RunLoop::main(), this, &ViewGestureController::checkForActiveLoads)
    6162#if PLATFORM(MAC)
    62     , m_pendingSwipeTracker(webPageProxy, std::bind(&ViewGestureController::trackSwipeGesture, this, std::placeholders::_1, std::placeholders::_2))
     63    , m_pendingSwipeTracker(webPageProxy, *this)
    6364#endif
    6465{
     
    8485    return gestureControllerIter->value;
    8586}
     87   
     88void ViewGestureController::setAlternateBackForwardListSourcePage(WebPageProxy* page)
     89{
     90    if (page)
     91        m_alternateBackForwardListSourcePage = page->createWeakPtr();
     92    else
     93        m_alternateBackForwardListSourcePage.clear();
     94}
     95   
     96bool ViewGestureController::canSwipeInDirection(SwipeDirection direction) const
     97{
     98    RefPtr<WebPageProxy> alternateBackForwardListSourcePage = m_alternateBackForwardListSourcePage.get();
     99    auto& backForwardList = alternateBackForwardListSourcePage ? alternateBackForwardListSourcePage->backForwardList() : m_webPageProxy.backForwardList();
     100    if (direction == SwipeDirection::Back)
     101        return !!backForwardList.backItem();
     102    return !!backForwardList.forwardItem();
     103}
     104
    86105
    87106void ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame()
  • trunk/Source/WebKit2/UIProcess/Cocoa/ViewGestureController.h

    r206936 r206950  
    2929#include "MessageReceiver.h"
    3030#include "SameDocumentNavigationType.h"
    31 #include "WeakObjCPtr.h"
    3231#include <WebCore/Color.h>
    3332#include <WebCore/FloatRect.h>
     
    3635#include <wtf/RetainPtr.h>
    3736#include <wtf/RunLoop.h>
    38 
    39 // FIXME: Move this file out of the mac/ subdirectory.
     37#include <wtf/WeakPtr.h>
    4038
    4139OBJC_CLASS CALayer;
     
    4442OBJC_CLASS UIView;
    4543OBJC_CLASS WKSwipeTransitionController;
    46 OBJC_CLASS WKWebView;
    4744OBJC_CLASS _UINavigationInteractiveTransitionBase;
    4845OBJC_CLASS _UIViewControllerOneToOneTransitionContext;
     
    110107#else
    111108    void installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView);
    112     void setAlternateBackForwardListSourceView(WKWebView *);
    113     bool canSwipeInDirection(SwipeDirection);
    114109    void beginSwipeGesture(_UINavigationInteractiveTransitionBase *, SwipeDirection);
    115110    void endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *, bool cancelled);
     
    117112    void setRenderTreeSize(uint64_t);
    118113#endif
     114   
     115    void setAlternateBackForwardListSourcePage(WebPageProxy*);
     116   
     117    bool canSwipeInDirection(SwipeDirection) const;
    119118
    120119    WebCore::Color backgroundColorForCurrentSnapshot() const { return m_backgroundColorForCurrentSnapshot; }
     
    203202    class PendingSwipeTracker {
    204203    public:
    205         PendingSwipeTracker(WebPageProxy&, std::function<void(NSEvent *, SwipeDirection)> trackSwipeCallback);
     204        PendingSwipeTracker(WebPageProxy&, ViewGestureController&);
    206205        bool handleEvent(NSEvent *);
    207206        void eventWasNotHandledByWebCore(NSEvent *);
     
    228227        bool m_shouldIgnorePinnedState { false };
    229228
    230         std::function<void(NSEvent *, SwipeDirection)> m_trackSwipeCallback;
     229        ViewGestureController& m_viewGestureController;
    231230        WebPageProxy& m_webPageProxy;
    232231    };
     
    239238
    240239    WebCore::Color m_backgroundColorForCurrentSnapshot;
     240   
     241    WeakPtr<WebPageProxy> m_alternateBackForwardListSourcePage;
     242    RefPtr<WebPageProxy> m_webPageProxyForBackForwardListForCurrentSwipe;
    241243
    242244#if PLATFORM(MAC)
     
    278280    RetainPtr<_UIViewControllerOneToOneTransitionContext> m_swipeTransitionContext;
    279281    uint64_t m_snapshotRemovalTargetRenderTreeSize { 0 };
    280     WeakObjCPtr<WKWebView> m_alternateBackForwardListSourceView;
    281     RefPtr<WebPageProxy> m_webPageProxyForBackForwardListForCurrentSwipe;
    282282    uint64_t m_gesturePendingSnapshotRemoval { 0 };
    283283#endif
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp

    r206929 r206950  
    451451    , m_potentiallyChangedViewStateFlags(ViewState::NoFlags)
    452452    , m_viewStateChangeWantsSynchronousReply(false)
     453    , m_weakPtrFactory(this)
    453454{
    454455    m_webProcessLifetimeTracker.addObserver(m_visitedLinkStore);
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r206937 r206950  
    11301130    void gamepadActivity(const Vector<GamepadData>&);
    11311131#endif
     1132       
     1133    WeakPtr<WebPageProxy> createWeakPtr() const { return m_weakPtrFactory.createWeakPtr(); }
    11321134
    11331135private:
     
    18901892    bool m_syncNavigationActionHasDownloadAttribute { false };
    18911893#endif
     1894       
     1895    WeakPtrFactory<WebPageProxy> m_weakPtrFactory;
    18921896};
    18931897
  • trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm

    r206833 r206950  
    3535#import "WKBackForwardListItemInternal.h"
    3636#import "WKWebViewInternal.h"
     37#import "WeakObjCPtr.h"
    3738#import "WebBackForwardList.h"
    3839#import "WebPageGroup.h"
     
    141142}
    142143
    143 void ViewGestureController::setAlternateBackForwardListSourceView(WKWebView *view)
    144 {
    145     m_alternateBackForwardListSourceView = view;
    146 }
    147 
    148144void ViewGestureController::installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView)
    149145{
     
    160156    m_webPageProxy.recordAutomaticNavigationSnapshot();
    161157
    162     m_webPageProxyForBackForwardListForCurrentSwipe = m_alternateBackForwardListSourceView.get() ? m_alternateBackForwardListSourceView.get()->_page : &m_webPageProxy;
     158    RefPtr<WebPageProxy> alternateBackForwardListSourcePage = m_alternateBackForwardListSourcePage.get();
     159    m_webPageProxyForBackForwardListForCurrentSwipe = alternateBackForwardListSourcePage ? alternateBackForwardListSourcePage.get() : &m_webPageProxy;
     160
    163161    m_webPageProxyForBackForwardListForCurrentSwipe->navigationGestureDidBegin();
    164162    if (&m_webPageProxy != m_webPageProxyForBackForwardListForCurrentSwipe)
     
    240238}
    241239
    242 bool ViewGestureController::canSwipeInDirection(SwipeDirection direction)
    243 {
    244     auto& backForwardList = m_alternateBackForwardListSourceView.get() ? m_alternateBackForwardListSourceView.get()->_page->backForwardList() : m_webPageProxy.backForwardList();
    245     if (direction == SwipeDirection::Back)
    246         return !!backForwardList.backItem();
    247     return !!backForwardList.forwardItem();
    248 }
    249 
    250240void ViewGestureController::endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *context, bool cancelled)
    251241{
  • trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm

    r206930 r206950  
    273273}
    274274
    275 ViewGestureController::PendingSwipeTracker::PendingSwipeTracker(WebPageProxy& webPageProxy, std::function<void(NSEvent *, SwipeDirection)> trackSwipeCallback)
    276     : m_trackSwipeCallback(WTFMove(trackSwipeCallback))
     275ViewGestureController::PendingSwipeTracker::PendingSwipeTracker(WebPageProxy& webPageProxy, ViewGestureController& viewGestureController)
     276    : m_viewGestureController(viewGestureController)
    277277    , m_webPageProxy(webPageProxy)
    278278{
     
    293293    bool isPinnedToRight = m_shouldIgnorePinnedState || m_webPageProxy.isPinnedToRightSide();
    294294
    295     bool willSwipeBack = false;
    296     bool willSwipeForward = false;
    297     if (m_webPageProxy.userInterfaceLayoutDirection() == WebCore::UserInterfaceLayoutDirection::LTR) {
    298         willSwipeBack = event.scrollingDeltaX > 0 && isPinnedToLeft && m_webPageProxy.backForwardList().backItem();
    299         willSwipeForward = event.scrollingDeltaX < 0 && isPinnedToRight && m_webPageProxy.backForwardList().forwardItem();
    300     } else {
    301         willSwipeBack = event.scrollingDeltaX < 0 && isPinnedToRight && m_webPageProxy.backForwardList().backItem();
    302         willSwipeForward = event.scrollingDeltaX > 0 && isPinnedToLeft && m_webPageProxy.backForwardList().forwardItem();
    303     }
    304     if (!willSwipeBack && !willSwipeForward)
    305         return false;
    306 
    307     potentialSwipeDirection = willSwipeBack ? ViewGestureController::SwipeDirection::Back : ViewGestureController::SwipeDirection::Forward;
    308 
    309     return true;
     295    bool tryingToSwipeBack = event.scrollingDeltaX > 0 && isPinnedToLeft;
     296    bool tryingToSwipeForward = event.scrollingDeltaX < 0 && isPinnedToRight;
     297    if (m_webPageProxy.userInterfaceLayoutDirection() != WebCore::UserInterfaceLayoutDirection::LTR)
     298        std::swap(tryingToSwipeBack, tryingToSwipeForward);
     299   
     300    if (!tryingToSwipeBack && !tryingToSwipeForward)
     301        return false;
     302
     303    potentialSwipeDirection = tryingToSwipeBack ? SwipeDirection::Back : SwipeDirection::Forward;
     304    return m_viewGestureController.canSwipeInDirection(potentialSwipeDirection);
    310305}
    311306
     
    373368
    374369    if (std::abs(m_cumulativeDelta.width()) >= minimumHorizontalSwipeDistance)
    375         m_trackSwipeCallback(event, m_direction);
     370        m_viewGestureController.trackSwipeGesture(event, m_direction);
    376371    else
    377372        m_state = State::InsufficientMagnitude;
Note: See TracChangeset for help on using the changeset viewer.