Changeset 260508 in webkit


Ignore:
Timestamp:
Apr 22, 2020 6:26:20 AM (4 years ago)
Author:
Claudio Saavedra
Message:

[GTK4] Several fixes to GdkEvent APIs for GTK4
https://bugs.webkit.org/show_bug.cgi?id=210856

Reviewed by Carlos Garcia Campos.

Source/WebCore:

No tests needed.

Several fixes to GdkEvent API changes for GTK4. This is far from
complete but it allows the GTK4 build to move forward. When
possible, add GTK3-API replacements to GtkVersioning.h to avoid
#ifdef blocks, where the API changes are too complex, just #ifdef.

  • platform/gtk/GtkUtilities.cpp:

(WebCore::wallTimeForEvent):

  • platform/gtk/GtkVersioning.h:

(gdk_event_get_state):
(gdk_event_get_coords):
(gdk_event_get_root_coords):
(gdk_event_is_scroll_stop_event):
(gdk_event_get_scroll_direction):
(gdk_event_get_scroll_deltas):
(gdk_event_get_button):
(gdk_keymap_get_for_display): Deleted as it was wrong and
it's not needed.

  • platform/gtk/PlatformKeyboardEventGtk.cpp:

(WebCore::PlatformKeyboardEvent::currentCapsLockState):
(WebCore::PlatformKeyboardEvent::getCurrentModifierState):
(WebCore::PlatformKeyboardEvent::modifiersContainCapsLock):

  • platform/gtk/PlatformWheelEventGtk.cpp:

(WebCore::PlatformWheelEvent::PlatformWheelEvent):

Source/WTF:

  • wtf/glib/GTypedefs.h: In GTK4 GdkEvent is a struct.
