Simplify checking for whether we should rubberband or not when at the edge
authorandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2012 20:46:15 +0000 (20:46 +0000)
committerandersca@apple.com <andersca@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2012 20:46:15 +0000 (20:46 +0000)
https://bugs.webkit.org/show_bug.cgi?id=77131

Reviewed by Beth Dakin.

We only need to check once if we're pinned at either edge whether we should rubber-band
or not. Do this when the wheel event phase is PlatformWheelEventPhaseBegan. This lets us
remove a bunch of code that would keep track of the current horizontal scroll direction.

* platform/mac/ScrollAnimatorMac.h:
(ScrollAnimatorMac):
* platform/mac/ScrollAnimatorMac.mm:
(WebCore::ScrollAnimatorMac::ScrollAnimatorMac):
(WebCore::ScrollAnimatorMac::handleWheelEvent):
(WebCore::ScrollAnimatorMac::beginScrollGesture):

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

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

index 754eff4..dc8e5dd 100644 (file)
@@ -1,3 +1,21 @@
+2012-01-26  Anders Carlsson  <andersca@apple.com>
+
+        Simplify checking for whether we should rubberband or not when at the edge
+        https://bugs.webkit.org/show_bug.cgi?id=77131
+
+        Reviewed by Beth Dakin.
+
+        We only need to check once if we're pinned at either edge whether we should rubber-band
+        or not. Do this when the wheel event phase is PlatformWheelEventPhaseBegan. This lets us
+        remove a bunch of code that would keep track of the current horizontal scroll direction.
+
+        * platform/mac/ScrollAnimatorMac.h:
+        (ScrollAnimatorMac):
+        * platform/mac/ScrollAnimatorMac.mm:
+        (WebCore::ScrollAnimatorMac::ScrollAnimatorMac):
+        (WebCore::ScrollAnimatorMac::handleWheelEvent):
+        (WebCore::ScrollAnimatorMac::beginScrollGesture):
+
 2012-01-26  Eli Fidler  <efidler@rim.com>
 
         [JSC] Inspector instrumentation for JavaScript calls.
index 5c28ca9..94825a1 100644 (file)
@@ -138,11 +138,6 @@ private:
 
     ScrollElasticityController m_scrollElasticityController;
     Timer<ScrollAnimatorMac> m_snapRubberBandTimer;
-
-    bool m_scrollerInitiallyPinnedOnLeft;
-    bool m_scrollerInitiallyPinnedOnRight;
-    int m_cumulativeHorizontalScroll;
-    bool m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin;
 #endif
 
     bool m_haveScrolledSincePageLoad;
index 2042585..b0422af 100644 (file)
@@ -553,10 +553,6 @@ ScrollAnimatorMac::ScrollAnimatorMac(ScrollableArea* scrollableArea)
 #if ENABLE(RUBBER_BANDING)
     , m_scrollElasticityController(this)
     , m_snapRubberBandTimer(this, &ScrollAnimatorMac::snapRubberBandTimerFired)
-    , m_scrollerInitiallyPinnedOnLeft(false)
-    , m_scrollerInitiallyPinnedOnRight(false)
-    , m_cumulativeHorizontalScroll(0)
-    , m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin(false)
 #endif
     , m_haveScrolledSincePageLoad(false)
     , m_needsScrollerStyleUpdate(false)
@@ -920,39 +916,20 @@ bool ScrollAnimatorMac::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
     } else {
         if (!allowsHorizontalStretching())
             return ScrollAnimator::handleWheelEvent(wheelEvent);
-        
-        if (m_scrollableArea->horizontalScrollbar()) {
-            // If there is a scrollbar, we aggregate the wheel events to get an
-            // overall trend of the scroll. If the direction of the scroll is ever
-            // in the opposite direction of the pin location, then we switch the
-            // boolean, and rubber band. That is, if we were pinned to the left,
-            // and we ended up scrolling to the right, we rubber band.
-            m_cumulativeHorizontalScroll += wheelEvent.deltaX();
-            if (m_scrollerInitiallyPinnedOnLeft && m_cumulativeHorizontalScroll < 0)
-                m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true;
-            if (m_scrollerInitiallyPinnedOnRight && m_cumulativeHorizontalScroll > 0)
-                m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = true;
-        }
-
-        // After a gesture begins, we go through:
-        // 1+ PlatformWheelEventPhaseNone
-        // 0+ PlatformWheelEventPhaseChanged
-        // 1 PlatformWheelEventPhaseEnded if there was at least one changed event
-        if (wheelEvent.momentumPhase() == PlatformWheelEventPhaseNone && !m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin) {
-            if ((isScrollingLeftAndShouldNotRubberBand(wheelEvent, m_scrollableArea) &&
-                m_scrollerInitiallyPinnedOnLeft &&
-                m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition()) ||
-                (isScrollingRightAndShouldNotRubberBand(wheelEvent, m_scrollableArea) &&
-                m_scrollerInitiallyPinnedOnRight &&
-                m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition())) {
-                return ScrollAnimator::handleWheelEvent(wheelEvent);
-            }
-        }
     }
 
     if (wheelEvent.phase() == PlatformWheelEventPhaseBegan) {
+        if (m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition() &&
+            isScrollingLeftAndShouldNotRubberBand(wheelEvent, m_scrollableArea))
+            return false;
+
+        if (m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition() &&
+            isScrollingRightAndShouldNotRubberBand(wheelEvent, m_scrollableArea))
+            return false;
+
         // We don't return after this because we still want the scroll elasticity controller to handle the wheel event.
         beginScrollGesture();
+
     } else if (wheelEvent.phase() == PlatformWheelEventPhaseEnded) {
         endScrollGesture();
         return true;
@@ -1088,11 +1065,7 @@ void ScrollAnimatorMac::beginScrollGesture()
 {
     didBeginScrollGesture();
 
-    m_scrollerInitiallyPinnedOnLeft = m_scrollableArea->isHorizontalScrollerPinnedToMinimumPosition();
-    m_scrollerInitiallyPinnedOnRight = m_scrollableArea->isHorizontalScrollerPinnedToMaximumPosition();
     m_haveScrolledSincePageLoad = true;
-    m_cumulativeHorizontalScroll = 0;
-    m_didCumulativeHorizontalScrollEverSwitchToOppositeDirectionOfPin = false;
 
     m_scrollElasticityController.beginScrollGesture();
 }