Changeset 280171 in webkit
- Timestamp:
- Jul 22, 2021 2:00:27 AM (12 months ago)
- Location:
- trunk/Source
- Files:
-
- 15 edited
-
WebCore/ChangeLog (modified) (1 diff)
-
WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp (modified) (3 diffs)
-
WebCore/page/scrolling/ScrollSnapOffsetsInfo.h (modified) (3 diffs)
-
WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp (modified) (1 diff)
-
WebCore/platform/ScrollAnimator.cpp (modified) (2 diffs)
-
WebCore/platform/ScrollAnimator.h (modified) (1 diff)
-
WebCore/platform/ScrollController.cpp (modified) (6 diffs)
-
WebCore/platform/ScrollController.h (modified) (2 diffs)
-
WebCore/platform/ScrollSnapAnimatorState.cpp (modified) (2 diffs)
-
WebCore/platform/ScrollSnapAnimatorState.h (modified) (1 diff)
-
WebCore/platform/ScrollableArea.cpp (modified) (1 diff)
-
WebKit/ChangeLog (modified) (1 diff)
-
WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.h (modified) (1 diff)
-
WebKit/UIProcess/RemoteLayerTree/ios/RemoteScrollingCoordinatorProxyIOS.mm (modified) (4 diffs)
-
WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.mm (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r280158 r280171 1 2021-07-22 Martin Robinson <mrobinson@webkit.org> 2 3 [css-scroll-snap] Pass the full target point when selecting a snap offset 4 https://bugs.webkit.org/show_bug.cgi?id=228023 5 6 Reviewed by Frédéric Wang. 7 8 Pass the full proposed destination scroll offset when calling closestSnapOffset. For 9 now, only the component in the scroll direction is used, but eventually the other 10 component will be used to avoid snapping to snap areas that are entirely off the screen. 11 12 No new tests. This change is simply a refactor in preparation for a behavior 13 change and shouldn't change behavior itself. 14 15 * page/scrolling/ScrollSnapOffsetsInfo.cpp: 16 (WebCore::closestSnapOffsetWithInfoAndAxis): 17 (WebCore::LayoutScrollSnapOffsetsInfo::closestSnapOffset const): 18 (WebCore::FloatScrollSnapOffsetsInfo::closestSnapOffset const): 19 * page/scrolling/ScrollSnapOffsetsInfo.h: 20 * page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp: 21 (WebCore::ScrollingTreeScrollingNodeDelegateNicosia::handleWheelEvent): 22 * platform/ScrollAnimator.cpp: 23 (WebCore::ScrollAnimator::scroll): 24 (WebCore::ScrollAnimator::adjustScrollOffsetForSnappingIfNeeded): 25 * platform/ScrollAnimator.h: 26 * platform/ScrollController.cpp: 27 (WebCore::ScrollController::setNearestScrollSnapIndexForAxisAndOffset): 28 (WebCore::ScrollController::adjustScrollDestination): 29 (WebCore::ScrollController::updateActiveScrollSnapIndexForClientOffset): 30 (WebCore::ScrollController::resnapAfterLayout): 31 * platform/ScrollController.h: 32 * platform/ScrollSnapAnimatorState.cpp: 33 (WebCore::ScrollSnapAnimatorState::setupAnimationForState): 34 (WebCore::ScrollSnapAnimatorState::targetOffsetForStartOffset const): 35 * platform/ScrollSnapAnimatorState.h: 36 * platform/ScrollableArea.cpp: 37 (WebCore::ScrollableArea::doPostThumbMoveSnapping): 38 1 39 2021-07-21 Alex Christensen <achristensen@webkit.org> 2 40 -
trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp
r279714 r280171 91 91 } 92 92 93 template <typename InfoType, typename SizeType, typename LayoutType> 94 static std::pair<LayoutType, std::optional<unsigned>> closestSnapOffsetWithInfoAndAxis(const InfoType& info, ScrollEventAxis axis, const SizeType& viewportSize, LayoutType scrollDestinationOffset, float velocity, std::optional<LayoutType> originalOffsetForDirectionalSnapping) 95 { 93 template <typename InfoType, typename SizeType, typename LayoutType, typename PointType> 94 static std::pair<LayoutType, std::optional<unsigned>> closestSnapOffsetWithInfoAndAxis(const InfoType& info, ScrollEventAxis axis, const SizeType& viewportSize, PointType scrollDestinationOffsetPoint, float velocity, std::optional<LayoutType> originalOffsetForDirectionalSnapping) 95 { 96 auto scrollDestinationOffset = axis == ScrollEventAxis::Horizontal ? scrollDestinationOffsetPoint.x() : scrollDestinationOffsetPoint.y(); 96 97 const auto& snapOffsets = info.offsetsForAxis(axis); 97 98 auto pairForNoSnapping = std::make_pair(scrollDestinationOffset, std::nullopt); … … 389 390 390 391 template <> template <> 391 std::pair<LayoutUnit, std::optional<unsigned>> LayoutScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis axis, const LayoutSize& viewportSize, Layout Unit scrollDestinationOffset, float velocity, std::optional<LayoutUnit> originalPositionForDirectionalSnapping) const392 std::pair<LayoutUnit, std::optional<unsigned>> LayoutScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis axis, const LayoutSize& viewportSize, LayoutPoint scrollDestinationOffset, float velocity, std::optional<LayoutUnit> originalPositionForDirectionalSnapping) const 392 393 { 393 394 return closestSnapOffsetWithInfoAndAxis(*this, axis, viewportSize, scrollDestinationOffset, velocity, originalPositionForDirectionalSnapping); … … 395 396 396 397 template <> template<> 397 std::pair<float, std::optional<unsigned>> FloatScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis axis, const FloatSize& viewportSize, float scrollDestinationOffset, float velocity, std::optional<float> originalPositionForDirectionalSnapping) const398 std::pair<float, std::optional<unsigned>> FloatScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis axis, const FloatSize& viewportSize, FloatPoint scrollDestinationOffset, float velocity, std::optional<float> originalPositionForDirectionalSnapping) const 398 399 { 399 400 return closestSnapOffsetWithInfoAndAxis(*this, axis, viewportSize, scrollDestinationOffset, velocity, originalPositionForDirectionalSnapping); -
trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.h
r279218 r280171 71 71 72 72 template<typename OutputType> OutputType convertUnits(float deviceScaleFactor = 0.0) const; 73 template<typename SizeType >74 WEBCORE_EXPORT std::pair<UnitType, std::optional<unsigned>> closestSnapOffset(ScrollEventAxis, const SizeType& viewportSize, UnitType scrollDestinationOffset, float velocity, std::optional<UnitType> originalPositionForDirectionalSnapping = std::nullopt) const;73 template<typename SizeType, typename PointType> 74 WEBCORE_EXPORT std::pair<UnitType, std::optional<unsigned>> closestSnapOffset(ScrollEventAxis, const SizeType& viewportSize, PointType scrollDestinationOffset, float velocity, std::optional<UnitType> originalPositionForDirectionalSnapping = std::nullopt) const; 75 75 }; 76 76 … … 81 81 LayoutScrollSnapOffsetsInfo FloatScrollSnapOffsetsInfo::convertUnits(float /* unusedScaleFactor */) const; 82 82 template <> template <> 83 WEBCORE_EXPORT std::pair<float, std::optional<unsigned>> FloatScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis, const FloatSize& viewportSize, float scrollDestinationOffset, float velocity, std::optional<float> originalPositionForDirectionalSnapping) const;83 WEBCORE_EXPORT std::pair<float, std::optional<unsigned>> FloatScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis, const FloatSize& viewportSize, FloatPoint scrollDestinationOffset, float velocity, std::optional<float> originalPositionForDirectionalSnapping) const; 84 84 85 85 … … 87 87 FloatScrollSnapOffsetsInfo LayoutScrollSnapOffsetsInfo::convertUnits(float deviceScaleFactor) const; 88 88 template <> template <> 89 WEBCORE_EXPORT std::pair<LayoutUnit, std::optional<unsigned>> LayoutScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis, const LayoutSize& viewportSize, Layout Unit scrollDestinationOffset, float velocity, std::optional<LayoutUnit> originalPositionForDirectionalSnapping) const;89 WEBCORE_EXPORT std::pair<LayoutUnit, std::optional<unsigned>> LayoutScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis, const LayoutSize& viewportSize, LayoutPoint scrollDestinationOffset, float velocity, std::optional<LayoutUnit> originalPositionForDirectionalSnapping) const; 90 90 91 91 // Update the snap offsets for this scrollable area, given the RenderBox of the scroll container, the RenderStyle -
trunk/Source/WebCore/page/scrolling/nicosia/ScrollingTreeScrollingNodeDelegateNicosia.cpp
r279218 r280171 170 170 float scale = pageScaleFactor(); 171 171 FloatPoint originalOffset = LayoutPoint(scrollingNode().currentScrollOffset().x() / scale, scrollingNode().currentScrollOffset().y() / scale); 172 FloatPoint newFloatOffset = scrollingNode().currentScrollOffset() + FloatSize(deltaX, deltaY);173 auto newOffset = LayoutPoint(newFloatOffset.x() / scale, newFloatOffset.y()/ scale);174 175 auto offsetX = scrollingNode().snapOffsetsInfo().closestSnapOffset(ScrollEventAxis::Horizontal, scrollableAreaSize(), newOffset .x(), deltaX, originalOffset.x()).first;176 auto offsetY = scrollingNode().snapOffsetsInfo().closestSnapOffset(ScrollEventAxis::Vertical, scrollableAreaSize(), newOffset .y(), deltaY, originalOffset.y()).first;172 auto newOffset = (scrollingNode().currentScrollOffset() + FloatSize(deltaX, deltaY)); 173 newOffset.scale(1.0 / scale); 174 175 auto offsetX = scrollingNode().snapOffsetsInfo().closestSnapOffset(ScrollEventAxis::Horizontal, scrollableAreaSize(), newOffset, deltaX, originalOffset.x()).first; 176 auto offsetY = scrollingNode().snapOffsetsInfo().closestSnapOffset(ScrollEventAxis::Vertical, scrollableAreaSize(), newOffset, deltaY, originalOffset.y()).first; 177 177 178 178 deltaX = (offsetX - originalOffset.x()) * scale; -
trunk/Source/WebCore/platform/ScrollAnimator.cpp
r279564 r280171 87 87 auto newOffset = currentOffset + delta; 88 88 if (orientation == HorizontalScrollbar) 89 newOffset.setX(m_scrollController.adjustScrollDestination(ScrollEventAxis::Horizontal, newOffset .x(), multiplier, currentOffset.x()));89 newOffset.setX(m_scrollController.adjustScrollDestination(ScrollEventAxis::Horizontal, newOffset, multiplier, currentOffset.x())); 90 90 else 91 newOffset.setY(m_scrollController.adjustScrollDestination(ScrollEventAxis::Vertical, newOffset .y(), multiplier, currentOffset.y()));91 newOffset.setY(m_scrollController.adjustScrollDestination(ScrollEventAxis::Vertical, newOffset, multiplier, currentOffset.y())); 92 92 auto newDelta = newOffset - currentOffset; 93 93 … … 398 398 399 399 FloatPoint newOffset = offset; 400 newOffset.setX(adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis::Horizontal, newOffset .x(), method));401 newOffset.setY(adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis::Vertical, newOffset .y(), method));400 newOffset.setX(adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis::Horizontal, newOffset, method)); 401 newOffset.setY(adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis::Vertical, newOffset, method)); 402 402 return newOffset; 403 403 } 404 404 405 float ScrollAnimator::adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis axis, floatnewOffset, ScrollSnapPointSelectionMethod method)405 float ScrollAnimator::adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis axis, const FloatPoint& newOffset, ScrollSnapPointSelectionMethod method) 406 406 { 407 407 if (!m_scrollController.usesScrollSnap()) 408 return newOffset;408 return axis == ScrollEventAxis::Horizontal ? newOffset.x() : newOffset.y(); 409 409 410 410 std::optional<float> originalOffset; 411 float velocity = 0.;411 float velocityInScrollAxis = 0.; 412 412 if (method == ScrollSnapPointSelectionMethod::Directional) { 413 413 FloatSize scrollOrigin = toFloatSize(m_scrollableArea.scrollOrigin()); 414 414 auto currentOffset = ScrollableArea::scrollOffsetFromPosition(this->currentPosition(), scrollOrigin); 415 auto velocity = newOffset - currentOffset; 415 416 originalOffset = axis == ScrollEventAxis::Horizontal ? currentOffset.x() : currentOffset.y(); 416 velocity = newOffset - (axis == ScrollEventAxis::Horizontal ? currentOffset.x() : currentOffset.y());417 velocityInScrollAxis = axis == ScrollEventAxis::Horizontal ? velocity.width() : velocity.height(); 417 418 } 418 419 419 return m_scrollController.adjustScrollDestination(axis, newOffset, velocity , originalOffset);420 return m_scrollController.adjustScrollDestination(axis, newOffset, velocityInScrollAxis, originalOffset); 420 421 } 421 422 -
trunk/Source/WebCore/platform/ScrollAnimator.h
r279564 r280171 135 135 136 136 FloatPoint adjustScrollOffsetForSnappingIfNeeded(const FloatPoint& offset, ScrollSnapPointSelectionMethod); 137 float adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis, floatnewOffset, ScrollSnapPointSelectionMethod);137 float adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis, const FloatPoint& newOffset, ScrollSnapPointSelectionMethod); 138 138 139 139 std::unique_ptr<ScrollControllerTimer> createTimer(Function<void()>&&) final; -
trunk/Source/WebCore/platform/ScrollController.cpp
r279218 r280171 128 128 } 129 129 130 void ScrollController::setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis axis, int offset)130 void ScrollController::setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis axis, ScrollOffset scrollOffset) 131 131 { 132 132 if (!usesScrollSnap()) … … 134 134 135 135 float scaleFactor = m_client.pageScaleFactor(); 136 LayoutPoint layoutScrollOffset(scrollOffset.x() / scaleFactor, scrollOffset.y() / scaleFactor); 136 137 ScrollSnapAnimatorState& snapState = *m_scrollSnapState; 137 138 … … 140 141 std::optional<unsigned> activeIndex; 141 142 if (snapOffsets.size()) 142 activeIndex = snapState.snapOffsetInfo().closestSnapOffset(axis, viewportSize, LayoutUnit(offset / scaleFactor), 0).second;143 activeIndex = snapState.snapOffsetInfo().closestSnapOffset(axis, viewportSize, layoutScrollOffset, 0).second; 143 144 144 145 if (activeIndex == activeScrollSnapIndexForAxis(axis)) … … 149 150 } 150 151 151 float ScrollController::adjustScrollDestination(ScrollEventAxis axis, float destinationOffset, float velocity, std::optional<float> originalOffset)152 { 153 if (!usesScrollSnap()) 154 return destinationOffset;152 float ScrollController::adjustScrollDestination(ScrollEventAxis axis, FloatPoint destinationOffset, float velocity, std::optional<float> originalOffset) 153 { 154 if (!usesScrollSnap()) 155 return axis == ScrollEventAxis::Horizontal ? destinationOffset.x() : destinationOffset.y(); 155 156 156 157 ScrollSnapAnimatorState& snapState = *m_scrollSnapState; 157 158 auto snapOffsets = snapState.snapOffsetsForAxis(axis); 158 159 if (!snapOffsets.size()) 159 return destinationOffset; 160 160 return axis == ScrollEventAxis::Horizontal ? destinationOffset.x() : destinationOffset.y(); 161 162 float scaleFactor = m_client.pageScaleFactor(); 161 163 std::optional<LayoutUnit> originalOffsetInLayoutUnits; 162 164 if (originalOffset) 163 originalOffsetInLayoutUnits = LayoutUnit(*originalOffset / m_client.pageScaleFactor());165 originalOffsetInLayoutUnits = LayoutUnit(*originalOffset / scaleFactor); 164 166 LayoutSize viewportSize(m_client.viewportSize().width(), m_client.viewportSize().height()); 165 LayoutUnit offset = snapState.snapOffsetInfo().closestSnapOffset(axis, viewportSize, LayoutUnit(destinationOffset / m_client.pageScaleFactor()), velocity, originalOffsetInLayoutUnits).first; 166 return offset * m_client.pageScaleFactor(); 167 LayoutPoint layoutDestinationOffset(destinationOffset.x() / scaleFactor, destinationOffset.y() / scaleFactor); 168 LayoutUnit offset = snapState.snapOffsetInfo().closestSnapOffset(axis, viewportSize, layoutDestinationOffset, velocity, originalOffsetInLayoutUnits).first; 169 return offset * scaleFactor; 167 170 } 168 171 … … 174 177 175 178 ScrollOffset offset = roundedIntPoint(m_client.scrollOffset()); 176 setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Horizontal, offset .x());177 setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Vertical, offset .y());179 setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Horizontal, offset); 180 setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Vertical, offset); 178 181 } 179 182 … … 189 192 auto activeHorizontalIndex = m_scrollSnapState->activeSnapIndexForAxis(ScrollEventAxis::Horizontal); 190 193 if (!activeHorizontalIndex || *activeHorizontalIndex >= snapState.snapOffsetsForAxis(ScrollEventAxis::Horizontal).size()) 191 setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Horizontal, offset .x());194 setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Horizontal, offset); 192 195 193 196 auto activeVerticalIndex = m_scrollSnapState->activeSnapIndexForAxis(ScrollEventAxis::Vertical); 194 197 if (!activeVerticalIndex || *activeVerticalIndex >= snapState.snapOffsetsForAxis(ScrollEventAxis::Vertical).size()) 195 setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Vertical, offset .y());198 setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Vertical, offset); 196 199 197 200 } -
trunk/Source/WebCore/platform/ScrollController.h
r279218 r280171 136 136 void updateScrollSnapState(const ScrollableArea&); 137 137 void updateGestureInProgressState(const PlatformWheelEvent&); 138 float adjustScrollDestination(ScrollEventAxis, float destinationOffset, float velocity, std::optional<float> originalOffset);138 float adjustScrollDestination(ScrollEventAxis, FloatPoint destinationOffset, float velocity, std::optional<float> originalOffset); 139 139 140 140 #if PLATFORM(MAC) … … 160 160 161 161 private: 162 void setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis, int);162 void setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis, ScrollOffset); 163 163 164 164 void updateScrollSnapAnimatingState(MonotonicTime); -
trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp
r279218 r280171 49 49 50 50 m_momentumCalculator = ScrollingMomentumCalculator::create(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity); 51 auto predictedScrollTarget = m_momentumCalculator->predictedDestinationOffset();51 FloatPoint predictedScrollTarget { m_momentumCalculator->predictedDestinationOffset() }; 52 52 53 53 float targetOffsetX, targetOffsetY; 54 std::tie(targetOffsetX, m_activeSnapIndexX) = targetOffsetForStartOffset(ScrollEventAxis::Horizontal, viewportSize, contentSize.width() - viewportSize.width(), initialOffset.x(), predictedScrollTarget .width(), pageScale, initialDelta.width());55 std::tie(targetOffsetY, m_activeSnapIndexY) = targetOffsetForStartOffset(ScrollEventAxis::Vertical, viewportSize, contentSize.height() - viewportSize.height(), initialOffset.y(), predictedScrollTarget .height(), pageScale, initialDelta.height());54 std::tie(targetOffsetX, m_activeSnapIndexX) = targetOffsetForStartOffset(ScrollEventAxis::Horizontal, viewportSize, contentSize.width() - viewportSize.width(), initialOffset.x(), predictedScrollTarget, pageScale, initialDelta.width()); 55 std::tie(targetOffsetY, m_activeSnapIndexY) = targetOffsetForStartOffset(ScrollEventAxis::Vertical, viewportSize, contentSize.height() - viewportSize.height(), initialOffset.y(), predictedScrollTarget, pageScale, initialDelta.height()); 56 56 m_momentumCalculator->setRetargetedScrollOffset({ targetOffsetX, targetOffsetY }); 57 57 m_startTime = MonotonicTime::now(); … … 92 92 } 93 93 94 std::pair<float, std::optional<unsigned>> ScrollSnapAnimatorState::targetOffsetForStartOffset(ScrollEventAxis axis, const FloatSize& viewportSize, float maxScrollOffset, float startOffset, float predictedOffset, float pageScale, float initialDelta) const94 std::pair<float, std::optional<unsigned>> ScrollSnapAnimatorState::targetOffsetForStartOffset(ScrollEventAxis axis, const FloatSize& viewportSize, float maxScrollOffset, float startOffset, FloatPoint predictedOffset, float pageScale, float initialDelta) const 95 95 { 96 96 const auto& snapOffsets = m_snapOffsetsInfo.offsetsForAxis(axis); 97 97 if (snapOffsets.isEmpty()) 98 return std::make_pair(clampTo<float>( predictedOffset, 0, maxScrollOffset), std::nullopt);98 return std::make_pair(clampTo<float>(axis == ScrollEventAxis::Horizontal ? predictedOffset.x() : predictedOffset.y(), 0, maxScrollOffset), std::nullopt); 99 99 100 auto [targetOffset, snapIndex] = m_snapOffsetsInfo.closestSnapOffset(axis, LayoutSize { viewportSize }, LayoutUnit(predictedOffset / pageScale), initialDelta, LayoutUnit(startOffset / pageScale)); 100 LayoutPoint predictedLayoutOffset(predictedOffset.x() / pageScale, predictedOffset.y() / pageScale); 101 auto [targetOffset, snapIndex] = m_snapOffsetsInfo.closestSnapOffset(axis, LayoutSize { viewportSize }, predictedLayoutOffset, initialDelta, LayoutUnit(startOffset / pageScale)); 101 102 return std::make_pair(pageScale * clampTo<float>(float { targetOffset }, 0, maxScrollOffset), snapIndex); 102 103 } -
trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h
r279218 r280171 83 83 84 84 private: 85 std::pair<float, std::optional<unsigned>> targetOffsetForStartOffset(ScrollEventAxis, const FloatSize& viewportSize, float maxScrollOffset, float startOffset, float predictedOffset, float pageScale, float initialDelta) const;85 std::pair<float, std::optional<unsigned>> targetOffsetForStartOffset(ScrollEventAxis, const FloatSize& viewportSize, float maxScrollOffset, float startOffset, FloatPoint predictedOffset, float pageScale, float initialDelta) const; 86 86 void teardownAnimationForState(ScrollSnapState); 87 87 void setupAnimationForState(ScrollSnapState, const FloatSize& contentSize, const FloatSize& viewportSize, float pageScale, const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta); -
trunk/Source/WebCore/platform/ScrollableArea.cpp
r279564 r280171 564 564 auto newOffset = currentOffset; 565 565 if (orientation == HorizontalScrollbar) 566 newOffset.setX(scrollAnimator->adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis::Horizontal, currentOffset .x(), ScrollSnapPointSelectionMethod::Closest));566 newOffset.setX(scrollAnimator->adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis::Horizontal, currentOffset, ScrollSnapPointSelectionMethod::Closest)); 567 567 else 568 newOffset.setY(scrollAnimator->adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis::Vertical, currentOffset .y(), ScrollSnapPointSelectionMethod::Closest));568 newOffset.setY(scrollAnimator->adjustScrollOffsetForSnappingIfNeeded(ScrollEventAxis::Vertical, currentOffset, ScrollSnapPointSelectionMethod::Closest)); 569 569 if (newOffset == currentOffset) 570 570 return; -
trunk/Source/WebKit/ChangeLog
r280160 r280171 1 2021-07-22 Martin Robinson <mrobinson@webkit.org> 2 3 [css-scroll-snap] Pass the full target point when selecting a snap offset 4 https://bugs.webkit.org/show_bug.cgi?id=228023 5 6 Reviewed by Frédéric Wang. 7 8 * UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.h: 9 * UIProcess/RemoteLayerTree/ios/RemoteScrollingCoordinatorProxyIOS.mm: 10 (WebKit::RemoteScrollingCoordinatorProxy::adjustTargetContentOffsetForSnapping): 11 (WebKit::RemoteScrollingCoordinatorProxy::closestSnapOffsetForMainFrameScrolling const): 12 * UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.mm: 13 (-[WKScrollingNodeScrollViewDelegate scrollViewWillEndDragging:withVelocity:targetContentOffset:]): 14 1 15 2021-07-21 Chris Dumez <cdumez@apple.com> 2 16 -
trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.h
r279218 r280171 119 119 120 120 bool shouldSnapForMainFrameScrolling(WebCore::ScrollEventAxis) const; 121 std::pair<float, std::optional<unsigned>> closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis, float currentScrollOffset, float scrollDestination, float velocity) const;121 std::pair<float, std::optional<unsigned>> closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis, float currentScrollOffset, WebCore::FloatPoint scrollDestination, float velocity) const; 122 122 123 123 void sendUIStateChangedIfNecessary(); -
trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteScrollingCoordinatorProxyIOS.mm
r279218 r280171 198 198 if (shouldSnapForMainFrameScrolling(WebCore::ScrollEventAxis::Horizontal)) { 199 199 float potentialSnapPosition; 200 std::tie(potentialSnapPosition, m_currentHorizontalSnapPointIndex) = closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis::Horizontal, currentContentOffset.x, targetContentOffset->x, velocity.x);200 std::tie(potentialSnapPosition, m_currentHorizontalSnapPointIndex) = closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis::Horizontal, currentContentOffset.x, FloatPoint(*targetContentOffset), velocity.x); 201 201 if (targetContentOffset->x > 0 && targetContentOffset->x < maxScrollOffsets.width) 202 202 targetContentOffset->x = std::min<float>(maxScrollOffsets.width, potentialSnapPosition); … … 205 205 if (shouldSnapForMainFrameScrolling(WebCore::ScrollEventAxis::Vertical)) { 206 206 float potentialSnapPosition; 207 std::tie(potentialSnapPosition, m_currentVerticalSnapPointIndex) = closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis::Vertical, currentContentOffset.y + topInset, targetContentOffset->y, velocity.y);207 std::tie(potentialSnapPosition, m_currentVerticalSnapPointIndex) = closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis::Vertical, currentContentOffset.y + topInset, FloatPoint(*targetContentOffset), velocity.y); 208 208 if (m_currentVerticalSnapPointIndex) 209 209 potentialSnapPosition -= topInset; … … 229 229 } 230 230 231 std::pair<float, std::optional<unsigned>> RemoteScrollingCoordinatorProxy::closestSnapOffsetForMainFrameScrolling(ScrollEventAxis axis, float currentScrollOffset, float scrollDestination, float velocity) const231 std::pair<float, std::optional<unsigned>> RemoteScrollingCoordinatorProxy::closestSnapOffsetForMainFrameScrolling(ScrollEventAxis axis, float currentScrollOffset, FloatPoint scrollDestination, float velocity) const 232 232 { 233 233 ScrollingTreeNode* root = m_scrollingTree->rootNode(); … … 236 236 const auto& snapOffsetsInfo = rootScrollingNode->snapOffsetsInfo(); 237 237 238 float scaledScrollDestination = scrollDestination / m_webPageProxy.displayedContentScale();238 scrollDestination.scale(1.0 / m_webPageProxy.displayedContentScale()); 239 239 float scaledCurrentScrollOffset = currentScrollOffset / m_webPageProxy.displayedContentScale(); 240 auto [rawClosestSnapOffset, newIndex] = snapOffsetsInfo.closestSnapOffset(axis, rootScrollingNode->layoutViewport().size(), sc aledScrollDestination, velocity, scaledCurrentScrollOffset);240 auto [rawClosestSnapOffset, newIndex] = snapOffsetsInfo.closestSnapOffset(axis, rootScrollingNode->layoutViewport().size(), scrollDestination, velocity, scaledCurrentScrollOffset); 241 241 return std::make_pair(rawClosestSnapOffset * m_webPageProxy.displayedContentScale(), newIndex); 242 242 } -
trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.mm
r279218 r280171 97 97 } 98 98 99 CGFloat horizontalTarget = targetContentOffset->x;100 CGFloat verticalTarget = targetContentOffset->y;101 102 99 std::optional<unsigned> originalHorizontalSnapPosition = _scrollingTreeNodeDelegate->scrollingNode().currentHorizontalSnapPointIndex(); 103 100 std::optional<unsigned> originalVerticalSnapPosition = _scrollingTreeNodeDelegate->scrollingNode().currentVerticalSnapPointIndex(); … … 106 103 const auto& snapOffsetsInfo = _scrollingTreeNodeDelegate->scrollingNode().snapOffsetsInfo(); 107 104 if (!snapOffsetsInfo.horizontalSnapOffsets.isEmpty()) { 108 auto [potentialSnapPosition, index] = snapOffsetsInfo.closestSnapOffset(WebCore::ScrollEventAxis::Horizontal, viewportSize, horizontalTarget, velocity.x, scrollView.contentOffset.x);105 auto [potentialSnapPosition, index] = snapOffsetsInfo.closestSnapOffset(WebCore::ScrollEventAxis::Horizontal, viewportSize, WebCore::FloatPoint(*targetContentOffset), velocity.x, scrollView.contentOffset.x); 109 106 _scrollingTreeNodeDelegate->scrollingNode().setCurrentHorizontalSnapPointIndex(index); 110 if ( horizontalTarget >= 0 && horizontalTarget<= scrollView.contentSize.width)107 if (targetContentOffset->x >= 0 && targetContentOffset->x <= scrollView.contentSize.width) 111 108 targetContentOffset->x = potentialSnapPosition; 112 109 } 113 110 114 111 if (!snapOffsetsInfo.verticalSnapOffsets.isEmpty()) { 115 auto [potentialSnapPosition, index] = snapOffsetsInfo.closestSnapOffset(WebCore::ScrollEventAxis::Vertical, viewportSize, verticalTarget, velocity.y, scrollView.contentOffset.y);112 auto [potentialSnapPosition, index] = snapOffsetsInfo.closestSnapOffset(WebCore::ScrollEventAxis::Vertical, viewportSize, WebCore::FloatPoint(*targetContentOffset), velocity.y, scrollView.contentOffset.y); 116 113 _scrollingTreeNodeDelegate->scrollingNode().setCurrentVerticalSnapPointIndex(index); 117 if ( verticalTarget >= 0 && verticalTarget<= scrollView.contentSize.height)114 if (targetContentOffset->y >= 0 && targetContentOffset->y <= scrollView.contentSize.height) 118 115 targetContentOffset->y = potentialSnapPosition; 119 116 }
Note: See TracChangeset
for help on using the changeset viewer.