Changeset 245065 in webkit


Ignore:
Timestamp:
May 8, 2019 1:28:22 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

[GTK] Support navigation gesture on touchscreens
https://bugs.webkit.org/show_bug.cgi?id=197690

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

Touch events generate scroll events that are handled in webkitWebViewBaseHandleWheelEvent(),
bypassing webkitWebViewBaseScrollEvent(). Because of that, ViewGestureController never receives
them. Hence pass scroll events to ViewGestureController in webkitWebViewBaseHandleWheelEvent()
instead.

For touch events, gesture progress calculation has to take window width into account to make
the page perfectly follow finger, and deltas are additionally divided by Scrollbar::pixelsPerLineStep(),
so compensate for that.

For touchpad events, change delta multiplier to 10 to match GTK behavior, and introduce a 400px
base width so the swipe speed doesn't change from the previous behavior.

Because of the multiplier change, threshold for triggering the gesture with touchpad is now 4
times larger.

  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseHandleWheelEvent): Move ViewGestureController bits here.
(webkitWebViewBaseScrollEvent): Removed ViewGestureController bits.

  • UIProcess/gtk/ViewGestureControllerGtk.cpp:

(WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe):
Allow events from touchscreen devices.
(WebKit::isTouchEvent): Added.
(WebKit::ViewGestureController::PendingSwipeTracker::scrollEventGetScrollingDeltas):
Change delta multipliers.
(WebKit::ViewGestureController::SwipeProgressTracker::handleEvent):
Change delta multipliers, account for view width for touchscreen events.

Location:
trunk/Source/WebKit
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r245062 r245065  
     12019-05-08  Alexander Mikhaylenko  <exalm7659@gmail.com>
     2
     3        [GTK] Support navigation gesture on touchscreens
     4        https://bugs.webkit.org/show_bug.cgi?id=197690
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Touch events generate scroll events that are handled in webkitWebViewBaseHandleWheelEvent(),
     9        bypassing webkitWebViewBaseScrollEvent(). Because of that, ViewGestureController never receives
     10        them. Hence pass scroll events to ViewGestureController in webkitWebViewBaseHandleWheelEvent()
     11        instead.
     12
     13        For touch events, gesture progress calculation has to take window width into account to make
     14        the page perfectly follow finger, and deltas are additionally divided by Scrollbar::pixelsPerLineStep(),
     15        so compensate for that.
     16
     17        For touchpad events, change delta multiplier to 10 to match GTK behavior, and introduce a 400px
     18        base width so the swipe speed doesn't change from the previous behavior.
     19
     20        Because of the multiplier change, threshold for triggering the gesture with touchpad is now 4
     21        times larger.
     22
     23        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     24        (webkitWebViewBaseHandleWheelEvent): Move ViewGestureController bits here.
     25        (webkitWebViewBaseScrollEvent): Removed ViewGestureController bits.
     26        * UIProcess/gtk/ViewGestureControllerGtk.cpp:
     27        (WebKit::ViewGestureController::PendingSwipeTracker::scrollEventCanInfluenceSwipe):
     28        Allow events from touchscreen devices.
     29        (WebKit::isTouchEvent): Added.
     30        (WebKit::ViewGestureController::PendingSwipeTracker::scrollEventGetScrollingDeltas):
     31        Change delta multipliers.
     32        (WebKit::ViewGestureController::SwipeProgressTracker::handleEvent):
     33        Change delta multipliers, account for view width for touchscreen events.
     34
    1352019-05-08  Wenson Hsieh  <wenson_hsieh@apple.com>
    236
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r245008 r245065  
    851851static void webkitWebViewBaseHandleWheelEvent(WebKitWebViewBase* webViewBase, GdkEvent* event, Optional<WebWheelEvent::Phase> phase = WTF::nullopt, Optional<WebWheelEvent::Phase> momentum = WTF::nullopt)
    852852{
     853    ViewGestureController* controller = webkitWebViewBaseViewGestureController(webViewBase);
     854    if (controller && controller->isSwipeGestureEnabled() && controller->handleScrollWheelEvent(reinterpret_cast<GdkEventScroll*>(event)))
     855        return;
     856
    853857    WebKitWebViewBasePrivate* priv = webViewBase->priv;
    854858    ASSERT(!priv->dialog);
     
    890894        }
    891895    }
    892 
    893     ViewGestureController* controller = webkitWebViewBaseViewGestureController(webViewBase);
    894     if (controller && controller->isSwipeGestureEnabled() && controller->handleScrollWheelEvent(event))
    895         return GDK_EVENT_STOP;
    896896
    897897    webkitWebViewBaseHandleWheelEvent(webViewBase, reinterpret_cast<GdkEvent*>(event));
  • trunk/Source/WebKit/UIProcess/gtk/ViewGestureControllerGtk.cpp

    r244649 r245065  
    3737static const double swipeAnimationBaseVelocity = 0.002;
    3838
     39// GTK divides all scroll deltas by 10, compensate for that
     40static const double gtkScrollDeltaMultiplier = 10;
     41static const double swipeTouchpadBaseWidth = 400;
     42
    3943// This is derivative of the easing function at t=0
    4044static const double swipeAnimationDurationMultiplier = 3;
     
    8387    // FIXME: Should it maybe be allowed on mice/trackpoints as well? The GDK_SCROLL_SMOOTH
    8488    // requirement already filters out most mice, and it works pretty well on a trackpoint
    85     return event->direction == GDK_SCROLL_SMOOTH && source == GDK_SOURCE_TOUCHPAD;
     89    return event->direction == GDK_SCROLL_SMOOTH && (source == GDK_SOURCE_TOUCHPAD || source == GDK_SOURCE_TOUCHSCREEN);
     90}
     91
     92static bool isTouchEvent(GdkEventScroll* event)
     93{
     94    GdkDevice* device = gdk_event_get_source_device(reinterpret_cast<GdkEvent*>(event));
     95    GdkInputSource source = gdk_device_get_source(device);
     96
     97    return source == GDK_SOURCE_TOUCHSCREEN;
    8698}
    8799
    88100FloatSize ViewGestureController::PendingSwipeTracker::scrollEventGetScrollingDeltas(GdkEventScroll* event)
    89101{
     102    double multiplier = isTouchEvent(event) ? Scrollbar::pixelsPerLineStep() : gtkScrollDeltaMultiplier;
     103
    90104    // GdkEventScroll deltas are inverted compared to NSEvent, so invert them again
    91     return -FloatSize(event->delta_x, event->delta_y) * Scrollbar::pixelsPerLineStep();
     105    return -FloatSize(event->delta_x, event->delta_y) * multiplier;
    92106}
    93107
     
    170184    }
    171185
    172     double deltaX = -event->delta_x / Scrollbar::pixelsPerLineStep();
     186    double deltaX = -event->delta_x;
     187    if (isTouchEvent(event))
     188        deltaX *= (double) Scrollbar::pixelsPerLineStep() / m_webPageProxy.viewSize().width();
     189    else
     190        deltaX *= gtkScrollDeltaMultiplier / swipeTouchpadBaseWidth;
    173191
    174192    Seconds time = Seconds::fromMilliseconds(event->time);
Note: See TracChangeset for help on using the changeset viewer.