Move AxisScrollSnapAnimator logic to ScrollController
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Mar 2015 19:32:27 +0000 (19:32 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 5 Mar 2015 19:32:27 +0000 (19:32 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142293
<rdar://problem/20039867>

Reviewed by Dean Jackson.

No change in function.

Move the animation logic out of 'AxisScrollSnapAnimator' into 'ScrollController'. Rename the remaining
bits of 'AxisScrollSnapAnimator' as 'ScrollSnapAnimatorState'. Remove a number of delegate methods required
by 'AxisScrollSnapAnimatorClient' that are no longer needed.

Also, break up some of the Scroll Snap Point math to be a little easier to understand.

* WebCore.xcodeproj/project.pbxproj: Rename 'platform/mac/AxisScrollSnapAnimator.{h,mm}' -> 'platform/cocoa/ScrollSnapAnimatorState.h'
* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h: Mark 'scrollOffsetOnAxis' as const.
* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
(WebCore::ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis): Make 'const'
* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::scrollOffsetOnAxis): Make 'const'
* platform/ScrollAnimator.h:
* platform/cocoa/ScrollController.h: No longer subclass from AxisScrollSnapAnimatorClient.
* platform/cocoa/ScrollController.mm:
(WebCore::ScrollController::scrollSnapPointState): Added accessors (const and non-const) for the individual
Scroll Snap State of each axis.
(WebCore::toWheelEventStatus): Moved from AxisScrollSnapAnimator.
(WebCore::ScrollController::processWheelEventForScrollSnapOnAxis): Added helper function containing the snap wheel handler code
from AxisScrollSnapAnimator.
(WebCore::ScrollController::shouldOverrideWheelEvent): Moved from AxisScrollSnapAnimator.
(WebCore::ScrollController::processWheelEventForScrollSnap): Update to use new methods moved from AxisScrollSnapAnimator.
(WebCore::ScrollController::updateScrollAnimatorsAndTimers): Update for new ScrollSnapAnimatorState class.
(WebCore::ScrollController::updateScrollSnapPoints): Ditto.
(WebCore::ScrollController::startScrollSnapTimer): Call client (delegate) method.
(WebCore::ScrollController::stopScrollSnapTimer): Ditto.
(WebCore::ScrollController::horizontalScrollSnapTimerFired): Call new 'scrollSnapAnimationUpdate' method passing the
correct axis to animate.
(WebCore::ScrollController::verticalScrollSnapTimerFired): Ditto.
(WebCore::ScrollController::scrollSnapAnimationUpdate): Moved from AxisScrollSnapAnimator.
(WebCore::projectedInertialScrollDistance): Moved from AxisScrollSnapAnimator.
(WebCore::ScrollController::initializeGlideParameters): Ditto.
(WebCore::ScrollController::beginScrollSnapAnimation): Ditto.
(WebCore::ScrollController::endScrollSnapAnimation): Ditto.
(WebCore::snapProgress): Created a new function for this calculation to make reasoning about the 'computeSnapDelta' and
'computeGlideDelta' easier.
(WebCore::clampedSnapMagnitude): Ditto.
(WebCore::ScrollController::computeSnapDelta): Moved from AxisScrollSnapAnimator.
(WebCore::snapGlide): Created a new function for this calculation to make reasoning about the 'computeGlideDelta' easier.
(WebCore::ScrollController::computeGlideDelta): Moved from AxisScrollSnapAnimator.
(WebCore::ScrollController::scrollOffsetOnAxis): Deleted.
(WebCore::ScrollController::immediateScrollOnAxis): Deleted.
* platform/cocoa/ScrollSnapAnimatorState.h: Copied from platform/mac/AxisScrollSnapAnimator.h.
(WebCore::AxisScrollSnapAnimatorClient::~AxisScrollSnapAnimatorClient): Deleted.
* platform/cocoa/ScrollSnapAnimatorState.mm: Copied from platform/mac/AxisScrollSnapAnimator.mm.
(WebCore::ScrollSnapAnimatorState::ScrollSnapAnimatorState):
(WebCore::ScrollSnapAnimatorState::pushInitialWheelDelta):
(WebCore::ScrollSnapAnimatorState::averageInitialWheelDelta):
(WebCore::ScrollSnapAnimatorState::clearInitialWheelDeltaWindow):
(WebCore::toWheelEventStatus): Deleted.
(WebCore::projectedInertialScrollDistance): Deleted.
(WebCore::AxisScrollSnapAnimator::AxisScrollSnapAnimator): Deleted.
(WebCore::AxisScrollSnapAnimator::handleWheelEvent): Deleted.
(WebCore::AxisScrollSnapAnimator::shouldOverrideWheelEvent): Deleted.
(WebCore::AxisScrollSnapAnimator::scrollSnapAnimationUpdate): Deleted.
(WebCore::AxisScrollSnapAnimator::beginScrollSnapAnimation): Deleted.
(WebCore::AxisScrollSnapAnimator::endScrollSnapAnimation): Deleted.
(WebCore::AxisScrollSnapAnimator::computeSnapDelta): Deleted.
(WebCore::AxisScrollSnapAnimator::computeGlideDelta): Deleted.
(WebCore::AxisScrollSnapAnimator::initializeGlideParameters): Deleted.
(WebCore::AxisScrollSnapAnimator::pushInitialWheelDelta): Deleted.
(WebCore::AxisScrollSnapAnimator::averageInitialWheelDelta): Deleted.
(WebCore::AxisScrollSnapAnimator::clearInitialWheelDeltaWindow): Deleted.
* platform/mac/AxisScrollSnapAnimator.h: Removed.
* platform/mac/AxisScrollSnapAnimator.mm: Removed.
* platform/mac/ScrollAnimatorMac.h:
* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::pinnedInDirection): Removed.

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

13 files changed:
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h
Source/WebCore/page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm
Source/WebCore/platform/ScrollAnimator.cpp
Source/WebCore/platform/ScrollAnimator.h
Source/WebCore/platform/cocoa/ScrollController.h
Source/WebCore/platform/cocoa/ScrollController.mm
Source/WebCore/platform/cocoa/ScrollSnapAnimatorState.h [moved from Source/WebCore/platform/mac/AxisScrollSnapAnimator.h with 66% similarity]
Source/WebCore/platform/cocoa/ScrollSnapAnimatorState.mm [new file with mode: 0644]
Source/WebCore/platform/mac/AxisScrollSnapAnimator.mm [deleted file]
Source/WebCore/platform/mac/ScrollAnimatorMac.h
Source/WebCore/platform/mac/ScrollAnimatorMac.mm

