Move scroll animating functions from ScrollAnimator to ScrollController
authorbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Mar 2015 01:36:51 +0000 (01:36 +0000)
committerbfulgham@apple.com <bfulgham@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 4 Mar 2015 01:36:51 +0000 (01:36 +0000)
https://bugs.webkit.org/show_bug.cgi?id=142102
<rdar://problem/20007161>

Reviewed by Simon Fraser.

Source/WebCore:

Tested by platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html.

Do some refactoring of the various scrolling classes:
1. Consolidate animation times to RunLoop::Timer instead of a combination of WebCore::Timer
   and CFRunLoopTimers. Do this for Scroll Snap Point and Rubberband animations.
2. Move ScrollController from platform/mac to platform/cocoa to enable sharing with iOS.
3. Move code from ScrollAnimator{Mac} -> ScrollController.
4. Rename scrollOffsetInAxis -> scrollOffsetOnAxis
5. Rename immediateScrollInAxis -> immediateScrollOnAxis

* WebCore.xcodeproj/project.pbxproj: Move ScrollController to 'platform/cocoa'
* page/mac/EventHandlerMac.mm: Make sure the scroll controller is notified of end-of-scroll
events, just as is done for the "event not handled" case in EventHandler.cpp.
(WebCore::EventHandler::platformCompleteWheelEvent):
* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h: Remove timer and some delegate
methods, now that ScrollController is controlling this state.
* page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
(WebCore::ScrollingTreeFrameScrollingNodeMac::~ScrollingTreeFrameScrollingNodeMac): We no longer
need to clean up the CFRunLoopTimer.
(WebCore::ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer): Make sure scroll
state is updated after rubber band snap.
(WebCore::ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis): Add temporary stub needed
until Bug1973 is completed.).
(WebCore::ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis): Ditto.
(WebCore::ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer): Deleted.
* platform/ScrollAnimator.cpp:
(WebCore::ScrollAnimator::ScrollAnimator):
(WebCore::ScrollAnimator::processWheelEventForScrollSnap): Just call the ScrollController method.
(WebCore::ScrollAnimator::handleWheelEvent): Ditto.
(WebCore::ScrollAnimator::updateScrollAnimatorsAndTimers): Ditto.
(WebCore::ScrollAnimator::scrollOffsetOnAxis): Renamed from scrollOffsetInAxis.
(WebCore::ScrollAnimator::immediateScrollOnAxis): Renamed from immediateScrollInAxis.
(WebCore::ScrollAnimator::scrollOffsetInAxis): Deleted.
(WebCore::ScrollAnimator::immediateScrollInAxis): Deleted.
(WebCore::ScrollAnimator::startScrollSnapTimer): Deleted.
(WebCore::ScrollAnimator::stopScrollSnapTimer): Deleted.
(WebCore::ScrollAnimator::horizontalScrollSnapTimerFired): Deleted.
(WebCore::ScrollAnimator::verticalScrollSnapTimerFired): Deleted.
* platform/ScrollAnimator.h:
* platform/cocoa/ScrollController.h: Copied from platform/mac/ScrollController.h.
(WebCore::ScrollControllerClient::startSnapRubberbandTimer):
(WebCore::ScrollControllerClient::stopSnapRubberbandTimer):
(WebCore::ScrollControllerClient::startScrollSnapTimer):
(WebCore::ScrollControllerClient::stopScrollSnapTimer):
* platform/cocoa/ScrollController.mm: Copied from platform/mac/ScrollController.mm.
(WebCore::ScrollController::ScrollController): Update to initialize new timers.
(WebCore::ScrollController::handleWheelEvent): Update to handle Scroll Snap Point events.
(WebCore::ScrollController::startSnapRubberbandTimer): Added.
(WebCore::ScrollController::stopSnapRubberbandTimer): Manage animation timers locally, do not
require client to maintain timers.
(WebCore::ScrollController::snapRubberBand): Ditto.
(WebCore::ScrollController::processWheelEventForScrollSnap): Added. (Moved from ScrollAnimatorMac)
(WebCore::ScrollController::updateScrollAnimatorsAndTimers): Ditto. Also updated to use RunLoop::Timer.
(WebCore::ScrollController::startScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer.
(WebCore::ScrollController::stopScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer.
(WebCore::ScrollController::horizontalScrollSnapTimerFired): Ditto.
(WebCore::ScrollController::verticalScrollSnapTimerFired): Ditto.
(WebCore::ScrollController::scrollOffsetOnAxis): Moved from ScrollAnimatorMac.
(WebCore::ScrollController::immediateScrollOnAxis): Ditto.
* platform/mac/AxisScrollSnapAnimator.h: Rename methods from 'InAxis' to 'OnAxis'
* platform/mac/AxisScrollSnapAnimator.mm:
(WebCore::AxisScrollSnapAnimator::handleWheelEvent): Update for 'InAxis' to 'OnAxis' renaming.
(WebCore::AxisScrollSnapAnimator::scrollSnapAnimationUpdate): Ditto.
(WebCore::AxisScrollSnapAnimator::beginScrollSnapAnimation): Ditto.
(WebCore::AxisScrollSnapAnimator::computeSnapDelta): Ditto.
(WebCore::AxisScrollSnapAnimator::computeGlideDelta): Ditto.
* platform/mac/ScrollAnimatorMac.h:
* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::ScrollAnimatorMac): Remove unused Rubberband timers (now that this is
controlled in the ScrollController)
(WebCore::ScrollAnimatorMac::startSnapRubberbandTimer): Deleted.
(WebCore::ScrollAnimatorMac::stopSnapRubberbandTimer): Deleted.
(WebCore::ScrollAnimatorMac::snapRubberBandTimerFired): Deleted.
* platform/mac/ScrollController.h: Removed.
* platform/mac/ScrollController.mm: Removed.

LayoutTests:

Add a new test that confirms that rubberband snap animations work properly when combined
with text zooming.

* platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom-expected.txt: Added.
* platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html: Added.

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

16 files changed:
LayoutTests/ChangeLog
LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom-expected.txt [new file with mode: 0644]
LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/page/mac/EventHandlerMac.mm
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 [moved from Source/WebCore/platform/mac/ScrollController.h with 62% similarity]
Source/WebCore/platform/cocoa/ScrollController.mm [moved from Source/WebCore/platform/mac/ScrollController.mm with 82% similarity]
Source/WebCore/platform/mac/AxisScrollSnapAnimator.h
Source/WebCore/platform/mac/AxisScrollSnapAnimator.mm
Source/WebCore/platform/mac/ScrollAnimatorMac.h
Source/WebCore/platform/mac/ScrollAnimatorMac.mm

index 6c0397d..ae4a08f 100644 (file)
@@ -1,3 +1,17 @@
+2015-03-03  Brent Fulgham  <bfulgham@apple.com>
+
+        Move scroll animating functions from ScrollAnimator to ScrollController
+        https://bugs.webkit.org/show_bug.cgi?id=142102
+        <rdar://problem/20007161>
+
+        Reviewed by Simon Fraser.
+
+        Add a new test that confirms that rubberband snap animations work properly when combined
+        with text zooming.
+
+        * platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom-expected.txt: Added.
+        * platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html: Added.
+
 2015-03-03  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r180683.
diff --git a/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom-expected.txt b/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom-expected.txt
new file mode 100644 (file)
index 0000000..89a5ce3
--- /dev/null
@@ -0,0 +1,15 @@
+Put mouse here and do the following:
+Perform two text zooms (in). (Command+ in Safari)
+Scroll down to the bottom. Be sure to scroll far enough that a rubberband animation is triggered.
+Perform two text zooms (out). (Commmand- in Safari)
+TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOPEND END END END END END END END END END END END END
+Tests that scroll dimensions return to correct size after rubber banding while zoomed.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Page properly handled rubber banding state.
+This should be at the very bottom of the page.
diff --git a/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html b/LayoutTests/platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html
new file mode 100644 (file)
index 0000000..a605975
--- /dev/null
@@ -0,0 +1,107 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src="../../../../resources/js-test-pre.js" type="text/javascript"></script>
+    </head>
+    <body>
+        <script type="text/javascript">
+            var pageScrollPositionBefore;
+            var pageScrollHeightBefore;
+            var continueCount = 5;
+
+            function checkForScrollOffset()
+            {
+                var pageScrollPositionAfter = document.body.scrollTop;
+                var pageScrollHeightAfter = document.body.scrollHeight;
+
+                if (pageScrollPositionAfter + 100 >= pageScrollPositionBefore)
+                    testFailed("Page did not properly handle rubber banding state.");
+                else
+                    testPassed("Page properly handled rubber banding state.");
+
+                testRunner.notifyDone();
+            }
+
+            var zoomOutCount = 0;
+            function zoomPageOut()
+            {
+                if (!zoomOutCount) {
+                    pageScrollPositionBefore = document.body.scrollTop;
+                    pageScrollHeightBefore = document.body.scrollHeight;
+                }
+
+                eventSender.zoomPageOut();
+                zoomOutCount = zoomOutCount + 1;
+                if (zoomOutCount >= 2)
+                    setTimeout(checkForScrollOffset, 100);
+                else
+                    setTimeout(zoomPageOut, 100);
+            }
+
+            function scrollDown()
+            {
+                // Scroll the #source until we reach the #target.
+                var selectTarget = document.getElementById('target');
+                var startPosX = Math.round(selectTarget.offsetLeft) + 20;
+                var startPosY = Math.round(selectTarget.offsetTop) - 42; // Slightly more than one wheel scroll away from the target div
+                eventSender.mouseMoveTo(startPosX, startPosY); // Make sure we are just outside the target div
+                eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -1, 'began', 'none', true);
+                for (var i = 0; i < 40; ++i) {
+                    eventSender.mouseScrollByWithWheelAndMomentumPhases(0, -10, 'changed', 'none', true);
+                }
+                eventSender.mouseScrollByWithWheelAndMomentumPhases(0, 0, 'ended', 'none');
+                 
+                setTimeout(zoomPageOut, 700);
+            }
+
+            var zoomInCount = 0;
+            function zoomPageIn()
+            {
+                eventSender.zoomPageIn();
+                zoomInCount = zoomInCount + 1;
+                if (zoomInCount >= 2)
+                    setTimeout(scrollDown, 100);
+                else
+                    setTimeout(zoomPageIn, 100);
+            }
+
+            function startTest()
+            {
+                if (window.eventSender) {
+                    testRunner.dumpAsText();
+                    testRunner.waitUntilDone();
+
+                    setTimeout(zoomPageIn, 0);
+                } else {
+                    var messageLocation = document.getElementById('parent');
+                    var message = document.createElement('div');
+                    message.innerHTML = "<p>This test is better run under DumpRenderTree. To manually test it, place the mouse pointer<br/>"
+                        + "at the top of the page, perform two text zooms, scroll to the bottom of the page, then zoom back out.<br/>"
+                    + "The bottom of the test page should not be offset from the bottom of the web view.<\/p>";
+                    messageLocation.appendChild(message);
+                }
+            }
+
+            window.addEventListener('load', startTest, false);
+        </script>
+        <div id="parent" style="height: 2000px;">
+            <div id="source" style="height: 100px">
+                Put mouse here and do the following:
+                <ol>
+                    <li>Perform two text zooms (in). (Command+ in Safari)</li>
+                    <li>Scroll down to the bottom. Be sure to scroll far enough that a rubberband animation is triggered.</li>
+                    <li>Perform two text zooms (out).  (Commmand- in Safari)</li>
+                </ol>
+            </div>
+            <div id="target" style="height: 1000px; position: relative">
+               <div style="position: absolute; top: 0">TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP</div>
+               <div style="position: absolute; bottom: 0">END END END END END END END END END END END END END</div>
+            </div>
+        </div>
+        <div id="console"></div><script type="text/javascript">
+            description("Tests that scroll dimensions return to correct size after rubber banding while zoomed.");
+        </script>
+        <div id="bottom">This should be at the very bottom of the page.</div>
+        <script src="../../../../resources/js-test-post.js" type="text/javascript"></script>
+    </body>
+</html>
index 331e228..f83e792 100644 (file)
@@ -1,3 +1,87 @@
+2015-03-03  Brent Fulgham  <bfulgham@apple.com>
+
+        Move scroll animating functions from ScrollAnimator to ScrollController
+        https://bugs.webkit.org/show_bug.cgi?id=142102
+        <rdar://problem/20007161>
+
+        Reviewed by Simon Fraser.
+
+        Tested by platform/mac-wk2/tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html.
+
+        Do some refactoring of the various scrolling classes:
+        1. Consolidate animation times to RunLoop::Timer instead of a combination of WebCore::Timer
+           and CFRunLoopTimers. Do this for Scroll Snap Point and Rubberband animations.
+        2. Move ScrollController from platform/mac to platform/cocoa to enable sharing with iOS.
+        3. Move code from ScrollAnimator{Mac} -> ScrollController.
+        4. Rename scrollOffsetInAxis -> scrollOffsetOnAxis
+        5. Rename immediateScrollInAxis -> immediateScrollOnAxis
+
+        * WebCore.xcodeproj/project.pbxproj: Move ScrollController to 'platform/cocoa'
+        * page/mac/EventHandlerMac.mm: Make sure the scroll controller is notified of end-of-scroll
+        events, just as is done for the "event not handled" case in EventHandler.cpp. 
+        (WebCore::EventHandler::platformCompleteWheelEvent):
+        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.h: Remove timer and some delegate
+        methods, now that ScrollController is controlling this state.
+        * page/scrolling/mac/ScrollingTreeFrameScrollingNodeMac.mm:
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::~ScrollingTreeFrameScrollingNodeMac): We no longer
+        need to clean up the CFRunLoopTimer.
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer): Make sure scroll
+        state is updated after rubber band snap.
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis): Add temporary stub needed
+        until Bug1973 is completed.).
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis): Ditto.
+        (WebCore::ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer): Deleted.
+        * platform/ScrollAnimator.cpp:
+        (WebCore::ScrollAnimator::ScrollAnimator):
+        (WebCore::ScrollAnimator::processWheelEventForScrollSnap): Just call the ScrollController method.
+        (WebCore::ScrollAnimator::handleWheelEvent): Ditto.
+        (WebCore::ScrollAnimator::updateScrollAnimatorsAndTimers): Ditto.
+        (WebCore::ScrollAnimator::scrollOffsetOnAxis): Renamed from scrollOffsetInAxis.
+        (WebCore::ScrollAnimator::immediateScrollOnAxis): Renamed from immediateScrollInAxis.
+        (WebCore::ScrollAnimator::scrollOffsetInAxis): Deleted.
+        (WebCore::ScrollAnimator::immediateScrollInAxis): Deleted.
+        (WebCore::ScrollAnimator::startScrollSnapTimer): Deleted.
+        (WebCore::ScrollAnimator::stopScrollSnapTimer): Deleted.
+        (WebCore::ScrollAnimator::horizontalScrollSnapTimerFired): Deleted.
+        (WebCore::ScrollAnimator::verticalScrollSnapTimerFired): Deleted.
+        * platform/ScrollAnimator.h:
+        * platform/cocoa/ScrollController.h: Copied from platform/mac/ScrollController.h.
+        (WebCore::ScrollControllerClient::startSnapRubberbandTimer):
+        (WebCore::ScrollControllerClient::stopSnapRubberbandTimer):
+        (WebCore::ScrollControllerClient::startScrollSnapTimer):
+        (WebCore::ScrollControllerClient::stopScrollSnapTimer):
+        * platform/cocoa/ScrollController.mm: Copied from platform/mac/ScrollController.mm.
+        (WebCore::ScrollController::ScrollController): Update to initialize new timers.
+        (WebCore::ScrollController::handleWheelEvent): Update to handle Scroll Snap Point events.
+        (WebCore::ScrollController::startSnapRubberbandTimer): Added.
+        (WebCore::ScrollController::stopSnapRubberbandTimer): Manage animation timers locally, do not
+        require client to maintain timers.
+        (WebCore::ScrollController::snapRubberBand): Ditto.
+        (WebCore::ScrollController::processWheelEventForScrollSnap): Added. (Moved from ScrollAnimatorMac)
+        (WebCore::ScrollController::updateScrollAnimatorsAndTimers): Ditto. Also updated to use RunLoop::Timer.
+        (WebCore::ScrollController::startScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer.
+        (WebCore::ScrollController::stopScrollSnapTimer): Ditto. Also updated to use RunLoop::Timer.
+        (WebCore::ScrollController::horizontalScrollSnapTimerFired): Ditto.
+        (WebCore::ScrollController::verticalScrollSnapTimerFired): Ditto.
+        (WebCore::ScrollController::scrollOffsetOnAxis): Moved from ScrollAnimatorMac.
+        (WebCore::ScrollController::immediateScrollOnAxis): Ditto.
+        * platform/mac/AxisScrollSnapAnimator.h: Rename methods from 'InAxis' to 'OnAxis'
+        * platform/mac/AxisScrollSnapAnimator.mm:
+        (WebCore::AxisScrollSnapAnimator::handleWheelEvent): Update for 'InAxis' to 'OnAxis' renaming.
+        (WebCore::AxisScrollSnapAnimator::scrollSnapAnimationUpdate): Ditto.
+        (WebCore::AxisScrollSnapAnimator::beginScrollSnapAnimation): Ditto.
+        (WebCore::AxisScrollSnapAnimator::computeSnapDelta): Ditto.
+        (WebCore::AxisScrollSnapAnimator::computeGlideDelta): Ditto.
+        * platform/mac/ScrollAnimatorMac.h:
+        * platform/mac/ScrollAnimatorMac.mm:
+        (WebCore::ScrollAnimatorMac::ScrollAnimatorMac): Remove unused Rubberband timers (now that this is
+        controlled in the ScrollController)
+        (WebCore::ScrollAnimatorMac::startSnapRubberbandTimer): Deleted.
+        (WebCore::ScrollAnimatorMac::stopSnapRubberbandTimer): Deleted.
+        (WebCore::ScrollAnimatorMac::snapRubberBandTimerFired): Deleted.
+        * platform/mac/ScrollController.h: Removed.
+        * platform/mac/ScrollController.mm: Removed.
+
 2015-03-03  Commit Queue  <commit-queue@webkit.org>
 
         Unreviewed, rolling out r180683.
index c0ed16b..9c4e9d4 100644 (file)
                                BC51156D12B1749C00C96754 /* ScrollAnimatorMac.mm */,
                                BC8B853C0E7C7F1100AB6984 /* ScrollbarThemeMac.h */,
                                BCEF869E0E844E9D00A85CD5 /* ScrollbarThemeMac.mm */,
-                               1AA84F03143BA7BD0051D153 /* ScrollController.h */,
-                               1AA84F02143BA7BD0051D153 /* ScrollController.mm */,
                                9353676A09AED88B00D35CD6 /* ScrollViewMac.mm */,
                                077AF14118F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.h */,
                                077AF14218F4B1BB0001ED61 /* SerializedPlatformRepresentationMac.mm */,
                                1A0409F21A43675C009E47F3 /* MachSendRight.cpp */,
                                1A0409DB1A4360B5009E47F3 /* MachSendRight.h */,
                                ADB6B29718FB90240081963E /* MemoryPressureHandlerCocoa.mm */,
+                               1AA84F03143BA7BD0051D153 /* ScrollController.h */,
+                               1AA84F02143BA7BD0051D153 /* ScrollController.mm */,
                                5D5975B119635F1100D00878 /* SystemVersion.h */,
                                5D5975B219635F1100D00878 /* SystemVersion.mm */,
                                7CC564B918BAC720001B9652 /* TelephoneNumberDetectorCocoa.cpp */,
index 75d143a..58fcb50 100644 (file)
@@ -961,6 +961,12 @@ bool EventHandler::platformCompleteWheelEvent(const PlatformWheelEvent& wheelEve
     
     bool didHandleEvent = view ? view->wheelEvent(wheelEvent) : false;
     m_isHandlingWheelEvent = false;
+
+#if ENABLE(CSS_SCROLL_SNAP)
+    if (scrollableArea)
+        platformNotifySnapIfNecessary(wheelEvent, *scrollableArea);
+#endif
+
     return didHandleEvent;
 }
 
index e632cb2..ebc9bc4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 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
@@ -51,39 +51,42 @@ private:
     virtual void handleWheelEvent(const PlatformWheelEvent&) override;
 
     // ScrollController member functions.
-    virtual bool allowsHorizontalStretching(const PlatformWheelEvent&) override;
-    virtual bool allowsVerticalStretching(const PlatformWheelEvent&) override;
-    virtual IntSize stretchAmount() override;
-    virtual bool pinnedInDirection(const FloatSize&) override;
-    virtual bool canScrollHorizontally() override;
-    virtual bool canScrollVertically() override;
-    virtual bool shouldRubberBandInDirection(ScrollDirection) override;
-    virtual IntPoint absoluteScrollPosition() override;
-    virtual void immediateScrollBy(const FloatSize&) override;
-    virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override;
-    virtual void startSnapRubberbandTimer() override;
-    virtual void stopSnapRubberbandTimer() override;
-    virtual void adjustScrollPositionToBoundsIfNecessary() override;
-
-    virtual FloatPoint scrollPosition() const override;
-    virtual void setScrollPosition(const FloatPoint&) override;
-    virtual void setScrollPositionWithoutContentEdgeConstraints(const FloatPoint&) override;
-
-    virtual void updateLayersAfterViewportChange(const FloatRect& fixedPositionRect, double scale) override;
-
-    virtual void setScrollLayerPosition(const FloatPoint&) override;
-
-    virtual FloatPoint minimumScrollPosition() const override;
-    virtual FloatPoint maximumScrollPosition() const override;
+    bool allowsHorizontalStretching(const PlatformWheelEvent&) override;
+    bool allowsVerticalStretching(const PlatformWheelEvent&) override;
+    IntSize stretchAmount() override;
+    bool pinnedInDirection(const FloatSize&) override;
+    bool canScrollHorizontally() override;
+    bool canScrollVertically() override;
+    bool shouldRubberBandInDirection(ScrollDirection) override;
+    IntPoint absoluteScrollPosition() override;
+    void immediateScrollBy(const FloatSize&) override;
+    void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override;
+    void stopSnapRubberbandTimer() override;
+    void adjustScrollPositionToBoundsIfNecessary() override;
+
+    FloatPoint scrollPosition() const override;
+    void setScrollPosition(const FloatPoint&) override;
+    void setScrollPositionWithoutContentEdgeConstraints(const FloatPoint&) override;
+
+    void updateLayersAfterViewportChange(const FloatRect& fixedPositionRect, double scale) override;
+
+    void setScrollLayerPosition(const FloatPoint&) override;
+
+    FloatPoint minimumScrollPosition() const override;
+    FloatPoint maximumScrollPosition() const override;
 
     void updateMainFramePinState(const FloatPoint& scrollPosition);
 
     bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis);
 
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
+    void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
+#endif
+
     void logExposedUnfilledArea();
 
     ScrollController m_scrollController;
