Title: [260508] trunk/Source
Revision
260508
Author
csaave...@igalia.com
Date
2020-04-22 06:26:20 -0700 (Wed, 22 Apr 2020)

Log 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.

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (260507 => 260508)


--- trunk/Source/WTF/ChangeLog	2020-04-22 11:48:44 UTC (rev 260507)
+++ trunk/Source/WTF/ChangeLog	2020-04-22 13:26:20 UTC (rev 260508)
@@ -1,3 +1,12 @@
+2020-04-22  Claudio Saavedra  <csaave...@igalia.com>
+
+        [GTK4] Several fixes to GdkEvent APIs for GTK4
+        https://bugs.webkit.org/show_bug.cgi?id=210856
+
+        Reviewed by Carlos Garcia Campos.
+
+        * wtf/glib/GTypedefs.h: In GTK4 GdkEvent is a struct.
+
 2020-04-21  Peng Liu  <peng.l...@apple.com>
 
         Fix MACCATALYST build failures

Modified: trunk/Source/WTF/wtf/glib/GTypedefs.h (260507 => 260508)


--- trunk/Source/WTF/wtf/glib/GTypedefs.h	2020-04-22 11:48:44 UTC (rev 260507)
+++ trunk/Source/WTF/wtf/glib/GTypedefs.h	2020-04-22 13:26:20 UTC (rev 260508)
@@ -63,7 +63,11 @@
 typedef struct _GVariantBuilder GVariantBuilder;
 typedef struct _GVariantIter GVariantIter;
 typedef struct _GVariantType GVariantType;
+#if USE(GTK4)
+typedef struct _GdkEvent GdkEvent;
+#else
 typedef union _GdkEvent GdkEvent;
+#endif
 typedef struct _GTimer GTimer;
 typedef struct _GKeyFile GKeyFile;
 typedef struct _GPtrArray GPtrArray;

Modified: trunk/Source/WebCore/ChangeLog (260507 => 260508)


--- trunk/Source/WebCore/ChangeLog	2020-04-22 11:48:44 UTC (rev 260507)
+++ trunk/Source/WebCore/ChangeLog	2020-04-22 13:26:20 UTC (rev 260508)
@@ -1,3 +1,36 @@
+2020-04-22  Claudio Saavedra  <csaave...@igalia.com>
+
+        [GTK4] Several fixes to GdkEvent APIs for GTK4
+        https://bugs.webkit.org/show_bug.cgi?id=210856
+
+        Reviewed by Carlos Garcia Campos.
+
+        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):
+
 2020-04-22  Youenn Fablet  <you...@apple.com>
 
         Simplify SWServerWorker::whenActivated logic

Modified: trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp (260507 => 260508)


--- trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp	2020-04-22 11:48:44 UTC (rev 260507)
+++ trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp	2020-04-22 13:26:20 UTC (rev 260508)
@@ -76,7 +76,11 @@
     // be using CLOCK_MONOTONIC for its monotonic time, and so long as
     // g_get_monotonic_time() continues to do so as well, and so long as
     // WTF::MonotonicTime continues to use g_get_monotonic_time().
+#if USE(GTK4)
+    auto time = gdk_event_get_time(const_cast<GdkEvent*>(event));
+#else
     auto time = gdk_event_get_time(event);
+#endif
     if (time == GDK_CURRENT_TIME)
         return WallTime::now();
     return MonotonicTime::fromRawSeconds(time / 1000.).approximateWallTime();

Modified: trunk/Source/WebCore/platform/gtk/GtkVersioning.h (260507 => 260508)


--- trunk/Source/WebCore/platform/gtk/GtkVersioning.h	2020-04-22 11:48:44 UTC (rev 260507)
+++ trunk/Source/WebCore/platform/gtk/GtkVersioning.h	2020-04-22 13:26:20 UTC (rev 260508)
@@ -57,10 +57,59 @@
     return gtk_init_check();
 }
 