index 289ed9d..935c508 100644 (file)
@@ -1,3 +1,82 @@
+2015-03-05  Brent Fulgham  <bfulgham@apple.com>
+
+        Move AxisScrollSnapAnimator logic to ScrollController
+        https://bugs.webkit.org/show_bug.cgi?id=142293
+        <rdar://problem/20039867>
+
+        Reviewed by Dean Jackson.
+
+        No change in function.
+
+        Move the animation logic out of 'AxisScrollSnapAnimator' into 'ScrollController'. Rename the remaining
+        bits of 'AxisScrollSnapAnimator' as 'ScrollSnapAnimatorState'. Remove a number of delegate methods required
+        by 'AxisScrollSnapAnimatorClient' that are no longer needed.
+
+        Also, break up some of the Scroll Snap Point math to be a little easier to understand.
+
+        * WebCore.xcodeproj/project.pbxproj: Rename 'platform/mac/AxisScrollSnapAnimator.{h,mm}' -> 'platform/cocoa/ScrollSnapAnimatorState.h'
+        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h: Mark 'scrollOffsetOnAxis' as const.
+        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis): Make 'const'
+        * platform/ScrollAnimator.cpp:
+        (WebCore::ScrollAnimator::scrollOffsetOnAxis): Make 'const'
+        * platform/ScrollAnimator.h:
+        * platform/cocoa/ScrollController.h: No longer subclass from AxisScrollSnapAnimatorClient.
+        * platform/cocoa/ScrollController.mm:
+        (WebCore::ScrollController::scrollSnapPointState): Added accessors (const and non-const) for the individual
+        Scroll Snap State of each axis.
+        (WebCore::toWheelEventStatus): Moved from AxisScrollSnapAnimator.
+        (WebCore::ScrollController::processWheelEventForScrollSnapOnAxis): Added helper function containing the snap wheel handler code
+        from AxisScrollSnapAnimator.
+        (WebCore::ScrollController::shouldOverrideWheelEvent): Moved from AxisScrollSnapAnimator.
+        (WebCore::ScrollController::processWheelEventForScrollSnap): Update to use new methods moved from AxisScrollSnapAnimator.
+        (WebCore::ScrollController::updateScrollAnimatorsAndTimers): Update for new ScrollSnapAnimatorState class.
+        (WebCore::ScrollController::updateScrollSnapPoints): Ditto.
+        (WebCore::ScrollController::startScrollSnapTimer): Call client (delegate) method.
+        (WebCore::ScrollController::stopScrollSnapTimer): Ditto.
+        (WebCore::ScrollController::horizontalScrollSnapTimerFired): Call new 'scrollSnapAnimationUpdate' method passing the
+        correct axis to animate.
+        (WebCore::ScrollController::verticalScrollSnapTimerFired): Ditto.
+        (WebCore::ScrollController::scrollSnapAnimationUpdate): Moved from AxisScrollSnapAnimator.
+        (WebCore::projectedInertialScrollDistance): Moved from AxisScrollSnapAnimator.
+        (WebCore::ScrollController::initializeGlideParameters): Ditto.
+        (WebCore::ScrollController::beginScrollSnapAnimation): Ditto.
+        (WebCore::ScrollController::endScrollSnapAnimation): Ditto.
+        (WebCore::snapProgress): Created a new function for this calculation to make reasoning about the 'computeSnapDelta' and
+        'computeGlideDelta' easier.
+        (WebCore::clampedSnapMagnitude): Ditto.
+        (WebCore::ScrollController::computeSnapDelta): Moved from AxisScrollSnapAnimator.
+        (WebCore::snapGlide): Created a new function for this calculation to make reasoning about the 'computeGlideDelta' easier.
+        (WebCore::ScrollController::computeGlideDelta): Moved from AxisScrollSnapAnimator.
+        (WebCore::ScrollController::scrollOffsetOnAxis): Deleted.
+        (WebCore::ScrollController::immediateScrollOnAxis): Deleted.
+        * platform/cocoa/ScrollSnapAnimatorState.h: Copied from platform/mac/AxisScrollSnapAnimator.h.
+        (WebCore::AxisScrollSnapAnimatorClient::~AxisScrollSnapAnimatorClient): Deleted.
+        * platform/cocoa/ScrollSnapAnimatorState.mm: Copied from platform/mac/AxisScrollSnapAnimator.mm.
+        (WebCore::ScrollSnapAnimatorState::ScrollSnapAnimatorState):
+        (WebCore::ScrollSnapAnimatorState::pushInitialWheelDelta):
+        (WebCore::ScrollSnapAnimatorState::averageInitialWheelDelta):
+        (WebCore::ScrollSnapAnimatorState::clearInitialWheelDeltaWindow):
+        (WebCore::toWheelEventStatus): Deleted.
+        (WebCore::projectedInertialScrollDistance): Deleted.
+        (WebCore::AxisScrollSnapAnimator::AxisScrollSnapAnimator): Deleted.
+        (WebCore::AxisScrollSnapAnimator::handleWheelEvent): Deleted.
+        (WebCore::AxisScrollSnapAnimator::shouldOverrideWheelEvent): Deleted.
+        (WebCore::AxisScrollSnapAnimator::scrollSnapAnimationUpdate): Deleted.
+        (WebCore::AxisScrollSnapAnimator::beginScrollSnapAnimation): Deleted.
+        (WebCore::AxisScrollSnapAnimator::endScrollSnapAnimation): Deleted.
+        (WebCore::AxisScrollSnapAnimator::computeSnapDelta): Deleted.
+        (WebCore::AxisScrollSnapAnimator::computeGlideDelta): Deleted.
+        (WebCore::AxisScrollSnapAnimator::initializeGlideParameters): Deleted.
+        (WebCore::AxisScrollSnapAnimator::pushInitialWheelDelta): Deleted.
+        (WebCore::AxisScrollSnapAnimator::averageInitialWheelDelta): Deleted.
+        (WebCore::AxisScrollSnapAnimator::clearInitialWheelDeltaWindow): Deleted.
+        * platform/mac/AxisScrollSnapAnimator.h: Removed.
+        * platform/mac/AxisScrollSnapAnimator.mm: Removed.
+        * platform/mac/ScrollAnimatorMac.h:
+        * platform/mac/ScrollAnimatorMac.mm:
+        (WebCore::ScrollAnimatorMac::pinnedInDirection): Removed.
+
 2015-03-04  Dean Jackson  <dino@apple.com>
 
         [iOS Media] Small inline controls can clip the time widgets
index 9501433..7ecb76f 100644 (file)
                F42FFB461984B71600F6837F /* LengthRepeat.h in Headers */ = {isa = PBXBuildFile; fileRef = F42FFB451984B71600F6837F /* LengthRepeat.h */; };
                F45C231D1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F45C231B1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp */; };
                F45C231E1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h in Headers */ = {isa = PBXBuildFile; fileRef = F45C231C1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               F478755419983AFF0024A287 /* AxisScrollSnapAnimator.h in Headers */ = {isa = PBXBuildFile; fileRef = F478755219983AFF0024A287 /* AxisScrollSnapAnimator.h */; settings = {ATTRIBUTES = (Private, ); }; };
-               F478755519983AFF0024A287 /* AxisScrollSnapAnimator.mm in Sources */ = {isa = PBXBuildFile; fileRef = F478755319983AFF0024A287 /* AxisScrollSnapAnimator.mm */; };
+               F478755419983AFF0024A287 /* ScrollSnapAnimatorState.h in Headers */ = {isa = PBXBuildFile; fileRef = F478755219983AFF0024A287 /* ScrollSnapAnimatorState.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               F478755519983AFF0024A287 /* ScrollSnapAnimatorState.mm in Sources */ = {isa = PBXBuildFile; fileRef = F478755319983AFF0024A287 /* ScrollSnapAnimatorState.mm */; };
                F47A5E3E195B8C8A00483100 /* StyleScrollSnapPoints.h in Headers */ = {isa = PBXBuildFile; fileRef = F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */; settings = {ATTRIBUTES = (Private, ); }; };
                F47A5E3F195B8E4800483100 /* StyleScrollSnapPoints.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F47A5E3A195B8C8A00483100 /* StyleScrollSnapPoints.cpp */; };
                F50664F7157F52DC00AC226F /* FormController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F50664F5157F52DC00AC226F /* FormController.cpp */; };
                F42FFB451984B71600F6837F /* LengthRepeat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LengthRepeat.h; sourceTree = "<group>"; };
                F45C231B1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AxisScrollSnapOffsets.cpp; sourceTree = "<group>"; };
                F45C231C1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AxisScrollSnapOffsets.h; sourceTree = "<group>"; };
-               F478755219983AFF0024A287 /* AxisScrollSnapAnimator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AxisScrollSnapAnimator.h; sourceTree = "<group>"; };
-               F478755319983AFF0024A287 /* AxisScrollSnapAnimator.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = AxisScrollSnapAnimator.mm; sourceTree = "<group>"; };
+               F478755219983AFF0024A287 /* ScrollSnapAnimatorState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScrollSnapAnimatorState.h; sourceTree = "<group>"; };
+               F478755319983AFF0024A287 /* ScrollSnapAnimatorState.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ScrollSnapAnimatorState.mm; sourceTree = "<group>"; };
                F47A5E3A195B8C8A00483100 /* StyleScrollSnapPoints.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StyleScrollSnapPoints.cpp; path = style/StyleScrollSnapPoints.cpp; sourceTree = "<group>"; };
                F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleScrollSnapPoints.h; path = style/StyleScrollSnapPoints.h; sourceTree = "<group>"; };
                F50664F5157F52DC00AC226F /* FormController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormController.cpp; sourceTree = "<group>"; };
                6582A14809999D6C00BEEB6D /* mac */ = {
                        isa = PBXGroup;
                        children = (
-                               F478755219983AFF0024A287 /* AxisScrollSnapAnimator.h */,
-                               F478755319983AFF0024A287 /* AxisScrollSnapAnimator.mm */,
                                65A640F00533BB1F0085E777 /* BlockExceptions.h */,
                                65F80697054D9F86008BF776 /* BlockExceptions.mm */,
                                06027CB20B1CC03D00884B2D /* ContextMenuItemMac.mm */,
                A5C974CE11485FDA0066F2AB /* cocoa */ = {
                        isa = PBXGroup;
                        children = (
+                               F478755219983AFF0024A287 /* ScrollSnapAnimatorState.h */,
+                               F478755319983AFF0024A287 /* ScrollSnapAnimatorState.mm */,
                                A14090FA1AA51E1D0091191A /* ContentFilterUnblockHandlerCocoa.mm */,
                                5D8C4DBD1428222C0026CE72 /* DisplaySleepDisablerCocoa.cpp */,
                                5D8C4DBE1428222C0026CE72 /* DisplaySleepDisablerCocoa.h */,
                                070363E4181A1CDC00C074A5 /* AVMediaCaptureSource.h in Headers */,
                                CD336F6217F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.h in Headers */,
                                070363E6181A1CDC00C074A5 /* AVVideoCaptureSource.h in Headers */,
-                               F478755419983AFF0024A287 /* AxisScrollSnapAnimator.h in Headers */,
+                               F478755419983AFF0024A287 /* ScrollSnapAnimatorState.h in Headers */,
                                F45C231E1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h in Headers */,
                                29A812380FBB9C1D00510293 /* AXObjectCache.h in Headers */,
                                51741D0F0B07259A00ED442C /* BackForwardClient.h in Headers */,
                                070363E5181A1CDC00C074A5 /* AVMediaCaptureSource.mm in Sources */,
                                CD336F6117F9F64700DDDCD0 /* AVTrackPrivateAVFObjCImpl.mm in Sources */,
                                070363E7181A1CDC00C074A5 /* AVVideoCaptureSource.mm in Sources */,
-                               F478755519983AFF0024A287 /* AxisScrollSnapAnimator.mm in Sources */,
+                               F478755519983AFF0024A287 /* ScrollSnapAnimatorState.mm in Sources */,
                                F45C231D1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp in Sources */,
                                37F57ACF1A5072DD00876F98 /* AXObjectCache.cpp in Sources */,
                                AAA728F916D1D8BC00D3BBC6 /* AXObjectCacheIOS.mm in Sources */,
index ebc9bc4..3dc8b58 100644 (file)
@@ -80,7 +80,7 @@ private:
     bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis);
 
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
+    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) const override;
     void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
 #endif
 
index c6fc4d7..2707251 100644 (file)
@@ -541,7 +541,7 @@ void logWheelEventHandlerCountChanged(unsigned count)
 }
 
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-LayoutUnit ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis(ScrollEventAxis axis)
+LayoutUnit ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis(ScrollEventAxis axis) const
 {
     const FloatPoint& currentPosition = scrollPosition();
     return axis == ScrollEventAxis::Horizontal ? currentPosition.x() : currentPosition.y();
index 5a2f2a1..28aa826 100644 (file)
@@ -178,7 +178,7 @@ void ScrollAnimator::updateScrollAnimatorsAndTimers()
     m_scrollController.updateScrollAnimatorsAndTimers(m_scrollableArea);
 }
 
-LayoutUnit ScrollAnimator::scrollOffsetOnAxis(ScrollEventAxis axis)
+LayoutUnit ScrollAnimator::scrollOffsetOnAxis(ScrollEventAxis axis) const
 {
     return axis == ScrollEventAxis::Horizontal ? m_currentPosX : m_currentPosY;
 }
index faaf1e7..5eaa7a9 100644 (file)
@@ -120,7 +120,7 @@ public:
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     bool processWheelEventForScrollSnap(const PlatformWheelEvent&);
     void updateScrollAnimatorsAndTimers();
-    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
+    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) const override;
     void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
 #endif
 
