Diff
Modified: trunk/Source/WebCore/ChangeLog (278922 => 278923)
--- trunk/Source/WebCore/ChangeLog 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/ChangeLog 2021-06-16 07:37:49 UTC (rev 278923)
@@ -1,3 +1,75 @@
+2021-06-16 Martin Robinson <mrobin...@webkit.org>
+
+ Replace invalidSnapOffsetIndex with std::optional<unsigned>
+ https://bugs.webkit.org/show_bug.cgi?id=226654
+
+ Reviewed by Simon Fraser.
+
+ Use std::optional<unsigned> in order to represent the situation
+ where we do not have a snap point selected rather than UINT_MAX.
+
+ No new tests. This should not change behavior.
+
+ * page/scrolling/AsyncScrollingCoordinator.cpp:
+ (WebCore::AsyncScrollingCoordinator::setActiveScrollSnapIndices):
+ * page/scrolling/AsyncScrollingCoordinator.h:
+ * page/scrolling/ScrollSnapOffsetsInfo.cpp:
+ (WebCore::indicesOfNearestSnapOffsets): Return a std::pair instead of splitting the
+ return values into the argument list.
+ (WebCore::closestSnapOffsetWithInfoAndAxis):
+ (WebCore::LayoutScrollSnapOffsetsInfo::closestSnapOffset const):
+ (WebCore::FloatScrollSnapOffsetsInfo::closestSnapOffset const):
+ * page/scrolling/ScrollSnapOffsetsInfo.h:
+ * page/scrolling/ScrollingStateScrollingNode.cpp:
+ (WebCore::ScrollingStateScrollingNode::setCurrentHorizontalSnapPointIndex):
+ (WebCore::ScrollingStateScrollingNode::setCurrentVerticalSnapPointIndex):
+ (WebCore::ScrollingStateScrollingNode::dumpProperties const):
+ * page/scrolling/ScrollingStateScrollingNode.h:
+ (WebCore::ScrollingStateScrollingNode::currentHorizontalSnapPointIndex const):
+ (WebCore::ScrollingStateScrollingNode::currentVerticalSnapPointIndex const):
+ * page/scrolling/ScrollingTree.h:
+ (WebCore::ScrollingTree::setActiveScrollSnapIndices):
+ * page/scrolling/ScrollingTreeScrollingNode.cpp:
+ (WebCore::ScrollingTreeScrollingNode::dumpProperties const):
+ * page/scrolling/ScrollingTreeScrollingNode.h: Move some methods into the
+ source file to satisfy the style checker. WEBCORE_EXPORT is applied to the
+ entire class declaration.
+ * page/scrolling/ThreadedScrollingTree.cpp:
+ (WebCore::ThreadedScrollingTree::currentSnapPointIndicesDidChange):
+ (WebCore::ThreadedScrollingTree::setActiveScrollSnapIndices):
+ * page/scrolling/ThreadedScrollingTree.h:
+ * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h:
+ * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
+ (WebCore::ScrollingTreeScrollingNodeDelegateMac::activeScrollSnapIndexForAxis const):
+ * platform/ScrollAnimator.cpp:
+ (WebCore::ScrollAnimator::activeScrollSnapIndexForAxis const):
+ (WebCore::ScrollAnimator::setActiveScrollSnapIndexForAxis):
+ * platform/ScrollAnimator.h:
+ * platform/ScrollController.cpp:
+ (WebCore::ScrollController::activeScrollSnapIndexForAxis const):
+ (WebCore::ScrollController::setActiveScrollSnapIndexForAxis): When there is no new
+ snap index, we need to actively change the value to std::nullopt. This wasn't
+ necessary because ScrollableArea was covering up this case in the past as a side-effect.
+ (WebCore::ScrollController::setNearestScrollSnapIndexForAxisAndOffset):
+ (WebCore::ScrollController::resnapAfterLayout): Also resnap if the snapped index is
+ greater than the current one. This case was being covered up by a side-effect in
+ ScrollableArea.
+ * platform/ScrollController.h:
+ * platform/ScrollSnapAnimatorState.cpp:
+ (WebCore::ScrollSnapAnimatorState::setupAnimationForState):
+ (WebCore::ScrollSnapAnimatorState::targetOffsetForStartOffset const): Return a std::pair
+ instead of splitting the output values into the argument list.
+ * platform/ScrollSnapAnimatorState.h:
+ (WebCore::ScrollSnapAnimatorState::activeSnapIndexForAxis const):
+ (WebCore::ScrollSnapAnimatorState::setActiveSnapIndexForAxis):
+ * platform/ScrollableArea.cpp:
+ (WebCore::ScrollableArea::currentHorizontalSnapPointIndex const):
+ (WebCore::ScrollableArea::currentVerticalSnapPointIndex const):
+ (WebCore::ScrollableArea::setCurrentHorizontalSnapPointIndex):
+ (WebCore::ScrollableArea::setCurrentVerticalSnapPointIndex):
+ (WebCore::ScrollableArea::resnapAfterLayout):
+ * platform/ScrollableArea.h:
+
2021-06-15 Peng Liu <peng.l...@apple.com>
some http/tests/ are crashing with ASSERTION FAILED: isInRoutingArbitrationForToken(token) || m_setupArbitrationOngoing
Modified: trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -871,7 +871,7 @@
}
#if PLATFORM(COCOA)
-void AsyncScrollingCoordinator::setActiveScrollSnapIndices(ScrollingNodeID scrollingNodeID, unsigned horizontalIndex, unsigned verticalIndex)
+void AsyncScrollingCoordinator::setActiveScrollSnapIndices(ScrollingNodeID scrollingNodeID, std::optional<unsigned> horizontalIndex, std::optional<unsigned> verticalIndex)
{
ASSERT(isMainThread());
Modified: trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/AsyncScrollingCoordinator.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -59,7 +59,7 @@
#if PLATFORM(COCOA)
WEBCORE_EXPORT void handleWheelEventPhase(ScrollingNodeID, PlatformWheelEventPhase) final;
- WEBCORE_EXPORT void setActiveScrollSnapIndices(ScrollingNodeID, unsigned horizontalIndex, unsigned verticalIndex);
+ WEBCORE_EXPORT void setActiveScrollSnapIndices(ScrollingNodeID, std::optional<unsigned> horizontalIndex, std::optional<unsigned> verticalIndex);
#endif
#if ENABLE(CSS_SCROLL_SNAP)
Modified: trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -43,10 +43,10 @@
namespace WebCore {
template <typename LayoutType>
-static void indicesOfNearestSnapOffsets(LayoutType offset, const Vector<SnapOffset<LayoutType>>& snapOffsets, unsigned& lowerIndex, unsigned& upperIndex)
+static std::pair<std::optional<unsigned>, std::optional<unsigned>> indicesOfNearestSnapOffsets(LayoutType offset, const Vector<SnapOffset<LayoutType>>& snapOffsets)
{
- lowerIndex = 0;
- upperIndex = snapOffsets.size() - 1;
+ unsigned lowerIndex = 0;
+ unsigned upperIndex = snapOffsets.size() - 1;
while (lowerIndex < upperIndex - 1) {
int middleIndex = (lowerIndex + upperIndex) / 2;
auto middleOffset = snapOffsets[middleIndex].offset;
@@ -61,6 +61,8 @@
else
upperIndex = middleIndex;
}
+
+ return std::make_pair(lowerIndex, upperIndex);
}
template <typename LayoutType>
@@ -95,16 +97,16 @@
}
template <typename InfoType, typename SizeType, typename LayoutType>
-static std::pair<LayoutType, unsigned> closestSnapOffsetWithInfoAndAxis(const InfoType& info, ScrollEventAxis axis, const SizeType& viewportSize, LayoutType scrollDestinationOffset, float velocity, std::optional<LayoutType> originalOffsetForDirectionalSnapping)
+static std::pair<LayoutType, std::optional<unsigned>> closestSnapOffsetWithInfoAndAxis(const InfoType& info, ScrollEventAxis axis, const SizeType& viewportSize, LayoutType scrollDestinationOffset, float velocity, std::optional<LayoutType> originalOffsetForDirectionalSnapping)
{
const auto& snapOffsets = info.offsetsForAxis(axis);
- auto pairForNoSnapping = std::make_pair(scrollDestinationOffset, invalidSnapOffsetIndex);
+ auto pairForNoSnapping = std::make_pair(scrollDestinationOffset, std::nullopt);
if (snapOffsets.isEmpty())
return pairForNoSnapping;
if (originalOffsetForDirectionalSnapping) {
if (auto firstSnapStopOffsetIndex = findFirstSnapStopOffsetBetweenOriginAndDestination(snapOffsets, *originalOffsetForDirectionalSnapping, scrollDestinationOffset))
- return std::make_pair(snapOffsets[*firstSnapStopOffsetIndex].offset, *firstSnapStopOffsetIndex);
+ return std::make_pair(snapOffsets[*firstSnapStopOffsetIndex].offset, firstSnapStopOffsetIndex);
}
auto viewportLength = axis == ScrollEventAxis::Horizontal ? viewportSize.width() : viewportSize.height();
@@ -119,32 +121,32 @@
};
if (scrollDestinationOffset <= snapOffsets.first().offset)
- return isNearEnoughToOffsetForProximity(snapOffsets.first().offset) ? std::make_pair(snapOffsets.first().offset, 0u) : pairForNoSnapping;
+ return isNearEnoughToOffsetForProximity(snapOffsets.first().offset) ? std::make_pair(snapOffsets.first().offset, std::make_optional(0u)) : pairForNoSnapping;
if (scrollDestinationOffset >= snapOffsets.last().offset) {
unsigned lastIndex = static_cast<unsigned>(snapOffsets.size() - 1);
- return isNearEnoughToOffsetForProximity(snapOffsets.last().offset) ? std::make_pair(snapOffsets.last().offset, lastIndex) : pairForNoSnapping;
+ return isNearEnoughToOffsetForProximity(snapOffsets.last().offset) ? std::make_pair(snapOffsets.last().offset, std::make_optional(lastIndex)) : pairForNoSnapping;
}
- unsigned lowerIndex;
- unsigned upperIndex;
- indicesOfNearestSnapOffsets<LayoutType>(scrollDestinationOffset, snapOffsets, lowerIndex, upperIndex);
- LayoutType lowerSnapPosition = snapOffsets[lowerIndex].offset;
- LayoutType upperSnapPosition = snapOffsets[upperIndex].offset;
+ auto [lowerIndex, upperIndex] = indicesOfNearestSnapOffsets<LayoutType>(scrollDestinationOffset, snapOffsets);
+ ASSERT(lowerIndex);
+ ASSERT(upperIndex);
+ LayoutType lowerSnapPosition = snapOffsets[*lowerIndex].offset;
+ LayoutType upperSnapPosition = snapOffsets[*upperIndex].offset;
if (!isNearEnoughToOffsetForProximity(lowerSnapPosition)) {
lowerSnapPosition = scrollDestinationOffset;
- lowerIndex = invalidSnapOffsetIndex;
+ lowerIndex.reset();
}
if (!isNearEnoughToOffsetForProximity(upperSnapPosition)) {
upperSnapPosition = scrollDestinationOffset;
- upperIndex = invalidSnapOffsetIndex;
+ upperIndex.reset();
+
}
if (!std::abs(velocity)) {
- bool isCloserToLowerSnapPosition = (upperIndex == invalidSnapOffsetIndex)
- || (lowerIndex != invalidSnapOffsetIndex && scrollDestinationOffset - lowerSnapPosition <= upperSnapPosition - scrollDestinationOffset);
+ bool isCloserToLowerSnapPosition = !upperIndex || (lowerIndex && scrollDestinationOffset - lowerSnapPosition <= upperSnapPosition - scrollDestinationOffset);
return isCloserToLowerSnapPosition ? std::make_pair(lowerSnapPosition, lowerIndex) : std::make_pair(upperSnapPosition, upperIndex);
}
@@ -153,12 +155,12 @@
// snapping, we should never snap to a point that was on the other side of the original position in the opposite direction of this scroll.
// This allows directional scrolling to escape snap points.
if (velocity < 0) {
- if (upperIndex != invalidSnapOffsetIndex && (!originalOffsetForDirectionalSnapping || *originalOffsetForDirectionalSnapping > upperSnapPosition))
+ if (upperIndex && (!originalOffsetForDirectionalSnapping || *originalOffsetForDirectionalSnapping > upperSnapPosition))
return std::make_pair(upperSnapPosition, upperIndex);
return std::make_pair(lowerSnapPosition, lowerIndex);
}
- if (lowerIndex != invalidSnapOffsetIndex && (!originalOffsetForDirectionalSnapping || *originalOffsetForDirectionalSnapping < lowerSnapPosition))
+ if (lowerIndex && (!originalOffsetForDirectionalSnapping || *originalOffsetForDirectionalSnapping < lowerSnapPosition))
return std::make_pair(lowerSnapPosition, lowerIndex);
return std::make_pair(upperSnapPosition, upperIndex);
}
@@ -375,13 +377,13 @@
}
template <> template <>
-std::pair<LayoutUnit, unsigned> LayoutScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis axis, const LayoutSize& viewportSize, LayoutUnit scrollDestinationOffset, float velocity, std::optional<LayoutUnit> originalPositionForDirectionalSnapping) const
+std::pair<LayoutUnit, std::optional<unsigned>> LayoutScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis axis, const LayoutSize& viewportSize, LayoutUnit scrollDestinationOffset, float velocity, std::optional<LayoutUnit> originalPositionForDirectionalSnapping) const
{
return closestSnapOffsetWithInfoAndAxis(*this, axis, viewportSize, scrollDestinationOffset, velocity, originalPositionForDirectionalSnapping);
}
template <> template<>
-std::pair<float, unsigned> FloatScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis axis, const FloatSize& viewportSize, float scrollDestinationOffset, float velocity, std::optional<float> originalPositionForDirectionalSnapping) const
+std::pair<float, std::optional<unsigned>> FloatScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis axis, const FloatSize& viewportSize, float scrollDestinationOffset, float velocity, std::optional<float> originalPositionForDirectionalSnapping) const
{
return closestSnapOffsetWithInfoAndAxis(*this, axis, viewportSize, scrollDestinationOffset, velocity, originalPositionForDirectionalSnapping);
}
Modified: trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.h (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ScrollSnapOffsetsInfo.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -73,7 +73,7 @@
template<typename OutputType> OutputType convertUnits(float deviceScaleFactor = 0.0) const;
template<typename SizeType>
- WEBCORE_EXPORT std::pair<UnitType, unsigned> closestSnapOffset(ScrollEventAxis, const SizeType& viewportSize, UnitType scrollDestinationOffset, float velocity, std::optional<UnitType> originalPositionForDirectionalSnapping = std::nullopt) const;
+ WEBCORE_EXPORT std::pair<UnitType, std::optional<unsigned>> closestSnapOffset(ScrollEventAxis, const SizeType& viewportSize, UnitType scrollDestinationOffset, float velocity, std::optional<UnitType> originalPositionForDirectionalSnapping = std::nullopt) const;
};
using LayoutScrollSnapOffsetsInfo = ScrollSnapOffsetsInfo<LayoutUnit, LayoutRect>;
@@ -82,17 +82,14 @@
template <> template <>
LayoutScrollSnapOffsetsInfo FloatScrollSnapOffsetsInfo::convertUnits(float /* unusedScaleFactor */) const;
template <> template <>
-WEBCORE_EXPORT std::pair<float, unsigned> FloatScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis, const FloatSize& viewportSize, float scrollDestinationOffset, float velocity, std::optional<float> originalPositionForDirectionalSnapping) const;
+WEBCORE_EXPORT std::pair<float, std::optional<unsigned>> FloatScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis, const FloatSize& viewportSize, float scrollDestinationOffset, float velocity, std::optional<float> originalPositionForDirectionalSnapping) const;
template <> template <>
FloatScrollSnapOffsetsInfo LayoutScrollSnapOffsetsInfo::convertUnits(float deviceScaleFactor) const;
template <> template <>
-WEBCORE_EXPORT std::pair<LayoutUnit, unsigned> LayoutScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis, const LayoutSize& viewportSize, LayoutUnit scrollDestinationOffset, float velocity, std::optional<LayoutUnit> originalPositionForDirectionalSnapping) const;
+WEBCORE_EXPORT std::pair<LayoutUnit, std::optional<unsigned>> LayoutScrollSnapOffsetsInfo::closestSnapOffset(ScrollEventAxis, const LayoutSize& viewportSize, LayoutUnit scrollDestinationOffset, float velocity, std::optional<LayoutUnit> originalPositionForDirectionalSnapping) const;
-
-const unsigned invalidSnapOffsetIndex = UINT_MAX;
-
// Update the snap offsets for this scrollable area, given the RenderBox of the scroll container, the RenderStyle
// which defines the scroll-snap properties, and the viewport rectangle with the origin at the top left of
// the scrolling container's border box.
Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -166,7 +166,7 @@
setPropertyChanged(Property::SnapOffsetsInfo);
}
-void ScrollingStateScrollingNode::setCurrentHorizontalSnapPointIndex(unsigned index)
+void ScrollingStateScrollingNode::setCurrentHorizontalSnapPointIndex(std::optional<unsigned> index)
{
if (m_currentHorizontalSnapPointIndex == index)
return;
@@ -175,7 +175,7 @@
setPropertyChanged(Property::CurrentHorizontalSnapOffsetIndex);
}
-void ScrollingStateScrollingNode::setCurrentVerticalSnapPointIndex(unsigned index)
+void ScrollingStateScrollingNode::setCurrentVerticalSnapPointIndex(std::optional<unsigned> index)
{
if (m_currentVerticalSnapPointIndex == index)
return;
@@ -313,10 +313,10 @@
if (m_snapOffsetsInfo.verticalSnapOffsets.size())
ts.dumpProperty("vertical snap offsets", m_snapOffsetsInfo.verticalSnapOffsets);
- if (m_currentHorizontalSnapPointIndex != invalidSnapOffsetIndex)
+ if (m_currentHorizontalSnapPointIndex)
ts.dumpProperty("current horizontal snap point index", m_currentHorizontalSnapPointIndex);
- if (m_currentVerticalSnapPointIndex != invalidSnapOffsetIndex)
+ if (m_currentVerticalSnapPointIndex)
ts.dumpProperty("current vertical snap point index", m_currentVerticalSnapPointIndex);
#endif
Modified: trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ScrollingStateScrollingNode.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -74,11 +74,11 @@
const FloatScrollSnapOffsetsInfo& snapOffsetsInfo() const { return m_snapOffsetsInfo; }
WEBCORE_EXPORT void setSnapOffsetsInfo(const FloatScrollSnapOffsetsInfo& newOffsetsInfo);
- unsigned currentHorizontalSnapPointIndex() const { return m_currentHorizontalSnapPointIndex; }
- WEBCORE_EXPORT void setCurrentHorizontalSnapPointIndex(unsigned);
+ std::optional<unsigned> currentHorizontalSnapPointIndex() const { return m_currentHorizontalSnapPointIndex; }
+ WEBCORE_EXPORT void setCurrentHorizontalSnapPointIndex(std::optional<unsigned>);
- unsigned currentVerticalSnapPointIndex() const { return m_currentVerticalSnapPointIndex; }
- WEBCORE_EXPORT void setCurrentVerticalSnapPointIndex(unsigned);
+ std::optional<unsigned> currentVerticalSnapPointIndex() const { return m_currentVerticalSnapPointIndex; }
+ WEBCORE_EXPORT void setCurrentVerticalSnapPointIndex(std::optional<unsigned>);
#endif
const ScrollableAreaParameters& scrollableAreaParameters() const { return m_scrollableAreaParameters; }
@@ -131,8 +131,8 @@
#if ENABLE(CSS_SCROLL_SNAP)
FloatScrollSnapOffsetsInfo m_snapOffsetsInfo;
- unsigned m_currentHorizontalSnapPointIndex { invalidSnapOffsetIndex };
- unsigned m_currentVerticalSnapPointIndex { invalidSnapOffsetIndex };
+ std::optional<unsigned> m_currentHorizontalSnapPointIndex;
+ std::optional<unsigned> m_currentVerticalSnapPointIndex;
#endif
LayerRepresentation m_scrollContainerLayer;
Modified: trunk/Source/WebCore/page/scrolling/ScrollingTree.h (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ScrollingTree.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTree.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -155,7 +155,7 @@
#if PLATFORM(MAC)
virtual void handleWheelEventPhase(ScrollingNodeID, PlatformWheelEventPhase) = 0;
- virtual void setActiveScrollSnapIndices(ScrollingNodeID, unsigned /*horizontalIndex*/, unsigned /*verticalIndex*/) { }
+ virtual void setActiveScrollSnapIndices(ScrollingNodeID, std::optional<unsigned> /*horizontalIndex*/, std::optional<unsigned> /*verticalIndex*/) { }
virtual void setWheelEventTestMonitor(RefPtr<WheelEventTestMonitor>&&) { }
@@ -166,7 +166,7 @@
#endif
#if PLATFORM(COCOA)
- WEBCORE_EXPORT virtual void currentSnapPointIndicesDidChange(ScrollingNodeID, unsigned horizontal, unsigned vertical) = 0;
+ WEBCORE_EXPORT virtual void currentSnapPointIndicesDidChange(ScrollingNodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical) = 0;
#endif
void setMainFramePinnedState(RectEdges<bool>);
Modified: trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -318,10 +318,10 @@
if (m_snapOffsetsInfo.verticalSnapOffsets.size())
ts.dumpProperty("vertical snap offsets", m_snapOffsetsInfo.verticalSnapOffsets);
- if (m_currentHorizontalSnapPointIndex != invalidSnapOffsetIndex)
+ if (m_currentHorizontalSnapPointIndex)
ts.dumpProperty("current horizontal snap point index", m_currentHorizontalSnapPointIndex);
- if (m_currentVerticalSnapPointIndex != invalidSnapOffsetIndex)
+ if (m_currentVerticalSnapPointIndex)
ts.dumpProperty("current vertical snap point index", m_currentVerticalSnapPointIndex);
#endif
@@ -339,6 +339,26 @@
{
return m_snapOffsetsInfo;
}
+
+std::optional<unsigned> ScrollingTreeScrollingNode::currentHorizontalSnapPointIndex() const
+{
+ return m_currentHorizontalSnapPointIndex;
+}
+
+std::optional<unsigned> ScrollingTreeScrollingNode::currentVerticalSnapPointIndex() const
+{
+ return m_currentVerticalSnapPointIndex;
+}
+
+void ScrollingTreeScrollingNode::setCurrentHorizontalSnapPointIndex(std::optional<unsigned> index)
+{
+ m_currentHorizontalSnapPointIndex = index;
+}
+
+void ScrollingTreeScrollingNode::setCurrentVerticalSnapPointIndex(std::optional<unsigned> index)
+{
+ m_currentVerticalSnapPointIndex = index;
+}
#endif
} // namespace WebCore
Modified: trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ScrollingTreeScrollingNode.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -96,10 +96,10 @@
#if ENABLE(CSS_SCROLL_SNAP)
const FloatScrollSnapOffsetsInfo& snapOffsetsInfo() const;
- unsigned currentHorizontalSnapPointIndex() const { return m_currentHorizontalSnapPointIndex; }
- unsigned currentVerticalSnapPointIndex() const { return m_currentVerticalSnapPointIndex; }
- void setCurrentHorizontalSnapPointIndex(unsigned index) { m_currentHorizontalSnapPointIndex = index; }
- void setCurrentVerticalSnapPointIndex(unsigned index) { m_currentVerticalSnapPointIndex = index; }
+ std::optional<unsigned> currentHorizontalSnapPointIndex() const;
+ std::optional<unsigned> currentVerticalSnapPointIndex() const;
+ void setCurrentHorizontalSnapPointIndex(std::optional<unsigned>);
+ void setCurrentVerticalSnapPointIndex(std::optional<unsigned>);
#endif
bool useDarkAppearanceForScrollbars() const { return m_scrollableAreaParameters.useDarkAppearanceForScrollbars; }
@@ -160,8 +160,8 @@
IntPoint m_scrollOrigin;
#if ENABLE(CSS_SCROLL_SNAP)
FloatScrollSnapOffsetsInfo m_snapOffsetsInfo;
- unsigned m_currentHorizontalSnapPointIndex { invalidSnapOffsetIndex };
- unsigned m_currentVerticalSnapPointIndex { invalidSnapOffsetIndex };
+ std::optional<unsigned> m_currentHorizontalSnapPointIndex;
+ std::optional<unsigned> m_currentVerticalSnapPointIndex;
#endif
ScrollableAreaParameters m_scrollableAreaParameters;
#if ENABLE(SCROLLING_THREAD)
Modified: trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -241,7 +241,7 @@
}
#if PLATFORM(COCOA)
-void ThreadedScrollingTree::currentSnapPointIndicesDidChange(ScrollingNodeID nodeID, unsigned horizontal, unsigned vertical)
+void ThreadedScrollingTree::currentSnapPointIndicesDidChange(ScrollingNodeID nodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical)
{
if (!m_scrollingCoordinator)
return;
@@ -263,7 +263,7 @@
});
}
-void ThreadedScrollingTree::setActiveScrollSnapIndices(ScrollingNodeID nodeID, unsigned horizontalIndex, unsigned verticalIndex)
+void ThreadedScrollingTree::setActiveScrollSnapIndices(ScrollingNodeID nodeID, std::optional<unsigned> horizontalIndex, std::optional<unsigned> verticalIndex)
{
if (!m_scrollingCoordinator)
return;
Modified: trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.h (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/ThreadedScrollingTree.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -70,11 +70,11 @@
void scrollingTreeNodeDidScroll(ScrollingTreeScrollingNode&, ScrollingLayerPositionAction = ScrollingLayerPositionAction::Sync) override;
#if PLATFORM(MAC)
void handleWheelEventPhase(ScrollingNodeID, PlatformWheelEventPhase) override;
- void setActiveScrollSnapIndices(ScrollingNodeID, unsigned horizontalIndex, unsigned verticalIndex) override;
+ void setActiveScrollSnapIndices(ScrollingNodeID, std::optional<unsigned> horizontalIndex, std::optional<unsigned> verticalIndex) override;
#endif
#if PLATFORM(COCOA)
- void currentSnapPointIndicesDidChange(ScrollingNodeID, unsigned horizontal, unsigned vertical) override;
+ void currentSnapPointIndicesDidChange(ScrollingNodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical) override;
#endif
void reportExposedUnfilledArea(MonotonicTime, unsigned unfilledArea) override;
Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -57,7 +57,7 @@
#if ENABLE(CSS_SCROLL_SNAP)
bool activeScrollSnapIndexDidChange() const;
- unsigned activeScrollSnapIndexForAxis(ScrollEventAxis) const;
+ std::optional<unsigned> activeScrollSnapIndexForAxis(ScrollEventAxis) const;
bool isScrollSnapInProgress() const;
#endif
Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm (278922 => 278923)
--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm 2021-06-16 07:37:49 UTC (rev 278923)
@@ -75,7 +75,7 @@
#endif
}
-unsigned ScrollingTreeScrollingNodeDelegateMac::activeScrollSnapIndexForAxis(ScrollEventAxis axis) const
+std::optional<unsigned> ScrollingTreeScrollingNodeDelegateMac::activeScrollSnapIndexForAxis(ScrollEventAxis axis) const
{
return m_scrollController.activeScrollSnapIndexForAxis(axis);
}
Modified: trunk/Source/WebCore/platform/ScrollAnimator.cpp (278922 => 278923)
--- trunk/Source/WebCore/platform/ScrollAnimator.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/platform/ScrollAnimator.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -184,12 +184,12 @@
return m_scrollController.activeScrollSnapIndexDidChange();
}
-unsigned ScrollAnimator::activeScrollSnapIndexForAxis(ScrollEventAxis axis) const
+std::optional<unsigned> ScrollAnimator::activeScrollSnapIndexForAxis(ScrollEventAxis axis) const
{
return m_scrollController.activeScrollSnapIndexForAxis(axis);
}
-void ScrollAnimator::setActiveScrollSnapIndexForAxis(ScrollEventAxis axis, unsigned index)
+void ScrollAnimator::setActiveScrollSnapIndexForAxis(ScrollEventAxis axis, std::optional<unsigned> index)
{
return m_scrollController.setActiveScrollSnapIndexForAxis(axis, index);
}
Modified: trunk/Source/WebCore/platform/ScrollAnimator.h (278922 => 278923)
--- trunk/Source/WebCore/platform/ScrollAnimator.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/platform/ScrollAnimator.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -157,8 +157,8 @@
virtual bool processWheelEventForScrollSnap(const PlatformWheelEvent&) { return false; }
void updateScrollSnapState();
bool activeScrollSnapIndexDidChange() const;
- unsigned activeScrollSnapIndexForAxis(ScrollEventAxis) const;
- void setActiveScrollSnapIndexForAxis(ScrollEventAxis, unsigned index);
+ std::optional<unsigned> activeScrollSnapIndexForAxis(ScrollEventAxis) const;
+ void setActiveScrollSnapIndexForAxis(ScrollEventAxis, std::optional<unsigned> index);
void setSnapOffsetsInfo(const LayoutScrollSnapOffsetsInfo&);
const LayoutScrollSnapOffsetsInfo* snapOffsetsInfo() const;
void resnapAfterLayout();
Modified: trunk/Source/WebCore/platform/ScrollController.cpp (278922 => 278923)
--- trunk/Source/WebCore/platform/ScrollController.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/platform/ScrollController.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -123,15 +123,14 @@
return m_scrollSnapState ? &m_scrollSnapState->snapOffsetInfo() : nullptr;
}
-unsigned ScrollController::activeScrollSnapIndexForAxis(ScrollEventAxis axis) const
+std::optional<unsigned> ScrollController::activeScrollSnapIndexForAxis(ScrollEventAxis axis) const
{
if (!usesScrollSnap())
- return invalidSnapOffsetIndex;
-
+ return std::nullopt;
return m_scrollSnapState->activeSnapIndexForAxis(axis);
}
-void ScrollController::setActiveScrollSnapIndexForAxis(ScrollEventAxis axis, unsigned index)
+void ScrollController::setActiveScrollSnapIndexForAxis(ScrollEventAxis axis, std::optional<unsigned> index)
{
if (!usesScrollSnap())
return;
@@ -148,11 +147,11 @@
ScrollSnapAnimatorState& snapState = *m_scrollSnapState;
auto snapOffsets = snapState.snapOffsetsForAxis(axis);
- if (!snapOffsets.size())
- return;
+ LayoutSize viewportSize(m_client.viewportSize().width(), m_client.viewportSize().height());
+ std::optional<unsigned> activeIndex;
+ if (snapOffsets.size())
+ activeIndex = snapState.snapOffsetInfo().closestSnapOffset(axis, viewportSize, LayoutUnit(offset / scaleFactor), 0).second;
- LayoutSize viewportSize(m_client.viewportSize().width(), m_client.viewportSize().height());
- unsigned activeIndex = snapState.snapOffsetInfo().closestSnapOffset(axis, viewportSize, LayoutUnit(offset / scaleFactor), 0).second;
if (activeIndex == activeScrollSnapIndexForAxis(axis))
return;
@@ -196,11 +195,14 @@
// If we are already snapped in a particular axis, maintain that. Otherwise, snap to the nearest eligible snap point.
ScrollOffset offset = roundedIntPoint(m_client.scrollOffset());
- size_t activeHorizontalIndex = m_scrollSnapState->activeSnapIndexForAxis(ScrollEventAxis::Horizontal);
- if (activeHorizontalIndex == invalidSnapOffsetIndex)
+ ScrollSnapAnimatorState& snapState = *m_scrollSnapState;
+
+ auto activeHorizontalIndex = m_scrollSnapState->activeSnapIndexForAxis(ScrollEventAxis::Horizontal);
+ if (!activeHorizontalIndex || *activeHorizontalIndex >= snapState.snapOffsetsForAxis(ScrollEventAxis::Horizontal).size())
setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Horizontal, offset.x());
- size_t activeVerticalIndex = m_scrollSnapState->activeSnapIndexForAxis(ScrollEventAxis::Vertical);
- if (activeVerticalIndex == invalidSnapOffsetIndex)
+
+ auto activeVerticalIndex = m_scrollSnapState->activeSnapIndexForAxis(ScrollEventAxis::Vertical);
+ if (!activeVerticalIndex || *activeVerticalIndex >= snapState.snapOffsetsForAxis(ScrollEventAxis::Vertical).size())
setNearestScrollSnapIndexForAxisAndOffset(ScrollEventAxis::Vertical, offset.y());
}
Modified: trunk/Source/WebCore/platform/ScrollController.h (278922 => 278923)
--- trunk/Source/WebCore/platform/ScrollController.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/platform/ScrollController.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -134,12 +134,12 @@
#if ENABLE(CSS_SCROLL_SNAP)
void setSnapOffsetsInfo(const LayoutScrollSnapOffsetsInfo&);
const LayoutScrollSnapOffsetsInfo* snapOffsetsInfo() const;
- void setActiveScrollSnapIndexForAxis(ScrollEventAxis, unsigned);
+ void setActiveScrollSnapIndexForAxis(ScrollEventAxis, std::optional<unsigned>);
void updateActiveScrollSnapIndexForClientOffset();
void resnapAfterLayout();
bool activeScrollSnapIndexDidChange() const { return m_activeScrollSnapIndexDidChange; }
void setScrollSnapIndexDidChange(bool state) { m_activeScrollSnapIndexDidChange = state; }
- unsigned activeScrollSnapIndexForAxis(ScrollEventAxis) const;
+ std::optional<unsigned> activeScrollSnapIndexForAxis(ScrollEventAxis) const;
void updateScrollSnapState(const ScrollableArea&);
void updateGestureInProgressState(const PlatformWheelEvent&);
float adjustScrollDestination(ScrollEventAxis, float destinationOffset, float velocity, std::optional<float> originalOffset);
Modified: trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp (278922 => 278923)
--- trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/platform/ScrollSnapAnimatorState.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -51,8 +51,10 @@
m_momentumCalculator = ScrollingMomentumCalculator::create(viewportSize, contentSize, initialOffset, initialDelta, initialVelocity);
auto predictedScrollTarget = m_momentumCalculator->predictedDestinationOffset();
- float targetOffsetX = targetOffsetForStartOffset(ScrollEventAxis::Horizontal, viewportSize, contentSize.width() - viewportSize.width(), initialOffset.x(), predictedScrollTarget.width(), pageScale, initialDelta.width(), m_activeSnapIndexX);
- float targetOffsetY = targetOffsetForStartOffset(ScrollEventAxis::Vertical, viewportSize, contentSize.height() - viewportSize.height(), initialOffset.y(), predictedScrollTarget.height(), pageScale, initialDelta.height(), m_activeSnapIndexY);
+
+ float targetOffsetX, targetOffsetY;
+ std::tie(targetOffsetX, m_activeSnapIndexX) = targetOffsetForStartOffset(ScrollEventAxis::Horizontal, viewportSize, contentSize.width() - viewportSize.width(), initialOffset.x(), predictedScrollTarget.width(), pageScale, initialDelta.width());
+ std::tie(targetOffsetY, m_activeSnapIndexY) = targetOffsetForStartOffset(ScrollEventAxis::Vertical, viewportSize, contentSize.height() - viewportSize.height(), initialOffset.y(), predictedScrollTarget.height(), pageScale, initialDelta.height());
m_momentumCalculator->setRetargetedScrollOffset({ targetOffsetX, targetOffsetY });
m_startTime = MonotonicTime::now();
m_currentState = state;
@@ -91,16 +93,14 @@
return m_momentumCalculator->scrollOffsetAfterElapsedTime(elapsedTime);
}
-float ScrollSnapAnimatorState::targetOffsetForStartOffset(ScrollEventAxis axis, const FloatSize& viewportSize, float maxScrollOffset, float startOffset, float predictedOffset, float pageScale, float initialDelta, unsigned& outActiveSnapIndex) const
+std::pair<float, std::optional<unsigned>> ScrollSnapAnimatorState::targetOffsetForStartOffset(ScrollEventAxis axis, const FloatSize& viewportSize, float maxScrollOffset, float startOffset, float predictedOffset, float pageScale, float initialDelta) const
{
const auto& snapOffsets = m_snapOffsetsInfo.offsetsForAxis(axis);
- if (snapOffsets.isEmpty()) {
- outActiveSnapIndex = invalidSnapOffsetIndex;
- return clampTo<float>(predictedOffset, 0, maxScrollOffset);
- }
+ if (snapOffsets.isEmpty())
+ return std::make_pair(clampTo<float>(predictedOffset, 0, maxScrollOffset), std::nullopt);
- float targetOffset = m_snapOffsetsInfo.closestSnapOffset(axis, LayoutSize { viewportSize }, LayoutUnit(predictedOffset / pageScale), initialDelta, LayoutUnit(startOffset / pageScale)).first;
- return pageScale * clampTo<float>(targetOffset, 0, maxScrollOffset);
+ auto [targetOffset, snapIndex] = m_snapOffsetsInfo.closestSnapOffset(axis, LayoutSize { viewportSize }, LayoutUnit(predictedOffset / pageScale), initialDelta, LayoutUnit(startOffset / pageScale));
+ return std::make_pair(pageScale * clampTo<float>(float { targetOffset }, 0, maxScrollOffset), snapIndex);
}
TextStream& operator<<(TextStream& ts, const ScrollSnapAnimatorState& state)
Modified: trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h (278922 => 278923)
--- trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/platform/ScrollSnapAnimatorState.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -62,12 +62,12 @@
ScrollSnapState currentState() const { return m_currentState; }
- unsigned activeSnapIndexForAxis(ScrollEventAxis axis) const
+ std::optional<unsigned> activeSnapIndexForAxis(ScrollEventAxis axis) const
{
return axis == ScrollEventAxis::Horizontal ? m_activeSnapIndexX : m_activeSnapIndexY;
}
- void setActiveSnapIndexForAxis(ScrollEventAxis axis, unsigned index)
+ void setActiveSnapIndexForAxis(ScrollEventAxis axis, std::optional<unsigned> index)
{
if (axis == ScrollEventAxis::Horizontal)
m_activeSnapIndexX = index;
@@ -84,7 +84,7 @@
void transitionToDestinationReachedState();
private:
- float targetOffsetForStartOffset(ScrollEventAxis, const FloatSize& viewportSize, float maxScrollOffset, float startOffset, float predictedOffset, float pageScale, float initialDelta, unsigned& outActiveSnapIndex) const;
+ std::pair<float, std::optional<unsigned>> targetOffsetForStartOffset(ScrollEventAxis, const FloatSize& viewportSize, float maxScrollOffset, float startOffset, float predictedOffset, float pageScale, float initialDelta) const;
void teardownAnimationForState(ScrollSnapState);
void setupAnimationForState(ScrollSnapState, const FloatSize& contentSize, const FloatSize& viewportSize, float pageScale, const FloatPoint& initialOffset, const FloatSize& initialVelocity, const FloatSize& initialDelta);
@@ -92,8 +92,8 @@
LayoutScrollSnapOffsetsInfo m_snapOffsetsInfo;
- unsigned m_activeSnapIndexX { invalidSnapOffsetIndex };
- unsigned m_activeSnapIndexY { invalidSnapOffsetIndex };
+ std::optional<unsigned> m_activeSnapIndexX;
+ std::optional<unsigned> m_activeSnapIndexY;
MonotonicTime m_startTime;
std::unique_ptr<ScrollingMomentumCalculator> m_momentumCalculator;
Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (278922 => 278923)
--- trunk/Source/WebCore/platform/ScrollableArea.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -490,26 +490,26 @@
return scrollAnimator->setSnapOffsetsInfo(LayoutScrollSnapOffsetsInfo());
}
-unsigned ScrollableArea::currentHorizontalSnapPointIndex() const
+std::optional<unsigned> ScrollableArea::currentHorizontalSnapPointIndex() const
{
if (auto* scrollAnimator = existingScrollAnimator())
return scrollAnimator->activeScrollSnapIndexForAxis(ScrollEventAxis::Horizontal);
- return invalidSnapOffsetIndex;
+ return std::nullopt;
}
-unsigned ScrollableArea::currentVerticalSnapPointIndex() const
+std::optional<unsigned> ScrollableArea::currentVerticalSnapPointIndex() const
{
if (auto* scrollAnimator = existingScrollAnimator())
return scrollAnimator->activeScrollSnapIndexForAxis(ScrollEventAxis::Vertical);
- return invalidSnapOffsetIndex;
+ return std::nullopt;
}
-void ScrollableArea::setCurrentHorizontalSnapPointIndex(unsigned index)
+void ScrollableArea::setCurrentHorizontalSnapPointIndex(std::optional<unsigned> index)
{
scrollAnimator().setActiveScrollSnapIndexForAxis(ScrollEventAxis::Horizontal, index);
}
-void ScrollableArea::setCurrentVerticalSnapPointIndex(unsigned index)
+void ScrollableArea::setCurrentVerticalSnapPointIndex(std::optional<unsigned> index)
{
scrollAnimator().setActiveScrollSnapIndexForAxis(ScrollEventAxis::Vertical, index);
}
@@ -532,13 +532,13 @@
auto correctedOffset = currentOffset;
const auto& horizontal = info->horizontalSnapOffsets;
auto activeHorizontalIndex = currentHorizontalSnapPointIndex();
- if (activeHorizontalIndex < horizontal.size())
- correctedOffset.setX(horizontal[activeHorizontalIndex].offset.toInt());
+ if (activeHorizontalIndex)
+ correctedOffset.setX(horizontal[*activeHorizontalIndex].offset.toInt());
const auto& vertical = info->verticalSnapOffsets;
auto activeVerticalIndex = currentVerticalSnapPointIndex();
- if (activeVerticalIndex < vertical.size())
- correctedOffset.setY(vertical[activeVerticalIndex].offset.toInt());
+ if (activeVerticalIndex)
+ correctedOffset.setY(vertical[*activeVerticalIndex].offset.toInt());
if (correctedOffset != currentOffset) {
LOG_WITH_STREAM(ScrollSnap, stream << " adjusting offset from " << currentOffset << " to " << correctedOffset);
Modified: trunk/Source/WebCore/platform/ScrollableArea.h (278922 => 278923)
--- trunk/Source/WebCore/platform/ScrollableArea.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebCore/platform/ScrollableArea.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -93,10 +93,10 @@
WEBCORE_EXPORT const LayoutScrollSnapOffsetsInfo* snapOffsetsInfo() const;
void setScrollSnapOffsetInfo(const LayoutScrollSnapOffsetsInfo&);
void clearSnapOffsets();
- WEBCORE_EXPORT unsigned currentHorizontalSnapPointIndex() const;
- WEBCORE_EXPORT unsigned currentVerticalSnapPointIndex() const;
- WEBCORE_EXPORT void setCurrentHorizontalSnapPointIndex(unsigned);
- WEBCORE_EXPORT void setCurrentVerticalSnapPointIndex(unsigned);
+ WEBCORE_EXPORT std::optional<unsigned> currentHorizontalSnapPointIndex() const;
+ WEBCORE_EXPORT std::optional<unsigned> currentVerticalSnapPointIndex() const;
+ WEBCORE_EXPORT void setCurrentHorizontalSnapPointIndex(std::optional<unsigned>);
+ WEBCORE_EXPORT void setCurrentVerticalSnapPointIndex(std::optional<unsigned>);
#endif
void resnapAfterLayout();
Modified: trunk/Source/WebKit/ChangeLog (278922 => 278923)
--- trunk/Source/WebKit/ChangeLog 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/ChangeLog 2021-06-16 07:37:49 UTC (rev 278923)
@@ -1,3 +1,31 @@
+2021-06-16 Martin Robinson <mrobin...@webkit.org>
+
+ Replace invalidSnapOffsetIndex with std::optional<unsigned>
+ https://bugs.webkit.org/show_bug.cgi?id=226654
+
+ Reviewed by Simon Fraser.
+
+ Use std::optional<unsigned> in order to represent the situation
+ where we do not have a snap point selected rather than UINT_MAX.
+
+ * Shared/RemoteLayerTree/RemoteScrollingCoordinatorTransaction.cpp:
+ (ArgumentCoder<ScrollingStateScrollingNode>::decode):
+ * UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.cpp:
+ (WebKit::RemoteScrollingCoordinatorProxy::currentSnapPointIndicesDidChange):
+ * UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.h:
+ * UIProcess/RemoteLayerTree/RemoteScrollingTree.cpp:
+ (WebKit::RemoteScrollingTree::currentSnapPointIndicesDidChange):
+ * UIProcess/RemoteLayerTree/RemoteScrollingTree.h:
+ * UIProcess/RemoteLayerTree/ios/RemoteScrollingCoordinatorProxyIOS.mm:
+ (WebKit::RemoteScrollingCoordinatorProxy::adjustTargetContentOffsetForSnapping):
+ (WebKit::RemoteScrollingCoordinatorProxy::shouldSnapForMainFrameScrolling const):
+ * UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.h:
+ * UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.mm:
+ (-[WKScrollingNodeScrollViewDelegate scrollViewWillEndDragging:withVelocity:targetContentOffset:]):
+ (WebKit::ScrollingTreeScrollingNodeDelegateIOS::currentSnapPointIndicesDidChange const):
+ * WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.mm:
+ (WebKit::RemoteScrollingCoordinator::currentSnapPointIndicesChangedForNode):
+
2021-06-15 Alex Christensen <achristen...@webkit.org>
Remove unused code on API::HTTPCookieStore
Modified: trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteScrollingCoordinatorTransaction.cpp (278922 => 278923)
--- trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteScrollingCoordinatorTransaction.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/Shared/RemoteLayerTree/RemoteScrollingCoordinatorTransaction.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -311,8 +311,8 @@
SCROLLING_NODE_DECODE(ScrollingStateNode::Property::ScrollOrigin, IntPoint, setScrollOrigin);
#if ENABLE(CSS_SCROLL_SNAP)
SCROLLING_NODE_DECODE(ScrollingStateNode::Property::SnapOffsetsInfo, FloatScrollSnapOffsetsInfo, setSnapOffsetsInfo);
- SCROLLING_NODE_DECODE(ScrollingStateNode::Property::CurrentHorizontalSnapOffsetIndex, unsigned, setCurrentHorizontalSnapPointIndex);
- SCROLLING_NODE_DECODE(ScrollingStateNode::Property::CurrentVerticalSnapOffsetIndex, unsigned, setCurrentVerticalSnapPointIndex);
+ SCROLLING_NODE_DECODE(ScrollingStateNode::Property::CurrentHorizontalSnapOffsetIndex, std::optional<unsigned>, setCurrentHorizontalSnapPointIndex);
+ SCROLLING_NODE_DECODE(ScrollingStateNode::Property::CurrentVerticalSnapOffsetIndex, std::optional<unsigned>, setCurrentVerticalSnapPointIndex);
#endif
SCROLLING_NODE_DECODE(ScrollingStateNode::Property::ScrollableAreaParams, ScrollableAreaParameters, setScrollableAreaParameters);
SCROLLING_NODE_DECODE(ScrollingStateNode::Property::RequestedScrollPosition, RequestedScrollData, setRequestedScrollData);
Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.cpp (278922 => 278923)
--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -210,7 +210,7 @@
m_scrollingTree->applyLayerPositionsAfterCommit();
}
-void RemoteScrollingCoordinatorProxy::currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID nodeID, unsigned horizontal, unsigned vertical)
+void RemoteScrollingCoordinatorProxy::currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID nodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical)
{
m_webPageProxy.send(Messages::RemoteScrollingCoordinator::CurrentSnapPointIndicesChangedForNode(nodeID, horizontal, vertical));
}
Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.h (278922 => 278923)
--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingCoordinatorProxy.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -68,7 +68,7 @@
void applyScrollingTreeLayerPositionsAfterCommit();
- void currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID, unsigned horizontal, unsigned vertical);
+ void currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical);
// FIXME: expose the tree and pass this to that?
bool handleWheelEvent(const WebCore::PlatformWheelEvent&);
@@ -121,7 +121,7 @@
#if ENABLE(CSS_SCROLL_SNAP)
bool shouldSnapForMainFrameScrolling(WebCore::ScrollEventAxis) const;
- float closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis, float scrollDestination, float velocity, unsigned& closestIndex) const;
+ std::pair<float, std::optional<unsigned>> closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis, float scrollDestination, float velocity) const;
#endif
void sendUIStateChangedIfNecessary();
@@ -132,8 +132,8 @@
RequestedScrollInfo* m_requestedScrollInfo { nullptr };
RemoteScrollingUIState m_uiState;
#if ENABLE(CSS_SCROLL_SNAP)
- unsigned m_currentHorizontalSnapPointIndex { WebCore::invalidSnapOffsetIndex };
- unsigned m_currentVerticalSnapPointIndex { WebCore::invalidSnapOffsetIndex };
+ std::optional<unsigned> m_currentHorizontalSnapPointIndex;
+ std::optional<unsigned> m_currentVerticalSnapPointIndex;
#endif
bool m_propagatesMainFrameScrolls { true };
HashSet<WebCore::GraphicsLayer::PlatformLayerID> m_layersWithScrollingRelations;
Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingTree.cpp (278922 => 278923)
--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingTree.cpp 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingTree.cpp 2021-06-16 07:37:49 UTC (rev 278923)
@@ -130,7 +130,7 @@
return ScrollingTreeFixedNode::create(*this, nodeID);
}
-void RemoteScrollingTree::currentSnapPointIndicesDidChange(ScrollingNodeID nodeID, unsigned horizontal, unsigned vertical)
+void RemoteScrollingTree::currentSnapPointIndicesDidChange(ScrollingNodeID nodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical)
{
m_scrollingCoordinatorProxy.currentSnapPointIndicesDidChange(nodeID, horizontal, vertical);
}
Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingTree.h (278922 => 278923)
--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingTree.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/RemoteScrollingTree.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -53,7 +53,7 @@
void scrollingTreeNodeDidScroll(WebCore::ScrollingTreeScrollingNode&, WebCore::ScrollingLayerPositionAction = WebCore::ScrollingLayerPositionAction::Sync) override;
void scrollingTreeNodeRequestsScroll(WebCore::ScrollingNodeID, const WebCore::FloatPoint& scrollPosition, WebCore::ScrollType, WebCore::ScrollClamping) override;
- void currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID, unsigned horizontal, unsigned vertical) override;
+ void currentSnapPointIndicesDidChange(WebCore::ScrollingNodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical) override;
private:
explicit RemoteScrollingTree(RemoteScrollingCoordinatorProxy&);
Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteScrollingCoordinatorProxyIOS.mm (278922 => 278923)
--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteScrollingCoordinatorProxyIOS.mm 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteScrollingCoordinatorProxyIOS.mm 2021-06-16 07:37:49 UTC (rev 278923)
@@ -200,14 +200,16 @@
{
// The bounds checking with maxScrollOffsets is to ensure that we won't interfere with rubber-banding when scrolling to the edge of the page.
if (shouldSnapForMainFrameScrolling(WebCore::ScrollEventAxis::Horizontal)) {
- float potentialSnapPosition = closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis::Horizontal, targetContentOffset->x, velocity.x, m_currentHorizontalSnapPointIndex);
+ float potentialSnapPosition;
+ std::tie(potentialSnapPosition, m_currentHorizontalSnapPointIndex) = closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis::Horizontal, targetContentOffset->x, velocity.x);
if (targetContentOffset->x > 0 && targetContentOffset->x < maxScrollOffsets.width)
targetContentOffset->x = std::min<float>(maxScrollOffsets.width, potentialSnapPosition);
}
if (shouldSnapForMainFrameScrolling(WebCore::ScrollEventAxis::Vertical)) {
- float potentialSnapPosition = closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis::Vertical, targetContentOffset->y, velocity.y, m_currentVerticalSnapPointIndex);
- if (m_currentVerticalSnapPointIndex != invalidSnapOffsetIndex)
+ float potentialSnapPosition;
+ std::tie(potentialSnapPosition, m_currentVerticalSnapPointIndex) = closestSnapOffsetForMainFrameScrolling(WebCore::ScrollEventAxis::Vertical, targetContentOffset->y, velocity.y);
+ if (m_currentVerticalSnapPointIndex)
potentialSnapPosition -= topInset;
if (targetContentOffset->y > 0 && targetContentOffset->y < maxScrollOffsets.height)
@@ -225,14 +227,12 @@
ScrollingTreeNode* root = m_scrollingTree->rootNode();
if (root && root->isFrameScrollingNode()) {
ScrollingTreeFrameScrollingNode* rootScrollingNode = static_cast<ScrollingTreeFrameScrollingNode*>(root);
- const auto& snapOffsets = rootScrollingNode->snapOffsetsInfo().offsetsForAxis(axis);
- unsigned currentIndex = axis == ScrollEventAxis::Horizontal ? m_currentHorizontalSnapPointIndex : m_currentVerticalSnapPointIndex;
- return snapOffsets.size() && (currentIndex < snapOffsets.size() || currentIndex == invalidSnapOffsetIndex);
+ return rootScrollingNode->snapOffsetsInfo().offsetsForAxis(axis).size();
}
return false;
}
-float RemoteScrollingCoordinatorProxy::closestSnapOffsetForMainFrameScrolling(ScrollEventAxis axis, float scrollDestination, float velocity, unsigned& currentIndex) const
+std::pair<float, std::optional<unsigned>> RemoteScrollingCoordinatorProxy::closestSnapOffsetForMainFrameScrolling(ScrollEventAxis axis, float scrollDestination, float velocity) const
{
ScrollingTreeNode* root = m_scrollingTree->rootNode();
ASSERT(root && root->isFrameScrollingNode());
@@ -240,9 +240,8 @@
const auto& snapOffsetsInfo = rootScrollingNode->snapOffsetsInfo();
float scaledScrollDestination = scrollDestination / m_webPageProxy.displayedContentScale();
- float rawClosestSnapOffset;
- std::tie(rawClosestSnapOffset, currentIndex) = snapOffsetsInfo.closestSnapOffset(axis, rootScrollingNode->layoutViewport().size(), scaledScrollDestination, velocity);
- return rawClosestSnapOffset * m_webPageProxy.displayedContentScale();
+ auto [rawClosestSnapOffset, newIndex] = snapOffsetsInfo.closestSnapOffset(axis, rootScrollingNode->layoutViewport().size(), scaledScrollDestination, velocity);
+ return std::make_pair(rawClosestSnapOffset * m_webPageProxy.displayedContentScale(), newIndex);
}
bool RemoteScrollingCoordinatorProxy::hasActiveSnapPoint() const
@@ -280,11 +279,11 @@
const auto& vertical = rootScrollingNode.snapOffsetsInfo().verticalSnapOffsets;
// The bounds checking with maxScrollOffsets is to ensure that we won't interfere with rubber-banding when scrolling to the edge of the page.
- if (!horizontal.isEmpty() && m_currentHorizontalSnapPointIndex < horizontal.size())
- activePoint.x = horizontal[m_currentHorizontalSnapPointIndex].offset * m_webPageProxy.displayedContentScale();
+ if (!horizontal.isEmpty() && m_currentHorizontalSnapPointIndex && *m_currentHorizontalSnapPointIndex < horizontal.size())
+ activePoint.x = horizontal[*m_currentHorizontalSnapPointIndex].offset * m_webPageProxy.displayedContentScale();
- if (!vertical.isEmpty() && m_currentVerticalSnapPointIndex < vertical.size()) {
- float potentialSnapPosition = vertical[m_currentVerticalSnapPointIndex].offset * m_webPageProxy.displayedContentScale();
+ if (!vertical.isEmpty() && m_currentVerticalSnapPointIndex && *m_currentVerticalSnapPointIndex < vertical.size()) {
+ float potentialSnapPosition = vertical[*m_currentVerticalSnapPointIndex].offset * m_webPageProxy.displayedContentScale();
potentialSnapPosition -= topInset;
activePoint.y = potentialSnapPosition;
}
Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.h (278922 => 278923)
--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -57,7 +57,7 @@
void scrollViewWillStartPanGesture() const;
void scrollViewDidScroll(const WebCore::FloatPoint& scrollOffset, bool inUserInteraction);
- void currentSnapPointIndicesDidChange(unsigned horizontal, unsigned vertical) const;
+ void currentSnapPointIndicesDidChange(std::optional<unsigned> horizontal, std::optional<unsigned> vertical) const;
CALayer *scrollLayer() const { return m_scrollLayer.get(); }
void resetScrollViewDelegate();
Modified: trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.mm (278922 => 278923)
--- trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.mm 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/UIProcess/RemoteLayerTree/ios/ScrollingTreeScrollingNodeDelegateIOS.mm 2021-06-16 07:37:49 UTC (rev 278923)
@@ -103,8 +103,8 @@
CGFloat horizontalTarget = targetContentOffset->x;
CGFloat verticalTarget = targetContentOffset->y;
- unsigned originalHorizontalSnapPosition = _scrollingTreeNodeDelegate->scrollingNode().currentHorizontalSnapPointIndex();
- unsigned originalVerticalSnapPosition = _scrollingTreeNodeDelegate->scrollingNode().currentVerticalSnapPointIndex();
+ std::optional<unsigned> originalHorizontalSnapPosition = _scrollingTreeNodeDelegate->scrollingNode().currentHorizontalSnapPointIndex();
+ std::optional<unsigned> originalVerticalSnapPosition = _scrollingTreeNodeDelegate->scrollingNode().currentVerticalSnapPointIndex();
WebCore::FloatSize viewportSize(static_cast<float>(CGRectGetWidth([scrollView bounds])), static_cast<float>(CGRectGetHeight([scrollView bounds])));
const auto& snapOffsetsInfo = _scrollingTreeNodeDelegate->scrollingNode().snapOffsetsInfo();
@@ -344,7 +344,7 @@
scrollingNode().wasScrolledByDelegatedScrolling(scrollPosition, { }, inUserInteraction ? ScrollingLayerPositionAction::Sync : ScrollingLayerPositionAction::Set);
}
-void ScrollingTreeScrollingNodeDelegateIOS::currentSnapPointIndicesDidChange(unsigned horizontal, unsigned vertical) const
+void ScrollingTreeScrollingNodeDelegateIOS::currentSnapPointIndicesDidChange(std::optional<unsigned> horizontal, std::optional<unsigned> vertical) const
{
if (m_updatingFromStateNode)
return;
Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.h (278922 => 278923)
--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.h 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.h 2021-06-16 07:37:49 UTC (rev 278923)
@@ -81,7 +81,7 @@
// Respond to UI process changes.
void scrollPositionChangedForNode(WebCore::ScrollingNodeID, const WebCore::FloatPoint& scrollPosition, bool syncLayerPosition);
- void currentSnapPointIndicesChangedForNode(WebCore::ScrollingNodeID, unsigned horizontal, unsigned vertical);
+ void currentSnapPointIndicesChangedForNode(WebCore::ScrollingNodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical);
WebPage* m_webPage;
Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.messages.in (278922 => 278923)
--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.messages.in 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.messages.in 2021-06-16 07:37:49 UTC (rev 278923)
@@ -24,7 +24,7 @@
messages -> RemoteScrollingCoordinator {
ScrollPositionChangedForNode(uint64_t nodeID, WebCore::FloatPoint scrollPosition, bool syncLayerPosition);
- CurrentSnapPointIndicesChangedForNode(uint64_t nodeID, unsigned horizontal, unsigned vertical);
+ CurrentSnapPointIndicesChangedForNode(uint64_t nodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical);
ScrollingStateInUIProcessChanged(WebKit::RemoteScrollingUIState uiState);
}
Modified: trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.mm (278922 => 278923)
--- trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.mm 2021-06-16 05:40:26 UTC (rev 278922)
+++ trunk/Source/WebKit/WebProcess/WebPage/RemoteLayerTree/RemoteScrollingCoordinator.mm 2021-06-16 07:37:49 UTC (rev 278923)
@@ -110,7 +110,7 @@
applyScrollUpdate(nodeID, scrollPosition, std::nullopt, ScrollType::User, syncLayerPosition ? ScrollingLayerPositionAction::Sync : ScrollingLayerPositionAction::Set);
}
-void RemoteScrollingCoordinator::currentSnapPointIndicesChangedForNode(ScrollingNodeID nodeID, unsigned horizontal, unsigned vertical)
+void RemoteScrollingCoordinator::currentSnapPointIndicesChangedForNode(ScrollingNodeID nodeID, std::optional<unsigned> horizontal, std::optional<unsigned> vertical)
{
setActiveScrollSnapIndices(nodeID, horizontal, vertical);
}