Changeset 260819 in webkit


Ignore:
Timestamp:
Apr 28, 2020 5:27:50 AM (4 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK4] Add support for motion events
https://bugs.webkit.org/show_bug.cgi?id=211073

Reviewed by Adrian Perez de Castro.

Source/WebKit:

Handle enter, leave and motion events using a GtkEventControllerMotion.

  • Shared/NativeWebMouseEvent.h:
  • Shared/gtk/NativeWebMouseEventGtk.cpp:

(WebKit::NativeWebMouseEvent::NativeWebMouseEvent):

  • Shared/gtk/WebEventFactory.cpp:

(WebKit::WebEventFactory::createWebMouseEvent):

  • Shared/gtk/WebEventFactory.h:
  • UIProcess/API/gtk/WebKitWebViewBase.cpp:

(webkitWebViewBaseEnter):
(webkitWebViewBaseMotion):
(webkitWebViewBaseLeave):
(webkitWebViewBaseConstructed):

Tools:

Use the GtkOverlay in GTK4 too so that status label is shown when hovering elements.

  • MiniBrowser/gtk/BrowserTab.c:

(browserTabConstructed):

Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r260818 r260819  
     12020-04-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK4] Add support for motion events
     4        https://bugs.webkit.org/show_bug.cgi?id=211073
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Handle enter, leave and motion events using a GtkEventControllerMotion.
     9
     10        * Shared/NativeWebMouseEvent.h:
     11        * Shared/gtk/NativeWebMouseEventGtk.cpp:
     12        (WebKit::NativeWebMouseEvent::NativeWebMouseEvent):
     13        * Shared/gtk/WebEventFactory.cpp:
     14        (WebKit::WebEventFactory::createWebMouseEvent):
     15        * Shared/gtk/WebEventFactory.h:
     16        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
     17        (webkitWebViewBaseEnter):
     18        (webkitWebViewBaseMotion):
     19        (webkitWebViewBaseLeave):
     20        (webkitWebViewBaseConstructed):
     21
    1222020-04-28  Adrian Perez de Castro  <aperez@igalia.com>
    223
  • trunk/Source/WebKit/Shared/NativeWebMouseEvent.h

    r260752 r260819  
    6666    NativeWebMouseEvent(const NativeWebMouseEvent&);
    6767    NativeWebMouseEvent(GdkEvent*, int, Optional<WebCore::IntPoint>);
     68    NativeWebMouseEvent(GdkEvent*, const WebCore::IntPoint&, int, Optional<WebCore::IntPoint>);
     69    explicit NativeWebMouseEvent(const WebCore::IntPoint&);
    6870#elif PLATFORM(IOS_FAMILY)
    6971    NativeWebMouseEvent(::WebEvent *);
  • trunk/Source/WebKit/Shared/gtk/NativeWebMouseEventGtk.cpp

    r260752 r260819  
    3838}
    3939
     40NativeWebMouseEvent::NativeWebMouseEvent(GdkEvent* event, const WebCore::IntPoint& position, int eventClickCount, Optional<WebCore::IntPoint> delta)
     41    : WebMouseEvent(WebEventFactory::createWebMouseEvent(event, position, position, eventClickCount, delta))
     42    , m_nativeEvent(gdk_event_copy(event))
     43{
     44}
     45
     46NativeWebMouseEvent::NativeWebMouseEvent(const WebCore::IntPoint& position)
     47    : WebMouseEvent(WebEventFactory::createWebMouseEvent(position))
     48{
     49}
     50
    4051NativeWebMouseEvent::NativeWebMouseEvent(const NativeWebMouseEvent& event)
    41     : WebMouseEvent(WebEventFactory::createWebMouseEvent(event.nativeEvent(), event.clickCount(), WebCore::IntPoint(event.deltaX(), event.deltaY())))
    42     , m_nativeEvent(gdk_event_copy(const_cast<GdkEvent*>(event.nativeEvent())))
     52    : WebMouseEvent(WebEventFactory::createWebMouseEvent(event.nativeEvent(), event.position(), event.globalPosition(), event.clickCount(), WebCore::IntPoint(event.deltaX(), event.deltaY())))
     53    , m_nativeEvent(event.nativeEvent() ? gdk_event_copy(const_cast<GdkEvent*>(event.nativeEvent())) : nullptr)
    4354{
    4455}
  • trunk/Source/WebKit/Shared/gtk/WebEventFactory.cpp

    r260817 r260819  
    141141WebMouseEvent WebEventFactory::createWebMouseEvent(const GdkEvent* event, int currentClickCount, Optional<IntPoint> delta)
    142142{
    143     double x, y, xRoot, yRoot;
     143    double x, y;
    144144    gdk_event_get_coords(event, &x, &y);
     145    double xRoot, yRoot;
    145146    gdk_event_get_root_coords(event, &xRoot, &yRoot);
     147
     148    return createWebMouseEvent(event, { clampToInteger(x), clampToInteger(y) }, { clampToInteger(xRoot), clampToInteger(yRoot) }, currentClickCount, delta);
     149}
     150
     151WebMouseEvent WebEventFactory::createWebMouseEvent(const GdkEvent* event, const IntPoint& position, const IntPoint& globalPosition, int currentClickCount, Optional<IntPoint> delta)
     152{
     153#if USE(GTK4)
     154    // This can happen when a NativeWebMouseEvent representing a crossing event is copied.
     155    if (!event)
     156        return createWebMouseEvent(position);
     157#endif
    146158
    147159    GdkModifierType state = static_cast<GdkModifierType>(0);
    148160    gdk_event_get_state(event, &state);
    149161
    150     guint eventButton;
    151     gdk_event_get_button(event, &eventButton);
    152 
    153162    WebEvent::Type type = static_cast<WebEvent::Type>(0);
    154163    IntPoint movementDelta;
    155164
    156     GdkEventType eventType = gdk_event_get_event_type(const_cast<GdkEvent*>(event));
    157     switch (eventType) {
     165    switch (gdk_event_get_event_type(const_cast<GdkEvent*>(event))) {
    158166    case GDK_MOTION_NOTIFY:
    159167    case GDK_ENTER_NOTIFY:
     
    169177    case GDK_BUTTON_PRESS: {
    170178        type = WebEvent::MouseDown;
     179        guint eventButton;
     180        gdk_event_get_button(event, &eventButton);
    171181        auto modifier = stateModifierForGdkButton(eventButton);
    172182        state = static_cast<GdkModifierType>(state | modifier);
     
    175185    case GDK_BUTTON_RELEASE: {
    176186        type = WebEvent::MouseUp;
     187        guint eventButton;
     188        gdk_event_get_button(event, &eventButton);
    177189        auto modifier = stateModifierForGdkButton(eventButton);
    178190        state = static_cast<GdkModifierType>(state & ~modifier);
     
    186198        buttonForEvent(event),
    187199        pressedMouseButtons(state),
    188         IntPoint(x, y),
    189         IntPoint(xRoot, yRoot),
     200        position,
     201        globalPosition,
    190202        movementDelta.x(),
    191203        movementDelta.y(),
     
    194206        modifiersForEvent(event),
    195207        wallTimeForEvent(event));
     208}
     209
     210WebMouseEvent WebEventFactory::createWebMouseEvent(const IntPoint& position)
     211{
     212    // Mouse events without GdkEvent are crossing events, handled as a mouse move.
     213    return WebMouseEvent(WebEvent::MouseMove, WebMouseEvent::NoButton, 0, position, position, 0, 0, 0, 0, { }, WallTime::now());
    196214}
    197215
  • trunk/Source/WebKit/Shared/gtk/WebEventFactory.h

    r260817 r260819  
    4040public:
    4141    static WebMouseEvent createWebMouseEvent(const GdkEvent*, int, Optional<WebCore::IntPoint>);
     42    static WebMouseEvent createWebMouseEvent(const GdkEvent*, const WebCore::IntPoint&, const WebCore::IntPoint&, int, Optional<WebCore::IntPoint>);
     43    static WebMouseEvent createWebMouseEvent(const WebCore::IntPoint&);
    4244    static WebWheelEvent createWebWheelEvent(const GdkEvent*);
    4345    static WebWheelEvent createWebWheelEvent(const GdkEvent*, WebWheelEvent::Phase, WebWheelEvent::Phase momentumPhase);
  • trunk/Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

    r260817 r260819  
    11121112#endif
    11131113
     1114#if USE(GTK4)
     1115static void webkitWebViewBaseEnter(WebKitWebViewBase* webViewBase, double x, double y, GdkCrossingMode, GtkEventController*)
     1116{
     1117    WebKitWebViewBasePrivate* priv = webViewBase->priv;
     1118    if (priv->dialog)
     1119        return;
     1120
     1121#if ENABLE(DEVELOPER_MODE)
     1122    // Do not send mouse move events to the WebProcess for crossing events during testing.
     1123    // WTR never generates crossing events and they can confuse tests.
     1124    // https://bugs.webkit.org/show_bug.cgi?id=185072.
     1125    if (UNLIKELY(priv->pageProxy->process().processPool().configuration().fullySynchronousModeIsAllowedForTesting()))
     1126        return;
     1127#endif
     1128
     1129    priv->pageProxy->handleMouseEvent(NativeWebMouseEvent({ clampToInteger(x), clampToInteger(y) }));
     1130}
     1131
     1132static gboolean webkitWebViewBaseMotion(WebKitWebViewBase* webViewBase, double x, double y, GtkEventController* controller)
     1133{
     1134    // FIXME: Forward event to dialog.
     1135    // FIXME: Pointer lock.
     1136    webViewBase->priv->pageProxy->handleMouseEvent(NativeWebMouseEvent(gtk_event_controller_get_current_event(controller), { clampToInteger(x), clampToInteger(y) }, 0, WTF::nullopt));
     1137
     1138    return GDK_EVENT_PROPAGATE;
     1139}
     1140
     1141static void webkitWebViewBaseLeave(WebKitWebViewBase* webViewBase, GdkCrossingMode, GtkEventController*)
     1142{
     1143    WebKitWebViewBasePrivate* priv = webViewBase->priv;
     1144    if (priv->dialog)
     1145        return;
     1146
     1147#if ENABLE(DEVELOPER_MODE)
     1148    // Do not send mouse move events to the WebProcess for crossing events during testing.
     1149    // WTR never generates crossing events and they can confuse tests.
     1150    // https://bugs.webkit.org/show_bug.cgi?id=185072.
     1151    if (UNLIKELY(priv->pageProxy->process().processPool().configuration().fullySynchronousModeIsAllowedForTesting()))
     1152        return;
     1153#endif
     1154
     1155    priv->pageProxy->handleMouseEvent(NativeWebMouseEvent({ -1, -1 }));
     1156}
     1157#endif
     1158
    11141159#if ENABLE(TOUCH_EVENTS) && !USE(GTK4)
    11151160static void appendTouchEvent(Vector<WebPlatformTouchPoint>& touchPoints, const GdkEvent* event, WebPlatformTouchPoint::TouchPointState state)
     
    15221567    g_signal_connect_object(controller, "scroll", G_CALLBACK(webkitWebViewBaseScroll), viewWidget, G_CONNECT_SWAPPED);
    15231568    gtk_widget_add_controller(viewWidget, controller);
     1569
     1570    controller = gtk_event_controller_motion_new();
     1571    g_signal_connect_object(controller, "enter", G_CALLBACK(webkitWebViewBaseEnter), viewWidget, G_CONNECT_SWAPPED);
     1572    g_signal_connect_object(controller, "motion", G_CALLBACK(webkitWebViewBaseMotion), viewWidget, G_CONNECT_SWAPPED);
     1573    g_signal_connect_object(controller, "leave", G_CALLBACK(webkitWebViewBaseLeave), viewWidget, G_CONNECT_SWAPPED);
     1574    gtk_widget_add_controller(viewWidget, controller);
    15241575#endif
    15251576}
  • trunk/Tools/ChangeLog

    r260816 r260819  
     12020-04-27  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK4] Add support for motion events
     4        https://bugs.webkit.org/show_bug.cgi?id=211073
     5
     6        Reviewed by Adrian Perez de Castro.
     7
     8        Use the GtkOverlay in GTK4 too so that status label is shown when hovering elements.
     9
     10        * MiniBrowser/gtk/BrowserTab.c:
     11        (browserTabConstructed):
     12
    1132020-04-28  Carlos Garcia Campos  <cgarcia@igalia.com>
    214
  • trunk/Tools/MiniBrowser/gtk/BrowserTab.c

    r260816 r260819  
    399399    tab->searchBar = BROWSER_SEARCH_BAR(browser_search_bar_new(tab->webView));
    400400    gtk_box_pack_start(GTK_BOX(tab), GTK_WIDGET(tab->searchBar), FALSE, FALSE, 0);
     401#endif
    401402
    402403    GtkWidget *overlay = gtk_overlay_new();
    403     gtk_box_pack_start(GTK_BOX(tab), overlay, TRUE, TRUE, 0);
     404    gtk_container_add(GTK_CONTAINER(tab), overlay);
    404405    gtk_widget_show(overlay);
    405406
     
    407408    gtk_widget_set_halign(tab->statusLabel, GTK_ALIGN_START);
    408409    gtk_widget_set_valign(tab->statusLabel, GTK_ALIGN_END);
     410#if !GTK_CHECK_VERSION(3, 98, 0)
    409411    gtk_widget_set_margin_left(tab->statusLabel, 1);
    410412    gtk_widget_set_margin_right(tab->statusLabel, 1);
    411413    gtk_widget_set_margin_top(tab->statusLabel, 1);
    412414    gtk_widget_set_margin_bottom(tab->statusLabel, 1);
     415#endif
    413416    gtk_overlay_add_overlay(GTK_OVERLAY(overlay), tab->statusLabel);
    414417
     
    416419    gtk_widget_set_halign(tab->fullScreenMessageLabel, GTK_ALIGN_CENTER);
    417420    gtk_widget_set_valign(tab->fullScreenMessageLabel, GTK_ALIGN_CENTER);
     421#if !GTK_CHECK_VERSION(3, 98, 0)
    418422    gtk_widget_set_no_show_all(tab->fullScreenMessageLabel, TRUE);
     423#endif
    419424    gtk_overlay_add_overlay(GTK_OVERLAY(overlay), tab->fullScreenMessageLabel);
    420425
     
    422427    gtk_widget_set_halign(tab->pointerLockMessageLabel, GTK_ALIGN_CENTER);
    423428    gtk_widget_set_valign(tab->pointerLockMessageLabel, GTK_ALIGN_START);
     429#if !GTK_CHECK_VERSION(3, 98, 0)
    424430    gtk_widget_set_no_show_all(tab->pointerLockMessageLabel, TRUE);
     431#endif
    425432    gtk_overlay_add_overlay(GTK_OVERLAY(overlay), tab->pointerLockMessageLabel);
    426433
     434    gtk_widget_set_vexpand(GTK_WIDGET(tab->webView), TRUE);
    427435    gtk_container_add(GTK_CONTAINER(overlay), GTK_WIDGET(tab->webView));
    428436    gtk_widget_show(GTK_WIDGET(tab->webView));
    429 #else
    430     gtk_widget_set_vexpand(GTK_WIDGET(tab->webView), TRUE);
    431     gtk_container_add(GTK_CONTAINER(tab), GTK_WIDGET(tab->webView));
    432 #endif
    433437
    434438#if !GTK_CHECK_VERSION(3, 98, 0)
Note: See TracChangeset for help on using the changeset viewer.