-    RetainPtr<CFRunLoopTimerRef> m_snapRubberbandTimer;
 
     RetainPtr<CALayer> m_scrollLayer;
     RetainPtr<CALayer> m_scrolledContentsLayer;
index 72e0345..76501bc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012, 2014 Apple Inc. All rights reserved.
+ * Copyright (C) 2012, 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
@@ -66,8 +66,6 @@ ScrollingTreeFrameScrollingNodeMac::ScrollingTreeFrameScrollingNodeMac(Scrolling
 
 ScrollingTreeFrameScrollingNodeMac::~ScrollingTreeFrameScrollingNodeMac()
 {
-    if (m_snapRubberbandTimer)
-        CFRunLoopTimerInvalidate(m_snapRubberbandTimer.get());
 }
 
 void ScrollingTreeFrameScrollingNodeMac::updateBeforeChildren(const ScrollingStateNode& stateNode)
@@ -296,30 +294,12 @@ void ScrollingTreeFrameScrollingNodeMac::immediateScrollByWithoutContentEdgeCons
     scrollByWithoutContentEdgeConstraints(offset);
 }
 
-void ScrollingTreeFrameScrollingNodeMac::startSnapRubberbandTimer()
-{
-    ASSERT(!m_snapRubberbandTimer);
-
-    CFTimeInterval timerInterval = 1.0 / 60.0;
-
-    m_snapRubberbandTimer = adoptCF(CFRunLoopTimerCreateWithHandler(kCFAllocatorDefault, CFAbsoluteTimeGetCurrent() + timerInterval, timerInterval, 0, 0, ^(CFRunLoopTimerRef) {
-        m_scrollController.snapRubberBandTimerFired();
-    }));
-    CFRunLoopAddTimer(CFRunLoopGetCurrent(), m_snapRubberbandTimer.get(), kCFRunLoopDefaultMode);
-}
-
 void ScrollingTreeFrameScrollingNodeMac::stopSnapRubberbandTimer()
 {
-    if (!m_snapRubberbandTimer)
-        return;
-
     scrollingTree().setMainFrameIsRubberBanding(false);
 
     // Since the rubberband timer has stopped, totalContentsSizeForRubberBand can be synchronized with totalContentsSize.
     setTotalContentsSizeForRubberBand(totalContentsSize());
-
-    CFRunLoopTimerInvalidate(m_snapRubberbandTimer.get());
-    m_snapRubberbandTimer = nullptr;
 }
 
 void ScrollingTreeFrameScrollingNodeMac::adjustScrollPositionToBoundsIfNecessary()
