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

Changeset 285964 in webkit


Ignore:
Timestamp:
Nov 17, 2021, 3:55:47 PM (5 years ago)
Author:
timothy_horton@apple.com
Message:

Momentum animator: Short scrolls are too far, medium scrolls aren't far enough
https://bugs.webkit.org/show_bug.cgi?id=233272
<rdar://problem/85472653>

Reviewed by Simon Fraser.

  • platform/mac/ScrollingEffectsController.mm:

(WebCore::adjustedVelocity):
(WebCore::ScrollingEffectsController::handleWheelEvent):
Attempt to apply a empirically-derived curve to the initial velocity
to fit the distance of a normal momentum scroll.

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r285956 r285964  
     12021-11-17  Tim Horton  <timothy_horton@apple.com>
     2
     3        Momentum animator: Short scrolls are too far, medium scrolls aren't far enough
     4        https://bugs.webkit.org/show_bug.cgi?id=233272
     5        <rdar://problem/85472653>
     6
     7        Reviewed by Simon Fraser.
     8
     9        * platform/mac/ScrollingEffectsController.mm:
     10        (WebCore::adjustedVelocity):
     11        (WebCore::ScrollingEffectsController::handleWheelEvent):
     12        Attempt to apply a empirically-derived curve to the initial velocity
     13        to fit the distance of a normal momentum scroll.
     14
    1152021-11-17  Alan Bujtas  <zalan@apple.com>
    216
  • trunk/Source/WebCore/platform/mac/ScrollingEffectsController.mm

    r285953 r285964  
    128128#endif
    129129
     130static FloatSize adjustedVelocity(FloatSize velocity)
     131{
     132    auto applyCurve = ^(float originalValue) {
     133        if (!originalValue)
     134            return originalValue;
     135
     136        float value = fabs(originalValue);
     137        float powerLow = 6.7 * pow(value, -.166);
     138        float powerHigh = 36.3 * pow(value, -.392);
     139        const float transitionVelocity = 2000;
     140
     141        auto interpolate = ^(float v0, float v1, float t) {
     142            return (1 - t) * v0 + t * v1;
     143        };
     144       
     145        float multiplier = interpolate(powerLow, powerHigh, std::min(value, transitionVelocity) / transitionVelocity);
     146        return copysign(value * multiplier, originalValue);
     147    };
     148
     149    return { applyCurve(velocity.width()), applyCurve(velocity.height()) };
     150}
     151
    130152bool ScrollingEffectsController::handleWheelEvent(const PlatformWheelEvent& wheelEvent)
    131153{
     
    226248        m_momentumScrollInProgress = true;
    227249        if (momentumScrollingAnimatorEnabled()) {
    228             startMomentumScrollWithInitialVelocity(m_client.scrollOffset(), -wheelEvent.scrollingVelocity(), -wheelEvent.delta(), [](const FloatPoint& targetOffset) { return targetOffset; });
     250            startMomentumScrollWithInitialVelocity(m_client.scrollOffset(), -adjustedVelocity(wheelEvent.scrollingVelocity()), -wheelEvent.delta(), [](const FloatPoint& targetOffset) { return targetOffset; });
    229251#if !LOG_DISABLED
    230252            m_eventDrivenScrollOffset = m_client.scrollOffset();
Note: See TracChangeset for help on using the changeset viewer.