Title: [188521] trunk/Source/WebKit2
Revision
188521
Author
[email protected]
Date
2015-08-16 17:52:50 -0700 (Sun, 16 Aug 2015)

Log Message

Refactor ViewGestureController swipe snapshot removal to be more platform-independent
https://bugs.webkit.org/show_bug.cgi?id=148062

Reviewed by Dan Bernstein.

* Platform/Logging.h:
Add a ViewGestures logging channel.

* UIProcess/ViewGestureController.cpp: Added.
(viewGestureControllersForAllPages):
(WebKit::ViewGestureController::ViewGestureController):
(WebKit::ViewGestureController::~ViewGestureController):
(WebKit::ViewGestureController::gestureControllerForPage):
(WebKit::ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame):
(WebKit::ViewGestureController::didRepaintAfterNavigation):
(WebKit::ViewGestureController::didHitRenderTreeSizeThreshold):
(WebKit::ViewGestureController::didRestoreScrollPosition):
(WebKit::ViewGestureController::didReachMainFrameLoadTerminalState):
(WebKit::ViewGestureController::didSameDocumentNavigationForMainFrame):
(WebKit::ViewGestureController::checkForActiveLoads):
(WebKit::ViewGestureController::SnapshotRemovalTracker::eventsDescription):
(WebKit::ViewGestureController::SnapshotRemovalTracker::SnapshotRemovalTracker):
(WebKit::ViewGestureController::SnapshotRemovalTracker::log):
(WebKit::ViewGestureController::SnapshotRemovalTracker::start):
(WebKit::ViewGestureController::SnapshotRemovalTracker::reset):
(WebKit::ViewGestureController::SnapshotRemovalTracker::eventOccurred):
(WebKit::ViewGestureController::SnapshotRemovalTracker::cancelOutstandingEvent):
(WebKit::ViewGestureController::SnapshotRemovalTracker::fireRemovalCallbackIfPossible):
(WebKit::ViewGestureController::SnapshotRemovalTracker::fireRemovalCallbackImmediately):
(WebKit::ViewGestureController::SnapshotRemovalTracker::watchdogTimerFired):
(WebKit::ViewGestureController::SnapshotRemovalTracker::startWatchdog):
Build a platform-independent SnapshotRemovalTracker, which keeps track of
various events that we wait for before removing the snapshot. This
is constructed from the union of ViewGestureController{IOS, Mac}'s snapshot
removal code, and each platform ViewGestureController can specify which
events to wait for (because this currently differs slightly).

Add logging to SnapshotRemovalTracker to make debugging snapshot removal
issues much easier.

* UIProcess/mac/ViewGestureController.h:
(WebKit::ViewGestureController::backgroundColorForCurrentSnapshot):
(WebKit::ViewGestureController::didFinishLoadForMainFrame):
(WebKit::ViewGestureController::didFailLoadForMainFrame):

* UIProcess/ios/ViewGestureControllerIOS.mm:
(WebKit::ViewGestureController::platformTeardown):
(WebKit::ViewGestureController::beginSwipeGesture):
(WebKit::ViewGestureController::endSwipeGesture):
(WebKit::ViewGestureController::setRenderTreeSize):
(WebKit::ViewGestureController::willCommitPostSwipeTransitionLayerTree):
(WebKit::ViewGestureController::removeSwipeSnapshot):
(viewGestureControllersForAllPages): Deleted.
(WebKit::ViewGestureController::ViewGestureController): Deleted.
(WebKit::ViewGestureController::~ViewGestureController): Deleted.
(WebKit::ViewGestureController::didRestoreScrollPosition): Deleted.
(WebKit::ViewGestureController::mainFrameLoadDidReachTerminalState): Deleted.
(WebKit::ViewGestureController::didSameDocumentNavigationForMainFrame): Deleted.
(WebKit::ViewGestureController::activeLoadMonitoringTimerFired): Deleted.
(WebKit::ViewGestureController::swipeSnapshotWatchdogTimerFired): Deleted.
(WebKit::ViewGestureController::removeSwipeSnapshotIfReady): Deleted.
* UIProcess/mac/ViewGestureControllerMac.mm:
(WebKit::ViewGestureController::platformTeardown):
(WebKit::ViewGestureController::endSwipeGesture):
(WebKit::ViewGestureController::forceRepaintIfNeeded):
(WebKit::ViewGestureController::removeSwipeSnapshot):
(WebKit::ViewGestureController::ViewGestureController): Deleted.
(WebKit::ViewGestureController::~ViewGestureController): Deleted.
(WebKit::ViewGestureController::beginSwipeGesture): Deleted.
(WebKit::ViewGestureController::didHitRenderTreeSizeThreshold): Deleted.
(WebKit::ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame): Deleted.
(WebKit::ViewGestureController::mainFrameLoadDidReachTerminalState): Deleted.
(WebKit::ViewGestureController::didSameDocumentNavigationForMainFrame): Deleted.
(WebKit::ViewGestureController::activeLoadMonitoringTimerFired): Deleted.
(WebKit::ViewGestureController::swipeSnapshotWatchdogTimerFired): Deleted.
(WebKit::ViewGestureController::removeSwipeSnapshotAfterRepaint): Deleted.
Move shareable snapshot removal code to a new platform-independent ViewGestureController file.
Move the ViewGestureController constructor/destructor to the platform-independent file.

* UIProcess/mac/ViewGestureController.messages.in:
* WebKit2.xcodeproj/project.pbxproj:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (188520 => 188521)