@@ -540,6 +520,19 @@ void logWheelEventHandlerCountChanged(unsigned count)
     WTFLogAlways("SCROLLING: Wheel event handler count changed. Time: %f Count: %u\n", WTF::monotonicallyIncreasingTime(), count);
 }
 
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+LayoutUnit ScrollingTreeFrameScrollingNodeMac::scrollOffsetOnAxis(ScrollEventAxis)
+{
+    // Temporary stub until http://webkit.org/b/141973.
+    return 0;
+}
+
+void ScrollingTreeFrameScrollingNodeMac::immediateScrollOnAxis(ScrollEventAxis, float)
+{
+    // Temporary stub until http://webkit.org/b/141973.
+}
+#endif
+
 } // namespace WebCore
 
 #endif // ENABLE(ASYNC_SCROLLING) && PLATFORM(MAC)
index aaf8050..5a2f2a1 100644 (file)
@@ -49,6 +49,9 @@ std::unique_ptr<ScrollAnimator> ScrollAnimator::create(ScrollableArea& scrollabl
 
 ScrollAnimator::ScrollAnimator(ScrollableArea& scrollableArea)
     : m_scrollableArea(scrollableArea)
+#if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC)
+    , m_scrollController(this)
+#endif
     , m_currentPosX(0)
     , m_currentPosY(0)
 {
@@ -81,28 +84,17 @@ void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset)
 }
 
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-void ScrollAnimator::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
+bool ScrollAnimator::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
 {
-    if (m_verticalScrollSnapAnimator)
-        m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent);
-    if (m_horizontalScrollSnapAnimator)
-        m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent);
+    return m_scrollController.processWheelEventForScrollSnap(wheelEvent);
 }
 #endif
 
 bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e)
 {
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-    if (m_verticalScrollSnapAnimator) {
-        m_verticalScrollSnapAnimator->handleWheelEvent(e);
-        if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(e))
-            return false;
-    }
-    if (m_horizontalScrollSnapAnimator) {
-        m_horizontalScrollSnapAnimator->handleWheelEvent(e);
-        if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(e))
-            return false;
-    }
+    if (!m_scrollController.processWheelEventForScrollSnap(e))
+        return false;
 #endif
 #if PLATFORM(COCOA)
     // Events in the PlatformWheelEventPhaseMayBegin phase have no deltas, and therefore never passes through the scroll handling logic below.
