⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 284596 in webkit


Ignore:
Timestamp:
Oct 21, 2021, 2:53:50 AM (5 years ago)
Author:
Chris Lord
Message:

[GTK] Slow scrolling (not matching GTK native scroll amount)
https://bugs.webkit.org/show_bug.cgi?id=197100

Reviewed by Simon Fraser.

Fix up behaviour with interrupting smooth scrolling, mainly on
keyboard-initiated scrolling, but also for the mouse-wheel. When
interrupting a smooth scroll, the animation curve is now changed from
ease-in-out to ease-out and the duration is recalculated.

No new tests, covered by existing tests.

  • platform/ScrollAnimation.h:

(WebCore::ScrollAnimation::destinationOffset const):

  • platform/ScrollAnimationSmooth.cpp:

(WebCore::ScrollAnimationSmooth::ScrollAnimationSmooth):
(WebCore::ScrollAnimationSmooth::startAnimatedScrollToDestination):
(WebCore::ScrollAnimationSmooth::retargetActiveAnimation):
(WebCore::ScrollAnimationSmooth::animateScroll):
(WebCore::ScrollAnimationSmooth::startOrRetargetAnimation): Deleted.

  • platform/ScrollAnimationSmooth.h:
  • platform/ScrollAnimator.cpp:

(WebCore::ScrollAnimator::scroll):

  • platform/ScrollingEffectsController.cpp:

(WebCore::ScrollingEffectsController::retargetAnimatedScrollBy):
(WebCore::ScrollingEffectsController::handleWheelEvent):

  • platform/ScrollingEffectsController.h:
Location:
trunk/Source/WebCore
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r284591 r284596  
     12021-10-21  Chris Lord  <clord@igalia.com>
     2
     3        [GTK] Slow scrolling (not matching GTK native scroll amount)
     4        https://bugs.webkit.org/show_bug.cgi?id=197100
     5
     6        Reviewed by Simon Fraser.
     7
     8        Fix up behaviour with interrupting smooth scrolling, mainly on
     9        keyboard-initiated scrolling, but also for the mouse-wheel. When
     10        interrupting a smooth scroll, the animation curve is now changed from
     11        ease-in-out to ease-out and the duration is recalculated.
     12
     13        No new tests, covered by existing tests.
     14
     15        * platform/ScrollAnimation.h:
     16        (WebCore::ScrollAnimation::destinationOffset const):
     17        * platform/ScrollAnimationSmooth.cpp:
     18        (WebCore::ScrollAnimationSmooth::ScrollAnimationSmooth):
     19        (WebCore::ScrollAnimationSmooth::startAnimatedScrollToDestination):
     20        (WebCore::ScrollAnimationSmooth::retargetActiveAnimation):
     21        (WebCore::ScrollAnimationSmooth::animateScroll):
     22        (WebCore::ScrollAnimationSmooth::startOrRetargetAnimation): Deleted.
     23        * platform/ScrollAnimationSmooth.h:
     24        * platform/ScrollAnimator.cpp:
     25        (WebCore::ScrollAnimator::scroll):
     26        * platform/ScrollingEffectsController.cpp:
     27        (WebCore::ScrollingEffectsController::retargetAnimatedScrollBy):
     28        (WebCore::ScrollingEffectsController::handleWheelEvent):
     29        * platform/ScrollingEffectsController.h:
     30
    1312021-10-20  Brady Eidson  <beidson@apple.com>
    232
  • trunk/Source/WebCore/platform/ScrollAnimation.h

    r284136 r284596  
    7979   
    8080    FloatPoint currentOffset() const { return m_currentOffset; }
     81    virtual std::optional<FloatPoint> destinationOffset() const { return std::nullopt; }
    8182
    8283    virtual void serviceAnimation(MonotonicTime) = 0;
  • trunk/Source/WebCore/platform/ScrollAnimationSmooth.cpp

    r283851 r284596  
    4242ScrollAnimationSmooth::ScrollAnimationSmooth(ScrollAnimationClient& client)
    4343    : ScrollAnimation(Type::Smooth, client)
    44     , m_easeInOutTimingFunction(CubicBezierTimingFunction::create(CubicBezierTimingFunction::TimingFunctionPreset::EaseInOut))
     44    , m_timingFunction(CubicBezierTimingFunction::create())
    4545{
    4646}
     
    5050bool ScrollAnimationSmooth::startAnimatedScrollToDestination(const FloatPoint& fromOffset, const FloatPoint& destinationOffset)
    5151{
    52     m_startOffset = fromOffset;
    53     m_duration = durationFromDistance(destinationOffset - m_startOffset);
     52    if (!isActive() && fromOffset == destinationOffset)
     53        return false;
    5454
    5555    auto extents = m_client.scrollExtentsForAnimation(*this);
    56     return startOrRetargetAnimation(extents, destinationOffset);
     56
     57    m_startTime = MonotonicTime::now();
     58    m_startOffset = fromOffset;
     59    m_destinationOffset = destinationOffset.constrainedBetween(extents.minimumScrollOffset(), extents.maximumScrollOffset());
     60    m_duration = durationFromDistance(m_destinationOffset - m_startOffset);
     61    downcast<CubicBezierTimingFunction>(*m_timingFunction).setTimingFunctionPreset(CubicBezierTimingFunction::TimingFunctionPreset::EaseInOut);
     62
     63    if (!isActive())
     64        didStart(MonotonicTime::now());
     65
     66    return true;
    5767}
    5868
     
    6373
    6474    auto extents = m_client.scrollExtentsForAnimation(*this);
    65     return startOrRetargetAnimation(extents, newOffset);
    66 }
    6775
    68 bool ScrollAnimationSmooth::startOrRetargetAnimation(const ScrollExtents& extents, const FloatPoint& destinationOffset)
    69 {
    70     m_destinationOffset = destinationOffset.constrainedBetween(extents.minimumScrollOffset(), extents.maximumScrollOffset());
    71     bool needToScroll = m_startOffset != m_destinationOffset;
     76    m_startTime = MonotonicTime::now();
     77    m_startOffset = m_currentOffset;
     78    m_destinationOffset = newOffset.constrainedBetween(extents.minimumScrollOffset(), extents.maximumScrollOffset());
     79    m_duration = durationFromDistance(m_destinationOffset - m_startOffset);
     80    downcast<CubicBezierTimingFunction>(*m_timingFunction).setTimingFunctionPreset(CubicBezierTimingFunction::TimingFunctionPreset::EaseOut);
     81    m_timingFunction = CubicBezierTimingFunction::create(CubicBezierTimingFunction::TimingFunctionPreset::EaseOut);
    7282
    73     if (needToScroll && !isActive())
    74         didStart(MonotonicTime::now());
     83    if (m_currentOffset == m_destinationOffset)
     84        return false;
    7585
    76     return needToScroll;
     86    return true;
    7787}
    7888
     
    109119
    110120    double fractionComplete = (currentTime - m_startTime) / m_duration;
    111     double progress = m_easeInOutTimingFunction->transformProgress(fractionComplete, m_duration.value());
     121    double progress = m_timingFunction->transformProgress(fractionComplete, m_duration.value());
    112122
    113123    m_currentOffset = {
  • trunk/Source/WebCore/platform/ScrollAnimationSmooth.h

    r283548 r284596  
    4242    bool retargetActiveAnimation(const FloatPoint& newOffset) final;
    4343
    44     const FloatPoint& destinationOffset() const { return m_destinationOffset; }
     44    std::optional<FloatPoint> destinationOffset() const final { return m_destinationOffset; }
    4545
    4646private:
    47 
    48     bool startOrRetargetAnimation(const ScrollExtents&, const FloatPoint& destinationOffset);
    4947
    5048    void updateScrollExtents() final;
     
    6058    FloatPoint m_destinationOffset;
    6159
    62     RefPtr<TimingFunction> m_easeInOutTimingFunction;
     60    RefPtr<TimingFunction> m_timingFunction;
    6361};
    6462
  • trunk/Source/WebCore/platform/ScrollAnimator.cpp

    r284575 r284596  
    9090
    9191    if (m_scrollableArea.scrollAnimatorEnabled() && platformAllowsScrollAnimation() && !behavior.contains(ScrollBehavior::NeverAnimate)) {
     92        if (m_scrollController.retargetAnimatedScrollBy(delta))
     93            return true;
     94
    9295        auto startOffset = offsetFromPosition(m_currentPosition);
    9396        auto extents = scrollExtents();
  • trunk/Source/WebCore/platform/ScrollingEffectsController.cpp

    r284302 r284596  
    119119}
    120120
     121bool ScrollingEffectsController::retargetAnimatedScrollBy(FloatSize offset)
     122{
     123    if (!is<ScrollAnimationSmooth>(m_currentAnimation.get()))
     124        return false;
     125
     126    LOG_WITH_STREAM(ScrollAnimations, stream << "ScrollingEffectsController " << this << " retargetAnimatedScrollBy " << offset);
     127
     128    ASSERT(m_currentAnimation->isActive());
     129    if (auto destinationOffset = m_currentAnimation->destinationOffset())
     130        return m_currentAnimation->retargetActiveAnimation(*destinationOffset + offset);
     131
     132    return false;
     133}
     134
    121135void ScrollingEffectsController::stopAnimatedScroll()
    122136{
     
    352366#if ENABLE(SMOOTH_SCROLLING)
    353367    if (m_client.scrollAnimationEnabled() && !m_inScrollGesture) {
    354         if (is<ScrollAnimationSmooth>(m_currentAnimation.get())) {
    355             auto lastDestinationOffset = downcast<ScrollAnimationSmooth>(*m_currentAnimation).destinationOffset();
    356             retargetAnimatedScroll(lastDestinationOffset + FloatSize { deltaX, deltaY });
    357         } else
     368        if (!retargetAnimatedScrollBy({ deltaX, deltaY }))
    358369            startAnimatedScrollToDestination(scrollOffset, scrollOffset + FloatSize { deltaX, deltaY });
    359370        return true;
  • trunk/Source/WebCore/platform/ScrollingEffectsController.h

    r284302 r284596  
    136136    bool startAnimatedScrollToDestination(FloatPoint startOffset, FloatPoint destinationOffset);
    137137    bool retargetAnimatedScroll(FloatPoint newDestinationOffset);
     138    bool retargetAnimatedScrollBy(FloatSize);
    138139    void stopAnimatedScroll();
    139140
Note: See TracChangeset for help on using the changeset viewer.