--- trunk/Source/WebKit2/ChangeLog	2015-08-16 18:58:48 UTC (rev 188520)
+++ trunk/Source/WebKit2/ChangeLog	2015-08-17 00:52:50 UTC (rev 188521)
@@ -1,3 +1,87 @@
+2015-08-16  Timothy Horton  <[email protected]>
+
+        Refactor ViewGestureController swipe snapshot removal to be more platform-independent
+        https://bugs.webkit.org/show_bug.cgi?id=148062
+
+        Reviewed by Dan Bernstein.
+
+        * Platform/Logging.h:
+        Add a ViewGestures logging channel.
+
+        * UIProcess/ViewGestureController.cpp: Added.
+        (viewGestureControllersForAllPages):
+        (WebKit::ViewGestureController::ViewGestureController):
+        (WebKit::ViewGestureController::~ViewGestureController):
+        (WebKit::ViewGestureController::gestureControllerForPage):
+        (WebKit::ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame):
+        (WebKit::ViewGestureController::didRepaintAfterNavigation):
+        (WebKit::ViewGestureController::didHitRenderTreeSizeThreshold):
+        (WebKit::ViewGestureController::didRestoreScrollPosition):
+        (WebKit::ViewGestureController::didReachMainFrameLoadTerminalState):
+        (WebKit::ViewGestureController::didSameDocumentNavigationForMainFrame):
+        (WebKit::ViewGestureController::checkForActiveLoads):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::eventsDescription):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::SnapshotRemovalTracker):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::log):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::start):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::reset):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::eventOccurred):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::cancelOutstandingEvent):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::fireRemovalCallbackIfPossible):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::fireRemovalCallbackImmediately):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::watchdogTimerFired):
+        (WebKit::ViewGestureController::SnapshotRemovalTracker::startWatchdog):
+        Build a platform-independent SnapshotRemovalTracker, which keeps track of
+        various events that we wait for before removing the snapshot. This
+        is constructed from the union of ViewGestureController{IOS, Mac}'s snapshot
+        removal code, and each platform ViewGestureController can specify which
+        events to wait for (because this currently differs slightly).
+
+        Add logging to SnapshotRemovalTracker to make debugging snapshot removal
+        issues much easier.
+
+        * UIProcess/mac/ViewGestureController.h:
+        (WebKit::ViewGestureController::backgroundColorForCurrentSnapshot):
+        (WebKit::ViewGestureController::didFinishLoadForMainFrame):
+        (WebKit::ViewGestureController::didFailLoadForMainFrame):
+
+        * UIProcess/ios/ViewGestureControllerIOS.mm:
+        (WebKit::ViewGestureController::platformTeardown):
+        (WebKit::ViewGestureController::beginSwipeGesture):
+        (WebKit::ViewGestureController::endSwipeGesture):
+        (WebKit::ViewGestureController::setRenderTreeSize):
+        (WebKit::ViewGestureController::willCommitPostSwipeTransitionLayerTree):
+        (WebKit::ViewGestureController::removeSwipeSnapshot):
+        (viewGestureControllersForAllPages): Deleted.
+        (WebKit::ViewGestureController::ViewGestureController): Deleted.
+        (WebKit::ViewGestureController::~ViewGestureController): Deleted.
+        (WebKit::ViewGestureController::didRestoreScrollPosition): Deleted.
+        (WebKit::ViewGestureController::mainFrameLoadDidReachTerminalState): Deleted.
+        (WebKit::ViewGestureController::didSameDocumentNavigationForMainFrame): Deleted.
+        (WebKit::ViewGestureController::activeLoadMonitoringTimerFired): Deleted.
+        (WebKit::ViewGestureController::swipeSnapshotWatchdogTimerFired): Deleted.
+        (WebKit::ViewGestureController::removeSwipeSnapshotIfReady): Deleted.
+        * UIProcess/mac/ViewGestureControllerMac.mm:
+        (WebKit::ViewGestureController::platformTeardown):
+        (WebKit::ViewGestureController::endSwipeGesture):
+        (WebKit::ViewGestureController::forceRepaintIfNeeded):
+        (WebKit::ViewGestureController::removeSwipeSnapshot):
+        (WebKit::ViewGestureController::ViewGestureController): Deleted.
+        (WebKit::ViewGestureController::~ViewGestureController): Deleted.
+        (WebKit::ViewGestureController::beginSwipeGesture): Deleted.
+        (WebKit::ViewGestureController::didHitRenderTreeSizeThreshold): Deleted.
+        (WebKit::ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame): Deleted.
+        (WebKit::ViewGestureController::mainFrameLoadDidReachTerminalState): Deleted.
+        (WebKit::ViewGestureController::didSameDocumentNavigationForMainFrame): Deleted.
+        (WebKit::ViewGestureController::activeLoadMonitoringTimerFired): Deleted.
+        (WebKit::ViewGestureController::swipeSnapshotWatchdogTimerFired): Deleted.
+        (WebKit::ViewGestureController::removeSwipeSnapshotAfterRepaint): Deleted.
+        Move shareable snapshot removal code to a new platform-independent ViewGestureController file.
+        Move the ViewGestureController constructor/destructor to the platform-independent file.
+
+        * UIProcess/mac/ViewGestureController.messages.in:
+        * WebKit2.xcodeproj/project.pbxproj:
+
 2015-08-11  Andy Estes  <[email protected]>
 
         [Cocoa] Add redirect support to CustomProtocolManager

Modified: trunk/Source/WebKit2/Platform/Logging.h (188520 => 188521)


--- trunk/Source/WebKit2/Platform/Logging.h	2015-08-16 18:58:48 UTC (rev 188520)
+++ trunk/Source/WebKit2/Platform/Logging.h	2015-08-17 00:52:50 UTC (rev 188521)
@@ -54,6 +54,7 @@
     M(SessionState) \
     M(StorageAPI) \
     M(TextInput) \
+    M(ViewGestures) \
 
 #define DECLARE_LOG_CHANNEL(name) \
     extern WTFLogChannel JOIN_LOG_CHANNEL_WITH_PREFIX(LOG_CHANNEL_PREFIX, name);

Added: trunk/Source/WebKit2/UIProcess/ViewGestureController.cpp (0 => 188521)