-static inline GdkKeymap*
-gdk_keymap_get_for_display(GdkDisplay *display)
+#define GDK_MOD1_MASK GDK_ALT_MASK
+
+static inline gboolean
+gdk_event_get_state(GdkEvent *event, GdkModifierType *state)
 {
-    return gdk_display_get_keymap(display);
+    *state = gdk_event_get_modifier_state(event);
+    // The GTK3 method returns TRUE if there is a state, otherwise
+    // FALSE.
+    return !!*state;
 }
 
+static inline gboolean
+gdk_event_get_coords(GdkEvent *event, double *x, double *y)
+{
+    return gdk_event_get_position(event, x, y);
+}
+
+static inline gboolean
+gdk_event_get_root_coords(GdkEvent *event, double *x, double *y)
+{
+    // GTK4 does not provide a way of obtaining screen-relative event coordinates, and even
+    // on Wayland GTK3 cannot know where a surface is and will return the surface-relative
+    // coordinates anyway, so do the same here.
+    return gdk_event_get_position(event, x, y);
+}
+
+static inline gboolean
+gdk_event_is_scroll_stop_event(GdkEvent* event)
+{
+    return gdk_scroll_event_is_stop(event);
+}
+
+static inline gboolean
+gdk_event_get_scroll_direction(GdkEvent* event, GdkScrollDirection* direction)
+{
+    *direction = gdk_scroll_event_get_direction(event);
+    // The GTK3 method returns TRUE if the scroll direction is not
+    // GDK_SCROLL_SMOOTH, so do the same here.
+    return *direction != GDK_SCROLL_SMOOTH;
+}
+
+static inline gboolean
+gdk_event_get_scroll_deltas(GdkEvent* event, gdouble *x, gdouble *y)
+{
+    gdk_scroll_event_get_deltas(event, x, y);
+    // The GTK3 method returns TRUE if the event is a smooth scroll
+    // event, so do the same here.
+    return gdk_scroll_event_get_direction(event) == GDK_SCROLL_SMOOTH;
+}
+
+static inline gboolean
+gdk_event_get_button(GdkEvent* event)
+{
+    return gdk_button_event_get_button(event);
+}
 #endif // USE(GTK4)

Modified: trunk/Source/WebCore/platform/gtk/PlatformKeyboardEventGtk.cpp (260507 => 260508)


--- trunk/Source/WebCore/platform/gtk/PlatformKeyboardEventGtk.cpp	2020-04-22 11:48:44 UTC (rev 260507)
+++ trunk/Source/WebCore/platform/gtk/PlatformKeyboardEventGtk.cpp	2020-04-22 13:26:20 UTC (rev 260508)
@@ -1342,13 +1342,21 @@
 
 bool PlatformKeyboardEvent::currentCapsLockState()
 {
+#if USE(GTK4)
+    return gdk_device_get_caps_lock_state(gdk_seat_get_keyboard(gdk_display_get_default_seat(gdk_display_get_default())));
+#else
     return gdk_keymap_get_caps_lock_state(gdk_keymap_get_for_display(gdk_display_get_default()));
+#endif
 }
 
 void PlatformKeyboardEvent::getCurrentModifierState(bool& shiftKey, bool& ctrlKey, bool& altKey, bool& metaKey)
 {
     GdkModifierType state;
+#if USE(GTK4)
+    state = static_cast<GdkModifierType>(0);
+#else
     gtk_get_current_event_state(&state);
+#endif
 
     shiftKey = state & GDK_SHIFT_MASK;
     ctrlKey = state & GDK_CONTROL_MASK;
@@ -1370,7 +1378,11 @@
     if (!initialized) {
         GUniqueOutPtr<GdkKeymapKey> keys;
         int entriesCount;
+#if USE(GTK4)
+        lockMaskIsCapsLock = gdk_display_map_keyval(gdk_display_get_default(), GDK_KEY_Caps_Lock, &keys.outPtr(), &entriesCount) && entriesCount;
+#else
         lockMaskIsCapsLock = gdk_keymap_get_entries_for_keyval(gdk_keymap_get_for_display(gdk_display_get_default()), GDK_KEY_Caps_Lock, &keys.outPtr(), &entriesCount) && entriesCount;
+#endif
     }
     return lockMaskIsCapsLock;
 }

