Move code into ScrollElasticityController::beginScrollGesture()
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Oct 2011 23:48:39 +0000 (23:48 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Oct 2011 23:48:39 +0000 (23:48 +0000)
https://bugs.webkit.org/show_bug.cgi?id=69383

Reviewed by John Sullivan.

* platform/mac/ScrollAnimatorMac.h:
Add new ScrollElasticityControllerClient member functions.

* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::isHorizontalScrollerPinnedToMinimumPosition):
(WebCore::ScrollAnimatorMac::isHorizontalScrollerPinnedToMaximumPosition):
(WebCore::ScrollAnimatorMac::stretchAmount):
(WebCore::ScrollAnimatorMac::startSnapRubberbandTimer):
(WebCore::ScrollAnimatorMac::stopSnapRubberbandTimer):
Implement the new ScrollElasticityControllerClient member functions.

(WebCore::ScrollAnimatorMac::beginScrollGesture):
Move code into ScrollElasticityController::beginScrollGesture and call it directly.

* platform/mac/ScrollElasticityController.h:
Add new ScrollElasticityControllerClient member functions.

* platform/mac/ScrollElasticityController.mm:
(WebCore::reboundDeltaForElasticDelta):
(WebCore::ScrollElasticityController::beginScrollGesture):
Set up the scroll gesture state.

(WebCore::ScrollElasticityController::stopSnapRubberbandTimer):
New helper function.

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

Source/WebCore/ChangeLog
Source/WebCore/platform/mac/ScrollAnimatorMac.h
Source/WebCore/platform/mac/ScrollAnimatorMac.mm
Source/WebCore/platform/mac/ScrollElasticityController.h
Source/WebCore/platform/mac/ScrollElasticityController.mm

index 7959040..2ed24dc 100644 (file)
@@ -1,3 +1,35 @@
+2011-10-04  Anders Carlsson  <andersca@apple.com>
+
+        Move code into ScrollElasticityController::beginScrollGesture()
+        https://bugs.webkit.org/show_bug.cgi?id=69383
+
+        Reviewed by John Sullivan.
+
+        * platform/mac/ScrollAnimatorMac.h:
+        Add new ScrollElasticityControllerClient member functions.
+
+        * platform/mac/ScrollAnimatorMac.mm:
+        (WebCore::ScrollAnimatorMac::isHorizontalScrollerPinnedToMinimumPosition):
+        (WebCore::ScrollAnimatorMac::isHorizontalScrollerPinnedToMaximumPosition):
+        (WebCore::ScrollAnimatorMac::stretchAmount):
+        (WebCore::ScrollAnimatorMac::startSnapRubberbandTimer):
+        (WebCore::ScrollAnimatorMac::stopSnapRubberbandTimer):
+        Implement the new ScrollElasticityControllerClient member functions.
+
+        (WebCore::ScrollAnimatorMac::beginScrollGesture):
+        Move code into ScrollElasticityController::beginScrollGesture and call it directly.
+
+        * platform/mac/ScrollElasticityController.h:
+        Add new ScrollElasticityControllerClient member functions.
+
+        * platform/mac/ScrollElasticityController.mm:
+        (WebCore::reboundDeltaForElasticDelta):
+        (WebCore::ScrollElasticityController::beginScrollGesture):
+        Set up the scroll gesture state.
+
+        (WebCore::ScrollElasticityController::stopSnapRubberbandTimer):
+        New helper function.
+
 2011-10-04  Scott Graham  <scottmg@chromium.org>
 
         Add GAMEPAD feature flag
index ebc7dae..55b7f72 100644 (file)
@@ -138,6 +138,13 @@ private:
     FloatPoint adjustScrollPositionIfNecessary(const FloatPoint&) const;
 
 #if ENABLE(RUBBER_BANDING)
+    /// ScrollElasticityControllerClient member functions.
+    virtual bool isHorizontalScrollerPinnedToMinimumPosition() OVERRIDE;
+    virtual bool isHorizontalScrollerPinnedToMaximumPosition() OVERRIDE;
+    virtual IntSize stretchAmount() OVERRIDE;
+    virtual void startSnapRubberbandTimer() OVERRIDE;
+    virtual void stopSnapRubberbandTimer() OVERRIDE;
+
     bool allowsVerticalStretching() const;
     bool allowsHorizontalStretching() const;
     bool pinnedInDirection(float deltaX, float deltaY);
index e9aabdd..f36c885 100644 (file)
@@ -882,6 +882,31 @@ bool ScrollAnimatorMac::pinnedInDirection(float deltaX, float deltaY)
     return false;
 }
 