@@ -183,30 +175,15 @@ void ScrollAnimator::notifyPositionChanged(const FloatSize& delta)
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
 void ScrollAnimator::updateScrollAnimatorsAndTimers()
 {
-    // FIXME: Currently, scroll snap animators are recreated even though the snap offsets alone can be updated.
-    if (m_scrollableArea.horizontalSnapOffsets()) {
-        m_horizontalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, m_scrollableArea.horizontalSnapOffsets(), ScrollEventAxis::Horizontal);
-        m_horizontalScrollSnapTimer = std::make_unique<Timer>(*this, &ScrollAnimator::horizontalScrollSnapTimerFired);
-    } else if (m_horizontalScrollSnapAnimator) {
-        m_horizontalScrollSnapAnimator = nullptr;
-        m_horizontalScrollSnapTimer = nullptr;
-    }
-    if (m_scrollableArea.verticalSnapOffsets()) {
-        m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, m_scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical);
-        m_verticalScrollSnapTimer = std::make_unique<Timer>(*this, &ScrollAnimator::verticalScrollSnapTimerFired);
-    } else if (m_verticalScrollSnapAnimator) {
-        m_verticalScrollSnapAnimator = nullptr;
-        m_verticalScrollSnapTimer = nullptr;
-    }
+    m_scrollController.updateScrollAnimatorsAndTimers(m_scrollableArea);
 }
 
