Title: [242440] releases/WebKitGTK/webkit-2.24/Source/WebKit
Revision
242440
Author
carlo...@webkit.org
Date
2019-03-05 04:40:31 -0800 (Tue, 05 Mar 2019)

Log Message

Merge r241952 - [GTK] Navigation gesture improvements
https://bugs.webkit.org/show_bug.cgi?id=194943

Patch by Alexander Mikhaylenko <exalm7...@gmail.com> on 2019-02-22
Reviewed by Michael Catanzaro.

Cancel the gesture if progress is less than 0.5 and velocity is not high enough.

Allow to continue the gesture during animation. Introduce finished state to be used
when showing snapshot after the animation ends.

Fix duration calculation, also slow it down so that the initial velocity matches
what it was during the gesture.

* UIProcess/ViewGestureController.h: Add shouldCancel() and State::Finishing to SwipeProgressTracker.
* UIProcess/gtk/ViewGestureControllerGtk.cpp:
(WebKit::ViewGestureController::SwipeProgressTracker::handleEvent):
Fix velocity calculation, allow scrolling during State::Animating.
(WebKit::ViewGestureController::SwipeProgressTracker::shouldCancel): Added.
(WebKit::ViewGestureController::SwipeProgressTracker::startAnimation): Use shouldCancel() and fix duration calculation.
(WebKit::ViewGestureController::SwipeProgressTracker::endAnimation): Set state to State::Finishing when the animation ends.

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/ChangeLog (242439 => 242440)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/ChangeLog	2019-03-05 12:40:28 UTC (rev 242439)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/ChangeLog	2019-03-05 12:40:31 UTC (rev 242440)
@@ -1,3 +1,26 @@
+2019-02-22  Alexander Mikhaylenko  <exalm7...@gmail.com>
+
+        [GTK] Navigation gesture improvements
+        https://bugs.webkit.org/show_bug.cgi?id=194943
+
+        Reviewed by Michael Catanzaro.
+
+        Cancel the gesture if progress is less than 0.5 and velocity is not high enough.
+
+        Allow to continue the gesture during animation. Introduce finished state to be used
+        when showing snapshot after the animation ends.
+
+        Fix duration calculation, also slow it down so that the initial velocity matches
+        what it was during the gesture.
+
+        * UIProcess/ViewGestureController.h: Add shouldCancel() and State::Finishing to SwipeProgressTracker.
+        * UIProcess/gtk/ViewGestureControllerGtk.cpp:
+        (WebKit::ViewGestureController::SwipeProgressTracker::handleEvent):
+        Fix velocity calculation, allow scrolling during State::Animating.
+        (WebKit::ViewGestureController::SwipeProgressTracker::shouldCancel): Added.
+        (WebKit::ViewGestureController::SwipeProgressTracker::startAnimation): Use shouldCancel() and fix duration calculation.
+        (WebKit::ViewGestureController::SwipeProgressTracker::endAnimation): Set state to State::Finishing when the animation ends.
+
 2019-02-21  Darin Adler  <da...@apple.com>
 
         Some refinements for Node and Document

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/UIProcess/ViewGestureController.h (242439 => 242440)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/UIProcess/ViewGestureController.h	2019-03-05 12:40:28 UTC (rev 242439)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/UIProcess/ViewGestureController.h	2019-03-05 12:40:31 UTC (rev 242440)
@@ -374,9 +374,12 @@
             None,
             Pending,
             Scrolling,
-            Animating
+            Animating,
+            Finishing
         };
 
+        bool shouldCancel();
+
         void startAnimation();
         gboolean onAnimationTick(GdkFrameClock*);
         void endAnimation();

Modified: releases/WebKitGTK/webkit-2.24/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp (242439 => 242440)


--- releases/WebKitGTK/webkit-2.24/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp	2019-03-05 12:40:28 UTC (rev 242439)
+++ releases/WebKitGTK/webkit-2.24/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp	2019-03-05 12:40:31 UTC (rev 242440)
@@ -35,6 +35,12 @@
 static const Seconds swipeMinAnimationDuration = 100_ms;
 static const Seconds swipeMaxAnimationDuration = 400_ms;
 