--- trunk/Source/WebKit2/UIProcess/ViewGestureController.cpp	                        (rev 0)
+++ trunk/Source/WebKit2/UIProcess/ViewGestureController.cpp	2015-08-17 00:52:50 UTC (rev 188521)
@@ -0,0 +1,274 @@
+/*
+ * Copyright (C) 2013-2015 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.
+ */
+
+#import "config.h"
+#import "ViewGestureController.h"
+
+#import "Logging.h"
+#import "ViewGestureControllerMessages.h"
+#import "WebPageProxy.h"
+#import "WebProcessProxy.h"
+#import <wtf/MathExtras.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+static const std::chrono::seconds swipeSnapshotRemovalWatchdogAfterFirstVisuallyNonEmptyLayoutDuration = 3_s;
+static const std::chrono::milliseconds swipeSnapshotRemovalActiveLoadMonitoringInterval = 250_ms;
+
+#if PLATFORM(MAC)
+static const std::chrono::seconds swipeSnapshotRemovalWatchdogDuration = 5_s;
+#else
+static const std::chrono::seconds swipeSnapshotRemovalWatchdogDuration = 3_s;
+#endif
+
+static HashMap<uint64_t, ViewGestureController*>& viewGestureControllersForAllPages()
+{
+    // The key in this map is the associated page ID.
+    static NeverDestroyed<HashMap<uint64_t, ViewGestureController*>> viewGestureControllers;
+    return viewGestureControllers.get();
+}
+
+
+ViewGestureController::ViewGestureController(WebPageProxy& webPageProxy)
+    : m_webPageProxy(webPageProxy)
+    , m_swipeActiveLoadMonitoringTimer(RunLoop::main(), this, &ViewGestureController::checkForActiveLoads)
+{
+    m_webPageProxy.process().addMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID(), *this);
+
+    viewGestureControllersForAllPages().add(webPageProxy.pageID(), this);
+}
+
+ViewGestureController::~ViewGestureController()
+{
+    platformTeardown();
+
+    viewGestureControllersForAllPages().remove(m_webPageProxy.pageID());
+
+    m_webPageProxy.process().removeMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID());
+}
+
+ViewGestureController* ViewGestureController::gestureControllerForPage(uint64_t pageID)
+{
+    auto gestureControllerIter = viewGestureControllersForAllPages().find(pageID);
+    if (gestureControllerIter == viewGestureControllersForAllPages().end())
+        return nullptr;
+    return gestureControllerIter->value;
+}
+
+void ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame()
+{
+    if (!m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::VisuallyNonEmptyLayout))
+        return;
+
+    m_snapshotRemovalTracker.startWatchdog(swipeSnapshotRemovalWatchdogAfterFirstVisuallyNonEmptyLayoutDuration);
+
+    // FIXME: Ideally, this would be sufficient to cancel waiting for the main frame load,
+    // and would make snapshot removal faster, but we need didRestoreScrollPosition
+    // to be usable/accurate on all platforms before doing that, or we get a flash
+    // of the new page in the wrong position.
+}
+
+void ViewGestureController::didRepaintAfterNavigation()
+{
+    m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::RepaintAfterNavigation);
+}
+
+void ViewGestureController::didHitRenderTreeSizeThreshold()
+{
+    m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::RenderTreeSizeThreshold);
+}
+
+void ViewGestureController::didRestoreScrollPosition()
+{
+    m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::ScrollPositionRestoration);
+}
+
+void ViewGestureController::didReachMainFrameLoadTerminalState()
+{
+    if (!m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::MainFrameLoad))
+        return;
+
+    // Coming back from the page cache will result in getting a load event, but no first visually non-empty layout.
+    // WebCore considers a loaded document enough to be considered visually non-empty, so that's good
+    // enough for us too.
+    m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::VisuallyNonEmptyLayout);
+
+    checkForActiveLoads();
+}
+
+void ViewGestureController::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType type)
+{
+    bool cancelledOutstandingEvent = false;
+
+    // Same-document navigations don't have a main frame load or first visually non-empty layout.
+    cancelledOutstandingEvent |= m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::MainFrameLoad);
+    cancelledOutstandingEvent |= m_snapshotRemovalTracker.cancelOutstandingEvent(SnapshotRemovalTracker::VisuallyNonEmptyLayout);
+
+    if (!cancelledOutstandingEvent)
+        return;
+
+    if (type != SameDocumentNavigationSessionStateReplace && type != SameDocumentNavigationSessionStatePop)
+        return;
+
+    checkForActiveLoads();
+}
+
+void ViewGestureController::checkForActiveLoads()
+{
+    if (m_webPageProxy.pageLoadState().isLoading()) {
+        if (!m_swipeActiveLoadMonitoringTimer.isActive())
+            m_swipeActiveLoadMonitoringTimer.startRepeating(swipeSnapshotRemovalActiveLoadMonitoringInterval);
+        return;
+    }
+
+    m_swipeActiveLoadMonitoringTimer.stop();
+    m_snapshotRemovalTracker.eventOccurred(SnapshotRemovalTracker::SubresourceLoads);
+}
+
+ViewGestureController::SnapshotRemovalTracker::SnapshotRemovalTracker()
+    : m_watchdogTimer(RunLoop::main(), this, &SnapshotRemovalTracker::watchdogTimerFired)
+{
+}
+
+String ViewGestureController::SnapshotRemovalTracker::eventsDescription(Events event)
+{
+    StringBuilder description;
+
+    if (event & ViewGestureController::SnapshotRemovalTracker::VisuallyNonEmptyLayout)
+        description.append("VisuallyNonEmptyLayout ");
+
+    if (event & ViewGestureController::SnapshotRemovalTracker::RenderTreeSizeThreshold)
+        description.append("RenderTreeSizeThreshold ");
+
+    if (event & ViewGestureController::SnapshotRemovalTracker::RepaintAfterNavigation)
+        description.append("RepaintAfterNavigation ");
+
+    if (event & ViewGestureController::SnapshotRemovalTracker::MainFrameLoad)
+        description.append("MainFrameLoad ");
+
+    if (event & ViewGestureController::SnapshotRemovalTracker::SubresourceLoads)
+        description.append("SubresourceLoads ");
+
+    if (event & ViewGestureController::SnapshotRemovalTracker::ScrollPositionRestoration)
+        description.append("ScrollPositionRestoration ");
+    
+    return description.toString();
+}
+
+
+void ViewGestureController::SnapshotRemovalTracker::log(const String& log) const
+{
+#if !LOG_DISABLED
+    auto now = std::chrono::steady_clock::now();
+    double millisecondsSinceStart = std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(now - m_startTime).count();
+#endif
+    LOG(ViewGestures, "Swipe Snapshot Removal (%0.2f ms) - %s", millisecondsSinceStart, log.utf8().data());
+}
+
+void ViewGestureController::SnapshotRemovalTracker::start(Events desiredEvents, std::function<void()> removalCallback)
+{
+    m_outstandingEvents = desiredEvents;
+    m_removalCallback = WTF::move(removalCallback);
+    m_startTime = std::chrono::steady_clock::now();
+
+    log("start");
+
+    startWatchdog(swipeSnapshotRemovalWatchdogDuration);
+}
+
+void ViewGestureController::SnapshotRemovalTracker::reset()
+{
+    if (m_outstandingEvents)
+        log("reset; had outstanding events: " + eventsDescription(m_outstandingEvents));
+    m_outstandingEvents = 0;
+    m_watchdogTimer.stop();
+    m_removalCallback = nullptr;
+}
+
+bool ViewGestureController::SnapshotRemovalTracker::stopWaitingForEvent(Events event, const String& logReason)
+{
+    ASSERT(hasOneBitSet(event));
+
+    if (!(m_outstandingEvents & event))
+        return false;
+
+#if LOG_DISABLED
+    UNUSED_PARAM(logReason);
+#endif
+    log(logReason +  eventsDescription(event));
+
+    m_outstandingEvents &= ~event;
+
+    fireRemovalCallbackIfPossible();
+    return true;
+}
+
+bool ViewGestureController::SnapshotRemovalTracker::eventOccurred(Events event)
+{
+    return stopWaitingForEvent(event, "outstanding event occurred: ");
+}
+
+bool ViewGestureController::SnapshotRemovalTracker::cancelOutstandingEvent(Events event)
+{
+    return stopWaitingForEvent(event, "wait for event cancelled: ");
+}
+
+void ViewGestureController::SnapshotRemovalTracker::fireRemovalCallbackIfPossible()
+{
+    if (m_outstandingEvents) {
+        log("deferring removal; had outstanding events: " + eventsDescription(m_outstandingEvents));
+        return;
+    }
+
+    fireRemovalCallbackImmediately();
+}
+
+void ViewGestureController::SnapshotRemovalTracker::fireRemovalCallbackImmediately()
+{
+    m_watchdogTimer.stop();
+
+    auto removalCallback = WTF::move(m_removalCallback);
+    if (removalCallback) {
+        log("removing snapshot");
+        reset();
+        removalCallback();
+    }
+}
+
+void ViewGestureController::SnapshotRemovalTracker::watchdogTimerFired()
+{
+    log("watchdog timer fired");
+    fireRemovalCallbackImmediately();
+}
+
+void ViewGestureController::SnapshotRemovalTracker::startWatchdog(std::chrono::seconds duration)
+{
+    log(String::format("(re)started watchdog timer for %lld seconds", duration.count()));
+    m_watchdogTimer.startOneShot(duration.count());
+}
+
+} // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm (188520 => 188521)


--- trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm	2015-08-16 18:58:48 UTC (rev 188520)
+++ trunk/Source/WebKit2/UIProcess/ios/ViewGestureControllerIOS.mm	2015-08-17 00:52:50 UTC (rev 188521)
@@ -64,16 +64,7 @@
 }
 
 static const float swipeSnapshotRemovalRenderTreeSizeTargetFraction = 0.5;
-static const std::chrono::seconds swipeSnapshotRemovalWatchdogDuration = 3_s;
-static const std::chrono::milliseconds swipeSnapshotRemovalActiveLoadMonitoringInterval = 250_ms;
 
-// The key in this map is the associated page ID.
-static HashMap<uint64_t, WebKit::ViewGestureController*>& viewGestureControllersForAllPages()
-{
-    static NeverDestroyed<HashMap<uint64_t, WebKit::ViewGestureController*>> viewGestureControllers;
-    return viewGestureControllers.get();
-}
-
 - (instancetype)initWithViewGestureController:(WebKit::ViewGestureController*)gestureController gestureRecognizerView:(UIView *)gestureRecognizerView
 {
     self = [super init];
@@ -146,21 +137,12 @@
 
 namespace WebKit {
 
-ViewGestureController::ViewGestureController(WebPageProxy& webPageProxy)
-    : m_webPageProxy(webPageProxy)
-    , m_swipeWatchdogTimer(RunLoop::main(), this, &ViewGestureController::swipeSnapshotWatchdogTimerFired)
-    , m_swipeActiveLoadMonitoringTimer(RunLoop::main(), this, &ViewGestureController::activeLoadMonitoringTimerFired)
+void ViewGestureController::platformTeardown()
 {
-    viewGestureControllersForAllPages().add(webPageProxy.pageID(), this);
-}
-
-ViewGestureController::~ViewGestureController()
-{
     [m_swipeTransitionContext _setTransitionIsInFlight:NO];
     [m_swipeTransitionContext _setInteractor:nil];
     [m_swipeTransitionContext _setAnimator:nil];
     [m_swipeInteractiveTransitionDelegate invalidate];
-    viewGestureControllersForAllPages().remove(m_webPageProxy.pageID());
 }
 
 void ViewGestureController::setAlternateBackForwardListSourceView(WKWebView *view)
@@ -249,9 +231,8 @@
     }];
     uint64_t pageID = m_webPageProxy.pageID();
     [m_swipeTransitionContext _setCompletionHandler:^(_UIViewControllerTransitionContext *context, BOOL didComplete) {
-        auto gestureControllerIter = viewGestureControllersForAllPages().find(pageID);
-        if (gestureControllerIter != viewGestureControllersForAllPages().end())
-            gestureControllerIter->value->endSwipeGesture(targetItem.get(), context, !didComplete);
+        if (auto gestureController = gestureControllerForPage(pageID))
+            gestureController->endSwipeGesture(targetItem.get(), context, !didComplete);
     }];
     [m_swipeTransitionContext _setInteractiveUpdateHandler:^(BOOL, CGFloat, BOOL, _UIViewControllerTransitionContext *) { }];
 
@@ -306,9 +287,10 @@
         uint64_t pageID = m_webPageProxy.pageID();
         uint64_t gesturePendingSnapshotRemoval = m_gesturePendingSnapshotRemoval;
         drawingArea->dispatchAfterEnsuringDrawing([pageID, gesturePendingSnapshotRemoval] (CallbackBase::Error error) {
-            auto gestureControllerIter = viewGestureControllersForAllPages().find(pageID);
-            if (gestureControllerIter != viewGestureControllersForAllPages().end() && gestureControllerIter->value->m_gesturePendingSnapshotRemoval == gesturePendingSnapshotRemoval)
-                gestureControllerIter->value->willCommitPostSwipeTransitionLayerTree(error == CallbackBase::Error::None);
+            if (auto gestureController = gestureControllerForPage(pageID)) {
+                if (gestureController->m_gesturePendingSnapshotRemoval == gesturePendingSnapshotRemoval)
+                    gestureController->willCommitPostSwipeTransitionLayerTree(error == CallbackBase::Error::None);
+            }
         });
         drawingArea->hideContentUntilPendingUpdate();
     } else {
@@ -316,140 +298,52 @@
         return;
     }
 
-    m_swipeWaitingForRenderTreeSizeThreshold = true;
-    m_swipeWaitingForRepaint = true;
-    m_swipeWaitingForTerminalLoadingState = true;
-    m_swipeWaitingForSubresourceLoads = true;
-    m_swipeWaitingForScrollPositionRestoration = true;
+    // FIXME: Should we wait for VisuallyNonEmptyLayout like we do on Mac?
+    m_snapshotRemovalTracker.start(SnapshotRemovalTracker::RenderTreeSizeThreshold
+        | SnapshotRemovalTracker::RepaintAfterNavigation
+        | SnapshotRemovalTracker::MainFrameLoad
+        | SnapshotRemovalTracker::SubresourceLoads
+        | SnapshotRemovalTracker::ScrollPositionRestoration, [this] {
+            this->removeSwipeSnapshot();
+    });
 
-    m_swipeWatchdogTimer.startOneShot(swipeSnapshotRemovalWatchdogDuration.count());
-
     if (ViewSnapshot* snapshot = targetItem->snapshot()) {
         m_backgroundColorForCurrentSnapshot = snapshot->backgroundColor();
         m_webPageProxy.didChangeBackgroundColor();
     }
 }
 