index d89ad89..beb95c0 100644 (file)
@@ -35,7 +35,7 @@
 #include <wtf/RunLoop.h>
 
 #if ENABLE(CSS_SCROLL_SNAP)
-#include "AxisScrollSnapAnimator.h"
+#include "ScrollSnapAnimatorState.h"
 #endif
 
 namespace WebCore {
@@ -76,7 +76,7 @@ public:
     virtual void adjustScrollPositionToBoundsIfNecessary() = 0;
 
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-    virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0;
+    virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) const = 0;
     virtual void immediateScrollOnAxis(ScrollEventAxis, float delta) = 0;
     virtual void startScrollSnapTimer(ScrollEventAxis)
     {
@@ -91,11 +91,7 @@ public:
 #endif
 };
 
-#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-class ScrollController : public AxisScrollSnapAnimatorClient {
-#else
 class ScrollController {
-#endif
     WTF_MAKE_NONCOPYABLE(ScrollController);
 
 public:
@@ -122,11 +118,23 @@ private:
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     void horizontalScrollSnapTimerFired();
     void verticalScrollSnapTimerFired();
-    void startScrollSnapTimer(ScrollEventAxis) override;
-    void stopScrollSnapTimer(ScrollEventAxis) override;
+    void startScrollSnapTimer(ScrollEventAxis);
+    void stopScrollSnapTimer(ScrollEventAxis);
+
+    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) const;
+    void processWheelEventForScrollSnapOnAxis(ScrollEventAxis, const PlatformWheelEvent&);
+    bool shouldOverrideWheelEvent(ScrollEventAxis, const PlatformWheelEvent&) const;
+
+    void beginScrollSnapAnimation(ScrollEventAxis, ScrollSnapState);
+    void scrollSnapAnimationUpdate(ScrollEventAxis);
+    void endScrollSnapAnimation(ScrollEventAxis, ScrollSnapState);
+
+    void initializeGlideParameters(ScrollEventAxis, bool);
+    float computeSnapDelta(ScrollEventAxis) const;
+    float computeGlideDelta(ScrollEventAxis) const;
 
-    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
-    void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
+    ScrollSnapAnimatorState& scrollSnapPointState(ScrollEventAxis);
+    const ScrollSnapAnimatorState& scrollSnapPointState(ScrollEventAxis) const;
 #endif
 
     ScrollControllerClient* m_client;
@@ -145,8 +153,8 @@ private:
 
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
     // FIXME: Find a way to consolidate both timers into one variable.
-    std::unique_ptr<AxisScrollSnapAnimator> m_horizontalScrollSnapAnimator;
-    std::unique_ptr<AxisScrollSnapAnimator> m_verticalScrollSnapAnimator;
+    std::unique_ptr<ScrollSnapAnimatorState> m_horizontalScrollSnapState;
+    std::unique_ptr<ScrollSnapAnimatorState> m_verticalScrollSnapState;
     RunLoop::Timer<ScrollController> m_horizontalScrollSnapTimer;
     RunLoop::Timer<ScrollController> m_verticalScrollSnapTimer;
 #endif
index 039c7da..b88bacc 100644 (file)
@@ -32,7 +32,7 @@
 #include <sys/time.h>
 
 #if ENABLE(CSS_SCROLL_SNAP)
-#include "AxisScrollSnapAnimator.h"
+#include "ScrollSnapAnimatorState.h"
 #include "ScrollableArea.h"
 #endif
 