Location:
trunk/Source
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r260486 r260508  
     12020-04-22  Claudio Saavedra  <csaavedra@igalia.com>
     2
     3        [GTK4] Several fixes to GdkEvent APIs for GTK4
     4        https://bugs.webkit.org/show_bug.cgi?id=210856
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        * wtf/glib/GTypedefs.h: In GTK4 GdkEvent is a struct.
     9
    1102020-04-21  Peng Liu  <peng.liu6@apple.com>
    211
  • trunk/Source/WTF/wtf/glib/GTypedefs.h

    r260425 r260508  
    6464typedef struct _GVariantIter GVariantIter;
    6565typedef struct _GVariantType GVariantType;
     66#if USE(GTK4)
     67typedef struct _GdkEvent GdkEvent;
     68#else
    6669typedef union _GdkEvent GdkEvent;
     70#endif
    6771typedef struct _GTimer GTimer;
    6872typedef struct _GKeyFile GKeyFile;
  • trunk/Source/WebCore/ChangeLog

    r260507 r260508  
     12020-04-22  Claudio Saavedra  <csaavedra@igalia.com>
     2
     3        [GTK4] Several fixes to GdkEvent APIs for GTK4
     4        https://bugs.webkit.org/show_bug.cgi?id=210856
     5
     6        Reviewed by Carlos Garcia Campos.
     7
     8        No tests needed.
     9
     10        Several fixes to GdkEvent API changes for GTK4. This is far from
     11        complete but it allows the GTK4 build to move forward. When
     12        possible, add GTK3-API replacements to GtkVersioning.h to avoid
     13        #ifdef blocks, where the API changes are too complex, just #ifdef.
     14
     15        * platform/gtk/GtkUtilities.cpp:
     16        (WebCore::wallTimeForEvent):
     17        * platform/gtk/GtkVersioning.h:
     18        (gdk_event_get_state):
     19        (gdk_event_get_coords):
     20        (gdk_event_get_root_coords):
     21        (gdk_event_is_scroll_stop_event):
     22        (gdk_event_get_scroll_direction):
     23        (gdk_event_get_scroll_deltas):
     24        (gdk_event_get_button):
     25        (gdk_keymap_get_for_display): Deleted as it was wrong and
     26        it's not needed.
     27        * platform/gtk/PlatformKeyboardEventGtk.cpp:
     28        (WebCore::PlatformKeyboardEvent::currentCapsLockState):
     29        (WebCore::PlatformKeyboardEvent::getCurrentModifierState):
     30        (WebCore::PlatformKeyboardEvent::modifiersContainCapsLock):
     31        * platform/gtk/PlatformWheelEventGtk.cpp:
     32        (WebCore::PlatformWheelEvent::PlatformWheelEvent):
     33
    1342020-04-22  Youenn Fablet  <youenn@apple.com>
    235
  • trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp

    r260125 r260508  
    7777    // g_get_monotonic_time() continues to do so as well, and so long as
    7878    // WTF::MonotonicTime continues to use g_get_monotonic_time().
     79#if USE(GTK4)
     80    auto time = gdk_event_get_time(const_cast<GdkEvent*>(event));
     81#else
    7982    auto time = gdk_event_get_time(event);
     83#endif
    8084    if (time == GDK_CURRENT_TIME)
    8185        return WallTime::now();
  • trunk/Source/WebCore/platform/gtk/GtkVersioning.h

    r260255 r260508  
    5858}
    5959
    60 static inline GdkKeymap*
    61 gdk_keymap_get_for_display(GdkDisplay *display)
     60#define GDK_MOD1_MASK GDK_ALT_MASK
     61
     62static inline gboolean
     63gdk_event_get_state(GdkEvent *event, GdkModifierType *state)
    6264{
    63     return gdk_display_get_keymap(display);
     65    *state = gdk_event_get_modifier_state(event);
     66    // The GTK3 method returns TRUE if there is a state, otherwise
     67    // FALSE.
     68    return !!*state;
    6469}
    6570
     71static inline gboolean
     72gdk_event_get_coords(GdkEvent *event, double *x, double *y)
     73{
     74    return gdk_event_get_position(event, x, y);
     75}
     76
     77static inline gboolean
     78gdk_event_get_root_coords(GdkEvent *event, double *x, double *y)
     79{
     80    // GTK4 does not provide a way of obtaining screen-relative event coordinates, and even
     81    // on Wayland GTK3 cannot know where a surface is and will return the surface-relative
     82    // coordinates anyway, so do the same here.
     83    return gdk_event_get_position(event, x, y);
     84}
     85
     86static inline gboolean
     87gdk_event_is_scroll_stop_event(GdkEvent* event)
     88{
     89    return gdk_scroll_event_is_stop(event);
     90}
     91
     92static inline gboolean
     93gdk_event_get_scroll_direction(GdkEvent* event, GdkScrollDirection* direction)
     94{
     95    *direction = gdk_scroll_event_get_direction(event);
     96    // The GTK3 method returns TRUE if the scroll direction is not
     97    // GDK_SCROLL_SMOOTH, so do the same here.
     98    return *direction != GDK_SCROLL_SMOOTH;
     99}
     100
     101static inline gboolean
     102gdk_event_get_scroll_deltas(GdkEvent* event, gdouble *x, gdouble *y)
     103{
     104    gdk_scroll_event_get_deltas(event, x, y);
     105    // The GTK3 method returns TRUE if the event is a smooth scroll
     106    // event, so do the same here.
     107    return gdk_scroll_event_get_direction(event) == GDK_SCROLL_SMOOTH;
     108}
     109
     110static inline gboolean
     111gdk_event_get_button(GdkEvent* event)
     112{
     113    return gdk_button_event_get_button(event);
     114}
    66115#endif // USE(GTK4)
  • trunk/Source/WebCore/platform/gtk/PlatformKeyboardEventGtk.cpp

    r260255 r260508  
    13431343bool PlatformKeyboardEvent::currentCapsLockState()
    13441344{
     1345#if USE(GTK4)
     1346    return gdk_device_get_caps_lock_state(gdk_seat_get_keyboard(gdk_display_get_default_seat(gdk_display_get_default())));
     1347#else
    13451348    return gdk_keymap_get_caps_lock_state(gdk_keymap_get_for_display(gdk_display_get_default()));
     1349#endif
    13461350}
    13471351
     
    13491353{
    13501354    GdkModifierType state;
     1355#if USE(GTK4)
     1356    state = static_cast<GdkModifierType>(0);
     1357#else
    13511358    gtk_get_current_event_state(&state);
     1359#endif
    13521360
    13531361    shiftKey = state & GDK_SHIFT_MASK;
     
    13711379        GUniqueOutPtr<GdkKeymapKey> keys;
    13721380        int entriesCount;
     1381#if USE(GTK4)
     1382        lockMaskIsCapsLock = gdk_display_map_keyval(gdk_display_get_default(), GDK_KEY_Caps_Lock, &keys.outPtr(), &entriesCount) && entriesCount;
     1383#else
    13731384        lockMaskIsCapsLock = gdk_keymap_get_entries_for_keyval(gdk_keymap_get_for_display(gdk_display_get_default()), GDK_KEY_Caps_Lock, &keys.outPtr(), &entriesCount) && entriesCount;
     1385#endif
    13741386    }
    13751387    return lockMaskIsCapsLock;
  • trunk/Source/WebCore/platform/gtk/PlatformWheelEventGtk.cpp

    r260008 r260508  
    3131#include "FloatPoint.h"
    3232#include "GtkUtilities.h"
     33#include "GtkVersioning.h"
    3334#include "PlatformKeyboardEvent.h"
    3435#include "Scrollbar.h"
     
    4849    m_timestamp = wallTimeForEvent(event);
    4950
    50 #if USE(GTK4)
    51     state = gdk_event_get_modifier_state(reinterpret_cast<GdkEvent*>(event));
    52 #else
    5351    gdk_event_get_state(reinterpret_cast<GdkEvent*>(event), &state);
    54 #endif
    5552
    5653    if (state & GDK_SHIFT_MASK)
     
    6966    GdkScrollDirection direction;
    7067
    71 #if USE(GTK4)
    72     direction = gdk_scroll_event_get_direction(reinterpret_cast<GdkEvent*>(event));
    73     if (direction == GDK_SCROLL_SMOOTH) {
    74         double deltaX, deltaY;
    75         gdk_scroll_event_get_deltas(reinterpret_cast<GdkEvent*>(event), &deltaX, &deltaY);
    76         m_deltaX = -deltaX;
    77         m_deltaY = -deltaY;
    78     }
    79 #else
    8068    if (!gdk_event_get_scroll_direction(reinterpret_cast<GdkEvent*>(event), &direction)) {
    8169        direction = GDK_SCROLL_SMOOTH;
     
    8674        }
    8775    }
    88 #endif
    8976
    9077    // Docs say an upwards scroll (away from the user) has a positive delta
     
    113100
    114101#if ENABLE(KINETIC_SCROLLING)
    115 #if USE(GTK4)
    116     const auto isStopEvent = gdk_scroll_event_is_stop(reinterpret_cast<GdkEvent*>(event));
    117 #else
    118102    const auto isStopEvent = gdk_event_is_scroll_stop_event(reinterpret_cast<GdkEvent*>(event));
    119 #endif
    120103    m_phase = isStopEvent ?  PlatformWheelEventPhaseEnded : PlatformWheelEventPhaseChanged;
    121104#endif // ENABLE(KINETIC_SCROLLING)
    122105
    123106    gdouble x, y, rootX, rootY;
    124 #if USE(GTK4)
    125     gdk_event_get_position(reinterpret_cast<GdkEvent*>(event), &x, &y);
    126     // GTK4 does not provide a way of obtaining screen-relative event coordinates, and even
    127     // on Wayland GTK3 cannot know where a surface is and will return the surface-relative
    128     // coordinates anyway, so do the same here.
    129     rootX = x;
    130     rootY = y;
    131 #else
    132107    gdk_event_get_coords(reinterpret_cast<GdkEvent*>(event), &x, &y);
    133108    gdk_event_get_root_coords(reinterpret_cast<GdkEvent*>(event), &rootX, &rootY);
    134 #endif
    135109
    136110    m_position = IntPoint(static_cast<int>(x), static_cast<int>(y));
Note: See TracChangeset for help on using the changeset viewer.