Scroll snapping should trigger when receiving a momentum end wheel event
authorwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Aug 2015 18:13:53 +0000 (18:13 +0000)
committerwenson_hsieh@apple.com <wenson_hsieh@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Aug 2015 18:13:53 +0000 (18:13 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148155

Reviewed by Alexey Proskuryakov.

No new tests, since the purpose of this patch is to get existing tests to pass when
allowing similar wheel events to coalesce. To accomplish this, we relax our assumption
that the user must have generated at least 3 momentum wheel events in order for the
gliding animation to trigger. Upon receiving a wheel event indicating the end of the
momentum phase, we now kick off the gliding animation as long as any momentum event
was tracked earlier in the gesture with a nonzero wheel delta.

* platform/cocoa/ScrollController.mm:
(WebCore::ScrollController::processWheelEventForScrollSnapOnAxis): Added logic to
    begin a glide animation if we have received a momentum end event but have not
    yet triggered a gliding animation.
* platform/cocoa/ScrollSnapAnimatorState.h:
* platform/cocoa/ScrollSnapAnimatorState.mm:
(WebCore::ScrollSnapAnimatorState::wheelDeltaTrackingIsInProgress): Minor refactoring
    to make the wheel event processing code more readable.
(WebCore::ScrollSnapAnimatorState::hasFinishedTrackingWheelDeltas): Ditto.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/cocoa/ScrollController.mm
Source/WebCore/platform/cocoa/ScrollSnapAnimatorState.h
Source/WebCore/platform/cocoa/ScrollSnapAnimatorState.mm

index 55701dadf1b51c02f6da81c5ff6a25050890d6ac..68ffac4d053b462e41debe1d5eb694393d6afe7e 100644 (file)
@@ -1,3 +1,27 @@
+2015-08-18  Wenson Hsieh  <wenson_hsieh@apple.com>
+
+        Scroll snapping should trigger when receiving a momentum end wheel event
+        https://bugs.webkit.org/show_bug.cgi?id=148155
+
+        Reviewed by Alexey Proskuryakov.
+
+        No new tests, since the purpose of this patch is to get existing tests to pass when
+        allowing similar wheel events to coalesce. To accomplish this, we relax our assumption
+        that the user must have generated at least 3 momentum wheel events in order for the
+        gliding animation to trigger. Upon receiving a wheel event indicating the end of the
+        momentum phase, we now kick off the gliding animation as long as any momentum event
+        was tracked earlier in the gesture with a nonzero wheel delta.
+
+        * platform/cocoa/ScrollController.mm:
+        (WebCore::ScrollController::processWheelEventForScrollSnapOnAxis): Added logic to
+            begin a glide animation if we have received a momentum end event but have not
+            yet triggered a gliding animation.
+        * platform/cocoa/ScrollSnapAnimatorState.h:
+        * platform/cocoa/ScrollSnapAnimatorState.mm:
+        (WebCore::ScrollSnapAnimatorState::wheelDeltaTrackingIsInProgress): Minor refactoring
+            to make the wheel event processing code more readable.
+        (WebCore::ScrollSnapAnimatorState::hasFinishedTrackingWheelDeltas): Ditto.
+
 2015-08-18  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [Cocoa] Punctuation near Hindi text is garbled when styled with the system font
index 695e284e272326ee7453d4c41e319d251cee9212..885201af3a6d1d61ffab7e642ff22736743376f7 100644 (file)
@@ -554,15 +554,18 @@ void ScrollController::processWheelEventForScrollSnapOnAxis(ScrollEventAxis axis
     case WheelEventStatus::InertialScrolling:
         // This check for DestinationReached ensures that we don't receive another set of momentum events after ending the last glide.
         if (snapState.m_currentState != ScrollSnapState::Gliding && snapState.m_currentState != ScrollSnapState::DestinationReached) {
-            if (snapState.m_numWheelDeltasTracked < snapState.wheelDeltaWindowSize && wheelDelta)
+            if (snapState.wheelDeltaTrackingIsInProgress() && wheelDelta)
                 snapState.pushInitialWheelDelta(wheelDelta);
             
-            if ((snapState.m_numWheelDeltasTracked == snapState.wheelDeltaWindowSize) && snapState.averageInitialWheelDelta())
+            if (snapState.hasFinishedTrackingWheelDeltas() && snapState.averageInitialWheelDelta())
                 beginScrollSnapAnimation(axis, ScrollSnapState::Gliding);
         }
         break;
         
     case WheelEventStatus::InertialScrollEnd:
+        if (snapState.wheelDeltaTrackingIsInProgress() && snapState.averageInitialWheelDelta())
+            beginScrollSnapAnimation(axis, ScrollSnapState::Gliding);
+
         snapState.clearInitialWheelDeltaWindow();
         snapState.m_shouldOverrideWheelEvent = false;
         break;
index 5b207faa404039094ba2e76579383a6cd9dd4719..1330105cadf1e5a78e646352b57487f3f21d179f 100644 (file)
@@ -52,6 +52,8 @@ struct ScrollSnapAnimatorState {
     void clearInitialWheelDeltaWindow();
     bool isSnapping() const;
     bool canReachTargetWithCurrentInitialScrollDelta() const;
+    bool wheelDeltaTrackingIsInProgress() const;
+    bool hasFinishedTrackingWheelDeltas() const;
     float interpolatedOffsetAtProgress(float) const;
     
     static const int wheelDeltaWindowSize = 3;
index 6f6980226f42a80deb80ac9883f43f210e7782f9..7fa64328f5fb7be25065ecb5499ac8f30c4d957d 100644 (file)
@@ -84,6 +84,16 @@ bool ScrollSnapAnimatorState::canReachTargetWithCurrentInitialScrollDelta() cons
     return m_initialOffset < m_targetOffset ? m_initialScrollDelta > 0 : m_initialScrollDelta < 0;
 }
     
+bool ScrollSnapAnimatorState::wheelDeltaTrackingIsInProgress() const
+{
+    return m_numWheelDeltasTracked && m_numWheelDeltasTracked < wheelDeltaWindowSize;
+}
+
+bool ScrollSnapAnimatorState::hasFinishedTrackingWheelDeltas() const
+{
+    return m_numWheelDeltasTracked == wheelDeltaWindowSize;
+}
+
 float ScrollSnapAnimatorState::interpolatedOffsetAtProgress(float progress) const
 {
     progress = std::max(0.0f, std::min(1.0f, progress));