@@ -68,6 +68,31 @@ static const float scrollVelocityZeroingTimeout = 0.10f;
 static const float rubberbandDirectionLockStretchRatio = 1;
 static const float rubberbandMinimumRequiredDeltaBeforeStretch = 10;
 
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+static const float snapMagnitudeMax = 25;
+static const float snapMagnitudeMin = 5;
+static const float snapThresholdHigh = 1000;
+static const float snapThresholdLow = 50;
+
+static const float inertialScrollPredictionFactor = 16.7;
+static const float initialToFinalMomentumFactor = 1.0 / 40.0;
+
+static const float glideBoostMultiplier = 3.5;
+
+static const float maxTargetWheelDelta = 7;
+static const float minTargetWheelDelta = 3.5;
+#endif
+
+enum class WheelEventStatus {
+    UserScrollBegin,
+    UserScrolling,
+    UserScrollEnd,
+    InertialScrollBegin,
+    InertialScrolling,
+    InertialScrollEnd,
+    Unknown
+};
+
 static float elasticDeltaForTimeDelta(float initialPosition, float initialVelocity, float elapsedTime)
 {
     return wkNSElasticDeltaForTimeDelta(initialPosition, initialVelocity, elapsedTime);
@@ -423,16 +448,123 @@ bool ScrollController::shouldRubberBandInHorizontalDirection(const PlatformWheel
 }
 
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+ScrollSnapAnimatorState& ScrollController::scrollSnapPointState(ScrollEventAxis axis)
+{
+    ASSERT(axis != ScrollEventAxis::Horizontal || m_horizontalScrollSnapState);
+    ASSERT(axis != ScrollEventAxis::Vertical || m_verticalScrollSnapState);
+
+    return (axis == ScrollEventAxis::Horizontal) ? *m_horizontalScrollSnapState : *m_verticalScrollSnapState;
+}
+
+const ScrollSnapAnimatorState& ScrollController::scrollSnapPointState(ScrollEventAxis axis) const
+{
+    ASSERT(axis != ScrollEventAxis::Horizontal || m_horizontalScrollSnapState);
+    ASSERT(axis != ScrollEventAxis::Vertical || m_verticalScrollSnapState);
+    
+    return (axis == ScrollEventAxis::Horizontal) ? *m_horizontalScrollSnapState : *m_verticalScrollSnapState;
+}
+
+static inline WheelEventStatus toWheelEventStatus(PlatformWheelEventPhase phase, PlatformWheelEventPhase momentumPhase)
+{
+    if (phase == PlatformWheelEventPhaseNone) {
+        switch (momentumPhase) {
+        case PlatformWheelEventPhaseBegan:
+            return WheelEventStatus::InertialScrollBegin;
+                
+        case PlatformWheelEventPhaseChanged:
+            return WheelEventStatus::InertialScrolling;
+                
+        case PlatformWheelEventPhaseEnded:
+            return WheelEventStatus::InertialScrollEnd;
+                
+        default:
+            return WheelEventStatus::Unknown;
+        }
+    }
+    if (momentumPhase == PlatformWheelEventPhaseNone) {
+        switch (phase) {
+        case PlatformWheelEventPhaseBegan:
+        case PlatformWheelEventPhaseMayBegin:
+            return WheelEventStatus::UserScrollBegin;
+                
+        case PlatformWheelEventPhaseChanged:
+            return WheelEventStatus::UserScrolling;
+                
+        case PlatformWheelEventPhaseEnded:
+        case PlatformWheelEventPhaseCancelled:
+            return WheelEventStatus::UserScrollEnd;
+                
+        default:
+            return WheelEventStatus::Unknown;
+        }
+    }
+    return WheelEventStatus::Unknown;
+}
+
+void ScrollController::processWheelEventForScrollSnapOnAxis(ScrollEventAxis axis, const PlatformWheelEvent& event)
+{
+    ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+
+    float wheelDelta = axis == ScrollEventAxis::Horizontal ? -event.deltaX() : -event.deltaY();
+    WheelEventStatus wheelStatus = toWheelEventStatus(event.phase(), event.momentumPhase());
+    
+    switch (wheelStatus) {
+    case WheelEventStatus::UserScrollBegin:
+    case WheelEventStatus::UserScrolling:
+        endScrollSnapAnimation(axis, ScrollSnapState::UserInteraction);
+        break;
+            
+    case WheelEventStatus::UserScrollEnd:
+        beginScrollSnapAnimation(axis, ScrollSnapState::Snapping);
+        break;
+        
+    case WheelEventStatus::InertialScrollBegin:
+        // Begin tracking wheel deltas for glide prediction.
+        endScrollSnapAnimation(axis, ScrollSnapState::UserInteraction);
+        snapState.pushInitialWheelDelta(wheelDelta);
+        snapState.m_beginTrackingWheelDeltaOffset = m_client->scrollOffsetOnAxis(axis);
+        break;
+            
+    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)
+                snapState.pushInitialWheelDelta(wheelDelta);
+            
+            if (snapState.m_numWheelDeltasTracked == snapState.wheelDeltaWindowSize)
+                beginScrollSnapAnimation(axis, ScrollSnapState::Gliding);
+        }
+        break;
+        
+    case WheelEventStatus::InertialScrollEnd:
+        beginScrollSnapAnimation(axis, ScrollSnapState::Snapping);
+        snapState.clearInitialWheelDeltaWindow();
+        snapState.m_shouldOverrideWheelEvent = false;
+        break;
+        
+    case WheelEventStatus::Unknown:
+        ASSERT_NOT_REACHED();
+        break;
+    }
+}
+
+bool ScrollController::shouldOverrideWheelEvent(ScrollEventAxis axis, const PlatformWheelEvent& event) const
+{
+    const ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+
+    return snapState.m_shouldOverrideWheelEvent && toWheelEventStatus(event.phase(), event.momentumPhase()) == WheelEventStatus::InertialScrolling;
+}
+
 bool ScrollController::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
 {
-    if (m_verticalScrollSnapAnimator) {
-        m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent);
-        if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent))
+    if (m_verticalScrollSnapState) {
+        processWheelEventForScrollSnapOnAxis(ScrollEventAxis::Vertical, wheelEvent);
+        if (shouldOverrideWheelEvent(ScrollEventAxis::Vertical, wheelEvent))
             return false;
     }
-    if (m_horizontalScrollSnapAnimator) {
-        m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent);
-        if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent))
+    if (m_horizontalScrollSnapState) {
+        processWheelEventForScrollSnapOnAxis(ScrollEventAxis::Horizontal, wheelEvent);
+        if (shouldOverrideWheelEvent(ScrollEventAxis::Horizontal, wheelEvent))
             return false;
     }
 
@@ -443,59 +575,223 @@ void ScrollController::updateScrollAnimatorsAndTimers(const ScrollableArea& scro
 {
     // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated.
     if (scrollableArea.horizontalSnapOffsets())
-        m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, *scrollableArea.horizontalSnapOffsets(), ScrollEventAxis::Horizontal);
-    else if (m_horizontalScrollSnapAnimator)
-        m_horizontalScrollSnapAnimator = nullptr;
+        m_horizontalScrollSnapState = std::make_unique<ScrollSnapAnimatorState>(ScrollEventAxis::Horizontal, *scrollableArea.horizontalSnapOffsets());
+    else if (m_horizontalScrollSnapState)
+        m_horizontalScrollSnapState = nullptr;
 
     if (scrollableArea.verticalSnapOffsets())
-        m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, *scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical);
-    else if (m_verticalScrollSnapAnimator)
-        m_verticalScrollSnapAnimator = nullptr;
+        m_verticalScrollSnapState = std::make_unique<ScrollSnapAnimatorState>(ScrollEventAxis::Vertical, *scrollableArea.verticalSnapOffsets());
+    else if (m_verticalScrollSnapState)
+        m_verticalScrollSnapState = nullptr;
 }
 
 void ScrollController::updateScrollSnapPoints(ScrollEventAxis axis, const Vector<LayoutUnit>& snapPoints)
 {
     // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated.
     if (axis == ScrollEventAxis::Horizontal)
-        m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, snapPoints, ScrollEventAxis::Horizontal);
+        m_horizontalScrollSnapState = std::make_unique<ScrollSnapAnimatorState>(ScrollEventAxis::Horizontal, snapPoints);
 
     if (axis == ScrollEventAxis::Vertical)
-        m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, snapPoints, ScrollEventAxis::Vertical);
+        m_verticalScrollSnapState = std::make_unique<ScrollSnapAnimatorState>(ScrollEventAxis::Vertical, snapPoints);
 }
 
 void ScrollController::startScrollSnapTimer(ScrollEventAxis axis)
 {
     RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer;
-    if (!scrollSnapTimer.isActive())
+    if (!scrollSnapTimer.isActive()) {
+        m_client->startScrollSnapTimer(axis);
         scrollSnapTimer.startRepeating(1.0 / 60.0);
+    }
 }
 
 void ScrollController::stopScrollSnapTimer(ScrollEventAxis axis)
 {
+    m_client->stopScrollSnapTimer(axis);
     RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer;
     scrollSnapTimer.stop();
 }
 
 void ScrollController::horizontalScrollSnapTimerFired()
 {
-    if (m_horizontalScrollSnapAnimator)
-        m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate();
+    scrollSnapAnimationUpdate(ScrollEventAxis::Horizontal);
 }
 
 void ScrollController::verticalScrollSnapTimerFired()
 {
-    if (m_verticalScrollSnapAnimator)
-        m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate();
+    scrollSnapAnimationUpdate(ScrollEventAxis::Vertical);
 }
 
