Changeset 274381 in webkit


Ignore:
Timestamp:
Mar 13, 2021 1:31:19 AM (16 months ago)
Author:
Martin Robinson
Message:

Add basic (non-momentum) wheel event handling for scroll snap
https://bugs.webkit.org/show_bug.cgi?id=222594
Source/WebCore:

Reviewed by Simon Fraser.

Test: css3/scroll-snap/scroll-snap-wheel-event.html

Enable scroll snapping for basic wheel events on GTK+ and WPE. The Mac port
has special wheel handling due to momentum scrolling. Other scroll-snap-enabled
ports can just use a basic version.

  • platform/ScrollAnimator.cpp:

(WebCore::ScrollAnimator::scroll): Accept a bitmask of options now. This
will allow using this method when handling wheel events that do not animate.
(WebCore::ScrollAnimator::handleWheelEvent): Trigger ::scroll with
scroll snapping enabled and pass the appropriate option to disable animations.
(WebCore::ScrollAnimator::processWheelEventForScrollSnap): Deleted.

  • platform/ScrollAnimator.h:

(WebCore::ScrollAnimator::ScrollAnimator::processWheelEventForScrollSnap): Made
this a method that can be overridden by subclasses.

  • platform/mac/ScrollAnimatorMac.h: Added processWheelEventForScrollSnap.
  • platform/mac/ScrollAnimatorMac.mm:

(WebCore::ScrollAnimatorMac::scroll): Pay attention to the NeverAnimate bitmask now.
(WebCore::ScrollAnimatorMac::processWheelEventForScrollSnap): Added.

LayoutTests:

Reviewed by Simon Fraser.

  • css3/scroll-snap/scroll-snap-wheel-event-expected.txt: Added.
  • css3/scroll-snap/scroll-snap-wheel-event.html: Added.
  • platform/ios-wk2/TestExpectations: Skip new test because it uses mouse event simulation.