Modified: trunk/Source/WebCore/platform/gtk/PlatformWheelEventGtk.cpp (260507 => 260508)


--- trunk/Source/WebCore/platform/gtk/PlatformWheelEventGtk.cpp	2020-04-22 11:48:44 UTC (rev 260507)
+++ trunk/Source/WebCore/platform/gtk/PlatformWheelEventGtk.cpp	2020-04-22 13:26:20 UTC (rev 260508)
@@ -30,6 +30,7 @@
 
 #include "FloatPoint.h"
 #include "GtkUtilities.h"
+#include "GtkVersioning.h"
 #include "PlatformKeyboardEvent.h"
 #include "Scrollbar.h"
 #include <gdk/gdk.h>
@@ -47,11 +48,7 @@
     m_type = PlatformEvent::Wheel;
     m_timestamp = wallTimeForEvent(event);
 
-#if USE(GTK4)
-    state = gdk_event_get_modifier_state(reinterpret_cast<GdkEvent*>(event));
-#else
     gdk_event_get_state(reinterpret_cast<GdkEvent*>(event), &state);
-#endif
 
     if (state & GDK_SHIFT_MASK)
         m_modifiers.add(Modifier::ShiftKey);
@@ -68,15 +65,6 @@
     m_deltaY = 0;
     GdkScrollDirection direction;
 
-#if USE(GTK4)
-    direction = gdk_scroll_event_get_direction(reinterpret_cast<GdkEvent*>(event));
-    if (direction == GDK_SCROLL_SMOOTH) {
-        double deltaX, deltaY;
-        gdk_scroll_event_get_deltas(reinterpret_cast<GdkEvent*>(event), &deltaX, &deltaY);
-        m_deltaX = -deltaX;
-        m_deltaY = -deltaY;
-    }
-#else
     if (!gdk_event_get_scroll_direction(reinterpret_cast<GdkEvent*>(event), &direction)) {
         direction = GDK_SCROLL_SMOOTH;
         gdouble deltaX, deltaY;
@@ -85,7 +73,6 @@
             m_deltaY = -deltaY;
         }
     }
-#endif
 
     // Docs say an upwards scroll (away from the user) has a positive delta
     if (!m_deltaX && !m_deltaY) {
@@ -112,26 +99,13 @@
     m_wheelTicksY = m_deltaY;
 
 #if ENABLE(KINETIC_SCROLLING)
-#if USE(GTK4)
-    const auto isStopEvent = gdk_scroll_event_is_stop(reinterpret_cast<GdkEvent*>(event));
-#else
     const auto isStopEvent = gdk_event_is_scroll_stop_event(reinterpret_cast<GdkEvent*>(event));
-#endif
     m_phase = isStopEvent ?  PlatformWheelEventPhaseEnded : PlatformWheelEventPhaseChanged;
 #endif // ENABLE(KINETIC_SCROLLING)
 
     gdouble x, y, rootX, rootY;
-#if USE(GTK4)
-    gdk_event_get_position(reinterpret_cast<GdkEvent*>(event), &x, &y);
-    // GTK4 does not provide a way of obtaining screen-relative event coordinates, and even
-    // on Wayland GTK3 cannot know where a surface is and will return the surface-relative
-    // coordinates anyway, so do the same here.
-    rootX = x;
-    rootY = y;
-#else
     gdk_event_get_coords(reinterpret_cast<GdkEvent*>(event), &x, &y);
     gdk_event_get_root_coords(reinterpret_cast<GdkEvent*>(event), &rootX, &rootY);
-#endif
 
     m_position = IntPoint(static_cast<int>(x), static_cast<int>(y));
     m_globalPosition = IntPoint(static_cast<int>(rootX), static_cast<int>(rootY));
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to