-LayoutUnit ScrollController::scrollOffsetOnAxis(ScrollEventAxis axis)
+void ScrollController::scrollSnapAnimationUpdate(ScrollEventAxis axis)
 {
-    return m_client->scrollOffsetOnAxis(axis);
+    if (axis == ScrollEventAxis::Horizontal && !m_horizontalScrollSnapState)
+        return;
+
+    if (axis == ScrollEventAxis::Vertical && !m_verticalScrollSnapState)
+        return;
+
+    ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+    if (snapState.m_currentState == ScrollSnapState::DestinationReached)
+        return;
+    
+    ASSERT(snapState.m_currentState == ScrollSnapState::Gliding || snapState.m_currentState == ScrollSnapState::Snapping);
+    float delta = snapState.m_currentState == ScrollSnapState::Snapping ? computeSnapDelta(axis) : computeGlideDelta(axis);
+    if (delta)
+        m_client->immediateScrollOnAxis(axis, delta);
+    else
+        endScrollSnapAnimation(axis, ScrollSnapState::DestinationReached);
+}
+
+static inline float projectedInertialScrollDistance(float initialWheelDelta)
+{
+    // FIXME: Experiments with inertial scrolling show a fairly consistent linear relationship between initial wheel delta and total distance scrolled.
+    // In the future, we'll want to find a more accurate way of inertial scroll prediction.
+    return inertialScrollPredictionFactor * initialWheelDelta;
+}
+
+void ScrollController::initializeGlideParameters(ScrollEventAxis axis, bool shouldIncreaseInitialWheelDelta)
+{
+    ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+    
+    // FIXME: Glide boost is a hacky way to speed up natural scrolling velocity. We should find a better way to accomplish this.
+    if (shouldIncreaseInitialWheelDelta)
+        snapState.m_glideInitialWheelDelta *= glideBoostMultiplier;
+    
+    // FIXME: There must be a better way to determine a good target delta than multiplying by a factor and clamping to min/max values.
+    float targetFinalWheelDelta = initialToFinalMomentumFactor * (snapState.m_glideInitialWheelDelta < 0 ? -snapState.m_glideInitialWheelDelta : snapState.m_glideInitialWheelDelta);
+    targetFinalWheelDelta = (snapState.m_glideInitialWheelDelta > 0 ? 1 : -1) * std::min(std::max(targetFinalWheelDelta, minTargetWheelDelta), maxTargetWheelDelta);
+    snapState.m_glideMagnitude = (snapState.m_glideInitialWheelDelta + targetFinalWheelDelta) / 2;
+    snapState.m_glidePhaseShift = acos((snapState.m_glideInitialWheelDelta - targetFinalWheelDelta) / (snapState.m_glideInitialWheelDelta + targetFinalWheelDelta));
+}
+
+void ScrollController::beginScrollSnapAnimation(ScrollEventAxis axis, ScrollSnapState newState)
+{
+    ASSERT(newState == ScrollSnapState::Gliding || newState == ScrollSnapState::Snapping);
+    
+    ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+
+    LayoutUnit offset = m_client->scrollOffsetOnAxis(axis);
+    float initialWheelDelta = newState == ScrollSnapState::Gliding ? snapState.averageInitialWheelDelta() : 0;
+    LayoutUnit projectedScrollDestination = newState == ScrollSnapState::Gliding ? snapState.m_beginTrackingWheelDeltaOffset + LayoutUnit(projectedInertialScrollDistance(initialWheelDelta)) : offset;
+    if (snapState.m_snapOffsets.isEmpty())
+        return;
+
+    projectedScrollDestination = std::min(std::max(projectedScrollDestination, snapState.m_snapOffsets.first()), snapState.m_snapOffsets.last());
+    snapState.m_initialOffset = offset;
+    snapState.m_targetOffset = closestSnapOffset<LayoutUnit, float>(snapState.m_snapOffsets, projectedScrollDestination, initialWheelDelta);
+    if (snapState.m_initialOffset == snapState.m_targetOffset)
+        return;
+    
+    snapState.m_currentState = newState;
+    if (newState == ScrollSnapState::Gliding) {
+        snapState.m_shouldOverrideWheelEvent = true;
+        snapState.m_glideInitialWheelDelta = initialWheelDelta;
+        bool glideRequiresBoost;
+        if (initialWheelDelta > 0)
+            glideRequiresBoost = projectedScrollDestination - offset < snapState.m_targetOffset - projectedScrollDestination;
+        else
+            glideRequiresBoost = offset - projectedScrollDestination < projectedScrollDestination - snapState.m_targetOffset;
+        
+        initializeGlideParameters(axis, glideRequiresBoost);
+        snapState.clearInitialWheelDeltaWindow();
+    }
+    startScrollSnapTimer(axis);
 }
 
-void ScrollController::immediateScrollOnAxis(ScrollEventAxis axis, float delta)
+void ScrollController::endScrollSnapAnimation(ScrollEventAxis axis, ScrollSnapState newState)
 {
-    m_client->immediateScrollOnAxis(axis, delta);
+    ASSERT(newState == ScrollSnapState::DestinationReached || newState == ScrollSnapState::UserInteraction);
+
+    ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+
+    if (snapState.m_currentState == ScrollSnapState::Gliding)
+        snapState.clearInitialWheelDeltaWindow();
+    
+    snapState.m_currentState = newState;
+    stopScrollSnapTimer(axis);
+}
+
+static inline float snapProgress(const LayoutUnit& offset, const ScrollSnapAnimatorState& snapState)
+{
+    const float distanceTraveled = static_cast<float>(offset - snapState.m_initialOffset);
+    const float totalDistance = static_cast<float>(snapState.m_targetOffset - snapState.m_initialOffset);
+
+    return distanceTraveled / totalDistance;
+}
+
+static inline float clampedSnapMagnitude(float thresholdedDistance)
+{
+    return snapMagnitudeMin + (snapMagnitudeMax - snapMagnitudeMin) * (thresholdedDistance - snapThresholdLow) / (snapThresholdHigh - snapThresholdLow);
+}
+
+// Computes the amount to scroll by when performing a "snap" operation, i.e. when a user releases the trackpad without flicking. The snap delta
+// is a function of progress t, where t is equal to DISTANCE_TRAVELED / TOTAL_DISTANCE, DISTANCE_TRAVELED is the distance from the initialOffset
+// to the current offset, and TOTAL_DISTANCE is the distance from initialOffset to targetOffset. The snapping equation is as follows:
+// delta(t) = MAGNITUDE * sin(PI * t). MAGNITUDE indicates the top speed reached near the middle of the animation (t = 0.5), and is a linear
+// relationship of the distance traveled, clamped by arbitrary min and max values.
+float ScrollController::computeSnapDelta(ScrollEventAxis axis) const
+{
+    const ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+
+    LayoutUnit offset = m_client->scrollOffsetOnAxis(axis);
+    bool canComputeSnap =  (snapState.m_initialOffset <= offset && offset < snapState.m_targetOffset) || (snapState.m_targetOffset < offset && offset <= snapState.m_initialOffset);
+    if (snapState.m_currentState != ScrollSnapState::Snapping || !canComputeSnap)
+        return 0;
+    
+    float progress = snapProgress(offset, snapState);
+
+    // Threshold the distance before computing magnitude, so only distances within a certain range are considered.
+    int sign = snapState.m_initialOffset < snapState.m_targetOffset ? 1 : -1;
+    float thresholdedDistance = std::min(std::max<float>((snapState.m_targetOffset - snapState.m_initialOffset) * sign, snapThresholdLow), snapThresholdHigh);
+
+    float magnitude = clampedSnapMagnitude(thresholdedDistance);
+
+    float rawSnapDelta = std::max<float>(1, magnitude * std::sin(piFloat * progress));
+    if ((snapState.m_targetOffset < offset && offset - rawSnapDelta < snapState.m_targetOffset) || (snapState.m_targetOffset > offset && offset + rawSnapDelta > snapState.m_targetOffset))
+        return snapState.m_targetOffset - offset;
+    
+    return sign * rawSnapDelta;
+}
+
+static inline float snapGlide(float progress, const ScrollSnapAnimatorState& snapState)
+{
+    // FIXME: We might want to investigate why -m_glidePhaseShift results in the behavior we want.
+    return ceil(snapState.m_glideMagnitude * (1.0f + std::cos(piFloat * progress - snapState.m_glidePhaseShift)));
+}
+
+// Computes the amount to scroll by when performing a "glide" operation, i.e. when a user releases the trackpad with an initial velocity. Here,
+// we want the scroll offset to animate directly to the snap point.
+//
+// The snap delta is a function of progress t, where: (1) t is equal to DISTANCE_TRAVELED / TOTAL_DISTANCE, (2) DISTANCE_TRAVELED is the distance
+// from the initialOffset to the current offset, and (3) TOTAL_DISTANCE is the distance from initialOffset to targetOffset.
+//
+// The general model of our gliding equation is delta(t) = MAGNITUDE * (1 + cos(PI * t + PHASE_SHIFT)). This was determined after examining the
+// momentum velocity curve as a function of progress. To compute MAGNITUDE and PHASE_SHIFT, we use initial velocity V0 and the final velocity VF,
+// both as wheel deltas (pixels per timestep). VF should be a small value (< 10) chosen based on the initial velocity and TOTAL_DISTANCE.
+// We also enforce the following constraints for the gliding equation:
+//   1. delta(0) = V0, since we want the initial velocity of the gliding animation to match the user's scroll velocity. The exception to this is
+//      when the glide velocity is not enough to naturally reach the next snap point, and thus requires a boost (see initializeGlideParameters)
+//   2. delta(1) = VF, since at t=1, the animation has completed and we want the last wheel delta to match the final velocity VF. Note that this
+//      doesn't guarantee that the final velocity will be exactly VF. However, assuming that the initial velocity is much less than TOTAL_DISTANCE,
+//      the last wheel delta will be very close, if not the same, as VF.
+// For MAGNITUDE = (V0 + VF) / 2 and PHASE_SHIFT = arccos((V0 - VF) / (V0 + VF)), observe that delta(0) and delta(1) evaluate respectively to V0
+// and VF. Thus, we can express our gliding equation all in terms of V0, VF and t.
+float ScrollController::computeGlideDelta(ScrollEventAxis axis) const
+{
+    const ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+
+    LayoutUnit offset = m_client->scrollOffsetOnAxis(axis);
+    bool canComputeGlide = (snapState.m_initialOffset <= offset && offset < snapState.m_targetOffset) || (snapState.m_targetOffset < offset && offset <= snapState.m_initialOffset);
+    if (snapState.m_currentState != ScrollSnapState::Gliding || !canComputeGlide)
+        return 0;
+
+    const float progress = snapProgress(offset, snapState);
+    const float rawGlideDelta = snapGlide(progress, snapState);
+
+    float glideDelta = snapState.m_initialOffset < snapState.m_targetOffset ? std::max<float>(rawGlideDelta, 1) : std::min<float>(rawGlideDelta, -1);
+    if ((snapState.m_initialOffset < snapState.m_targetOffset && offset + glideDelta > snapState.m_targetOffset) || (snapState.m_initialOffset > snapState.m_targetOffset && offset + glideDelta < snapState.m_targetOffset))
+        return snapState.m_targetOffset - offset;
+    
+    return glideDelta;
 }
 #endif
 