-LayoutUnit ScrollAnimator::scrollOffsetInAxis(ScrollEventAxis axis)
+LayoutUnit ScrollAnimator::scrollOffsetOnAxis(ScrollEventAxis axis)
 {
-    FloatPoint currentPosition = this->currentPosition();
-    return axis == ScrollEventAxis::Horizontal ? currentPosition.x() : currentPosition.y();
+    return axis == ScrollEventAxis::Horizontal ? m_currentPosX : m_currentPosY;
 }
 
-void ScrollAnimator::immediateScrollInAxis(ScrollEventAxis axis, float delta)
+void ScrollAnimator::immediateScrollOnAxis(ScrollEventAxis axis, float delta)
 {
     FloatPoint currentPosition = this->currentPosition();
     if (axis == ScrollEventAxis::Horizontal)
@@ -214,30 +191,6 @@ void ScrollAnimator::immediateScrollInAxis(ScrollEventAxis axis, float delta)
     else
         scrollToOffsetWithoutAnimation(FloatPoint(currentPosition.x(), currentPosition.y() + delta));
 }
-
-void ScrollAnimator::startScrollSnapTimer(ScrollEventAxis axis)
-{
-    Timer* scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer.get() : m_verticalScrollSnapTimer.get();
-    if (!scrollSnapTimer->isActive())
-        scrollSnapTimer->startRepeating(1.0 / 60.0);
-}
-
-void ScrollAnimator::stopScrollSnapTimer(ScrollEventAxis axis)
-{
-    Timer* scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer.get() : m_verticalScrollSnapTimer.get();
-    if (scrollSnapTimer->isActive())
-        scrollSnapTimer->stop();
-}
-
-void ScrollAnimator::horizontalScrollSnapTimerFired()
-{
-    m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate();
-}
-
-void ScrollAnimator::verticalScrollSnapTimerFired()
-{
-    m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate();
-}
 #endif
 
 } // namespace WebCore