-void ViewGestureController::willCommitPostSwipeTransitionLayerTree(bool successful)
-{
-    if (m_activeGestureType != ViewGestureType::Swipe)
-        return;
-
-    if (!successful) {
-        removeSwipeSnapshot();
-        return;
-    }
-
-    if (!m_swipeWaitingForRepaint)
-        return;
-
-    m_swipeWaitingForRepaint = false;
-    removeSwipeSnapshotIfReady();
-}
-
 void ViewGestureController::setRenderTreeSize(uint64_t renderTreeSize)
 {
     if (m_activeGestureType != ViewGestureType::Swipe)
         return;
 
-    if (!m_swipeWaitingForRenderTreeSizeThreshold)
-        return;
-
-    if (!m_snapshotRemovalTargetRenderTreeSize || renderTreeSize > m_snapshotRemovalTargetRenderTreeSize) {
-        m_swipeWaitingForRenderTreeSizeThreshold = false;
-        removeSwipeSnapshotIfReady();
-    }
+    if (!m_snapshotRemovalTargetRenderTreeSize || renderTreeSize > m_snapshotRemovalTargetRenderTreeSize)
+        didHitRenderTreeSizeThreshold();
 }
 
-void ViewGestureController::didRestoreScrollPosition()
+void ViewGestureController::willCommitPostSwipeTransitionLayerTree(bool successful)
 {
     if (m_activeGestureType != ViewGestureType::Swipe)
         return;
 
-    if (!m_swipeWaitingForScrollPositionRestoration)
+    if (!successful) {
+        removeSwipeSnapshot();
         return;
-
-    m_swipeWaitingForScrollPositionRestoration = false;
-    removeSwipeSnapshotIfReady();
-}
-
-void ViewGestureController::mainFrameLoadDidReachTerminalState()
-{
-    if (m_activeGestureType != ViewGestureType::Swipe)
-        return;
-
-    if (!m_swipeWaitingForTerminalLoadingState)
-        return;
-
-    m_swipeWaitingForTerminalLoadingState = false;
-
-    if (m_webPageProxy.pageLoadState().isLoading()) {
-        m_swipeActiveLoadMonitoringTimer.startRepeating(swipeSnapshotRemovalActiveLoadMonitoringInterval);
-        return;
     }
 
-    m_swipeWaitingForSubresourceLoads = false;
-    removeSwipeSnapshotIfReady();
+    didRepaintAfterNavigation();
 }
 
-void ViewGestureController::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType type)
-{
-    if (m_activeGestureType != ViewGestureType::Swipe)
-        return;
-
-    // This is nearly equivalent to didFinishLoad in the same document navigation case.
-    if (!m_swipeWaitingForTerminalLoadingState)
-        return;
-
-    m_swipeWaitingForTerminalLoadingState = false;
-
-    if (type != SameDocumentNavigationSessionStateReplace && type != SameDocumentNavigationSessionStatePop)
-        return;
-
-    m_swipeActiveLoadMonitoringTimer.startRepeating(swipeSnapshotRemovalActiveLoadMonitoringInterval);
-}
-
-void ViewGestureController::activeLoadMonitoringTimerFired()
-{
-    if (m_webPageProxy.pageLoadState().isLoading())
-        return;
-
-    if (!m_swipeWaitingForSubresourceLoads)
-        return;
-
-    m_swipeWaitingForSubresourceLoads = false;
-    removeSwipeSnapshotIfReady();
-}
-
-void ViewGestureController::swipeSnapshotWatchdogTimerFired()
-{
-    removeSwipeSnapshot();
-}
-
-void ViewGestureController::removeSwipeSnapshotIfReady()
-{
-    if (m_swipeWaitingForRenderTreeSizeThreshold || m_swipeWaitingForRepaint || m_swipeWaitingForTerminalLoadingState || m_swipeWaitingForSubresourceLoads || m_swipeWaitingForScrollPositionRestoration)
-        return;
-
-    removeSwipeSnapshot();
-}
-
 void ViewGestureController::removeSwipeSnapshot()
 {
-    m_swipeWaitingForRenderTreeSizeThreshold = false;
-    m_swipeWaitingForRepaint = false;
-    m_swipeWaitingForTerminalLoadingState = false;
-    m_swipeWaitingForSubresourceLoads = false;
-    m_swipeWaitingForScrollPositionRestoration = false;
+    m_snapshotRemovalTracker.reset();
 
-    m_swipeWatchdogTimer.stop();
-    m_swipeActiveLoadMonitoringTimer.stop();
-
     if (m_activeGestureType != ViewGestureType::Swipe)
         return;
-    
+
     ++m_gesturePendingSnapshotRemoval;
-    
+
     [m_snapshotView removeFromSuperview];
     m_snapshotView = nullptr;
     

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h (188520 => 188521)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h	2015-08-16 18:58:48 UTC (rev 188520)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.h	2015-08-17 00:52:50 UTC (rev 188521)
@@ -31,9 +31,12 @@
 #include "WeakObjCPtr.h"
 #include <WebCore/Color.h>
 #include <WebCore/FloatRect.h>
+#include <chrono>
 #include <wtf/RetainPtr.h>
 #include <wtf/RunLoop.h>
 
+// FIXME: Move this file out of the mac/ subdirectory.
+
 OBJC_CLASS CALayer;
 
 #if PLATFORM(IOS)
@@ -65,6 +68,7 @@
 public:
     ViewGestureController(WebPageProxy&);
     ~ViewGestureController();
+    void platformTeardown();
     
     enum class ViewGestureType {
         None,
@@ -109,8 +113,6 @@
 
     bool shouldIgnorePinnedState() { return m_shouldIgnorePinnedState; }
     void setShouldIgnorePinnedState(bool ignore) { m_shouldIgnorePinnedState = ignore; }
-
-    void didFirstVisuallyNonEmptyLayoutForMainFrame();
 #else
     void installSwipeHandler(UIView *gestureRecognizerView, UIView *swipingView);
     void setAlternateBackForwardListSourceView(WKWebView *);
@@ -119,30 +121,72 @@
     void endSwipeGesture(WebBackForwardListItem* targetItem, _UIViewControllerTransitionContext *, bool cancelled);
     void willCommitPostSwipeTransitionLayerTree(bool);
     void setRenderTreeSize(uint64_t);
-    void didRestoreScrollPosition();
 #endif
 
-    void didFinishLoadForMainFrame() { mainFrameLoadDidReachTerminalState(); }
-    void didFailLoadForMainFrame() { mainFrameLoadDidReachTerminalState(); }
-    void mainFrameLoadDidReachTerminalState();
-    void removeSwipeSnapshot();
+    WebCore::Color backgroundColorForCurrentSnapshot() const { return m_backgroundColorForCurrentSnapshot; }
+
+    void didFinishLoadForMainFrame() { didReachMainFrameLoadTerminalState(); }
+    void didFailLoadForMainFrame() { didReachMainFrameLoadTerminalState(); }
+    void didFirstVisuallyNonEmptyLayoutForMainFrame();
+    void didRepaintAfterNavigation();
+    void didHitRenderTreeSizeThreshold();
+    void didRestoreScrollPosition();
+    void didReachMainFrameLoadTerminalState();
     void didSameDocumentNavigationForMainFrame(SameDocumentNavigationType);
 
-    WebCore::Color backgroundColorForCurrentSnapshot() const { return m_backgroundColorForCurrentSnapshot; }
+    void checkForActiveLoads();
 
+    void removeSwipeSnapshot();
+
 private:
     // IPC::MessageReceiver.
     virtual void didReceiveMessage(IPC::Connection&, IPC::MessageDecoder&) override;
 
-    void swipeSnapshotWatchdogTimerFired();
-    void activeLoadMonitoringTimerFired();
+    static ViewGestureController* gestureControllerForPage(uint64_t);
 
+    class SnapshotRemovalTracker {
+    public:
+        enum Event : uint8_t {
+            VisuallyNonEmptyLayout = 1 << 0,
+            RenderTreeSizeThreshold = 1 << 1,
+            RepaintAfterNavigation = 1 << 2,
+            MainFrameLoad = 1 << 3,
+            SubresourceLoads = 1 << 4,
+            ScrollPositionRestoration = 1 << 5
+        };
+        typedef uint8_t Events;
+
+        SnapshotRemovalTracker();
+
+        void start(Events, std::function<void()>);
+        void reset();
+
+        bool eventOccurred(Events);
+        bool cancelOutstandingEvent(Events);
+
+        void startWatchdog(std::chrono::seconds);
+
+    private:
+        static String eventsDescription(Events);
+        void log(const String&) const;
+
+        void fireRemovalCallbackImmediately();
+        void fireRemovalCallbackIfPossible();
+        void watchdogTimerFired();
+
+        bool stopWaitingForEvent(Events, const String& logReason);
+
+        Events m_outstandingEvents { 0 };
+        std::function<void()> m_removalCallback;
+        std::chrono::steady_clock::time_point m_startTime;
+
+        RunLoop::Timer<SnapshotRemovalTracker> m_watchdogTimer;
+    };
+
 #if PLATFORM(MAC)
     // Message handlers.
     void didCollectGeometryForMagnificationGesture(WebCore::FloatRect visibleContentBounds, bool frameHandlesMagnificationGesture);
     void didCollectGeometryForSmartMagnificationGesture(WebCore::FloatPoint origin, WebCore::FloatRect renderRect, WebCore::FloatRect visibleContentBounds, bool isReplacedElement, double viewportMinimumScale, double viewportMaximumScale);
-    void didHitRenderTreeSizeThreshold();
-    void removeSwipeSnapshotAfterRepaint();
 
     WebCore::FloatPoint scaledMagnificationOrigin(WebCore::FloatPoint origin, double scale);
 
@@ -159,14 +203,13 @@
     CALayer *determineLayerAdjacentToSnapshotForParent(SwipeDirection, CALayer *snapshotLayerParent) const;
     void applyDebuggingPropertiesToSwipeViews();
     void didMoveSwipeSnapshotLayer();
-#else
-    void removeSwipeSnapshotIfReady();
+
+    void forceRepaintIfNeeded();
 #endif
 
     WebPageProxy& m_webPageProxy;
     ViewGestureType m_activeGestureType { ViewGestureType::None };
 
-    RunLoop::Timer<ViewGestureController> m_swipeWatchdogTimer;
     RunLoop::Timer<ViewGestureController> m_swipeActiveLoadMonitoringTimer;
 
     WebCore::Color m_backgroundColorForCurrentSnapshot;
@@ -174,8 +217,6 @@
 #if PLATFORM(MAC)
     RefPtr<ViewSnapshot> m_currentSwipeSnapshot;
 
-    RunLoop::Timer<ViewGestureController> m_swipeWatchdogAfterFirstVisuallyNonEmptyLayoutTimer;
-
     double m_magnification;
     WebCore::FloatPoint m_magnificationOrigin;
 
@@ -208,7 +249,8 @@
     void (^m_didMoveSwipeSnapshotCallback)(CGRect) { nullptr };
 
     bool m_shouldIgnorePinnedState { false };
-    bool m_swipeInProgress { false };
+
+    bool m_hasOutstandingRepaintRequest { false };
 #else    
     UIView *m_liveSwipeView { nullptr };
     RetainPtr<UIView> m_liveSwipeViewClippingView;
@@ -222,12 +264,7 @@
     uint64_t m_gesturePendingSnapshotRemoval { 0 };
 #endif
 
-    bool m_swipeWaitingForVisuallyNonEmptyLayout { false };
-    bool m_swipeWaitingForRenderTreeSizeThreshold { false };
-    bool m_swipeWaitingForRepaint { false };
-    bool m_swipeWaitingForTerminalLoadingState { false };
-    bool m_swipeWaitingForSubresourceLoads { false };
-    bool m_swipeWaitingForScrollPositionRestoration { false };
+    SnapshotRemovalTracker m_snapshotRemovalTracker;
 };
 
 } // namespace WebKit

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.messages.in (188520 => 188521)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.messages.in	2015-08-16 18:58:48 UTC (rev 188520)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureController.messages.in	2015-08-17 00:52:50 UTC (rev 188521)
@@ -21,7 +21,7 @@
 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 messages -> ViewGestureController {
-#if !PLATFORM(IOS)
+#if PLATFORM(MAC)
     DidCollectGeometryForMagnificationGesture(WebCore::FloatRect visibleContentBounds, bool frameHandlesMagnificationGesture)
     DidCollectGeometryForSmartMagnificationGesture(WebCore::FloatPoint origin, WebCore::FloatRect renderRect, WebCore::FloatRect visibleContentBounds, bool isReplacedElement, double viewportMinimumScale, double viewportMaximumScale)
     DidHitRenderTreeSizeThreshold()

Modified: trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm (188520 => 188521)


--- trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2015-08-16 18:58:48 UTC (rev 188520)
+++ trunk/Source/WebKit2/UIProcess/mac/ViewGestureControllerMac.mm	2015-08-17 00:52:50 UTC (rev 188521)
@@ -47,7 +47,7 @@
 
 using namespace WebCore;
 
-#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
+#if __MAC_OS_X_VERSION_MIN_REQUIRED < 101000
 #define ENABLE_LEGACY_SWIPE_SHADOW_STYLE 1
 #else
 #define ENABLE_LEGACY_SWIPE_SHADOW_STYLE 0
@@ -78,9 +78,6 @@
 static const float minimumScrollEventRatioForSwipe = 0.5;
 
 static const float swipeSnapshotRemovalRenderTreeSizeTargetFraction = 0.5;
-static const std::chrono::seconds swipeSnapshotRemovalWatchdogDuration = 5_s;
-static const std::chrono::seconds swipeSnapshotRemovalWatchdogAfterFirstVisuallyNonEmptyLayoutDuration = 3_s;
-static const std::chrono::milliseconds swipeSnapshotRemovalActiveLoadMonitoringInterval = 250_ms;
 
 @interface WKSwipeCancellationTracker : NSObject {
 @private
@@ -97,17 +94,8 @@
 
 namespace WebKit {
 
-ViewGestureController::ViewGestureController(WebPageProxy& webPageProxy)
-    : m_webPageProxy(webPageProxy)
-    , m_swipeWatchdogTimer(RunLoop::main(), this, &ViewGestureController::swipeSnapshotWatchdogTimerFired)
-    , m_swipeActiveLoadMonitoringTimer(RunLoop::main(), this, &ViewGestureController::activeLoadMonitoringTimerFired)
-    , m_swipeWatchdogAfterFirstVisuallyNonEmptyLayoutTimer(RunLoop::main(), this, &ViewGestureController::swipeSnapshotWatchdogTimerFired)
+void ViewGestureController::platformTeardown()
 {
-    m_webPageProxy.process().addMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID(), *this);
-}
-
-ViewGestureController::~ViewGestureController()
-{
     if (m_swipeCancellationTracker)
         [m_swipeCancellationTracker setIsCancelled:YES];
 
@@ -118,8 +106,6 @@
         Block_release(m_didMoveSwipeSnapshotCallback);
         m_didMoveSwipeSnapshotCallback = nullptr;
     }
-
-    m_webPageProxy.process().removeMessageReceiver(Messages::ViewGestureController::messageReceiverName(), m_webPageProxy.pageID());
 }
 
 static double resistanceForDelta(double deltaScale, double currentScale)
@@ -535,7 +521,6 @@
     m_webPageProxy.navigationGestureDidBegin();
 
     m_activeGestureType = ViewGestureType::Swipe;
-    m_swipeInProgress = true;
 
     CALayer *rootContentLayer = m_webPageProxy.acceleratedCompositingRootLayer();
 
@@ -752,8 +737,6 @@
 
     m_swipeCancellationTracker = nullptr;
 
-    m_swipeInProgress = false;
-
     CALayer *rootLayer = m_webPageProxy.acceleratedCompositingRootLayer();
 
     [rootLayer setShadowOpacity:0];
@@ -771,110 +754,47 @@
 
     m_webPageProxy.process().send(Messages::ViewGestureGeometryCollector::SetRenderTreeSizeNotificationThreshold(renderTreeSize * swipeSnapshotRemovalRenderTreeSizeTargetFraction), m_webPageProxy.pageID());
 
-    m_swipeWaitingForVisuallyNonEmptyLayout = true;
-    m_swipeWaitingForRenderTreeSizeThreshold = true;
-
     m_webPageProxy.navigationGestureDidEnd(true, *targetItem);
     m_webPageProxy.goToBackForwardItem(targetItem);
 
+    // FIXME: We should be able to include scroll position restoration here,
+    // and then can address the FIXME in didFirstVisuallyNonEmptyLayoutForMainFrame.
+    m_snapshotRemovalTracker.start(SnapshotRemovalTracker::VisuallyNonEmptyLayout
+        | SnapshotRemovalTracker::RenderTreeSizeThreshold
+        | SnapshotRemovalTracker::MainFrameLoad
+        | SnapshotRemovalTracker::SubresourceLoads, [this] {
+            this->forceRepaintIfNeeded();
+        });
+
     // FIXME: Like on iOS, we should ensure that even if one of the timeouts fires,
-    // we never show the old page content, instead showing white (or the snapshot background color).
-    m_swipeWatchdogTimer.startOneShot(swipeSnapshotRemovalWatchdogDuration.count());
+    // we never show the old page content, instead showing the snapshot background color.
 
     if (ViewSnapshot* snapshot = targetItem->snapshot())
         m_backgroundColorForCurrentSnapshot = snapshot->backgroundColor();
 }
 
