Provide a mechanism through the legacy SPI to know when swipe gestures begin and end
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Apr 2015 18:31:00 +0000 (18:31 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Apr 2015 18:31:00 +0000 (18:31 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143740
<rdar://problem/20468540>

Reviewed by Dan Bernstein.

In the C SPI, add three WKPageLoaderClient callbacks for the three
navigation gesture events (did begin, will end, did end).

* UIProcess/API/C/WKPageLoaderClient.h:
Add the callbacks.

* UIProcess/API/APILoaderClient.h:
(API::LoaderClient::navigationGestureDidBegin):
(API::LoaderClient::navigationGestureWillEnd):
(API::LoaderClient::navigationGestureDidEnd):
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::navigationGestureDidBegin):
(WebKit::WebPageProxy::navigationGestureWillEnd):
(WebKit::WebPageProxy::navigationGestureDidEnd):
Dispatch navigation gesture events to the loader client as well as
(after a bounce through the PageClient) the navigation delegate.

* UIProcess/API/C/WKPage.cpp:
(WKPageSetPageLoaderClient):
Call the callbacks.

* UIProcess/mac/ViewGestureController.h:
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::trackSwipeGesture):
(WebKit::ViewGestureController::willEndSwipeGesture):
While we were already informing WebPageProxy of 'did begin' and 'did end'
navigation gesture events, we were missing 'will end'. Add it.

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

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/APILoaderClient.h
Source/WebKit2/UIProcess/API/C/WKPage.cpp
Source/WebKit2/UIProcess/API/C/WKPageLoaderClient.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/mac/ViewGestureController.h
Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm

index a8557be..7c22759 100644 (file)
@@ -1,3 +1,39 @@
+2015-04-16  Timothy Horton  <timothy_horton@apple.com>
+
+        Provide a mechanism through the legacy SPI to know when swipe gestures begin and end
+        https://bugs.webkit.org/show_bug.cgi?id=143740
+        <rdar://problem/20468540>
+
+        Reviewed by Dan Bernstein.
+
+        In the C SPI, add three WKPageLoaderClient callbacks for the three
+        navigation gesture events (did begin, will end, did end).
+
+        * UIProcess/API/C/WKPageLoaderClient.h:
+        Add the callbacks.
+
+        * UIProcess/API/APILoaderClient.h:
+        (API::LoaderClient::navigationGestureDidBegin):
+        (API::LoaderClient::navigationGestureWillEnd):
+        (API::LoaderClient::navigationGestureDidEnd):
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::navigationGestureDidBegin):
+        (WebKit::WebPageProxy::navigationGestureWillEnd):
+        (WebKit::WebPageProxy::navigationGestureDidEnd):
+        Dispatch navigation gesture events to the loader client as well as
+        (after a bounce through the PageClient) the navigation delegate.
+
+        * UIProcess/API/C/WKPage.cpp:
+        (WKPageSetPageLoaderClient):
+        Call the callbacks.
+
+        * UIProcess/mac/ViewGestureController.h:
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::trackSwipeGesture):
+        (WebKit::ViewGestureController::willEndSwipeGesture):
+        While we were already informing WebPageProxy of 'did begin' and 'did end'
+        navigation gesture events, we were missing 'will end'. Add it.
+
 2015-04-16  Tim Horton  <timothy_horton@apple.com>
 
         Dispatching multiple asynchronous animated resizes in parallel causes page scale to detach from reality