+bool ScrollAnimatorMac::isHorizontalScrollerPinnedToMinimumPosition()
+{
+    return m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition();
+}
+
+bool ScrollAnimatorMac::isHorizontalScrollerPinnedToMaximumPosition()
+{
+    return m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition();
+}
+
+IntSize ScrollAnimatorMac::stretchAmount()
+{
+    return m_scrollableArea->overhangAmount();
+}
+
+void ScrollAnimatorMac::startSnapRubberbandTimer()
+{
+    m_snapRubberBandTimer.startRepeating(1.0 / 60.0);
+}
+
+void ScrollAnimatorMac::stopSnapRubberbandTimer()
+{
+    m_snapRubberBandTimer.stop();
+}
+
 bool ScrollAnimatorMac::allowsVerticalStretching() const
 {
     switch (m_scrollableArea->verticalScrollElasticity()) {
@@ -1075,26 +1100,9 @@ void ScrollAnimatorMac::smoothScrollWithEvent(const PlatformWheelEvent& wheelEve
 void ScrollAnimatorMac::beginScrollGesture()
 {
     didBeginScrollGesture();
-
     m_haveScrolledSincePageLoad = true;
-    m_scrollElasticityController.m_inScrollGesture = true;
-    m_scrollElasticityController.m_momentumScrollInProgress = false;
-    m_scrollElasticityController.m_ignoreMomentumScrolls = false;
-    m_scrollElasticityController.m_lastMomentumScrollTimestamp = 0;
-    m_scrollElasticityController.m_momentumVelocity = FloatSize();
-    m_scrollElasticityController.m_scrollerInitiallyPinnedOnLeft = m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition();
-    m_scrollElasticityController.m_scrollerInitiallyPinnedOnRight = m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition();
-    m_scrollElasticityController.m_cumulativeHorizontalScroll = 0;
-    m_scrollElasticityController.m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = false;
-    
-    IntSize stretchAmount = m_scrollableArea->overhangAmount();
-    m_scrollElasticityController.m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount.width()));
-    m_scrollElasticityController.m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(stretchAmount.height()));
 
-    m_scrollElasticityController.m_overflowScrollDelta = FloatSize();
-    
-    m_snapRubberBandTimer.stop();
-    m_scrollElasticityController.m_snapRubberbandTimerIsActive = false;
+    m_scrollElasticityController.beginScrollGesture();
 }
 
 void ScrollAnimatorMac::endScrollGesture()
index 73b343b..b60b464 100644 (file)
 namespace WebCore {
 
 class ScrollElasticityControllerClient {
-public:
+protected:
     virtual ~ScrollElasticityControllerClient() { } 
+
+public:
+    virtual bool isHorizontalScrollerPinnedToMinimumPosition() = 0;
+    virtual bool isHorizontalScrollerPinnedToMaximumPosition() = 0;
+
+    virtual IntSize stretchAmount() = 0;
+
+    virtual void startSnapRubberbandTimer() = 0;
+    virtual void stopSnapRubberbandTimer() = 0;
 };
 
 class ScrollElasticityController {
@@ -45,9 +54,13 @@ class ScrollElasticityController {
 public:
     explicit ScrollElasticityController(ScrollElasticityControllerClient*);
 
+    void beginScrollGesture();
+
 private:
     ScrollElasticityControllerClient* m_client;
 
+    void stopSnapRubberbandTimer();
+
     // FIXME: These member variables should be private. They are currently public as a stop-gap measure, while
     // the rubber-band related code from ScrollAnimatorMac is being moved over.
 public:
index 607087e..ff66f6b 100644 (file)
 
 namespace WebCore {
 
+static const float rubberbandStiffness = 20;
+
+static float reboundDeltaForElasticDelta(float delta)
+{
+    return delta * rubberbandStiffness;
+}
+
 ScrollElasticityController::ScrollElasticityController(ScrollElasticityControllerClient* client)
     : m_client(client)
     , m_inScrollGesture(false)
@@ -45,6 +52,33 @@ ScrollElasticityController::ScrollElasticityController(ScrollElasticityControlle
 {
 }
 
+void ScrollElasticityController::beginScrollGesture()
+{
+    m_inScrollGesture = true;
+    m_momentumScrollInProgress = false;
+    m_ignoreMomentumScrolls = false;
+    m_lastMomentumScrollTimestamp = 0;
+    m_momentumVelocity = FloatSize();
+    m_scrollerInitiallyPinnedOnLeft = m_client->isHorizontalScrollerPinnedToMinimumPosition();
+    m_scrollerInitiallyPinnedOnRight = m_client->isHorizontalScrollerPinnedToMaximumPosition();
+    m_cumulativeHorizontalScroll = 0;
+    m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = false;
+    
+    IntSize stretchAmount = m_client->stretchAmount();
+    m_stretchScrollForce.setWidth(reboundDeltaForElasticDelta(stretchAmount.width()));
+    m_stretchScrollForce.setHeight(reboundDeltaForElasticDelta(stretchAmount.height()));
+    
+    m_overflowScrollDelta = FloatSize();
+
+    stopSnapRubberbandTimer();
+}
+
+void ScrollElasticityController::stopSnapRubberbandTimer()
+{
+    m_client->stopSnapRubberbandTimer();
+    m_snapRubberbandTimerIsActive = false;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(RUBBER_BANDING)