@@ -23,8 +23,8 @@
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#ifndef AxisScrollSnapAnimator_h
-#define AxisScrollSnapAnimator_h
+#ifndef ScrollSnapAnimatorState_h
+#define ScrollSnapAnimatorState_h
 
 #if ENABLE(CSS_SCROLL_SNAP)
 
@@ -42,49 +42,15 @@ enum class ScrollSnapState {
     UserInteraction
 };
 
-enum class WheelEventStatus {
-    UserScrollBegin,
-    UserScrolling,
-    UserScrollEnd,
-    InertialScrollBegin,
-    InertialScrolling,
-    InertialScrollEnd,
-    Unknown
-};
-
-class AxisScrollSnapAnimatorClient {
-protected:
-    virtual ~AxisScrollSnapAnimatorClient() { }
-
-public:
-    virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0;
-    virtual void immediateScrollOnAxis(ScrollEventAxis, float velocity) = 0;
-    virtual void startScrollSnapTimer(ScrollEventAxis) = 0;
-    virtual void stopScrollSnapTimer(ScrollEventAxis) = 0;
-};
-
-class AxisScrollSnapAnimator {
-public:
-    AxisScrollSnapAnimator(AxisScrollSnapAnimatorClient*, const Vector<LayoutUnit>&, ScrollEventAxis);
-    void handleWheelEvent(const PlatformWheelEvent&);
-    bool shouldOverrideWheelEvent(const PlatformWheelEvent&) const;
-    void scrollSnapAnimationUpdate();
-
-private:
-    void beginScrollSnapAnimation(ScrollSnapState);
-    void endScrollSnapAnimation(ScrollSnapState);
-
-    float computeSnapDelta() const;
-    float computeGlideDelta() const;
+struct ScrollSnapAnimatorState {
+    ScrollSnapAnimatorState(ScrollEventAxis, const Vector<LayoutUnit>&);
 
-    void initializeGlideParameters(bool);
     void pushInitialWheelDelta(float);
     float averageInitialWheelDelta() const;
     void clearInitialWheelDeltaWindow();
 
     static const int wheelDeltaWindowSize = 3;
 
-    AxisScrollSnapAnimatorClient* m_client;
     Vector<LayoutUnit> m_snapOffsets;
     ScrollEventAxis m_axis;
     // Used to track both snapping and gliding behaviors.
@@ -105,4 +71,4 @@ private:
 
 #endif // ENABLE(CSS_SCROLL_SNAP)
 
-#endif // AxisScrollSnapAnimator_h
+#endif // ScrollSnapAnimatorState_h
diff --git a/Source/WebCore/platform/cocoa/ScrollSnapAnimatorState.mm b/Source/WebCore/platform/cocoa/ScrollSnapAnimatorState.mm
new file mode 100644 (file)
index 0000000..8335f6a
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2014-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.
+ */
+
+#include "config.h"
+#include "ScrollSnapAnimatorState.h"
+
+#if ENABLE(CSS_SCROLL_SNAP)
+
+namespace WebCore {
+
+ScrollSnapAnimatorState::ScrollSnapAnimatorState(ScrollEventAxis axis, const Vector<LayoutUnit>& snapOffsets)
+    : m_snapOffsets(snapOffsets)
+    , m_axis(axis)
+    , m_currentState(ScrollSnapState::DestinationReached)
+    , m_initialOffset(0)
+    , m_targetOffset(0)
+    , m_beginTrackingWheelDeltaOffset(0)
+    , m_numWheelDeltasTracked(0)
+    , m_glideMagnitude(0)
+    , m_glidePhaseShift(0)
+    , m_glideInitialWheelDelta(0)
+    , m_shouldOverrideWheelEvent(false)
+{
+}
+
+void ScrollSnapAnimatorState::pushInitialWheelDelta(float wheelDelta)
+{
+    if (m_numWheelDeltasTracked < wheelDeltaWindowSize)
+        m_wheelDeltaWindow[m_numWheelDeltasTracked++] = wheelDelta;
+}
+
+float ScrollSnapAnimatorState::averageInitialWheelDelta() const
+{
+    if (!m_numWheelDeltasTracked)
+        return 0;
+
+    float sum = 0;
+    for (int i = 0; i < m_numWheelDeltasTracked; i++)
+        sum += m_wheelDeltaWindow[i];
+
+    return sum / m_numWheelDeltasTracked;
+}
+
+void ScrollSnapAnimatorState::clearInitialWheelDeltaWindow()
+{
+    for (int i = 0; i < m_numWheelDeltasTracked; i++)
+        m_wheelDeltaWindow[i] = 0;
+
+    m_numWheelDeltasTracked = 0;
+}
+
+} // namespace WebCore
+
+#endif // CSS_SCROLL_SNAP
diff --git a/Source/WebCore/platform/mac/AxisScrollSnapAnimator.mm b/Source/WebCore/platform/mac/AxisScrollSnapAnimator.mm
deleted file mode 100644 (file)
index 5d511e5..0000000
+++ /dev/null
@@ -1,304 +0,0 @@
-/*
- * Copyright (C) 2014-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.
- */
-
-#include "config.h"
-#include "AxisScrollSnapAnimator.h"
-
-#if ENABLE(CSS_SCROLL_SNAP)
-
-namespace WebCore {
-
-const float inertialScrollPredictionFactor = 16.7;
-const float snapMagnitudeMax = 25;
-const float snapMagnitudeMin = 5;
-const float snapThresholdHigh = 1000;
-const float snapThresholdLow = 50;
-const float glideBoostMultiplier = 3.5;
-const float maxTargetWheelDelta = 7;
-const float minTargetWheelDelta = 3.5;
-const float initialToFinalMomentumFactor = 1.0 / 40.0;
-
-static inline WheelEventStatus toWheelEventStatus(PlatformWheelEventPhase phase, PlatformWheelEventPhase momentumPhase)
-{
-    if (phase == PlatformWheelEventPhaseNone) {
-        switch (momentumPhase) {
-        case PlatformWheelEventPhaseBegan:
-            return WheelEventStatus::InertialScrollBegin;
-
-        case PlatformWheelEventPhaseChanged:
-            return WheelEventStatus::InertialScrolling;
-
-        case PlatformWheelEventPhaseEnded:
-            return WheelEventStatus::InertialScrollEnd;
-
-        default:
-            return WheelEventStatus::Unknown; 
-        }
-    }
-    if (momentumPhase == PlatformWheelEventPhaseNone) {
-        switch (phase) {
-        case PlatformWheelEventPhaseBegan:
-        case PlatformWheelEventPhaseMayBegin:
-            return WheelEventStatus::UserScrollBegin;
-
-        case PlatformWheelEventPhaseChanged:
-            return WheelEventStatus::UserScrolling;
-
-        case PlatformWheelEventPhaseEnded:
-        case PlatformWheelEventPhaseCancelled:
-            return WheelEventStatus::UserScrollEnd;
-
-        default:
-            return WheelEventStatus::Unknown;
-        }
-    }
-    return WheelEventStatus::Unknown;
-}
-
-static inline float projectedInertialScrollDistance(float initialWheelDelta)
-{
-    // FIXME: Experiments with inertial scrolling show a fairly consistent linear relationship between initial wheel delta and total distance scrolled.
-    // In the future, we'll want to find a more accurate way of inertial scroll prediction.
-    return inertialScrollPredictionFactor * initialWheelDelta;
-}
-
-AxisScrollSnapAnimator::AxisScrollSnapAnimator(AxisScrollSnapAnimatorClient* client, const Vector<LayoutUnit>& snapOffsets, ScrollEventAxis axis)
-    : m_client(client)
-    , m_snapOffsets(snapOffsets)
-    , m_axis(axis)
-    , m_currentState(ScrollSnapState::DestinationReached)
-    , m_initialOffset(0)
-    , m_targetOffset(0)
-    , m_beginTrackingWheelDeltaOffset(0)
-    , m_numWheelDeltasTracked(0)
-    , m_glideMagnitude(0)
-    , m_glidePhaseShift(0)
-    , m_glideInitialWheelDelta(0)
-    , m_shouldOverrideWheelEvent(false)
-{
-}
-
-void AxisScrollSnapAnimator::handleWheelEvent(const PlatformWheelEvent& event)
-{
-    float wheelDelta = m_axis == ScrollEventAxis::Horizontal ? -event.deltaX() : -event.deltaY();
-    WheelEventStatus wheelStatus = toWheelEventStatus(event.phase(), event.momentumPhase());
-
-    switch (wheelStatus) {
-    case WheelEventStatus::UserScrollBegin:
-    case WheelEventStatus::UserScrolling:
-        endScrollSnapAnimation(ScrollSnapState::UserInteraction);
-        break;
-
-    case WheelEventStatus::UserScrollEnd:
-        beginScrollSnapAnimation(ScrollSnapState::Snapping);
-        break;
-
-    case WheelEventStatus::InertialScrollBegin:
-        // Begin tracking wheel deltas for glide prediction.
-        endScrollSnapAnimation(ScrollSnapState::UserInteraction);
-        pushInitialWheelDelta(wheelDelta);
-        m_beginTrackingWheelDeltaOffset = m_client->scrollOffsetOnAxis(m_axis);
-        break;
-
-    case WheelEventStatus::InertialScrolling:
-        // This check for DestinationReached ensures that we don't receive another set of momentum events after ending the last glide.
-        if (m_currentState != ScrollSnapState::Gliding && m_currentState != ScrollSnapState::DestinationReached) {
-            if (m_numWheelDeltasTracked < wheelDeltaWindowSize)
-                pushInitialWheelDelta(wheelDelta);
-
-            if (m_numWheelDeltasTracked == wheelDeltaWindowSize)
-                beginScrollSnapAnimation(ScrollSnapState::Gliding);
-        }
-        break;
-
-    case WheelEventStatus::InertialScrollEnd:
-        beginScrollSnapAnimation(ScrollSnapState::Snapping);
-        clearInitialWheelDeltaWindow();
-        m_shouldOverrideWheelEvent = false;
-        break;
-
-    case WheelEventStatus::Unknown:
-        ASSERT_NOT_REACHED();
-        break;
-    }
-}
-
-bool AxisScrollSnapAnimator::shouldOverrideWheelEvent(const PlatformWheelEvent& event) const
-{
-    return m_shouldOverrideWheelEvent && toWheelEventStatus(event.phase(), event.momentumPhase()) == WheelEventStatus::InertialScrolling;
-}
-
-void AxisScrollSnapAnimator::scrollSnapAnimationUpdate()
-{
-    if (m_currentState == ScrollSnapState::DestinationReached)
-        return;
-
-    ASSERT(m_currentState == ScrollSnapState::Gliding || m_currentState == ScrollSnapState::Snapping);
-    float delta = m_currentState == ScrollSnapState::Snapping ? computeSnapDelta() : computeGlideDelta();
-    if (delta)
-        m_client->immediateScrollOnAxis(m_axis, delta);
-    else
-        endScrollSnapAnimation(ScrollSnapState::DestinationReached);
-}
-
-void AxisScrollSnapAnimator::beginScrollSnapAnimation(ScrollSnapState newState)
-{
-    ASSERT(newState == ScrollSnapState::Gliding || newState == ScrollSnapState::Snapping);
-    LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis);
-    float initialWheelDelta = newState == ScrollSnapState::Gliding ? averageInitialWheelDelta() : 0;
-    LayoutUnit projectedScrollDestination = newState == ScrollSnapState::Gliding ? m_beginTrackingWheelDeltaOffset + LayoutUnit(projectedInertialScrollDistance(initialWheelDelta)) : offset;
-    if (m_snapOffsets.isEmpty())
-        return;
-
-    projectedScrollDestination = std::min(std::max(projectedScrollDestination, m_snapOffsets.first()), m_snapOffsets.last());
-    m_initialOffset = offset;
-    m_targetOffset = closestSnapOffset<LayoutUnit, float>(m_snapOffsets, projectedScrollDestination, initialWheelDelta);
-    if (m_initialOffset == m_targetOffset)
-        return;
-
-    m_currentState = newState;
-    if (newState == ScrollSnapState::Gliding) {
-        m_shouldOverrideWheelEvent = true;
-        m_glideInitialWheelDelta = initialWheelDelta;
-        bool glideRequiresBoost;
-        if (initialWheelDelta > 0)
-            glideRequiresBoost = projectedScrollDestination - offset < m_targetOffset - projectedScrollDestination;
-        else
-            glideRequiresBoost = offset - projectedScrollDestination < projectedScrollDestination - m_targetOffset;
-
-        initializeGlideParameters(glideRequiresBoost);
-        clearInitialWheelDeltaWindow();
-    }
-    m_client->startScrollSnapTimer(m_axis);
-}
-
-void AxisScrollSnapAnimator::endScrollSnapAnimation(ScrollSnapState newState)
-{
-    ASSERT(newState == ScrollSnapState::DestinationReached || newState == ScrollSnapState::UserInteraction);
-    if (m_currentState == ScrollSnapState::Gliding)
-        clearInitialWheelDeltaWindow();
-
-    m_currentState = newState;
-    m_client->stopScrollSnapTimer(m_axis);
-}
-
-// Computes the amount to scroll by when performing a "snap" operation, i.e. when a user releases the trackpad without flicking. The snap delta
-// is a function of progress t, where t is equal to DISTANCE_TRAVELED / TOTAL_DISTANCE, DISTANCE_TRAVELED is the distance from the initialOffset
-// to the current offset, and TOTAL_DISTANCE is the distance from initialOffset to targetOffset. The snapping equation is as follows:
-// delta(t) = MAGNITUDE * sin(PI * t). MAGNITUDE indicates the top speed reached near the middle of the animation (t = 0.5), and is a linear
-// relationship of the distance traveled, clamped by arbitrary min and max values.
-float AxisScrollSnapAnimator::computeSnapDelta() const
-{
-    LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis);
-    bool canComputeSnap =  (m_initialOffset <= offset && offset < m_targetOffset) || (m_targetOffset < offset && offset <= m_initialOffset);
-    if (m_currentState != ScrollSnapState::Snapping || !canComputeSnap)
-        return 0;
-
-    int sign = m_initialOffset < m_targetOffset ? 1 : -1;
-    float progress = ((float)(offset - m_initialOffset)) / (m_targetOffset - m_initialOffset);
-    // Threshold the distance before computing magnitude, so only distances within a certain range are considered.
-    float thresholdedDistance = std::min(std::max<float>((m_targetOffset - m_initialOffset) * sign, snapThresholdLow), snapThresholdHigh);
-    float magnitude = snapMagnitudeMin + (snapMagnitudeMax - snapMagnitudeMin) * (thresholdedDistance - snapThresholdLow) / (snapThresholdHigh - snapThresholdLow);
-    float rawSnapAmount = std::max<float>(1, magnitude * sin(piFloat * progress));
-    if ((m_targetOffset < offset && offset - rawSnapAmount < m_targetOffset) || (m_targetOffset > offset && offset + rawSnapAmount > m_targetOffset))
-        return m_targetOffset - offset;
-
-    return sign * rawSnapAmount;
-}
-
-// Computes the amount to scroll by when performing a "glide" operation, i.e. when a user releases the trackpad with an initial velocity. Here,
-// we want the scroll offset to animate directly to the snap point. The snap delta is a function of progress t, where t is equal to
-// DISTANCE_TRAVELED / TOTAL_DISTANCE, DISTANCE_TRAVELED is the distance from the initialOffset to the current offset, and TOTAL_DISTANCE is
-// the distance from initialOffset to targetOffset.
-// The general model of our gliding equation is delta(t) = MAGNITUDE * (1 + cos(PI * t + PHASE_SHIFT)). This was determined after examining the
-// momentum velocity curve as a function of progress. To compute MAGNITUDE and PHASE_SHIFT, we use initial velocity V0 and the final velocity VF,
-// both as wheel deltas (pixels per timestep). VF should be a small value (< 10) chosen based on the initial velocity and TOTAL_DISTANCE.
-// We also enforce the following constraints for the gliding equation:
-//   1. delta(0) = V0, since we want the initial velocity of the gliding animation to match the user's scroll velocity. The exception to this is
-//      when the glide velocity is not enough to naturally reach the next snap point, and thus requires a boost (see initializeGlideParameters)
-//   2. delta(1) = VF, since at t=1, the animation has completed and we want the last wheel delta to match the final velocity VF. Note that this
-//      doesn't guarantee that the final velocity will be exactly VF. However, assuming that the initial velocity is much less than TOTAL_DISTANCE,
-//      the last wheel delta will be very close, if not the same, as VF.
-// For MAGNITUDE = (V0 + VF) / 2 and PHASE_SHIFT = arccos((V0 - VF) / (V0 + VF)), observe that delta(0) and delta(1) evaluate respectively to V0
-// and VF. Thus, we can express our gliding equation all in terms of V0, VF and t.
-float AxisScrollSnapAnimator::computeGlideDelta() const
-{
-    LayoutUnit offset = m_client->scrollOffsetOnAxis(m_axis);
-    bool canComputeGlide = (m_initialOffset <= offset && offset < m_targetOffset) || (m_targetOffset < offset && offset <= m_initialOffset);
-    if (m_currentState != ScrollSnapState::Gliding || !canComputeGlide)
-        return 0;
-
-    float progress = ((float)(offset - m_initialOffset)) / (m_targetOffset - m_initialOffset);
-    // FIXME: We might want to investigate why -m_glidePhaseShift results in the behavior we want.
-    float shift = ceil(m_glideMagnitude * (1 + cos(piFloat * progress - m_glidePhaseShift)));
-    shift = m_initialOffset < m_targetOffset ? std::max<float>(shift, 1) : std::min<float>(shift, -1);
-    if ((m_initialOffset < m_targetOffset && offset + shift > m_targetOffset) || (m_initialOffset > m_targetOffset && offset + shift < m_targetOffset))
-        return m_targetOffset - offset;
-
-    return shift;
-}
-
-void AxisScrollSnapAnimator::initializeGlideParameters(bool shouldIncreaseInitialWheelDelta)
-{
-    // FIXME: Glide boost is a hacky way to speed up natural scrolling velocity. We should find a better way to accomplish this.
-    if (shouldIncreaseInitialWheelDelta)
-        m_glideInitialWheelDelta *= glideBoostMultiplier;
-
-    // FIXME: There must be a better way to determine a good target delta than multiplying by a factor and clamping to min/max values.
-    float targetFinalWheelDelta = initialToFinalMomentumFactor * (m_glideInitialWheelDelta < 0 ? -m_glideInitialWheelDelta : m_glideInitialWheelDelta);
-    targetFinalWheelDelta = (m_glideInitialWheelDelta > 0 ? 1 : -1) * std::min(std::max(targetFinalWheelDelta, minTargetWheelDelta), maxTargetWheelDelta);
-    m_glideMagnitude = (m_glideInitialWheelDelta + targetFinalWheelDelta) / 2;
-    m_glidePhaseShift = acos((m_glideInitialWheelDelta - targetFinalWheelDelta) / (m_glideInitialWheelDelta + targetFinalWheelDelta));
-}
-
-void AxisScrollSnapAnimator::pushInitialWheelDelta(float wheelDelta)
-{
-    if (m_numWheelDeltasTracked < wheelDeltaWindowSize)
-        m_wheelDeltaWindow[m_numWheelDeltasTracked++] = wheelDelta;
-}
-
-float AxisScrollSnapAnimator::averageInitialWheelDelta() const
-{
-    if (!m_numWheelDeltasTracked)
-        return 0;
-
-    float sum = 0;
-    for (int i = 0; i < m_numWheelDeltasTracked; i++)
-        sum += m_wheelDeltaWindow[i];
-
-    return sum / m_numWheelDeltasTracked;
-}
-
-void AxisScrollSnapAnimator::clearInitialWheelDeltaWindow()
-{
-    for (int i = 0; i < m_numWheelDeltasTracked; i++)
-        m_wheelDeltaWindow[i] = 0;
-
-    m_numWheelDeltasTracked = 0;
-}
-
-} // namespace WebCore
-
-#endif // CSS_SCROLL_SNAP
index 38d9cc8..d78f379 100644 (file)
@@ -147,8 +147,6 @@ private:
     virtual void immediateScrollBy(const FloatSize&) override;
     virtual void adjustScrollPositionToBoundsIfNecessary() override;
 
