Title: [184733] branches/safari-601.1.32.2-branch/Source/WebCore

Diff

Modified: branches/safari-601.1.32.2-branch/Source/WebCore/ChangeLog (184732 => 184733)


--- branches/safari-601.1.32.2-branch/Source/WebCore/ChangeLog	2015-05-21 20:26:45 UTC (rev 184732)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/ChangeLog	2015-05-21 20:27:43 UTC (rev 184733)
@@ -1,3 +1,39 @@
+2015-05-21  Babak Shafiei  <bshaf...@apple.com>
+
+        Merge r184728.
+
+    2015-05-21  Brent Fulgham  <bfulg...@apple.com>
+
+            Scroll-snap points needs to be updated during programmatic scrolls
+            https://bugs.webkit.org/show_bug.cgi?id=145216
+            <rdar://problem/21051039>
+
+            Reviewed by Dean Jackson.
+
+            Whenever we adjust the current scroll position, make sure we also update the current
+            active scroll snap offset index (if applicable).
+
+            * platform/ScrollAnimator.cpp:
+            (WebCore::ScrollAnimator::scrollToOffsetWithoutAnimation): Call the new 'updateActiveScrollSnapIndexForOffset'
+            method after moving to a new position.
+            (WebCore::ScrollAnimator::setCurrentPosition): Ditto.
+            (WebCore::ScrollAnimator::updateActiveScrollSnapIndexForOffset): New method. Asks the scroll controller to
+            identify the closest scroll snap offset index. If it finds something relevant, update the ScrollableArea state
+            to track these new values.
+            * platform/ScrollAnimator.h:
+            * platform/cocoa/ScrollController.h:
+            (WebCore::ScrollController::activeScrollSnapIndexDidChange):
+            (WebCore::ScrollController::setScrollSnapIndexDidChange):
+            * platform/cocoa/ScrollController.mm:
+            (WebCore::ScrollController::setNearestScrollSnapIndexForAxisAndOffset): Added. Find the closest relevant scroll snap offset
+            index for the given scroll offset, and update the internal scroll snap state to reflect it.
+            (WebCore::ScrollController::setActiveScrollSnapIndicesForOffset): Given the x and y offset for a scroll,
+            set the relevant scroll snap offset indices.
+            * platform/mac/ScrollAnimatorMac.mm:
+            (WebCore::ScrollAnimatorMac::immediateScrollTo): Call the new 'updateActiveScrollSnapIndexForOffset' method
+            after moving to a new position.
+            (WebCore::ScrollAnimatorMac::immediateScrollBy): Ditto.
+
 2015-05-20  Babak Shafiei  <bshaf...@apple.com>
 
         Merge r184308.

Modified: branches/safari-601.1.32.2-branch/Source/WebCore/platform/ScrollAnimator.cpp (184732 => 184733)


--- branches/safari-601.1.32.2-branch/Source/WebCore/platform/ScrollAnimator.cpp	2015-05-21 20:26:45 UTC (rev 184732)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/platform/ScrollAnimator.cpp	2015-05-21 20:27:43 UTC (rev 184733)
@@ -80,6 +80,7 @@
     m_currentPosX = offset.x();
     m_currentPosY = offset.y();
     notifyPositionChanged(delta);
+    updateActiveScrollSnapIndexForOffset();
 }
 
 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
@@ -168,6 +169,7 @@
 {
     m_currentPosX = position.x();
     m_currentPosY = position.y();
+    updateActiveScrollSnapIndexForOffset();
 }
 
 FloatPoint ScrollAnimator::currentPosition() const
@@ -175,6 +177,17 @@
     return FloatPoint(m_currentPosX, m_currentPosY);
 }
 