+// This is derivative of the easing function at t=0
+static const double swipeAnimationDurationMultiplier = 3;
+
+static const double swipeCancelArea = 0.5;
+static const double swipeCancelVelocityThreshold = 0.001;
+
 static const double swipeOverlayShadowOpacity = 0.06;
 static const double swipeOverlayDimmingOpacity = 0.12;
 static const double swipeOverlayShadowWidth = 81;
@@ -135,15 +141,25 @@
 
 bool ViewGestureController::SwipeProgressTracker::handleEvent(GdkEventScroll* event)
 {
+    // Don't allow scrolling while the next page is loading
+    if (m_state == State::Finishing)
+        return true;
+
+    // Stop current animation, if any
+    if (m_state == State::Animating) {
+        GtkWidget* widget = m_webPageProxy.viewWidget();
+        gtk_widget_remove_tick_callback(widget, m_tickCallbackID);
+        m_tickCallbackID = 0;
+
+        m_cancelled = false;
+        m_state = State::Pending;
+    }
+
     if (m_state == State::Pending) {
         m_viewGestureController.beginSwipeGesture(m_targetItem.get(), m_direction);
         m_state = State::Scrolling;
     }
 
-    // Don't allow scrolling during animation
-    if (m_state == State::Animating)
-        return true;
-
     if (m_state != State::Scrolling)
         return false;
 
@@ -152,11 +168,14 @@
         return false;
     }
 
+    double deltaX = -event->delta_x / Scrollbar::pixelsPerLineStep();
+
     Seconds time = Seconds::fromMilliseconds(event->time);
-    m_velocity = -event->delta_x / (time - m_prevTime).milliseconds();
+    if (time != m_prevTime)
+        m_velocity = deltaX / (time - m_prevTime).milliseconds();
 
     m_prevTime = time;
-    m_progress -= event->delta_x / Scrollbar::pixelsPerLineStep();
+    m_progress += deltaX;
 
     bool swipingLeft = m_viewGestureController.isPhysicallySwipingLeft(m_direction);
     float maxProgress = swipingLeft ? 1 : 0;
@@ -168,11 +187,23 @@
     return true;
 }
 
-void ViewGestureController::SwipeProgressTracker::startAnimation()
+bool ViewGestureController::SwipeProgressTracker::shouldCancel()
 {
     bool swipingLeft = m_viewGestureController.isPhysicallySwipingLeft(m_direction);
-    m_cancelled = swipingLeft ? (m_velocity <= 0) : (m_velocity >= 0);
 
+    if (swipingLeft && m_velocity < 0)
+        return true;
+
+    if (!swipingLeft && m_velocity > 0)
+        return true;
+
+    return (abs(m_progress) < swipeCancelArea && abs(m_velocity) < swipeCancelVelocityThreshold);
+}
+
+void ViewGestureController::SwipeProgressTracker::startAnimation()
+{
+    m_cancelled = shouldCancel();
+
     m_state = State::Animating;
     m_viewGestureController.willEndSwipeGesture(*m_targetItem, m_cancelled);
 
@@ -180,10 +211,13 @@
     if (m_cancelled)
         m_endProgress = 0;
     else
-        m_endProgress = swipingLeft ? 1 : -1;
+        m_endProgress = m_viewGestureController.isPhysicallySwipingLeft(m_direction) ? 1 : -1;
 
-    Seconds duration = Seconds::fromMilliseconds(std::abs((m_progress - m_endProgress) / m_velocity) * Scrollbar::pixelsPerLineStep());
-    duration = std::min(std::max(duration, swipeMinAnimationDuration), swipeMaxAnimationDuration);
+    Seconds duration = swipeMaxAnimationDuration;
+    if ((m_endProgress - m_progress) * m_velocity > 0) {
+        duration = Seconds::fromMilliseconds(std::abs((m_progress - m_endProgress) / m_velocity * swipeAnimationDurationMultiplier));
+        duration = clampTo<WTF::Seconds>(duration, swipeMinAnimationDuration, swipeMaxAnimationDuration);
+    }
 
     GtkWidget* widget = m_webPageProxy.viewWidget();
     m_startTime = Seconds::fromMicroseconds(gdk_frame_clock_get_frame_time(gtk_widget_get_frame_clock(widget)));
@@ -226,6 +260,7 @@
 
 void ViewGestureController::SwipeProgressTracker::endAnimation()
 {
+    m_state = State::Finishing;
     m_viewGestureController.endSwipeGesture(m_targetItem.get(), m_cancelled);
 }
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to