<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Add kinetic scrolling"
   href="https://bugs.webkit.org/show_bug.cgi?id=155750#c5">Comment # 5</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - [GTK] Add kinetic scrolling"
   href="https://bugs.webkit.org/show_bug.cgi?id=155750">bug 155750</a>
              from <span class="vcard"><a class="email" href="mailto:cgarcia&#64;igalia.com" title="Carlos Garcia Campos &lt;cgarcia&#64;igalia.com&gt;"> <span class="fn">Carlos Garcia Campos</span></a>
</span></b>
        <pre>Comment on <span class=""><a href="attachment.cgi?id=274652&amp;action=diff" name="attach_274652" title="WIP patch">attachment 274652</a> <a href="attachment.cgi?id=274652&amp;action=edit" title="WIP patch">[details]</a></span>
WIP patch

View in context: <a href="https://bugs.webkit.org/attachment.cgi?id=274652&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=274652&amp;action=review</a>

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:35
&gt; +static const double overshootFriction = 20;</span >

This is only about kinetic scrolling for now, this patch doesn't really support overshot animations, so let's keep that out for now.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:50
&gt; +    , m_dx(orientation == HorizontalScrollbar ? step * multiplier : 0)
&gt; +    , m_dy(orientation == VerticalScrollbar ? step * multiplier : 0)</span >

Do not use abbreviations for variables, use m_delatX, m_deltaY for example instead of m_dx, m_dy. Or even better FloatSize m_delta

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:54
&gt; +ScrollAnimationKinetic::KineticScrolling::KineticScrolling ()</span >

Space between KineticScrolling and ()

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:59
&gt; +ScrollAnimationKinetic::KineticScrolling::KineticScrolling (double lower, double upper, double initialPosition, double initialVelocity)</span >