index 3858d55..e45886a 100644 (file)
@@ -102,6 +102,10 @@ public:
     virtual void didPerformServerRedirect(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { }
     virtual void didUpdateHistoryTitle(WebKit::WebPageProxy&, const WTF::String&, const WTF::String&, WebKit::WebFrameProxy&) { }
 
+    virtual void navigationGestureDidBegin(WebKit::WebPageProxy&) { }
+    virtual void navigationGestureWillEnd(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { }
+    virtual void navigationGestureDidEnd(WebKit::WebPageProxy&, bool willNavigate, WebKit::WebBackForwardListItem&) { }
+
 #if ENABLE(NETSCAPE_PLUGIN_API)
     virtual WebKit::PluginModuleLoadPolicy pluginLoadPolicy(WebKit::WebPageProxy&, WebKit::PluginModuleLoadPolicy currentPluginLoadPolicy, API::Dictionary*, WTF::String& /* unavailabilityDescription */) { return currentPluginLoadPolicy; }
     virtual void didFailToInitializePlugin(WebKit::WebPageProxy&, API::Dictionary*) { }
index c049963..d278282 100644 (file)
@@ -83,7 +83,7 @@ using namespace WebKit;
 
 namespace API {
 template<> struct ClientTraits<WKPageLoaderClientBase> {
-    typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5> Versions;
+    typedef std::tuple<WKPageLoaderClientV0, WKPageLoaderClientV1, WKPageLoaderClientV2, WKPageLoaderClientV3, WKPageLoaderClientV4, WKPageLoaderClientV5, WKPageLoaderClientV6> Versions;
 };
 
 template<> struct ClientTraits<WKPageNavigationClientBase> {
@@ -1138,6 +1138,24 @@ void WKPageSetPageLoaderClient(WKPageRef pageRef, const WKPageLoaderClientBase*
             return page.process().processPool().client().copyWebCryptoMasterKey(&page.process().processPool());
         }
 
+        virtual void navigationGestureDidBegin(WebPageProxy& page) override
+        {
+            if (m_client.navigationGestureDidBegin)
+                m_client.navigationGestureDidBegin(toAPI(&page), m_client.base.clientInfo);
+        }
+
+        virtual void navigationGestureWillEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
+        {
+            if (m_client.navigationGestureWillEnd)
+                m_client.navigationGestureWillEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
+        }
+
+        virtual void navigationGestureDidEnd(WebPageProxy& page, bool willNavigate, WebBackForwardListItem& item) override
+        {
+            if (m_client.navigationGestureDidEnd)
+                m_client.navigationGestureDidEnd(toAPI(&page), willNavigate, toAPI(&item), m_client.base.clientInfo);
+        }
+
 #if ENABLE(NETSCAPE_PLUGIN_API)
         virtual void didFailToInitializePlugin(WebPageProxy& page, API::Dictionary* pluginInformation) override
         {
index 3b32432..a45b8ce 100644 (file)
@@ -68,6 +68,9 @@ typedef void (*WKPageDidLayoutCallback)(WKPageRef page, WKLayoutMilestones miles
 typedef WKPluginLoadPolicy (*WKPagePluginLoadPolicyCallback)(WKPageRef page, WKPluginLoadPolicy currentPluginLoadPolicy, WKDictionaryRef pluginInfoDictionary, WKStringRef* unavailabilityDescription, const void* clientInfo);
 typedef void (*WKPagePluginDidFailCallback)(WKPageRef page, uint32_t errorCode, WKDictionaryRef pluginInfoDictionary, const void* clientInfo);
 typedef WKWebGLLoadPolicy (*WKPageWebGLLoadPolicyCallback)(WKPageRef page, WKStringRef url, const void* clientInfo);
+typedef void (*WKPageNavigationGestureDidBeginCallback)(WKPageRef page, const void* clientInfo);
+typedef void (*WKPageNavigationGestureWillEndCallback)(WKPageRef page, bool willNavigate, WKBackForwardListItemRef item, const void* clientInfo);
+typedef void (*WKPageNavigationGestureDidEndCallback)(WKPageRef page, bool willNavigate, WKBackForwardListItemRef item, const void* clientInfo);
 
 // Deprecated
 typedef void (*WKPageDidFailToInitializePluginCallback_deprecatedForUseWithV0)(WKPageRef page, WKStringRef mimeType, const void* clientInfo);
@@ -391,6 +394,74 @@ typedef struct WKPageLoaderClientV5 {
     WKPageShouldKeepCurrentBackForwardListItemInListCallback            shouldKeepCurrentBackForwardListItemInList;
 } WKPageLoaderClientV5;
 
+typedef struct WKPageLoaderClientV6 {
+    WKPageLoaderClientBase                                              base;
+
+    // Version 0.
+    WKPageDidStartProvisionalLoadForFrameCallback                       didStartProvisionalLoadForFrame;
+    WKPageDidReceiveServerRedirectForProvisionalLoadForFrameCallback    didReceiveServerRedirectForProvisionalLoadForFrame;
+    WKPageDidFailProvisionalLoadWithErrorForFrameCallback               didFailProvisionalLoadWithErrorForFrame;
+    WKPageDidCommitLoadForFrameCallback                                 didCommitLoadForFrame;
+    WKPageDidFinishDocumentLoadForFrameCallback                         didFinishDocumentLoadForFrame;
+    WKPageDidFinishLoadForFrameCallback                                 didFinishLoadForFrame;
+    WKPageDidFailLoadWithErrorForFrameCallback                          didFailLoadWithErrorForFrame;
+    WKPageDidSameDocumentNavigationForFrameCallback                     didSameDocumentNavigationForFrame;
+    WKPageDidReceiveTitleForFrameCallback                               didReceiveTitleForFrame;
+    WKPageDidFirstLayoutForFrameCallback                                didFirstLayoutForFrame;
+    WKPageDidFirstVisuallyNonEmptyLayoutForFrameCallback                didFirstVisuallyNonEmptyLayoutForFrame;
+    WKPageDidRemoveFrameFromHierarchyCallback                           didRemoveFrameFromHierarchy;
+    WKPageDidDisplayInsecureContentForFrameCallback                     didDisplayInsecureContentForFrame;
+    WKPageDidRunInsecureContentForFrameCallback                         didRunInsecureContentForFrame;
+    WKPageCanAuthenticateAgainstProtectionSpaceInFrameCallback          canAuthenticateAgainstProtectionSpaceInFrame;
+    WKPageDidReceiveAuthenticationChallengeInFrameCallback              didReceiveAuthenticationChallengeInFrame;
+
+    // FIXME: Move to progress client.
+    WKPageLoaderClientCallback                                          didStartProgress;
+    WKPageLoaderClientCallback                                          didChangeProgress;
+    WKPageLoaderClientCallback                                          didFinishProgress;
+
+    // FIXME: These three functions should not be part of this client.
+    WKPageLoaderClientCallback                                          processDidBecomeUnresponsive;
+    WKPageLoaderClientCallback                                          processDidBecomeResponsive;
+    WKPageLoaderClientCallback                                          processDidCrash;
+    WKPageDidChangeBackForwardListCallback                              didChangeBackForwardList;
+    WKPageShouldGoToBackForwardListItemCallback                         shouldGoToBackForwardListItem;
+    WKPageDidFailToInitializePluginCallback_deprecatedForUseWithV0      didFailToInitializePlugin_deprecatedForUseWithV0;
+
+    // Version 1.
+    WKPageDidDetectXSSForFrameCallback                                  didDetectXSSForFrame;
+
+    void*                                                               didNewFirstVisuallyNonEmptyLayout_unavailable;
+
+    WKPageWillGoToBackForwardListItemCallback                           willGoToBackForwardListItem;
+
+    WKPageLoaderClientCallback                                          interactionOccurredWhileProcessUnresponsive;
+    WKPagePluginDidFailCallback_deprecatedForUseWithV1                  pluginDidFail_deprecatedForUseWithV1;
+
+    // Version 2.
+    void                                                                (*didReceiveIntentForFrame_unavailable)(void);
+    void                                                                (*registerIntentServiceForFrame_unavailable)(void);
+
+    WKPageDidLayoutCallback                                             didLayout;
+    WKPagePluginLoadPolicyCallback_deprecatedForUseWithV2               pluginLoadPolicy_deprecatedForUseWithV2;
+    WKPagePluginDidFailCallback                                         pluginDidFail;
+
+    // Version 3.
+    WKPagePluginLoadPolicyCallback                                      pluginLoadPolicy;
+
+    // Version 4.
+    WKPageWebGLLoadPolicyCallback                                       webGLLoadPolicy;
+    WKPageWebGLLoadPolicyCallback                                       resolveWebGLLoadPolicy;
+    
+    // Version 5.
+    WKPageShouldKeepCurrentBackForwardListItemInListCallback            shouldKeepCurrentBackForwardListItemInList;
+
+    // Version 6.
+    WKPageNavigationGestureDidBeginCallback                             navigationGestureDidBegin;
+    WKPageNavigationGestureWillEndCallback                              navigationGestureWillEnd;
+    WKPageNavigationGestureDidEndCallback                               navigationGestureDidEnd;
+} WKPageLoaderClientV6;
+
 // FIXME: These should be deprecated.
 enum { kWKPageLoaderClientCurrentVersion WK_ENUM_DEPRECATED("Use an explicit version number instead") = 3 };
 typedef struct WKPageLoaderClient {
index 1e0bd36..d78ae45 100644 (file)
@@ -5618,16 +5618,19 @@ void WebPageProxy::navigationGestureDidBegin()
 {
     m_isShowingNavigationGestureSnapshot = true;
     m_pageClient.navigationGestureDidBegin();
+    m_loaderClient->navigationGestureDidBegin(*this);
 }
 
 void WebPageProxy::navigationGestureWillEnd(bool willNavigate, WebBackForwardListItem& item)
 {
     m_pageClient.navigationGestureWillEnd(willNavigate, item);
+    m_loaderClient->navigationGestureWillEnd(*this, willNavigate, item);
 }
 
 void WebPageProxy::navigationGestureDidEnd(bool willNavigate, WebBackForwardListItem& item)
 {
     m_pageClient.navigationGestureDidEnd(willNavigate, item);
+    m_loaderClient->navigationGestureDidEnd(*this, willNavigate, item);
 }
 
 void WebPageProxy::willRecordNavigationSnapshot(WebBackForwardListItem& item)
index 307249f..cfca418 100644 (file)
@@ -146,6 +146,7 @@ private:
     void trackSwipeGesture(NSEvent *, SwipeDirection);
     void beginSwipeGesture(WebBackForwardListItem* targetItem, SwipeDirection);
     void handleSwipeGesture(WebBackForwardListItem* targetItem, double progress, SwipeDirection);
+    void willEndSwipeGesture(WebBackForwardListItem& targetItem, bool cancelled);
     void endSwipeGesture(WebBackForwardListItem* targetItem, bool cancelled);
     bool deltaIsSufficientToBeginSwipe(NSEvent *);
     bool scrollEventCanBecomeSwipe(NSEvent *, SwipeDirection&);
index a8a6f49..86630b2 100644 (file)
@@ -417,11 +417,18 @@ void ViewGestureController::trackSwipeGesture(NSEvent *event, SwipeDirection dir
         this->handleSwipeGesture(targetItem.get(), clampedProgress, direction);
         if (phase == NSEventPhaseCancelled)
             swipeCancelled = true;
+        if (phase == NSEventPhaseEnded || phase == NSEventPhaseCancelled)
+            this->willEndSwipeGesture(*targetItem, swipeCancelled);
         if (isComplete)
             this->endSwipeGesture(targetItem.get(), swipeCancelled);
     }];
 }
 
+void ViewGestureController::willEndSwipeGesture(WebBackForwardListItem& targetItem, bool cancelled)
+{
+    m_webPageProxy.navigationGestureWillEnd(!cancelled, targetItem);
+}
+
 FloatRect ViewGestureController::windowRelativeBoundsForCustomSwipeViews() const
 {
     FloatRect swipeArea;