-    bool pinnedInDirection(float deltaX, float deltaY);
-
     bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis);
 #endif
 
index 3351387..1e667d4 100644 (file)
@@ -1102,19 +1102,19 @@ bool ScrollAnimatorMac::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
     return didHandleEvent;
 }
 
-bool ScrollAnimatorMac::pinnedInDirection(float deltaX, float deltaY)
+bool ScrollAnimatorMac::pinnedInDirection(const FloatSize& direction)
 {
     FloatSize limitDelta;
-    if (std::fabsf(deltaY) >= fabsf(deltaX)) {
-        if (deltaY < 0) {
+    if (fabsf(direction.height()) >= fabsf(direction.width())) {
+        if (direction.height() < 0) {
             // We are trying to scroll up.  Make sure we are not pinned to the top
             limitDelta.setHeight(m_scrollableArea.visibleContentRect().y() + m_scrollableArea.scrollOrigin().y());
         } else {
             // We are trying to scroll down.  Make sure we are not pinned to the bottom
             limitDelta.setHeight(m_scrollableArea.totalContentsSize().height() - (m_scrollableArea.visibleContentRect().maxY() + m_scrollableArea.scrollOrigin().y()));
         }
-    } else if (deltaX != 0) {
-        if (deltaX < 0) {
+    } else if (direction.width()) {
+        if (direction.width() < 0) {
             // We are trying to scroll left.  Make sure we are not pinned to the left
             limitDelta.setWidth(m_scrollableArea.visibleContentRect().x() + m_scrollableArea.scrollOrigin().x());
         } else {
@@ -1123,7 +1123,7 @@ bool ScrollAnimatorMac::pinnedInDirection(float deltaX, float deltaY)
         }
     }
     
-    if ((deltaX != 0 || deltaY != 0) && (limitDelta.width() < 1 && limitDelta.height() < 1))
+    if ((direction.width() || direction.height()) && (limitDelta.width() < 1 && limitDelta.height() < 1))
         return true;
     return false;
 }
@@ -1216,11 +1216,6 @@ IntSize ScrollAnimatorMac::stretchAmount()
     return m_scrollableArea.overhangAmount();
 }
 
-bool ScrollAnimatorMac::pinnedInDirection(const FloatSize& direction)
-{
-    return pinnedInDirection(direction.width(), direction.height());
-}
-
 bool ScrollAnimatorMac::canScrollHorizontally()
 {
     Scrollbar* scrollbar = m_scrollableArea.horizontalScrollbar();