Move existing classification to better section as well.

  • platform/mac-wk1/fast/scrolling/latching/scroll-snap-latching-expected.txt: Rebased this previous failing test.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r274379 r274381  
     12021-03-13  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Add basic (non-momentum) wheel event handling for scroll snap
     4        https://bugs.webkit.org/show_bug.cgi?id=222594
     5        Reviewed by Simon Fraser.
     6
     7        * css3/scroll-snap/scroll-snap-wheel-event-expected.txt: Added.
     8        * css3/scroll-snap/scroll-snap-wheel-event.html: Added.
     9        * platform/ios-wk2/TestExpectations: Skip new test because it uses mouse event simulation.
     10        Move existing classification to better section as well.
     11        * platform/mac-wk1/fast/scrolling/latching/scroll-snap-latching-expected.txt: Rebased this previous failing test.
     12
    1132021-03-13  Alexey Shvayka  <shvaikalesh@gmail.com>
    214
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r273932 r274381  
    138138css3/scroll-snap/scroll-padding-mainframe-paging.html [ Failure ]
    139139css3/scroll-snap/scroll-padding-overflow-paging.html [ Failure ]
    140 css3/scroll-snap/scroll-snap-click-scrollbar-gutter.html [ Failure ]
    141140
    142141# SVG tests that time out (these require EventSender)
     
    934933editing/selection/select-out-of-floated-non-editable-11.html [ Skip ]
    935934editing/selection/select-out-of-floated-non-editable-12.html [ Skip ]
     935css3/scroll-snap/scroll-snap-click-scrollbar-gutter.html [ Skip ]
     936css3/scroll-snap/scroll-snap-wheel-event.html [ Skip ]
    936937
    937938webkit.org/b/192088 media/no-fullscreen-when-hidden.html [ Failure Pass ]
  • trunk/LayoutTests/platform/mac-wk1/fast/scrolling/latching/scroll-snap-latching-expected.txt

    r271072 r274381  
    55
    66PASS overflowScrollEventCount > 0 is true
    7 FAIL windowScrollEventCount should be 0. Was 7.
     7FAIL windowScrollEventCount should be 0. Was 11.
    88PASS successfullyParsed is true
    99
  • trunk/Source/WebCore/ChangeLog

    r274379 r274381  
     12021-03-13  Martin Robinson  <mrobinson@webkit.org>
     2
     3        Add basic (non-momentum) wheel event handling for scroll snap
     4        https://bugs.webkit.org/show_bug.cgi?id=222594
     5
     6        Reviewed by Simon Fraser.
     7
     8        Test: css3/scroll-snap/scroll-snap-wheel-event.html
     9
     10        Enable scroll snapping for basic wheel events on GTK+ and WPE. The Mac port
     11        has special wheel handling due to momentum scrolling. Other scroll-snap-enabled
     12        ports can just use a basic version.
     13
     14        * platform/ScrollAnimator.cpp:
     15        (WebCore::ScrollAnimator::scroll): Accept a bitmask of options now. This
     16        will allow using this method when handling wheel events that do not animate.
     17        (WebCore::ScrollAnimator::handleWheelEvent): Trigger ::scroll with
     18        scroll snapping enabled and pass the appropriate option to disable animations.
     19        (WebCore::ScrollAnimator::processWheelEventForScrollSnap): Deleted.
     20        * platform/ScrollAnimator.h:
     21        (WebCore::ScrollAnimator::ScrollAnimator::processWheelEventForScrollSnap): Made
     22        this a method that can be overridden by subclasses.
     23        * platform/mac/ScrollAnimatorMac.h: Added processWheelEventForScrollSnap.
     24        * platform/mac/ScrollAnimatorMac.mm:
     25        (WebCore::ScrollAnimatorMac::scroll): Pay attention to the NeverAnimate bitmask now.
     26        (WebCore::ScrollAnimatorMac::processWheelEventForScrollSnap): Added.
     27
    1282021-03-13  Alexey Shvayka  <shvaikalesh@gmail.com>
    229
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r273733 r274381  
    8282}
    8383
    84 bool ScrollAnimator::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier, ScrollBehavior behavior)
    85 {
    86 #if ENABLE(CSS_SCROLL_SNAP)
    87     if (behavior == ScrollBehavior::DoDirectionalSnapping) {
     84bool ScrollAnimator::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier, OptionSet<ScrollBehavior> behavior)
     85{
     86#if ENABLE(CSS_SCROLL_SNAP)
     87    if (behavior.contains(ScrollBehavior::DoDirectionalSnapping)) {
    8888        auto newOffset = ScrollableArea::scrollOffsetFromPosition(positionFromStep(orientation, step, multiplier), toFloatSize(m_scrollableArea.scrollOrigin()));
    8989        auto currentOffset = m_scrollableArea.scrollOffset();
     90        behavior.remove(ScrollBehavior::DoDirectionalSnapping);
    9091        if (orientation == HorizontalScrollbar) {
    9192            newOffset.setX(m_scrollController.adjustScrollDestination(ScrollEventAxis::Horizontal, newOffset.x(), multiplier, currentOffset.x()));
    92             return scroll(HorizontalScrollbar, granularity, newOffset.x() - currentOffset.x(), 1.0);
     93            return scroll(HorizontalScrollbar, granularity, newOffset.x() - currentOffset.x(), 1.0, behavior);
    9394        }
    9495        newOffset.setY(m_scrollController.adjustScrollDestination(ScrollEventAxis::Vertical, newOffset.y(), multiplier, currentOffset.y()));
    95         return scroll(VerticalScrollbar, granularity, newOffset.y() - currentOffset.y(), 1.0);
     96        return scroll(VerticalScrollbar, granularity, newOffset.y() - currentOffset.y(), 1.0, behavior);
    9697    }
    9798#else
     
    101102
    102103#if ENABLE(SMOOTH_SCROLLING) && !PLATFORM(IOS_FAMILY)
    103     if (m_scrollableArea.scrollAnimatorEnabled()) {
     104    if (m_scrollableArea.scrollAnimatorEnabled() && !behavior.contains(ScrollBehavior::NeverAnimate)) {
    104105        m_scrollAnimation->setCurrentPosition(m_currentPosition);
    105106        return m_scrollAnimation->scroll(orientation, granularity, step, multiplier);
     
    161162#if ENABLE(CSS_SCROLL_SNAP)
    162163#if PLATFORM(MAC)
    163 bool ScrollAnimator::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
    164 {
    165     return m_scrollController.processWheelEventForScrollSnap(wheelEvent);
    166 }
    167164#endif
    168165
     
    180177bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e)
    181178{
    182 #if ENABLE(CSS_SCROLL_SNAP) && PLATFORM(MAC)
    183     if (m_scrollController.processWheelEventForScrollSnap(e))
     179#if ENABLE(CSS_SCROLL_SNAP)
     180    if (processWheelEventForScrollSnap(e))
    184181        return false;
    185182#endif
     183
    186184#if PLATFORM(COCOA)
    187185    // Events in the PlatformWheelEventPhase::MayBegin phase have no deltas, and therefore never passes through the scroll handling logic below.
     
    204202    bool handled = false;
    205203
    206     ScrollGranularity granularity = ScrollByPixel;
    207204    IntSize maxForwardScrollDelta = m_scrollableArea.maximumScrollPosition() - m_scrollableArea.scrollPosition();
    208205    IntSize maxBackwardScrollDelta = m_scrollableArea.scrollPosition() - m_scrollableArea.minimumScrollPosition();
     
    213210        handled = true;
    214211
     212        OptionSet<ScrollBehavior> behavior(ScrollBehavior::DoDirectionalSnapping);
     213        if (e.hasPreciseScrollingDeltas())
     214            behavior.add(ScrollBehavior::NeverAnimate);
     215
    215216        if (deltaY) {
    216217            if (e.granularity() == ScrollByPageWheelEvent) {
     
    220221                    deltaY = -deltaY;
    221222            }
    222             if (e.hasPreciseScrollingDeltas())
    223                 scrollToPositionWithoutAnimation(positionFromStep(VerticalScrollbar, verticalScrollbar->pixelStep(), -deltaY));
    224             else
    225                 scroll(VerticalScrollbar, granularity, verticalScrollbar->pixelStep(), -deltaY);
     223            scroll(VerticalScrollbar, ScrollByPixel, verticalScrollbar->pixelStep(), -deltaY, behavior);
    226224        }
    227225
     
    233231                    deltaX = -deltaX;
    234232            }
    235             if (e.hasPreciseScrollingDeltas())
    236                 scrollToPositionWithoutAnimation(positionFromStep(HorizontalScrollbar, horizontalScrollbar->pixelStep(), -deltaX));
    237             else
    238                 scroll(HorizontalScrollbar, granularity, horizontalScrollbar->pixelStep(), -deltaX);
     233            scroll(HorizontalScrollbar, ScrollByPixel, horizontalScrollbar->pixelStep(), -deltaX, behavior);
    239234        }
    240235    }
  • trunk/Source/WebCore/platform/ScrollAnimator.h

    r273733 r274381  
    7070
    7171    enum ScrollBehavior {
    72         Default,
    73         DoDirectionalSnapping,
     72        Default = 0,
     73        DoDirectionalSnapping = 1 << 1,
     74        NeverAnimate = 1 << 2,
    7475    };
    7576
     
    7879    // destination and returns true.  Scrolling may be immediate or animated.
    7980    // The base class implementation always scrolls immediately, never animates.
    80     virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior = ScrollBehavior::Default);
     81    virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, OptionSet<ScrollBehavior>);
    8182
    8283    bool scrollToOffsetWithoutAnimation(const FloatPoint&, ScrollClamping = ScrollClamping::Clamped);
     
    150151
    151152#if ENABLE(CSS_SCROLL_SNAP)
    152 #if PLATFORM(MAC)
    153     bool processWheelEventForScrollSnap(const PlatformWheelEvent&);
    154 #endif
     153    virtual bool processWheelEventForScrollSnap(const PlatformWheelEvent&) { return false; }
    155154    void updateScrollSnapState();
    156155    bool activeScrollSnapIndexDidChange() const;
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.h

    r273275 r274381  
    8080    FloatSize m_contentAreaScrolledTimerScrollDelta;
    8181
    82     bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, ScrollBehavior) override;
     82    bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier, OptionSet<ScrollBehavior>) override;
    8383    bool scrollToPositionWithAnimation(const FloatPoint&) override;
    8484    bool scrollToPositionWithoutAnimation(const FloatPoint& position, ScrollClamping = ScrollClamping::Clamped) override;
     
    141141    String verticalScrollbarStateForTesting() const final;
    142142
     143    bool processWheelEventForScrollSnap(const PlatformWheelEvent&) override;
     144
    143145    // ScrollControllerClient.
    144146#if ENABLE(RUBBER_BANDING)
  • trunk/Source/WebCore/platform/mac/ScrollAnimatorMac.mm

    r273657 r274381  
    752752#endif
    753753
    754 bool ScrollAnimatorMac::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier, ScrollBehavior behavior)
     754bool ScrollAnimatorMac::scroll(ScrollbarOrientation orientation, ScrollGranularity granularity, float step, float multiplier, OptionSet<ScrollBehavior> behavior)
    755755{
    756756    m_haveScrolledSincePageLoad = true;
     
    758758    // This method doesn't do directional snapping, but our base class does. It will call into
    759759    // ScrollAnimatorMac::scroll again with the snapped positions and ScrollBehavior::Default.
    760     if (behavior == ScrollBehavior::DoDirectionalSnapping)
     760    if (behavior.contains(ScrollBehavior::DoDirectionalSnapping))
    761761        return ScrollAnimator::scroll(orientation, granularity, step, multiplier, behavior);
    762762
    763     bool shouldAnimate = scrollAnimationEnabledForSystem() && m_scrollableArea.scrollAnimatorEnabled() && granularity != ScrollByPixel;
     763    bool shouldAnimate = scrollAnimationEnabledForSystem() && m_scrollableArea.scrollAnimatorEnabled() && granularity != ScrollByPixel
     764        && !behavior.contains(ScrollBehavior::NeverAnimate);
    764765    FloatPoint newPosition = positionFromStep(orientation, step, multiplier);
    765766    newPosition = newPosition.constrainedBetween(scrollableArea().minimumScrollPosition(), scrollableArea().maximumScrollPosition());
     
    15011502}
    15021503
     1504bool ScrollAnimatorMac::processWheelEventForScrollSnap(const PlatformWheelEvent& wheelEvent)
     1505{
     1506    return m_scrollController.processWheelEventForScrollSnap(wheelEvent);
     1507}
     1508
    15031509} // namespace WebCore
    15041510
Note: See TracChangeset for help on using the changeset viewer.