-void ViewGestureController::didHitRenderTreeSizeThreshold()
+void ViewGestureController::forceRepaintIfNeeded()
 {
-    if (m_activeGestureType != ViewGestureType::Swipe || m_swipeInProgress)
+    if (m_activeGestureType != ViewGestureType::Swipe)
         return;
 
-    m_swipeWaitingForRenderTreeSizeThreshold = false;
-
-    if (!m_swipeWaitingForVisuallyNonEmptyLayout) {
-        // FIXME: Ideally we would call removeSwipeSnapshotAfterRepaint() here, but sometimes
-        // scroll position isn't done restoring until didFinishLoadForFrame, so we flash the wrong content.
-    }
-}
-
-void ViewGestureController::didFirstVisuallyNonEmptyLayoutForMainFrame()
-{
-    if (m_activeGestureType != ViewGestureType::Swipe || m_swipeInProgress)
+    if (m_hasOutstandingRepaintRequest)
         return;
 
-    m_swipeWaitingForVisuallyNonEmptyLayout = false;
+    m_hasOutstandingRepaintRequest = true;
 
-    if (!m_swipeWaitingForRenderTreeSizeThreshold) {
-        // FIXME: Ideally we would call removeSwipeSnapshotAfterRepaint() here, but sometimes
-        // scroll position isn't done restoring until didFinishLoadForFrame, so we flash the wrong content.
-    } else {
-        m_swipeWatchdogAfterFirstVisuallyNonEmptyLayoutTimer.startOneShot(swipeSnapshotRemovalWatchdogAfterFirstVisuallyNonEmptyLayoutDuration.count());
-        m_swipeWatchdogTimer.stop();
-    }
-}
-
-void ViewGestureController::mainFrameLoadDidReachTerminalState()
-{
-    if (m_activeGestureType != ViewGestureType::Swipe || m_swipeInProgress)
-        return;
-
-    if (m_webPageProxy.pageLoadState().isLoading()) {
-        m_swipeActiveLoadMonitoringTimer.startRepeating(swipeSnapshotRemovalActiveLoadMonitoringInterval);
-        return;
-    }
-
-    removeSwipeSnapshotAfterRepaint();
-}
-
-void ViewGestureController::didSameDocumentNavigationForMainFrame(SameDocumentNavigationType type)
-{
-    if (m_activeGestureType != ViewGestureType::Swipe || m_swipeInProgress)
-        return;
-
-    if (type != SameDocumentNavigationSessionStateReplace && type != SameDocumentNavigationSessionStatePop)
-        return;
-
-    m_swipeActiveLoadMonitoringTimer.startRepeating(swipeSnapshotRemovalActiveLoadMonitoringInterval);
-}
-
-void ViewGestureController::activeLoadMonitoringTimerFired()
-{
-    if (m_webPageProxy.pageLoadState().isLoading())
-        return;
-
-    removeSwipeSnapshotAfterRepaint();
-}
-
-void ViewGestureController::swipeSnapshotWatchdogTimerFired()
-{
-    removeSwipeSnapshotAfterRepaint();
-}
-
-void ViewGestureController::removeSwipeSnapshotAfterRepaint()
-{
-    m_swipeActiveLoadMonitoringTimer.stop();
-
-    if (m_activeGestureType != ViewGestureType::Swipe || m_swipeInProgress)
-        return;
-
-    if (m_swipeWaitingForRepaint)
-        return;
-
-    m_swipeWaitingForRepaint = true;
-
-    WebPageProxy* webPageProxy = &m_webPageProxy;
-    m_webPageProxy.forceRepaint(VoidCallback::create([webPageProxy] (CallbackBase::Error error) {
-        webPageProxy->removeNavigationGestureSnapshot();
+    uint64_t pageID = m_webPageProxy.pageID();
+    m_webPageProxy.forceRepaint(VoidCallback::create([this, pageID] (CallbackBase::Error error) {
+        if (auto gestureController = gestureControllerForPage(pageID))
+            gestureController->removeSwipeSnapshot();
     }));
 }
 
 void ViewGestureController::removeSwipeSnapshot()
 {
-    m_swipeWaitingForRepaint = false;
+    m_snapshotRemovalTracker.reset();
 
-    m_swipeWatchdogTimer.stop();
-    m_swipeWatchdogAfterFirstVisuallyNonEmptyLayoutTimer.stop();
+    m_hasOutstandingRepaintRequest = false;
 
     if (m_activeGestureType != ViewGestureType::Swipe)
         return;
@@ -921,4 +841,4 @@
 
 } // namespace WebKit
 
-#endif // !PLATFORM(IOS)
+#endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj (188520 => 188521)


--- trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2015-08-16 18:58:48 UTC (rev 188520)
+++ trunk/Source/WebKit2/WebKit2.xcodeproj/project.pbxproj	2015-08-17 00:52:50 UTC (rev 188521)
@@ -661,6 +661,7 @@
 		2DACE64E18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DACE64D18ADBFF000E4CA76 /* _WKThumbnailViewInternal.h */; };
 		2DAF06D618BD1A470081CEB1 /* SmartMagnificationController.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DAF06D418BD1A470081CEB1 /* SmartMagnificationController.h */; };
 		2DAF06D718BD1A470081CEB1 /* SmartMagnificationController.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DAF06D518BD1A470081CEB1 /* SmartMagnificationController.mm */; };
