Move snapRubberBand to ScrollElasticityController
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jan 2012 20:25:19 +0000 (20:25 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 12 Jan 2012 20:25:19 +0000 (20:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=76200

Reviewed by Andreas Kling.

* platform/mac/ScrollAnimatorMac.h:
* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::smoothScrollWithEvent):
(WebCore::ScrollAnimatorMac::endScrollGesture):
* platform/mac/ScrollElasticityController.h:
* platform/mac/ScrollElasticityController.mm:
(systemUptime):
(WebCore::ScrollElasticityController::snapRubberBand):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@104846 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 9eb1d1e..c7a94ab 100644 (file)
@@ -1,3 +1,19 @@
+2012-01-12  Anders Carlsson  <andersca@apple.com>
+
+        Move snapRubberBand to ScrollElasticityController
+        https://bugs.webkit.org/show_bug.cgi?id=76200
+
+        Reviewed by Andreas Kling.
+
+        * platform/mac/ScrollAnimatorMac.h:
+        * platform/mac/ScrollAnimatorMac.mm:
+        (WebCore::ScrollAnimatorMac::smoothScrollWithEvent):
+        (WebCore::ScrollAnimatorMac::endScrollGesture):
+        * platform/mac/ScrollElasticityController.h:
+        * platform/mac/ScrollElasticityController.mm:
+        (systemUptime):
+        (WebCore::ScrollElasticityController::snapRubberBand):
+
 2012-01-12  Antti Koivisto  <antti@apple.com>
 
         REGRESSION(r104060): Setting user stylesheet may leave CSSStyleSelector with stale rule pointers 
index 94383ca..0ca4d3f 100644 (file)
@@ -139,7 +139,6 @@ private:
     bool allowsVerticalStretching() const;
     bool allowsHorizontalStretching() const;
     bool pinnedInDirection(float deltaX, float deltaY);
-    void snapRubberBand();
     void snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*);
     bool smoothScrollWithEvent(const PlatformWheelEvent&);
     void beginScrollGesture();
index f133ab9..9b34ee0 100644 (file)
 #include "ScrollbarTheme.h"
 #include "ScrollbarThemeMac.h"
 #include "WebCoreSystemInterface.h"
-#include <sys/time.h>
-#include <sys/sysctl.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/UnusedParam.h>
 
 using namespace WebCore;
 using namespace std;
 
-#ifdef BUILDING_ON_LEOPARD
-@interface NSProcessInfo (ScrollAnimatorMacExt)
-- (NSTimeInterval)systemUptime;
-@end
-#endif
-
 static bool supportsUIStateTransitionProgress()
 {
     // FIXME: This is temporary until all platforms that support ScrollbarPainter support this part of the API.
@@ -75,31 +67,6 @@ static ScrollbarPainter scrollbarPainterForScrollbar(Scrollbar* scrollbar)
     return nil;
 }
 
-#if ENABLE(RUBBER_BANDING)
-static NSTimeInterval systemUptime()
-{
-    if ([[NSProcessInfo processInfo] respondsToSelector:@selector(systemUptime)])
-        return [[NSProcessInfo processInfo] systemUptime];
-
-    // Get how long system has been up. Found by looking getting "boottime" from the kernel.
-    static struct timeval boottime = {0, 0};
-    if (!boottime.tv_sec) {
-        int mib[2] = {CTL_KERN, KERN_BOOTTIME};
-        size_t size = sizeof(boottime);
-        if (-1 == sysctl(mib, 2, &boottime, &size, 0, 0))
-            boottime.tv_sec = 0;
-    }
-    struct timeval now;
-    if (boottime.tv_sec && -1 != gettimeofday(&now, 0)) {
-        struct timeval uptime;
-        timersub(&now, &boottime, &uptime);
-        NSTimeInterval result = uptime.tv_sec + (uptime.tv_usec / 1E+6);
-        return result;
-    }
-    return 0;
-}
-#endif
-
 @interface NSObject (ScrollAnimationHelperDetails)
 - (id)initWithDelegate:(id)delegate;
 - (void)_stopRun;