index 566085d..faaf1e7 100644 (file)
 #define ScrollAnimator_h
 
 #include "FloatSize.h"
+#include "LayoutUnit.h"
 #include "PlatformWheelEvent.h"
 #include "ScrollTypes.h"
 #include <wtf/FastMalloc.h>
 #include <wtf/Forward.h>
 
-#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-#include "AxisScrollSnapAnimator.h"
-#include "Timer.h"
+#if (ENABLE(RUBBER_BANDING) || ENABLE(CSS_SCROLL_SNAP)) && PLATFORM(MAC)
+#include "ScrollController.h"
 #endif
 
 namespace WebCore {
@@ -50,8 +50,8 @@ class PlatformTouchEvent;
 class ScrollableArea;
 class Scrollbar;
 
-#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-class ScrollAnimator : public AxisScrollSnapAnimatorClient {
+#if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC)
+class ScrollAnimator : private ScrollControllerClient {
 #else
 class ScrollAnimator {
 #endif
@@ -118,33 +118,21 @@ public:
     virtual bool isRubberBandInProgress() const { return false; }
 
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-    void processWheelEventForScrollSnap(const PlatformWheelEvent&);
+    bool processWheelEventForScrollSnap(const PlatformWheelEvent&);
     void updateScrollAnimatorsAndTimers();
-    virtual LayoutUnit scrollOffsetInAxis(ScrollEventAxis) override;
-    virtual void immediateScrollInAxis(ScrollEventAxis, float delta) override;
-    virtual void startScrollSnapTimer(ScrollEventAxis) override;
-    virtual void stopScrollSnapTimer(ScrollEventAxis) override;
+    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
+    void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
 #endif
 
 protected:
     virtual void notifyPositionChanged(const FloatSize& delta);
 
-#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-    // Trivial wrappers around the actual update loop in AxisScrollSnapAnimator, since WebCore Timer requires a Timer argument.
-    void horizontalScrollSnapTimerFired();
-    void verticalScrollSnapTimerFired();
-#endif
-
     ScrollableArea& m_scrollableArea;
+#if (ENABLE(CSS_SCROLL_SNAP) || ENABLE(RUBBER_BANDING)) && PLATFORM(MAC)
+    ScrollController m_scrollController;
+#endif
     float m_currentPosX; // We avoid using a FloatPoint in order to reduce
     float m_currentPosY; // subclass code complexity.
-#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
-    std::unique_ptr<AxisScrollSnapAnimator> m_horizontalScrollSnapAnimator;
-    std::unique_ptr<Timer> m_horizontalScrollSnapTimer;
-    // FIXME: Find a way to consolidate both timers into one variable.
-    std::unique_ptr<AxisScrollSnapAnimator> m_verticalScrollSnapAnimator;
-    std::unique_ptr<Timer> m_verticalScrollSnapTimer;
-#endif
 };
 
 } // namespace WebCore
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Apple Inc. All rights reserved.
+ * Copyright (C) 2011, 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
 #include "FloatSize.h"
 #include "ScrollTypes.h"
 #include <wtf/Noncopyable.h>
+#include <wtf/RunLoop.h>
+
+#if ENABLE(CSS_SCROLL_SNAP)
+#include "AxisScrollSnapAnimator.h"
+#endif
 
 namespace WebCore {
 
 class PlatformWheelEvent;
+class ScrollableArea;
 
 class ScrollControllerClient {
 protected:
@@ -55,36 +61,74 @@ public:
 
     virtual void immediateScrollBy(const FloatSize&) = 0;
     virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) = 0;
-    virtual void startSnapRubberbandTimer() = 0;
-    virtual void stopSnapRubberbandTimer() = 0;
-
+    virtual void startSnapRubberbandTimer()
+    {
+        // Override to perform client-specific snap start logic
+    }
+
+    virtual void stopSnapRubberbandTimer()
+    {
+        // Override to perform client-specific snap end logic
+    }
+    
     // If the current scroll position is within the overhang area, this function will cause
     // the page to scroll to the nearest boundary point.
     virtual void adjustScrollPositionToBoundsIfNecessary() = 0;
+
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+    virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0;
+    virtual void immediateScrollOnAxis(ScrollEventAxis, float delta) = 0;
+    virtual void startScrollSnapTimer(ScrollEventAxis)
+    {
+        // Override to perform client-specific scroll snap point start logic
+    }
+
+    virtual void stopScrollSnapTimer(ScrollEventAxis)
+    {
+        // Override to perform client-specific scroll snap point end logic
+        
+    }
+#endif
 };
 
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+class ScrollController : public AxisScrollSnapAnimatorClient {
+#else
 class ScrollController {
+#endif
     WTF_MAKE_NONCOPYABLE(ScrollController);
 
 public:
     explicit ScrollController(ScrollControllerClient*);
 
     bool handleWheelEvent(const PlatformWheelEvent&);
-    void snapRubberBandTimerFired();
 
     bool isRubberBandInProgress() const;
 
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+    bool processWheelEventForScrollSnap(const PlatformWheelEvent&);
+    void updateScrollAnimatorsAndTimers(const ScrollableArea&);
+#endif
+
 private:
+    void startSnapRubberbandTimer();
     void stopSnapRubberbandTimer();
     void snapRubberBand();
+    void snapRubberBandTimerFired();
 
     bool shouldRubberBandInHorizontalDirection(const PlatformWheelEvent&);
 
-    ScrollControllerClient* m_client;
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+    void horizontalScrollSnapTimerFired();
+    void verticalScrollSnapTimerFired();
+    void startScrollSnapTimer(ScrollEventAxis) override;
+    void stopScrollSnapTimer(ScrollEventAxis) override;
 
-    bool m_inScrollGesture;
-    bool m_momentumScrollInProgress;
-    bool m_ignoreMomentumScrolls;
+    LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) override;
+    void immediateScrollOnAxis(ScrollEventAxis, float delta) override;
+#endif
+
+    ScrollControllerClient* m_client;
     
     CFTimeInterval m_lastMomentumScrollTimestamp;
     FloatSize m_overflowScrollDelta;
@@ -96,7 +140,19 @@ private:
     FloatSize m_startStretch;
     FloatPoint m_origOrigin;
     FloatSize m_origVelocity;
+    RunLoop::Timer<ScrollController> m_snapRubberbandTimer;
 
+#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;
+    RunLoop::Timer<ScrollController> m_horizontalScrollSnapTimer;
+    RunLoop::Timer<ScrollController> m_verticalScrollSnapTimer;
+#endif
+
+    bool m_inScrollGesture;
+    bool m_momentumScrollInProgress;
+    bool m_ignoreMomentumScrolls;
     bool m_snapRubberbandTimerIsActive;
 };
 
 #include <sys/sysctl.h>
 #include <sys/time.h>
 
+#if ENABLE(CSS_SCROLL_SNAP)
+#include "AxisScrollSnapAnimator.h"
+#include "ScrollableArea.h"
+#endif
+
 #if ENABLE(RUBBER_BANDING)
 
 static NSTimeInterval systemUptime()
@@ -91,17 +96,26 @@ static float scrollWheelMultiplier()
 
 ScrollController::ScrollController(ScrollControllerClient* client)
     : m_client(client)
+    , m_lastMomentumScrollTimestamp(0)
+    , m_startTime(0)
+    , m_snapRubberbandTimer(RunLoop::current(), this, &ScrollController::snapRubberBandTimerFired)
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+    , m_horizontalScrollSnapTimer(RunLoop::current(), this, &ScrollController::horizontalScrollSnapTimerFired)
+    , m_verticalScrollSnapTimer(RunLoop::current(), this, &ScrollController::verticalScrollSnapTimerFired)
+#endif
     , m_inScrollGesture(false)
     , m_momentumScrollInProgress(false)
     , m_ignoreMomentumScrolls(false)
-    , m_lastMomentumScrollTimestamp(0)
-    , m_startTime(0)
     , m_snapRubberbandTimerIsActive(false)
 {
 }
 
 bool ScrollController::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
 {
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+    if (!processWheelEventForScrollSnap(wheelEvent))
+        return false;
+#endif
     if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) {
         // First, check if we should rubber-band at all.
         if (m_client->pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0))
@@ -365,9 +379,16 @@ bool ScrollController::isRubberBandInProgress() const
     return !m_client->stretchAmount().isZero();
 }
 