+void ScrollAnimator::updateActiveScrollSnapIndexForOffset()
+{
+#if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
+    m_scrollController.setActiveScrollSnapIndicesForOffset(m_currentPosX, m_currentPosY);
+    if (m_scrollController.activeScrollSnapIndexDidChange()) {
+        m_scrollableArea.setCurrentHorizontalSnapPointIndex(m_scrollController.activeScrollSnapIndexForAxis(ScrollEventAxis::Horizontal));
+        m_scrollableArea.setCurrentVerticalSnapPointIndex(m_scrollController.activeScrollSnapIndexForAxis(ScrollEventAxis::Vertical));
+    }
+#endif
+}
+
 void ScrollAnimator::notifyPositionChanged(const FloatSize& delta)
 {
     UNUSED_PARAM(delta);

Modified: branches/safari-601.1.32.2-branch/Source/WebCore/platform/ScrollAnimator.h (184732 => 184733)


--- branches/safari-601.1.32.2-branch/Source/WebCore/platform/ScrollAnimator.h	2015-05-21 20:26:45 UTC (rev 184732)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/platform/ScrollAnimator.h	2015-05-21 20:27:43 UTC (rev 184733)
@@ -137,6 +137,7 @@
 
 protected:
     virtual void notifyPositionChanged(const FloatSize& delta);
+    void updateActiveScrollSnapIndexForOffset();
 
     ScrollableArea& m_scrollableArea;
     RefPtr<WheelEventTestTrigger> m_wheelEventTestTrigger;

Modified: branches/safari-601.1.32.2-branch/Source/WebCore/platform/cocoa/ScrollController.h (184732 => 184733)


--- branches/safari-601.1.32.2-branch/Source/WebCore/platform/cocoa/ScrollController.h	2015-05-21 20:26:45 UTC (rev 184732)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/platform/cocoa/ScrollController.h	2015-05-21 20:27:43 UTC (rev 184733)
@@ -122,6 +122,7 @@
     void updateScrollSnapPoints(ScrollEventAxis, const Vector<LayoutUnit>&);
     unsigned activeScrollSnapIndexForAxis(ScrollEventAxis) const;
     void setActiveScrollSnapIndexForAxis(ScrollEventAxis, unsigned);
+    void setActiveScrollSnapIndicesForOffset(int x, int y);
     bool activeScrollSnapIndexDidChange() const { return m_activeScrollSnapIndexDidChange; }
     void setScrollSnapIndexDidChange(bool state) { m_activeScrollSnapIndexDidChange = state; }
     bool hasActiveScrollSnapTimerForAxis(ScrollEventAxis) const;
@@ -144,6 +145,7 @@
     LayoutUnit scrollOffsetOnAxis(ScrollEventAxis) const;
     void processWheelEventForScrollSnapOnAxis(ScrollEventAxis, const PlatformWheelEvent&);
     bool shouldOverrideWheelEvent(ScrollEventAxis, const PlatformWheelEvent&) const;
+    void setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis, int);
 
     void beginScrollSnapAnimation(ScrollEventAxis, ScrollSnapState);
     void scrollSnapAnimationUpdate(ScrollEventAxis);

Modified: branches/safari-601.1.32.2-branch/Source/WebCore/platform/cocoa/ScrollController.mm (184732 => 184733)


--- branches/safari-601.1.32.2-branch/Source/WebCore/platform/cocoa/ScrollController.mm	2015-05-21 20:26:45 UTC (rev 184732)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/platform/cocoa/ScrollController.mm	2015-05-21 20:27:43 UTC (rev 184733)
@@ -719,6 +719,31 @@
     snapState->m_activeSnapIndex = index;
 }
 
+void ScrollController::setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis axis, int offset)
+{
+    float scaleFactor = m_client.pageScaleFactor();
+    ScrollSnapAnimatorState& snapState = scrollSnapPointState(axis);
+    
+    LayoutUnit clampedOffset = std::min(std::max(LayoutUnit(offset / scaleFactor), snapState.m_snapOffsets.first()), snapState.m_snapOffsets.last());
+
+    unsigned activeIndex = 0;
+    (void)closestSnapOffset<LayoutUnit, float>(snapState.m_snapOffsets, clampedOffset, 0, activeIndex);
+
+    if (activeIndex == snapState.m_activeSnapIndex)
+        return;
+
+    m_activeScrollSnapIndexDidChange = true;
+    snapState.m_activeSnapIndex = activeIndex;
+}
+
+void ScrollController::setActiveScrollSnapIndicesForOffset(int x, int y)
+{
+    if (m_horizontalScrollSnapState)
+        setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Horizontal, x);
+    if (m_verticalScrollSnapState)
+        setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Vertical, y);
+}
+
 void ScrollController::beginScrollSnapAnimation(ScrollEventAxis axis, ScrollSnapState newState)
 {
     ASSERT(newState == ScrollSnapState::Gliding || newState == ScrollSnapState::Snapping);

Modified: branches/safari-601.1.32.2-branch/Source/WebCore/platform/mac/ScrollAnimatorMac.mm (184732 => 184733)


--- branches/safari-601.1.32.2-branch/Source/WebCore/platform/mac/ScrollAnimatorMac.mm	2015-05-21 20:26:45 UTC (rev 184732)
+++ branches/safari-601.1.32.2-branch/Source/WebCore/platform/mac/ScrollAnimatorMac.mm	2015-05-21 20:27:43 UTC (rev 184733)
@@ -758,6 +758,7 @@
     m_currentPosX = adjustedPosition.x();
     m_currentPosY = adjustedPosition.y();
     notifyPositionChanged(delta);
+    updateActiveScrollSnapIndexForOffset();
 }
 
 bool ScrollAnimatorMac::isRubberBandInProgress() const
@@ -1276,6 +1277,7 @@
     m_currentPosX = newPos.x();
     m_currentPosY = newPos.y();
     notifyPositionChanged(adjustedDelta);
+    updateActiveScrollSnapIndexForOffset();
 }
 #endif
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to