Space between KineticScrolling and (

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:60
&gt; +    : m_phase(Phase::Decelerating)</span >

This should be the only phase for now, since we only implement deceleration in this patch.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:63
&gt; +    , m_overshootWidth(0)</span >

Initialize constant values in class declaration.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:64
&gt; +    , m_decelFriction(decelFriction)</span >

Why do we need a member for a constant value?

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:67
&gt; +    , m_c1(0)
&gt; +    , m_c2(0)</span >

Do not use abbreviations, and move initialization to the class declaration.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:69
&gt; +    , m_t(0)</span >

Ditto.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:73
&gt; +    if(initialPosition &lt; lower)</span >

Missing space between if and (

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:81
&gt; +        m_t = 0;</span >

This is already 0

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:83
&gt; +        m_position = initialPosition;
&gt; +        m_velocity = initialVelocity;</span >

And these also have their own initial values already.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:87
&gt; +bool ScrollAnimationKinetic::KineticScrolling::tick (double time_delta)</span >

tick (-&gt; tick(
time_delta -&gt; timeDelta

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:93
&gt; +        double exp_part = exp (-m_decelFriction * m_t);</span >

exp_part -&gt; whatever it stands for without _

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:150
&gt; +#if USE(REQUEST_ANIMATION_FRAME_TIMER)</span >

Since this will be supported only by GTK+ for now, and you are not going to test the !REQUEST_ANIMATION_FRAME_TIMER case, let's get rid of this, and use always a timer.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:167
&gt; +    m_scrollHistory.append(ScrollEvent(orientation, step, multiplier, monotonicallyIncreasingTime()));</span >

This can grow indefinitely, it seems GTK+ removes events older than a constant threshold (150ms). ScrollEvent doesn't really need both step and multiplier, so you can pass the delta directly, and the current time can also be obtained by the ScrollEvent constructor instead of passing it. But I don't think it's the current time what we want, but the event time.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:169
&gt; +    FloatPoint currentPosition = m_position;</span >

This is not actually used, you can use m_position below, since you are not changing it.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:200
&gt; +void ScrollAnimationKinetic::setCurrentPosition(const FloatPoint&amp; p)</span >

p -&gt; position

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:207
&gt; +void ScrollAnimationKinetic::startDeceleration() {</span >

the { should be in the next line.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:214
&gt; +void ScrollAnimationKinetic::cancelDeceleration() {
&gt; +    stop();
&gt; +}</span >

Do we need this?

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:230
&gt; +    double accum_dx = 0;
&gt; +    double accum_dy = 0;</span >

Don't use abbreviations nor _

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:231
&gt; +    for (auto i = m_scrollHistory.begin(); i != m_scrollHistory.end(); i++) {</span >

for (const auto&amp; scrollEvent : m_scrollHistory)
    scrollEvent.dx();

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:236
&gt; +    double first = m_scrollHistory.begin()-&gt;time();</span >

You can use m_scrollHistory[0].time()

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:260
&gt; +    if (!m_scrollHistory.isEmpty())
&gt; +        initDeceleration();</span >

initDeceleration already checks if scroll history is empty. I don't understand why the animation fire is starting the deceleration, I think it should be the other way around, startDeceleration should schedule the timer animation.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.cpp:266
&gt; +    if (m_horizontalData.tick(deltaToNextFrame))</span >

Use animateScroll or decelerate instead of tick

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.h:31
&gt; +#if ENABLE(SMOOTH_SCROLLING)</span >

This should not depend on SMOOTH_SCROLLING

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.h:35
&gt; +#if !ENABLE(REQUEST_ANIMATION_FRAME)
&gt; +#error &quot;SMOOTH_SCROLLING requires REQUEST_ANIMATION_FRAME to be enabled.&quot;
&gt; +#endif</span >

Remove this also.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.h:58
&gt; +    class ScrollEvent {
&gt; +    public:
&gt; +        ScrollEvent(ScrollbarOrientation, float step, float multiplier, double time);
&gt; +        double time() const { return m_time; }
&gt; +        double dx() const { return m_dx; }
&gt; +        double dy() const { return m_dy; }
&gt; +
&gt; +    private:
&gt; +        double m_time;
&gt; +        double m_dx;
&gt; +        double m_dy;
&gt; +
&gt; +    };</span >

This could probably be a struct

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.h:60
&gt; +    // KineticScrolling is a port of GtkKineticScrolling as of GTK+ 3.20, mimicking its API and its behavior.</span >

We can mention in the cpp that the whole implementation is based on GTK+ code.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.h:97
&gt; +        Phase m_phase;
&gt; +        double m_lower;
&gt; +        double m_upper;
&gt; +        double m_overshootWidth;
&gt; +        double m_decelFriction;
&gt; +        double m_overshootFriction;
&gt; +
&gt; +        double m_c1;
&gt; +        double m_c2;
&gt; +        double m_equilibriumPosition;
&gt; +
&gt; +        double m_t;
&gt; +        double m_position;
&gt; +        double m_velocity;
&gt; +    };</span >

And we don't probably need a class for this either.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.h:109
&gt; +    enum class Curve {
&gt; +        Linear,
&gt; +        Quadratic,
&gt; +        Cubic,
&gt; +        Quartic,
&gt; +        Bounce
&gt; +    };</span >

Copy paste leftover, I guess.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.h:112
&gt; +    void updateVisibleLengths() override;</span >

Since this is pure virtual, but unimplemented, you can add { } here instead of adding the empty implementation in the cpp file.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimationKinetic.h:115
&gt; +    void startDeceleration();
&gt; +    void cancelDeceleration();</span >

These could be just start() and stop()

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimator.cpp:129
&gt; +#elif PLATFORM(GTK)
&gt; +    // GDK scroll stop events are used to notify that the scrolling came to an end and that deceleration can be triggered.
&gt; +    if (e.isStop()) {
&gt; +        startDeceleration();
&gt; +        return true;
&gt; +    }
&gt; +    else
&gt; +        cancelDeceleration();</span >

We should override handleWheelEvent in ScrollAnimatorGtk and handle this there instead.

<span class="quote">&gt; Source/WebCore/platform/ScrollAnimator.h:94
&gt; +    virtual void startDeceleration() { }
&gt; +    virtual void cancelDeceleration() { }</span >

I don't think this belongs here, ScrollAnimatorGtk can start/stop its animations internally

<span class="quote">&gt; Source/WebCore/platform/gtk/PlatformWheelEventGtk.cpp:90
&gt; +#if GTK_CHECK_VERSION(3, 19, 7)
&gt; +    m_isStop = event-&gt;is_stop;
&gt; +#else
&gt; +    m_isStop = false;
&gt; +#endif</span >

Hmm, I'm surprised this depends on GTK+ 3.19, kinetic scrolling was supported before, there should be another way.

<span class="quote">&gt; Source/WebCore/platform/gtk/ScrollAnimatorGtk.cpp:80
&gt; +    if (m_kinetic_animation)</span >

m_kinetic_animation -&gt; m_kineticAnimation

<span class="quote">&gt; Source/WebCore/platform/gtk/ScrollAnimatorGtk.cpp:93
&gt; +    ensureKineticScrollingAnimation();</span >

We don't need the ensure method here, since this is created unconditionally in the constructor.

<span class="quote">&gt; Source/WebCore/platform/gtk/ScrollAnimatorGtk.cpp:97
&gt; +    m_kinetic_animation-&gt;scroll(orientation, granularity, step, multiplier);
&gt; +
&gt;      if (!m_scrollableArea.scrollAnimatorEnabled() || granularity == ScrollByPrecisePixel)
&gt;          return ScrollAnimator::scroll(orientation, granularity, step, multiplier);</span >

How does smooth and kinetic work together? I guess we should check if there's a deceleration in progress and only do the smooth when there isn't (if enabled, of course)

<span class="quote">&gt; Source/WebCore/platform/gtk/ScrollAnimatorGtk.cpp:109
&gt;      if (m_animation)</span >

We should rename this now to m_smoothAnimation

<span class="quote">&gt; Source/WebKit2/Shared/gtk/WebEventFactory.cpp:185
&gt; +#if GTK_CHECK_VERSION(3, 19, 7)
&gt; +    bool isStop = gdk_event_is_scroll_stop_event (event);
&gt; +#else
&gt; +    bool isStop = false;
&gt; +#endif</span >

Maybe we can guess this, if direction is smooth and delta x = delta y = 0 then it's stop. Not sure that's always true, though.

<span class="quote">&gt; Source/WebKit2/UIProcess/gtk/GestureController.cpp:92
&gt; +    scrollEvent-&gt;scroll.is_stop = false;</span >

false -&gt; FALSE

<span class="quote">&gt; Source/WebKit2/UIProcess/gtk/GestureController.cpp:111
&gt; +    scrollEvent-&gt;scroll.is_stop = false;</span >

Ditto.

<span class="quote">&gt; Source/WebKit2/UIProcess/gtk/GestureController.cpp:130
&gt; +    scrollEvent-&gt;scroll.is_stop = true;</span >

Ditto.

<span class="quote">&gt; Source/WebKit2/UIProcess/gtk/GestureController.h:74
&gt; +        void stopDrag(const GdkEvent*);</span >

Shouldn't we use a swipe gesture instead?</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>