Diff
Modified: trunk/Source/WebCore/ChangeLog (271080 => 271081)
--- trunk/Source/WebCore/ChangeLog 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/ChangeLog 2020-12-24 01:01:45 UTC (rev 271081)
@@ -1,3 +1,55 @@
+2020-12-23 Simon Fraser <[email protected]>
+
+ Clean up some code related to scroll pinning
+ https://bugs.webkit.org/show_bug.cgi?id=220128
+
+ Reviewed by Sam Weinig.
+
+ ScrollAnimatorMac and ScrollingTreeScrollingNodeDelegateMac share a lot of similar code
+ related to being "pinned" to an edge for scrolling (i.e. already scrolled to an edge).
+
+ There are too many functions implementing similar functionality in slightly different
+ ways. Reduce this count by one by rewriting isAlreadyPinnedInDirectionOfGesture()
+ and calling it from isPinnedForScrollDelta().
+
+ Rename bool pinnedInDirection() to isPinnedForScrollDelta().
+
+ Make use of wheelEvent.isGestureStart().
+
+ * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h:
+ * page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm:
+ (WebCore::ScrollingTreeScrollingNodeDelegateMac::isPinnedForScrollDeltaOnAxis const):
+ (WebCore::ScrollingTreeScrollingNodeDelegateMac::allowsHorizontalStretching const):
+ (WebCore::ScrollingTreeScrollingNodeDelegateMac::allowsVerticalStretching const):
+ (WebCore::ScrollingTreeScrollingNodeDelegateMac::isPinnedForScrollDelta const):
+ (WebCore::ScrollingTreeScrollingNodeDelegateMac::isAlreadyPinnedInDirectionOfGesture const): Deleted.
+ (WebCore::ScrollingTreeScrollingNodeDelegateMac::pinnedInDirection const): Deleted.
+ * platform/ScrollableArea.cpp:
+ (WebCore::ScrollableArea::isPinnedForScrollDeltaOnAxis const):
+ (WebCore::ScrollableArea::isPinnedForScrollDelta const):
+ (WebCore::ScrollableArea::isPinnedInBothDirections const): Deleted.
+ (WebCore::ScrollableArea::isPinnedHorizontallyInDirection const): Deleted.
+ (WebCore::ScrollableArea::isPinnedVerticallyInDirection const): Deleted.
+ * platform/ScrollableArea.h:
+ (WebCore::ScrollableArea::isHorizontalScrollerPinnedToMinimumPosition const): Deleted.
+ (WebCore::ScrollableArea::isHorizontalScrollerPinnedToMaximumPosition const): Deleted.
+ (WebCore::ScrollableArea::isVerticalScrollerPinnedToMinimumPosition const): Deleted.
+ (WebCore::ScrollableArea::isVerticalScrollerPinnedToMaximumPosition const): Deleted.
+ * platform/cocoa/ScrollController.h:
+ * platform/cocoa/ScrollController.mm:
+ (WebCore::ScrollController::handleWheelEvent):
+ * platform/ios/ScrollAnimatorIOS.mm:
+ (WebCore::ScrollAnimatorIOS::determineScrollableAreaForTouchSequence):
+ * platform/mac/ScrollAnimatorMac.h:
+ * platform/mac/ScrollAnimatorMac.mm:
+ (WebCore::ScrollAnimatorMac::isPinnedForScrollDelta const):
+ (WebCore::ScrollAnimatorMac::allowsVerticalStretching const):
+ (WebCore::ScrollAnimatorMac::allowsHorizontalStretching const):
+ (WebCore::ScrollAnimatorMac::pinnedInDirection const): Deleted.
+ (WebCore::newGestureIsStarting): Deleted.
+ (WebCore::ScrollAnimatorMac::isAlreadyPinnedInDirectionOfGesture const): Deleted.
+ * platform/mock/ScrollAnimatorMock.h:
+
2020-12-23 Said Abou-Hallawa <[email protected]>
[GPU Process]: Don't call flushDrawingContext() in the middle of recording drawing commands
Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h (271080 => 271081)
--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.h 2020-12-24 01:01:45 UTC (rev 271081)
@@ -71,7 +71,7 @@
void removeWheelEventTestCompletionDeferralForReason(WheelEventTestMonitor::ScrollableAreaIdentifier, WheelEventTestMonitor::DeferReason) const override;
private:
- bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis) const;
+ bool isPinnedForScrollDeltaOnAxis(float scrollDelta, ScrollEventAxis, float scrollLimit = 0) const;
// ScrollControllerClient.
std::unique_ptr<ScrollControllerTimer> createTimer(Function<void()>&&) final;
@@ -78,7 +78,7 @@
bool allowsHorizontalStretching(const PlatformWheelEvent&) const final;
bool allowsVerticalStretching(const PlatformWheelEvent&) const final;
IntSize stretchAmount() const final;
- bool pinnedInDirection(const FloatSize&) const final;
+ bool isPinnedForScrollDelta(const FloatSize&) const final;
RectEdges<bool> edgePinnedState() const final;
bool allowsHorizontalScrolling() const final;
bool allowsVerticalScrolling() const final;
Modified: trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm (271080 => 271081)
--- trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/page/scrolling/mac/ScrollingTreeScrollingNodeDelegateMac.mm 2020-12-24 01:01:45 UTC (rev 271081)
@@ -215,19 +215,34 @@
return m_scrollController.isScrollSnapInProgress();
}
-// FIXME: We should find a way to share some of the code from newGestureIsStarting(), isAlreadyPinnedInDirectionOfGesture(),
-// allowsVerticalStretching(), and allowsHorizontalStretching() with the implementation in ScrollAnimatorMac.
-bool ScrollingTreeScrollingNodeDelegateMac::isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent& wheelEvent, ScrollEventAxis axis) const
+bool ScrollingTreeScrollingNodeDelegateMac::isPinnedForScrollDeltaOnAxis(float scrollDelta, ScrollEventAxis axis, float scrollLimit) const
{
auto scrollPosition = currentScrollPosition();
switch (axis) {
case ScrollEventAxis::Vertical:
- return (wheelEvent.deltaY() > 0 && scrollPosition.y() <= minimumScrollPosition().y()) || (wheelEvent.deltaY() < 0 && scrollPosition.y() >= maximumScrollPosition().y());
+ if (scrollDelta < 0) {
+ auto topOffset = scrollPosition.y() - minimumScrollPosition().y();
+ return topOffset <= scrollLimit;
+ }
+
+ if (scrollDelta > 0) {
+ auto bottomOffset = maximumScrollPosition().y() - scrollPosition.y();
+ return bottomOffset <= scrollLimit;
+ }
+ break;
case ScrollEventAxis::Horizontal:
- return (wheelEvent.deltaX() > 0 && scrollPosition.x() <= minimumScrollPosition().x()) || (wheelEvent.deltaX() < 0 && scrollPosition.x() >= maximumScrollPosition().x());
+ if (scrollDelta < 0) {
+ auto leftOffset = scrollPosition.x() - minimumScrollPosition().x();
+ return leftOffset <= scrollLimit;
+ }
+
+ if (scrollDelta > 0) {
+ auto rightOffset = maximumScrollPosition().x() - scrollPosition.x();
+ return rightOffset <= scrollLimit;
+ }
+ break;
}
- ASSERT_NOT_REACHED();
return false;
}
@@ -244,7 +259,7 @@
switch (horizontalScrollElasticity()) {
case ScrollElasticityAutomatic: {
bool scrollbarsAllowStretching = allowsHorizontalScrolling() || !allowsVerticalScrolling();
- bool eventPreventsStretching = wheelEvent.isGestureStart() && isAlreadyPinnedInDirectionOfGesture(wheelEvent, ScrollEventAxis::Horizontal);
+ bool eventPreventsStretching = wheelEvent.isGestureStart() && isPinnedForScrollDeltaOnAxis(-wheelEvent.deltaX(), ScrollEventAxis::Horizontal);
return scrollbarsAllowStretching && !eventPreventsStretching;
}
case ScrollElasticityNone:
@@ -266,7 +281,7 @@
switch (verticalScrollElasticity()) {
case ScrollElasticityAutomatic: {
bool scrollbarsAllowStretching = allowsVerticalScrolling() || !allowsHorizontalScrolling();
- bool eventPreventsStretching = wheelEvent.isGestureStart() && isAlreadyPinnedInDirectionOfGesture(wheelEvent, ScrollEventAxis::Vertical);
+ bool eventPreventsStretching = wheelEvent.isGestureStart() && isPinnedForScrollDeltaOnAxis(-wheelEvent.deltaY(), ScrollEventAxis::Vertical);
return scrollbarsAllowStretching && !eventPreventsStretching;
}
case ScrollElasticityNone:
@@ -301,32 +316,16 @@
return stretch;
}
-// FIXME: Share more with ScrollingTreeScrollingNode::edgePinnedState().
-bool ScrollingTreeScrollingNodeDelegateMac::pinnedInDirection(const FloatSize& delta) const
+bool ScrollingTreeScrollingNodeDelegateMac::isPinnedForScrollDelta(const FloatSize& delta) const
{
- FloatSize limitDelta;
- auto scrollPosition = currentScrollPosition();
+ // This "offset < 1" logic was added in r107488. Unclear if it's needed.
+ constexpr float scrollOffsetLimit = 1.0f - std::numeric_limits<float>::epsilon();
- if (fabsf(delta.height()) >= fabsf(delta.width())) {
- if (delta.height() < 0) {
- // We are trying to scroll up. Make sure we are not pinned to the top.
- limitDelta.setHeight(scrollPosition.y() - minimumScrollPosition().y());
- } else {
- // We are trying to scroll down. Make sure we are not pinned to the bottom.
- limitDelta.setHeight(maximumScrollPosition().y() - scrollPosition.y());
- }
- } else if (delta.width()) {
- if (delta.width() < 0) {
- // We are trying to scroll left. Make sure we are not pinned to the left.
- limitDelta.setWidth(scrollPosition.x() - minimumScrollPosition().x());
- } else {
- // We are trying to scroll right. Make sure we are not pinned to the right.
- limitDelta.setWidth(maximumScrollPosition().x() - scrollPosition.x());
- }
- }
+ if (fabsf(delta.height()) >= fabsf(delta.width()))
+ return isPinnedForScrollDeltaOnAxis(delta.height(), ScrollEventAxis::Vertical, scrollOffsetLimit);
- if ((delta.width() || delta.height()) && (limitDelta.width() < 1 && limitDelta.height() < 1))
- return true;
+ if (delta.width())
+ return isPinnedForScrollDeltaOnAxis(delta.width(), ScrollEventAxis::Horizontal, scrollOffsetLimit);
return false;
}
Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (271080 => 271081)
--- trunk/Source/WebCore/platform/ScrollableArea.cpp 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp 2020-12-24 01:01:45 UTC (rev 271081)
@@ -629,28 +629,34 @@
}
#endif
-
-bool ScrollableArea::isPinnedInBothDirections(const IntSize& scrollDelta) const
+bool ScrollableArea::isPinnedForScrollDeltaOnAxis(float scrollDelta, ScrollEventAxis axis) const
{
- return isPinnedHorizontallyInDirection(scrollDelta.width()) && isPinnedVerticallyInDirection(scrollDelta.height());
-}
+ auto scrollPosition = this->scrollPosition();
+ switch (axis) {
+ case ScrollEventAxis::Vertical:
+ if (scrollDelta < 0) // top
+ return scrollPosition.y() <= minimumScrollPosition().y();
-bool ScrollableArea::isPinnedHorizontallyInDirection(int horizontalScrollDelta) const
-{
- if (horizontalScrollDelta < 0 && isHorizontalScrollerPinnedToMinimumPosition())
- return true;
- if (horizontalScrollDelta > 0 && isHorizontalScrollerPinnedToMaximumPosition())
- return true;
+ if (scrollDelta > 0) // bottom
+ return scrollPosition.y() >= maximumScrollPosition().y();
+
+ break;
+ case ScrollEventAxis::Horizontal:
+ if (scrollDelta < 0) // left
+ return scrollPosition.x() <= minimumScrollPosition().x();
+
+ if (scrollDelta > 0) // right
+ return scrollPosition.x() >= maximumScrollPosition().x();
+
+ break;
+ }
+
return false;
}
-bool ScrollableArea::isPinnedVerticallyInDirection(int verticalScrollDelta) const
+bool ScrollableArea::isPinnedForScrollDelta(const FloatSize& scrollDelta) const
{
- if (verticalScrollDelta < 0 && isVerticalScrollerPinnedToMinimumPosition())
- return true;
- if (verticalScrollDelta > 0 && isVerticalScrollerPinnedToMaximumPosition())
- return true;
- return false;
+ return isPinnedForScrollDeltaOnAxis(scrollDelta.width(), ScrollEventAxis::Horizontal) && isPinnedForScrollDeltaOnAxis(scrollDelta.height(), ScrollEventAxis::Vertical);
}
RectEdges<bool> ScrollableArea::edgePinnedState() const
Modified: trunk/Source/WebCore/platform/ScrollableArea.h (271080 => 271081)
--- trunk/Source/WebCore/platform/ScrollableArea.h 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/platform/ScrollableArea.h 2020-12-24 01:01:45 UTC (rev 271081)
@@ -326,15 +326,8 @@
// This function is static so that it can be called from the main thread or the scrolling thread.
WEBCORE_EXPORT static void computeScrollbarValueAndOverhang(float currentPosition, float totalSize, float visibleSize, float& doubleValue, float& overhangAmount);
- bool isHorizontalScrollerPinnedToMinimumPosition() const { return !horizontalScrollbar() || scrollOffset().x() <= 0; }
- bool isHorizontalScrollerPinnedToMaximumPosition() const { return !horizontalScrollbar() || scrollOffset().x() >= maximumScrollOffset().x(); }
- bool isVerticalScrollerPinnedToMinimumPosition() const { return !verticalScrollbar() || scrollOffset().y() <= 0; }
- bool isVerticalScrollerPinnedToMaximumPosition() const { return !verticalScrollbar() || scrollOffset().y() >= maximumScrollOffset().y(); }
-
- bool isPinnedInBothDirections(const IntSize&) const;
- bool isPinnedHorizontallyInDirection(int horizontalScrollDelta) const;
- bool isPinnedVerticallyInDirection(int verticalScrollDelta) const;
-
+ bool isPinnedForScrollDeltaOnAxis(float scrollDelta, ScrollEventAxis) const;
+ bool isPinnedForScrollDelta(const FloatSize&) const;
RectEdges<bool> edgePinnedState() const;
// True if scrolling happens by moving compositing layers.
Modified: trunk/Source/WebCore/platform/cocoa/ScrollController.h (271080 => 271081)
--- trunk/Source/WebCore/platform/cocoa/ScrollController.h 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/platform/cocoa/ScrollController.h 2020-12-24 01:01:45 UTC (rev 271081)
@@ -77,7 +77,7 @@
virtual bool allowsVerticalStretching(const PlatformWheelEvent&) const = 0;
virtual IntSize stretchAmount() const = 0;
- virtual bool pinnedInDirection(const FloatSize&) const = 0;
+ virtual bool isPinnedForScrollDelta(const FloatSize&) const = 0;
virtual RectEdges<bool> edgePinnedState() const = 0;
Modified: trunk/Source/WebCore/platform/cocoa/ScrollController.mm (271080 => 271081)
--- trunk/Source/WebCore/platform/cocoa/ScrollController.mm 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/platform/cocoa/ScrollController.mm 2020-12-24 01:01:45 UTC (rev 271081)
@@ -129,12 +129,11 @@
if (wheelEvent.phase() == PlatformWheelEventPhase::Began) {
// FIXME: Trying to decide if a gesture is horizontal or vertical at the "began" phase is very error-prone.
auto direction = directionFromEvent(wheelEvent, ScrollEventAxis::Horizontal);
- // FIXME: pinnedInDirection() needs cleanup.
- if (direction && m_client.pinnedInDirection(FloatSize(-wheelEvent.deltaX(), 0)) && !shouldRubberBandInDirection(direction.value()))
+ if (direction && m_client.isPinnedForScrollDelta(FloatSize(-wheelEvent.deltaX(), 0)) && !shouldRubberBandInDirection(direction.value()))
return false;
direction = directionFromEvent(wheelEvent, ScrollEventAxis::Vertical);
- if (direction && m_client.pinnedInDirection(FloatSize(0, -wheelEvent.deltaY())) && !shouldRubberBandInDirection(direction.value()))
+ if (direction && m_client.isPinnedForScrollDelta(FloatSize(0, -wheelEvent.deltaY())) && !shouldRubberBandInDirection(direction.value()))
return false;
m_momentumScrollInProgress = false;
@@ -222,7 +221,7 @@
}
if (isVerticallyStretched) {
- if (!isHorizontallyStretched && m_client.pinnedInDirection(FloatSize(deltaX, 0))) {
+ if (!isHorizontallyStretched && m_client.isPinnedForScrollDelta(FloatSize(deltaX, 0))) {
// Stretching only in the vertical.
if (deltaY && (fabsf(deltaX / deltaY) < rubberbandDirectionLockStretchRatio))
deltaX = 0;
@@ -234,7 +233,7 @@
}
} else if (isHorizontallyStretched) {
// Stretching only in the horizontal.
- if (m_client.pinnedInDirection(FloatSize(0, deltaY))) {
+ if (m_client.isPinnedForScrollDelta(FloatSize(0, deltaY))) {
if (deltaX && (fabsf(deltaY / deltaX) < rubberbandDirectionLockStretchRatio))
deltaY = 0;
else if (fabsf(deltaY) < rubberbandMinimumRequiredDeltaBeforeStretch) {
@@ -245,7 +244,7 @@
}
} else {
// Not stretching at all yet.
- if (m_client.pinnedInDirection(FloatSize(deltaX, deltaY))) {
+ if (m_client.isPinnedForScrollDelta(FloatSize(deltaX, deltaY))) {
if (fabsf(deltaY) >= fabsf(deltaX)) {
if (fabsf(deltaX) < rubberbandMinimumRequiredDeltaBeforeStretch) {
m_overflowScrollDelta.setWidth(m_overflowScrollDelta.width() + deltaX);
@@ -257,7 +256,7 @@
}
}
- LOG_WITH_STREAM(Scrolling, stream << "ScrollController::handleWheelEvent() - deltaX " << deltaX << " deltaY " << deltaY << " pinned " << m_client.pinnedInDirection(FloatSize(deltaX, deltaY)) << " shouldStretch " << shouldStretch);
+ LOG_WITH_STREAM(Scrolling, stream << "ScrollController::handleWheelEvent() - deltaX " << deltaX << " deltaY " << deltaY << " pinned " << m_client.isPinnedForScrollDelta(FloatSize(deltaX, deltaY)) << " shouldStretch " << shouldStretch);
}
bool handled = true;
@@ -278,7 +277,7 @@
deltaX = 0;
eventCoalescedDeltaX = 0;
handled = false;
- } else if (!isHorizontallyStretched && !m_client.pinnedInDirection(FloatSize(deltaX, 0))) {
+ } else if (!isHorizontallyStretched && !m_client.isPinnedForScrollDelta(FloatSize(deltaX, 0))) {
deltaX *= scrollWheelMultiplier();
m_client.immediateScrollByWithoutContentEdgeConstraints(FloatSize(deltaX, 0));
@@ -291,7 +290,7 @@
deltaY = 0;
eventCoalescedDeltaY = 0;
handled = false;
- } else if (!isVerticallyStretched && !m_client.pinnedInDirection(FloatSize(0, deltaY))) {
+ } else if (!isVerticallyStretched && !m_client.isPinnedForScrollDelta(FloatSize(0, deltaY))) {
deltaY *= scrollWheelMultiplier();
m_client.immediateScrollByWithoutContentEdgeConstraints(FloatSize(0, deltaY));
@@ -302,7 +301,7 @@
IntSize stretchAmount = m_client.stretchAmount();
if (m_momentumScrollInProgress) {
- if ((m_client.pinnedInDirection(FloatSize(eventCoalescedDeltaX, eventCoalescedDeltaY)) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_lastMomentumScrollTimestamp) {
+ if ((m_client.isPinnedForScrollDelta(FloatSize(eventCoalescedDeltaX, eventCoalescedDeltaY)) || (fabsf(eventCoalescedDeltaX) + fabsf(eventCoalescedDeltaY) <= 0)) && m_lastMomentumScrollTimestamp) {
m_ignoreMomentumScrolls = true;
m_momentumScrollInProgress = false;
snapRubberBand();
Modified: trunk/Source/WebCore/platform/ios/ScrollAnimatorIOS.mm (271080 => 271081)
--- trunk/Source/WebCore/platform/ios/ScrollAnimatorIOS.mm 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/platform/ios/ScrollAnimatorIOS.mm 2020-12-24 01:01:45 UTC (rev 271081)
@@ -172,7 +172,7 @@
ScrollableArea* scrollableArea = &m_scrollableArea;
while (true) {
- if (!scrollableArea->isPinnedInBothDirections(scrollDelta))
+ if (!scrollableArea->isPinnedForScrollDelta(scrollDelta))
break;
ScrollableArea* enclosingArea = scrollableArea->enclosingScrollableArea();
Modified: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h (271080 => 271081)
--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h 2020-12-24 01:01:45 UTC (rev 271081)
@@ -146,7 +146,7 @@
IntSize stretchAmount() const final;
bool allowsHorizontalStretching(const PlatformWheelEvent&) const final;
bool allowsVerticalStretching(const PlatformWheelEvent&) const final;
- bool pinnedInDirection(const FloatSize&) const final;
+ bool isPinnedForScrollDelta(const FloatSize&) const final;
RectEdges<bool> edgePinnedState() const final;
bool allowsHorizontalScrolling() const final;
bool allowsVerticalScrolling() const final;
@@ -154,8 +154,6 @@
void immediateScrollByWithoutContentEdgeConstraints(const FloatSize&) final;
void immediateScrollBy(const FloatSize&) final;
void adjustScrollPositionToBoundsIfNecessary() final;
-
- bool isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent&, ScrollEventAxis) const;
#endif
bool m_haveScrolledSincePageLoad;
Modified: trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm (271080 => 271081)
--- trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm 2020-12-24 01:01:45 UTC (rev 271081)
@@ -1299,54 +1299,19 @@
return didHandleEvent;
}
-bool ScrollAnimatorMac::pinnedInDirection(const FloatSize& direction) const
-{
- FloatSize limitDelta;
- if (fabsf(direction.height()) >= fabsf(direction.width())) {
- if (direction.height() < 0) {
- // We are trying to scroll up. Make sure we are not pinned to the top
- limitDelta.setHeight(m_scrollableArea.visibleContentRect().y() + m_scrollableArea.scrollOrigin().y());
- } else {
- // We are trying to scroll down. Make sure we are not pinned to the bottom
- limitDelta.setHeight(m_scrollableArea.totalContentsSize().height() - (m_scrollableArea.visibleContentRect().maxY() + m_scrollableArea.scrollOrigin().y()));
- }
- } else if (direction.width()) {
- if (direction.width() < 0) {
- // We are trying to scroll left. Make sure we are not pinned to the left
- limitDelta.setWidth(m_scrollableArea.visibleContentRect().x() + m_scrollableArea.scrollOrigin().x());
- } else {
- // We are trying to scroll right. Make sure we are not pinned to the right
- limitDelta.setWidth(m_scrollableArea.totalContentsSize().width() - (m_scrollableArea.visibleContentRect().maxX() + m_scrollableArea.scrollOrigin().x()));
- }
- }
-
- if ((direction.width() || direction.height()) && (limitDelta.width() < 1 && limitDelta.height() < 1))
- return true;
- return false;
-}
-
RectEdges<bool> ScrollAnimatorMac::edgePinnedState() const
{
return m_scrollableArea.edgePinnedState();
}
-// FIXME: We should find a way to share some of the code from newGestureIsStarting(), isAlreadyPinnedInDirectionOfGesture(),
-// allowsVerticalStretching(), and allowsHorizontalStretching() with the implementation in ScrollingTreeFrameScrollingNodeMac.
-static bool newGestureIsStarting(const PlatformWheelEvent& wheelEvent)
+bool ScrollAnimatorMac::isPinnedForScrollDelta(const FloatSize& delta) const
{
- return wheelEvent.phase() == PlatformWheelEventPhase::MayBegin || wheelEvent.phase() == PlatformWheelEventPhase::Began;
-}
+ if (fabsf(delta.height()) >= fabsf(delta.width()))
+ return m_scrollableArea.isPinnedForScrollDeltaOnAxis(delta.height(), ScrollEventAxis::Vertical);
-bool ScrollAnimatorMac::isAlreadyPinnedInDirectionOfGesture(const PlatformWheelEvent& wheelEvent, ScrollEventAxis axis) const
-{
- switch (axis) {
- case ScrollEventAxis::Vertical:
- return (wheelEvent.deltaY() > 0 && m_scrollableArea.scrolledToTop()) || (wheelEvent.deltaY() < 0 && m_scrollableArea.scrolledToBottom());
- case ScrollEventAxis::Horizontal:
- return (wheelEvent.deltaX() > 0 && m_scrollableArea.scrolledToLeft()) || (wheelEvent.deltaX() < 0 && m_scrollableArea.scrolledToRight());
- }
+ if (delta.width())
+ return m_scrollableArea.isPinnedForScrollDeltaOnAxis(delta.width(), ScrollEventAxis::Horizontal);
- ASSERT_NOT_REACHED();
return false;
}
@@ -1370,7 +1335,7 @@
Scrollbar* hScroller = m_scrollableArea.horizontalScrollbar();
Scrollbar* vScroller = m_scrollableArea.verticalScrollbar();
bool scrollbarsAllowStretching = ((vScroller && vScroller->enabled()) || (!hScroller || !hScroller->enabled()));
- bool eventPreventsStretching = m_scrollableArea.hasScrollableOrRubberbandableAncestor() && newGestureIsStarting(wheelEvent) && isAlreadyPinnedInDirectionOfGesture(wheelEvent, ScrollEventAxis::Vertical);
+ bool eventPreventsStretching = m_scrollableArea.hasScrollableOrRubberbandableAncestor() && wheelEvent.isGestureStart() && m_scrollableArea.isPinnedForScrollDeltaOnAxis(-wheelEvent.deltaY(), ScrollEventAxis::Vertical);
#if ENABLE(CSS_SCROLL_SNAP)
if (!eventPreventsStretching)
eventPreventsStretching = gestureShouldBeginSnap(wheelEvent, m_scrollableArea.verticalSnapOffsets());
@@ -1394,7 +1359,7 @@
Scrollbar* hScroller = m_scrollableArea.horizontalScrollbar();
Scrollbar* vScroller = m_scrollableArea.verticalScrollbar();
bool scrollbarsAllowStretching = ((hScroller && hScroller->enabled()) || (!vScroller || !vScroller->enabled()));
- bool eventPreventsStretching = m_scrollableArea.hasScrollableOrRubberbandableAncestor() && newGestureIsStarting(wheelEvent) && isAlreadyPinnedInDirectionOfGesture(wheelEvent, ScrollEventAxis::Horizontal);
+ bool eventPreventsStretching = m_scrollableArea.hasScrollableOrRubberbandableAncestor() && wheelEvent.isGestureStart() && m_scrollableArea.isPinnedForScrollDeltaOnAxis(-wheelEvent.deltaX(), ScrollEventAxis::Horizontal);
#if ENABLE(CSS_SCROLL_SNAP)
if (!eventPreventsStretching)
eventPreventsStretching = gestureShouldBeginSnap(wheelEvent, m_scrollableArea.horizontalSnapOffsets());
Modified: trunk/Source/WebCore/platform/mock/ScrollAnimatorMock.h (271080 => 271081)
--- trunk/Source/WebCore/platform/mock/ScrollAnimatorMock.h 2020-12-24 01:00:32 UTC (rev 271080)
+++ trunk/Source/WebCore/platform/mock/ScrollAnimatorMock.h 2020-12-24 01:01:45 UTC (rev 271081)
@@ -48,7 +48,7 @@
bool allowsHorizontalStretching(const PlatformWheelEvent&) const override { return false; }
bool allowsVerticalStretching(const PlatformWheelEvent&) const override { return false; }
IntSize stretchAmount() const override { return IntSize(); }
- bool pinnedInDirection(const FloatSize&) const override { return false; }
+ bool isPinnedForScrollDelta(const FloatSize&) const override { return false; }
RectEdges<bool> edgePinnedState() const override { return { }; }
bool allowsHorizontalScrolling() const override { return false; }
bool allowsVerticalScrolling() const override { return false; }