- Revision
- 184728
- Author
- bfulg...@apple.com
- Date
- 2015-05-21 12:37:50 -0700 (Thu, 21 May 2015)
Log Message
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.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (184727 => 184728)
--- trunk/Source/WebCore/ChangeLog 2015-05-21 19:12:17 UTC (rev 184727)
+++ trunk/Source/WebCore/ChangeLog 2015-05-21 19:37:50 UTC (rev 184728)
@@ -1,3 +1,35 @@
+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-21 Matt Baker <mattba...@apple.com>
Unreviewed build fix.
Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (184727 => 184728)
--- trunk/Source/WebCore/platform/ScrollAnimator.cpp 2015-05-21 19:12:17 UTC (rev 184727)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp 2015-05-21 19:37:50 UTC (rev 184728)
@@ -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: trunk/Source/WebCore/platform/ScrollAnimator.h (184727 => 184728)
--- trunk/Source/WebCore/platform/ScrollAnimator.h 2015-05-21 19:12:17 UTC (rev 184727)
+++ trunk/Source/WebCore/platform/ScrollAnimator.h 2015-05-21 19:37:50 UTC (rev 184728)
@@ -137,6 +137,7 @@
protected:
virtual void notifyPositionChanged(const FloatSize& delta);
+ void updateActiveScrollSnapIndexForOffset();
ScrollableArea& m_scrollableArea;
RefPtr<WheelEventTestTrigger> m_wheelEventTestTrigger;
Modified: trunk/Source/WebCore/platform/cocoa/ScrollController.h (184727 => 184728)
--- trunk/Source/WebCore/platform/cocoa/ScrollController.h 2015-05-21 19:12:17 UTC (rev 184727)
+++ trunk/Source/WebCore/platform/cocoa/ScrollController.h 2015-05-21 19:37:50 UTC (rev 184728)
@@ -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: trunk/Source/WebCore/platform/cocoa/ScrollController.mm (184727 => 184728)
--- trunk/Source/WebCore/platform/cocoa/ScrollController.mm 2015-05-21 19:12:17 UTC (rev 184727)
+++ trunk/Source/WebCore/platform/cocoa/ScrollController.mm 2015-05-21 19:37:50 UTC (rev 184728)
@@ -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: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm (184727 => 184728)
--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2015-05-21 19:12:17 UTC (rev 184727)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2015-05-21 19:37:50 UTC (rev 184728)
@@ -758,6 +758,7 @@
m_currentPosX = adjustedPosition.x();
m_currentPosY = adjustedPosition.y();
notifyPositionChanged(delta);
+ updateActiveScrollSnapIndexForOffset();
}
bool ScrollAnimatorMac::isRubberBandInProgress() const
@@ -1278,6 +1279,7 @@
m_currentPosX = newPos.x();
m_currentPosY = newPos.y();
notifyPositionChanged(adjustedDelta);
+ updateActiveScrollSnapIndexForOffset();
}
#endif