+		2DAF4FFB1B636181006013D6 /* ViewGestureController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2DAF4FFA1B636181006013D6 /* ViewGestureController.cpp */; };
 		2DB9C4AC1B3251BD0070F27F /* SafariServicesSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DB9C4AB1B3251BD0070F27F /* SafariServicesSPI.h */; };
 		2DC6D9C318C44A610043BAD4 /* WKWebViewContentProviderRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */; };
 		2DC6D9C418C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */; };
@@ -2806,6 +2807,7 @@
 		2DAF06D418BD1A470081CEB1 /* SmartMagnificationController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SmartMagnificationController.h; path = ios/SmartMagnificationController.h; sourceTree = "<group>"; };
 		2DAF06D518BD1A470081CEB1 /* SmartMagnificationController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = SmartMagnificationController.mm; path = ios/SmartMagnificationController.mm; sourceTree = "<group>"; };
 		2DAF06D818BD23BA0081CEB1 /* SmartMagnificationController.messages.in */ = {isa = PBXFileReference; lastKnownFileType = text; name = SmartMagnificationController.messages.in; path = ios/SmartMagnificationController.messages.in; sourceTree = "<group>"; };
+		2DAF4FFA1B636181006013D6 /* ViewGestureController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ViewGestureController.cpp; sourceTree = "<group>"; };
 		2DB9C4AB1B3251BD0070F27F /* SafariServicesSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SafariServicesSPI.h; sourceTree = "<group>"; };
 		2DC6D9C118C44A610043BAD4 /* WKWebViewContentProviderRegistry.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WKWebViewContentProviderRegistry.h; sourceTree = "<group>"; };
 		2DC6D9C218C44A610043BAD4 /* WKWebViewContentProviderRegistry.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WKWebViewContentProviderRegistry.mm; sourceTree = "<group>"; };
@@ -6107,6 +6109,7 @@
 				4A410F3A19AF7B04002EBAB5 /* UserMediaPermissionRequestManagerProxy.h */,
 				4A410F3B19AF7B04002EBAB5 /* UserMediaPermissionRequestProxy.cpp */,
 				4A410F3C19AF7B04002EBAB5 /* UserMediaPermissionRequestProxy.h */,
+				2DAF4FFA1B636181006013D6 /* ViewGestureController.cpp */,
 				1A0F29E1120B44420053D1B9 /* VisitedLinkProvider.cpp */,
 				1A0F29E2120B44420053D1B9 /* VisitedLinkProvider.h */,
 				1A60224918C16B0800C3E8C9 /* VisitedLinkProvider.messages.in */,
@@ -9442,6 +9445,7 @@
 				1A64230812DD09EB00CAAE2C /* DrawingAreaProxyMessageReceiver.cpp in Sources */,
 				5DA6ED0B1490606900B41D12 /* DynamicLinkerEnvironmentExtractor.mm in Sources */,
 				8CFECE941490F140002AAA32 /* EditorState.cpp in Sources */,
+				2DAF4FFB1B636181006013D6 /* ViewGestureController.cpp in Sources */,
 				51B15A8413843A3900321AD8 /* EnvironmentUtilities.cpp in Sources */,
 				1A7C6CDA1378950800B9C04D /* EnvironmentVariables.cpp in Sources */,
 				1AA575FA1496B52600A4EE06 /* EventDispatcher.cpp in Sources */,
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to