@@ -1256,7 +1223,7 @@ bool ScrollAnimatorMac::smoothScrollWithEvent(const PlatformWheelEvent& wheelEve
                 if ((pinnedInDirection(eventCoalescedDeltaX, eventCoalescedDeltaY) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_scrollElasticityController.m_lastMomentumScrollTimestamp) {
                     m_scrollElasticityController.m_ignoreMomentumScrolls = true;
                     m_scrollElasticityController.m_momentumScrollInProgress = false;
-                    snapRubberBand();
+                    m_scrollElasticityController.snapRubberBand();
                 }
             }
 
@@ -1295,27 +1262,7 @@ void ScrollAnimatorMac::endScrollGesture()
 {
     didEndScrollGesture();
 
-    snapRubberBand();
-}
-
-void ScrollAnimatorMac::snapRubberBand()
-{
-    CFTimeInterval timeDelta = systemUptime() - m_scrollElasticityController.m_lastMomentumScrollTimestamp;
-    if (m_scrollElasticityController.m_lastMomentumScrollTimestamp && timeDelta >= scrollVelocityZeroingTimeout)
-        m_scrollElasticityController.m_momentumVelocity = FloatSize();
-
-    m_scrollElasticityController.m_inScrollGesture = false;
-
-    if (m_scrollElasticityController.m_snapRubberbandTimerIsActive)
-        return;
-
-    m_scrollElasticityController.m_startTime = [NSDate timeIntervalSinceReferenceDate];
-    m_scrollElasticityController.m_startStretch = FloatSize();
-    m_scrollElasticityController.m_origOrigin = FloatPoint();
-    m_scrollElasticityController.m_origVelocity = FloatSize();
-
-    m_scrollElasticityController.m_client->startSnapRubberbandTimer();
-    m_scrollElasticityController.m_snapRubberbandTimerIsActive = true;
+    m_scrollElasticityController.snapRubberBand();
 }
 
 void ScrollAnimatorMac::snapRubberBandTimerFired(Timer<ScrollAnimatorMac>*)
index 2d31468..6bfe9a1 100644 (file)
@@ -66,9 +66,11 @@ public:
 private:
     void stopSnapRubberbandTimer();
 
-    // FIXME: These member variables should be private. They are currently public as a stop-gap measure, while
+    // FIXME: These members 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:
+    void snapRubberBand();
+
     ScrollElasticityControllerClient* m_client;
 
     bool m_inScrollGesture;
index 03e5ac8..c47e102 100644 (file)
 #include "config.h"
 #include "ScrollElasticityController.h"
 
+#include <sys/time.h>
+#include <sys/sysctl.h>
+
+#if ENABLE(RUBBER_BANDING)
+
+#ifdef BUILDING_ON_LEOPARD
+@interface NSProcessInfo (ScrollAnimatorMacExt)
+- (NSTimeInterval)systemUptime;
+@end
+#endif
+
 #if ENABLE(RUBBER_BANDING)
+static NSTimeInterval systemUptime()
+{
+    if ([[NSProcessInfo processInfo] respondsToSelector:@selector(systemUptime)])
+        return [[NSProcessInfo processInfo] systemUptime];
+
+    // Get how long system has been up. Found by looking getting "boottime" from the kernel.
+    static struct timeval boottime = {0, 0};
+    if (!boottime.tv_sec) {
+        int mib[2] = {CTL_KERN, KERN_BOOTTIME};
+        size_t size = sizeof(boottime);
+        if (-1 == sysctl(mib, 2, &boottime, &size, 0, 0))
+            boottime.tv_sec = 0;
+    }
+    struct timeval now;
+    if (boottime.tv_sec && -1 != gettimeofday(&now, 0)) {
+        struct timeval uptime;
+        timersub(&now, &boottime, &uptime);
+        NSTimeInterval result = uptime.tv_sec + (uptime.tv_usec / 1E+6);
+        return result;
+    }
+    return 0;
+}
+#endif
+
 
 namespace WebCore {
 
+static const float scrollVelocityZeroingTimeout = 0.10f;
 static const float rubberbandStiffness = 20;
 static const float rubberbandAmplitude = 0.31f;
 static const float rubberbandPeriod = 1.6f;
@@ -161,6 +197,26 @@ void ScrollElasticityController::stopSnapRubberbandTimer()
     m_snapRubberbandTimerIsActive = false;
 }
 
+void ScrollElasticityController::snapRubberBand()
+{
+    CFTimeInterval timeDelta = systemUptime() - m_lastMomentumScrollTimestamp;
+    if (m_lastMomentumScrollTimestamp && timeDelta >= scrollVelocityZeroingTimeout)
+        m_momentumVelocity = FloatSize();
+
+    m_inScrollGesture = false;
+
+    if (m_snapRubberbandTimerIsActive)
+        return;
+
+    m_startTime = [NSDate timeIntervalSinceReferenceDate];
+    m_startStretch = FloatSize();
+    m_origOrigin = FloatPoint();
+    m_origVelocity = FloatSize();
+
+    m_client->startSnapRubberbandTimer();
+    m_snapRubberbandTimerIsActive = true;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(RUBBER_BANDING)