+void ScrollController::startSnapRubberbandTimer()
+{
+    m_client->startSnapRubberbandTimer();
+    m_snapRubberbandTimer.startRepeating(1.0 / 60.0);
+}
+
 void ScrollController::stopSnapRubberbandTimer()
 {
     m_client->stopSnapRubberbandTimer();
+    m_snapRubberbandTimer.stop();
     m_snapRubberbandTimerIsActive = false;
 }
 
@@ -387,7 +408,7 @@ void ScrollController::snapRubberBand()
     m_origOrigin = FloatPoint();
     m_origVelocity = FloatSize();
 
-    m_client->startSnapRubberbandTimer();
+    startSnapRubberbandTimer();
     m_snapRubberbandTimerIsActive = true;
 }
 
@@ -401,6 +422,73 @@ bool ScrollController::shouldRubberBandInHorizontalDirection(const PlatformWheel
     return true;
 }
 
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+bool ScrollController::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
+{
+    if (m_verticalScrollSnapAnimator) {
+        m_verticalScrollSnapAnimator->handleWheelEvent(wheelEvent);
+        if (m_verticalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent))
+            return false;
+    }
+    if (m_horizontalScrollSnapAnimator) {
+        m_horizontalScrollSnapAnimator->handleWheelEvent(wheelEvent);
+        if (m_horizontalScrollSnapAnimator->shouldOverrideWheelEvent(wheelEvent))
+            return false;
+    }
+
+    return true;
+}
+
+void ScrollController::updateScrollAnimatorsAndTimers(const ScrollableArea& scrollableArea)
+{
+    // 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;
+
+    if (scrollableArea.verticalSnapOffsets())
+        m_verticalScrollSnapAnimator = std::make_unique<AxisScrollSnapAnimator>(this, scrollableArea.verticalSnapOffsets(), ScrollEventAxis::Vertical);
+    else if (m_verticalScrollSnapAnimator)
+        m_verticalScrollSnapAnimator = nullptr;
+}
+
+void ScrollController::startScrollSnapTimer(ScrollEventAxis axis)
+{
+    RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer;
+    if (!scrollSnapTimer.isActive())
+        scrollSnapTimer.startRepeating(1.0 / 60.0);
+}
+
+void ScrollController::stopScrollSnapTimer(ScrollEventAxis axis)
+{
+    RunLoop::Timer<ScrollController>& scrollSnapTimer = axis == ScrollEventAxis::Horizontal ? m_horizontalScrollSnapTimer : m_verticalScrollSnapTimer;
+    scrollSnapTimer.stop();
+}
+
+void ScrollController::horizontalScrollSnapTimerFired()
+{
+    if (m_horizontalScrollSnapAnimator)
+        m_horizontalScrollSnapAnimator->scrollSnapAnimationUpdate();
+}
+
+void ScrollController::verticalScrollSnapTimerFired()
+{
+    if (m_verticalScrollSnapAnimator)
+        m_verticalScrollSnapAnimator->scrollSnapAnimationUpdate();
+}
+
+LayoutUnit ScrollController::scrollOffsetOnAxis(ScrollEventAxis axis)
+{
+    return m_client->scrollOffsetOnAxis(axis);
+}
+
+void ScrollController::immediateScrollOnAxis(ScrollEventAxis axis, float delta)
+{
+    m_client->immediateScrollOnAxis(axis, delta);
+}
+#endif
+
 } // namespace WebCore
 
 #endif // ENABLE(RUBBER_BANDING)
