Changeset 241952 in webkit


Ignore:
Timestamp:
Feb 22, 2019 10:46:25 AM (5 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Navigation gesture improvements
https://bugs.webkit.org/show_bug.cgi?id=194943

Patch by Alexander Mikhaylenko <exalm7659@gmail.com> on 2019-02-22
Reviewed by Michael Catanzaro.

Cancel the gesture if progress is less than 0.5 and velocity is not high enough.

Allow to continue the gesture during animation. Introduce finished state to be used
when showing snapshot after the animation ends.

Fix duration calculation, also slow it down so that the initial velocity matches
what it was during the gesture.

  • UIProcess/ViewGestureController.h: Add shouldCancel() and State::Finishing to SwipeProgressTracker.
  • UIProcess/gtk/ViewGestureControllerGtk.cpp:

(WebKit::ViewGestureController::SwipeProgressTracker::handleEvent):
Fix velocity calculation, allow scrolling during State::Animating.
(WebKit::ViewGestureController::SwipeProgressTracker::shouldCancel): Added.
(WebKit::ViewGestureController::SwipeProgressTracker::startAnimation): Use shouldCancel() and fix duration calculation.
(WebKit::ViewGestureController::SwipeProgressTracker::endAnimation): Set state to State::Finishing when the animation ends.

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r241950 r241952  
     12019-02-22  Alexander Mikhaylenko  <exalm7659@gmail.com>
     2
     3        [GTK] Navigation gesture improvements
     4        https://bugs.webkit.org/show_bug.cgi?id=194943
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Cancel the gesture if progress is less than 0.5 and velocity is not high enough.
     9
     10        Allow to continue the gesture during animation. Introduce finished state to be used
     11        when showing snapshot after the animation ends.
     12
     13        Fix duration calculation, also slow it down so that the initial velocity matches
     14        what it was during the gesture.
     15
     16        * UIProcess/ViewGestureController.h: Add shouldCancel() and State::Finishing to SwipeProgressTracker.
     17        * UIProcess/gtk/ViewGestureControllerGtk.cpp:
     18        (WebKit::ViewGestureController::SwipeProgressTracker::handleEvent):
     19        Fix velocity calculation, allow scrolling during State::Animating.
     20        (WebKit::ViewGestureController::SwipeProgressTracker::shouldCancel): Added.
     21        (WebKit::ViewGestureController::SwipeProgressTracker::startAnimation): Use shouldCancel() and fix duration calculation.
     22        (WebKit::ViewGestureController::SwipeProgressTracker::endAnimation): Set state to State::Finishing when the animation ends.
     23
    1242019-02-22  Chris Dumez  <cdumez@apple.com>
    225
  • trunk/Source/WebKit/UIProcess/ViewGestureController.h

    r241224 r241952  
    375375            Pending,
    376376            Scrolling,
    377             Animating
     377            Animating,
     378            Finishing
    378379        };
     380
     381        bool shouldCancel();
    379382
    380383        void startAnimation();
  • trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp

    r241224 r241952  
    3636static const Seconds swipeMaxAnimationDuration = 400_ms;
    3737
     38// This is derivative of the easing function at t=0
     39static const double swipeAnimationDurationMultiplier = 3;
     40
     41static const double swipeCancelArea = 0.5;
     42static const double swipeCancelVelocityThreshold = 0.001;
     43
    3844static const double swipeOverlayShadowOpacity = 0.06;
    3945static const double swipeOverlayDimmingOpacity = 0.12;
     
    136142bool ViewGestureController::SwipeProgressTracker::handleEvent(GdkEventScroll* event)
    137143{
     144    // Don't allow scrolling while the next page is loading
     145    if (m_state == State::Finishing)
     146        return true;
     147
     148    // Stop current animation, if any
     149    if (m_state == State::Animating) {
     150        GtkWidget* widget = m_webPageProxy.viewWidget();
     151        gtk_widget_remove_tick_callback(widget, m_tickCallbackID);
     152        m_tickCallbackID = 0;
     153
     154        m_cancelled = false;
     155        m_state = State::Pending;
     156    }
     157
    138158    if (m_state == State::Pending) {
    139159        m_viewGestureController.beginSwipeGesture(m_targetItem.get(), m_direction);
     
    141161    }
    142162
    143     // Don't allow scrolling during animation
    144     if (m_state == State::Animating)
    145         return true;
    146 
    147163    if (m_state != State::Scrolling)
    148164        return false;
     
    153169    }
    154170
     171    double deltaX = -event->delta_x / Scrollbar::pixelsPerLineStep();
     172
    155173    Seconds time = Seconds::fromMilliseconds(event->time);
    156     m_velocity = -event->delta_x / (time - m_prevTime).milliseconds();
     174    if (time != m_prevTime)
     175        m_velocity = deltaX / (time - m_prevTime).milliseconds();
    157176
    158177    m_prevTime = time;
    159     m_progress -= event->delta_x / Scrollbar::pixelsPerLineStep();
     178    m_progress += deltaX;
    160179
    161180    bool swipingLeft = m_viewGestureController.isPhysicallySwipingLeft(m_direction);
     
    169188}
    170189
     190bool ViewGestureController::SwipeProgressTracker::shouldCancel()
     191{
     192    bool swipingLeft = m_viewGestureController.isPhysicallySwipingLeft(m_direction);
     193
     194    if (swipingLeft && m_velocity < 0)
     195        return true;
     196
     197    if (!swipingLeft && m_velocity > 0)
     198        return true;
     199
     200    return (abs(m_progress) < swipeCancelArea && abs(m_velocity) < swipeCancelVelocityThreshold);
     201}
     202
    171203void ViewGestureController::SwipeProgressTracker::startAnimation()
    172204{
    173     bool swipingLeft = m_viewGestureController.isPhysicallySwipingLeft(m_direction);
    174     m_cancelled = swipingLeft ? (m_velocity <= 0) : (m_velocity >= 0);
     205    m_cancelled = shouldCancel();
    175206
    176207    m_state = State::Animating;
     
    181212        m_endProgress = 0;
    182213    else
    183         m_endProgress = swipingLeft ? 1 : -1;
    184 
    185     Seconds duration = Seconds::fromMilliseconds(std::abs((m_progress - m_endProgress) / m_velocity) * Scrollbar::pixelsPerLineStep());
    186     duration = std::min(std::max(duration, swipeMinAnimationDuration), swipeMaxAnimationDuration);
     214        m_endProgress = m_viewGestureController.isPhysicallySwipingLeft(m_direction) ? 1 : -1;
     215
     216    Seconds duration = swipeMaxAnimationDuration;
     217    if ((m_endProgress - m_progress) * m_velocity > 0) {
     218        duration = Seconds::fromMilliseconds(std::abs((m_progress - m_endProgress) / m_velocity * swipeAnimationDurationMultiplier));
     219        duration = clampTo<WTF::Seconds>(duration, swipeMinAnimationDuration, swipeMaxAnimationDuration);
     220    }
    187221
    188222    GtkWidget* widget = m_webPageProxy.viewWidget();
     
    227261void ViewGestureController::SwipeProgressTracker::endAnimation()
    228262{
     263    m_state = State::Finishing;
    229264    m_viewGestureController.endSwipeGesture(m_targetItem.get(), m_cancelled);
    230265}
Note: See TracChangeset for help on using the changeset viewer.