index ce15639..2993a23 100644 (file)
@@ -57,8 +57,8 @@ protected:
     virtual ~AxisScrollSnapAnimatorClient() { }
 
 public:
-    virtual LayoutUnit scrollOffsetInAxis(ScrollEventAxis) = 0;
-    virtual void immediateScrollInAxis(ScrollEventAxis, float velocity) = 0;
+    virtual LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) = 0;
+    virtual void immediateScrollOnAxis(ScrollEventAxis, float velocity) = 0;
     virtual void startScrollSnapTimer(ScrollEventAxis) = 0;
     virtual void stopScrollSnapTimer(ScrollEventAxis) = 0;
 };
index 70ea7fb..b16c79f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2014 Apple Inc. All rights reserved.
+ * 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
@@ -117,7 +117,7 @@ void AxisScrollSnapAnimator::handleWheelEvent(const PlatformWheelEvent& event)
         // Begin tracking wheel deltas for glide prediction.
         endScrollSnapAnimation(ScrollSnapState::UserInteraction);
         pushInitialWheelDelta(wheelDelta);
-        m_beginTrackingWheelDeltaOffset = m_client->scrollOffsetInAxis(m_axis);
+        m_beginTrackingWheelDeltaOffset = m_client->scrollOffsetOnAxis(m_axis);
         break;
 
     case WheelEventStatus::InertialScrolling:
@@ -153,7 +153,7 @@ void AxisScrollSnapAnimator::scrollSnapAnimationUpdate()
     ASSERT(m_currentState == ScrollSnapState::Gliding || m_currentState == ScrollSnapState::Snapping);
     float delta = m_currentState == ScrollSnapState::Snapping ? computeSnapDelta() : computeGlideDelta();
     if (delta)
-        m_client->immediateScrollInAxis(m_axis, delta);
+        m_client->immediateScrollOnAxis(m_axis, delta);
     else
         endScrollSnapAnimation(ScrollSnapState::DestinationReached);
 }
@@ -161,7 +161,7 @@ void AxisScrollSnapAnimator::scrollSnapAnimationUpdate()
 void AxisScrollSnapAnimator::beginScrollSnapAnimation(ScrollSnapState newState)
 {
     ASSERT(newState == ScrollSnapState::Gliding || newState == ScrollSnapState::Snapping);
-    LayoutUnit offset = m_client->scrollOffsetInAxis(m_axis);
+    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;
     projectedScrollDestination = std::min(std::max(projectedScrollDestination, m_snapOffsets->first()), m_snapOffsets->last());
@@ -203,7 +203,7 @@ void AxisScrollSnapAnimator::endScrollSnapAnimation(ScrollSnapState newState)
 // relationship of the distance traveled, clamped by arbitrary min and max values.
 float AxisScrollSnapAnimator::computeSnapDelta() const
 {
-    LayoutUnit offset = m_client->scrollOffsetInAxis(m_axis);
+    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;
@@ -237,7 +237,7 @@ float AxisScrollSnapAnimator::computeSnapDelta() const
 // 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->scrollOffsetInAxis(m_axis);
+    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;
index 5025198..38d9cc8 100644 (file)
@@ -32,7 +32,6 @@
 #include "FloatPoint.h"
 #include "FloatSize.h"
 #include "ScrollAnimator.h"
-#include "ScrollController.h"
 #include "Timer.h"
 #include <wtf/RetainPtr.h>
 
@@ -42,15 +41,11 @@ OBJC_CLASS WebScrollbarPainterDelegate;
 
 typedef id ScrollbarPainterController;
 
-#if !ENABLE(RUBBER_BANDING)
-class ScrollControllerClient { };
-#endif
-
 namespace WebCore {
 
 class Scrollbar;
 
-class ScrollAnimatorMac : public ScrollAnimator, private ScrollControllerClient {
+class ScrollAnimatorMac : public ScrollAnimator {
 
 public:
     ScrollAnimatorMac(ScrollableArea&);
@@ -150,17 +145,11 @@ private:
     virtual WebCore::IntPoint absoluteScrollPosition() override;
     virtual void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) override;
     virtual void immediateScrollBy(const FloatSize&) override;
-    virtual void startSnapRubberbandTimer() override;
-    virtual void stopSnapRubberbandTimer() override;
     virtual void adjustScrollPositionToBoundsIfNecessary() override;
 
     bool pinnedInDirection(float deltaX, float deltaY);
-    void snapRubberBandTimerFired();
 
     bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis);
-
-    ScrollController m_scrollController;
-    Timer m_snapRubberBandTimer;
 #endif
 
     bool m_haveScrolledSincePageLoad;
index aeda5d9..3351387 100644 (file)
@@ -643,10 +643,6 @@ ScrollAnimatorMac::ScrollAnimatorMac(ScrollableArea& scrollableArea)
     : ScrollAnimator(scrollableArea)
     , m_initialScrollbarPaintTimer(*this, &ScrollAnimatorMac::initialScrollbarPaintTimerFired)
     , m_sendContentAreaScrolledTimer(*this, &ScrollAnimatorMac::sendContentAreaScrolledTimerFired)
-#if ENABLE(RUBBER_BANDING)
-    , m_scrollController(this)
-    , m_snapRubberBandTimer(*this, &ScrollAnimatorMac::snapRubberBandTimerFired)
-#endif
     , m_haveScrolledSincePageLoad(false)
     , m_needsScrollerStyleUpdate(false)
 {
@@ -1270,21 +1266,6 @@ void ScrollAnimatorMac::immediateScrollBy(const FloatSize& delta)
     m_currentPosY = newPos.y();
     notifyPositionChanged(adjustedDelta);
 }
-
-void ScrollAnimatorMac::startSnapRubberbandTimer()
-{
-    m_snapRubberBandTimer.startRepeating(1.0 / 60.0);
-}
-
-void ScrollAnimatorMac::stopSnapRubberbandTimer()
-{
-    m_snapRubberBandTimer.stop();
-}
-
-void ScrollAnimatorMac::snapRubberBandTimerFired()
-{
-    m_scrollController.snapRubberBandTimerFired();
-}
 #endif
 
 void ScrollAnimatorMac::updateScrollerStyle()