- Revision
- 260125
- Author
- [email protected]
- Date
- 2020-04-15 07:25:12 -0700 (Wed, 15 Apr 2020)
Log Message
[GTK4] Provide an alternative to gtk_widget_{get,is}_toplevel()
https://bugs.webkit.org/show_bug.cgi?id=210463
Reviewed by Carlos Garcia Campos.
Source/WebCore:
Adapt utility functions to GTK4, and provide replacement implementations for the
gtk_widget_get_tolevel() and gtk_widget_is_toplevel() functions for GTK4 builds.
No new tests needed.
* platform/gtk/GtkUtilities.cpp:
(WebCore::gtkWindowGetOrigin): Added.
(WebCore::convertWidgetPointToScreenPoint): Move code used to find the window position
into a separate function, and use it to avoid the USE(GTK4) conditional here.
(WebCore::widgetIsOnscreenToplevelWindow): Adapt to make it work with GTK4.
* platform/gtk/GtkVersioning.h: Added.
(gtk_widget_is_toplevel): Alternative implementation for GTK4.
(gtk_widget_get_toplevel): Ditto.
(gtk_window_get_position): Ditto.
Source/WebKit:
* UIProcess/API/glib/WebKitUIClient.cpp: Adapt to take into account that GTK4 does not
provide the GtkWidget.configure-event signal.
Modified Paths
Added Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (260124 => 260125)
--- trunk/Source/WebCore/ChangeLog 2020-04-15 13:50:25 UTC (rev 260124)
+++ trunk/Source/WebCore/ChangeLog 2020-04-15 14:25:12 UTC (rev 260125)
@@ -1,5 +1,27 @@
2020-04-15 Adrian Perez de Castro <[email protected]>
+ [GTK4] Provide an alternative to gtk_widget_{get,is}_toplevel()
+ https://bugs.webkit.org/show_bug.cgi?id=210463
+
+ Reviewed by Carlos Garcia Campos.
+
+ Adapt utility functions to GTK4, and provide replacement implementations for the
+ gtk_widget_get_tolevel() and gtk_widget_is_toplevel() functions for GTK4 builds.
+
+ No new tests needed.
+
+ * platform/gtk/GtkUtilities.cpp:
+ (WebCore::gtkWindowGetOrigin): Added.
+ (WebCore::convertWidgetPointToScreenPoint): Move code used to find the window position
+ into a separate function, and use it to avoid the USE(GTK4) conditional here.
+ (WebCore::widgetIsOnscreenToplevelWindow): Adapt to make it work with GTK4.
+ * platform/gtk/GtkVersioning.h: Added.
+ (gtk_widget_is_toplevel): Alternative implementation for GTK4.
+ (gtk_widget_get_toplevel): Ditto.
+ (gtk_window_get_position): Ditto.
+
+2020-04-15 Adrian Perez de Castro <[email protected]>
+
[GTK4] Adapt to cursor API changes
https://bugs.webkit.org/show_bug.cgi?id=210453
Modified: trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp (260124 => 260125)
--- trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp 2020-04-15 13:50:25 UTC (rev 260124)
+++ trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp 2020-04-15 14:25:12 UTC (rev 260125)
@@ -19,6 +19,7 @@
#include "config.h"
#include "GtkUtilities.h"
+#include "GtkVersioning.h"
#include "IntPoint.h"
#include <gtk/gtk.h>
#include <wtf/glib/GUniquePtr.h>
@@ -25,6 +26,20 @@
namespace WebCore {
+static IntPoint gtkWindowGetOrigin(GtkWidget* window)
+{
+ int x = 0, y = 0;
+
+#if USE(GTK4)
+ UNUSED_PARAM(window);
+#else
+ if (auto* gdkWindow = gtk_widget_get_window(window))
+ gdk_window_get_origin(gdkWindow, &x, &y);
+#endif // !USE(GTK4)
+
+ return IntPoint(x, y);
+}
+
IntPoint convertWidgetPointToScreenPoint(GtkWidget* widget, const IntPoint& point)
{
// FIXME: This is actually a very tricky operation and the results of this function should
@@ -35,22 +50,23 @@
if (!toplevelWidget || !gtk_widget_is_toplevel(toplevelWidget) || !GTK_IS_WINDOW(toplevelWidget))
return point;
- GdkWindow* gdkWindow = gtk_widget_get_window(toplevelWidget);
- if (!gdkWindow)
- return point;
-
int xInWindow, yInWindow;
gtk_widget_translate_coordinates(widget, toplevelWidget, point.x(), point.y(), &xInWindow, &yInWindow);
- int windowOriginX, windowOriginY;
- gdk_window_get_origin(gdkWindow, &windowOriginX, &windowOriginY);
-
- return IntPoint(windowOriginX + xInWindow, windowOriginY + yInWindow);
+ const auto origin = gtkWindowGetOrigin(toplevelWidget);
+ return IntPoint(origin.x() + xInWindow, origin.y() + yInWindow);
}
bool widgetIsOnscreenToplevelWindow(GtkWidget* widget)
{
- return widget && gtk_widget_is_toplevel(widget) && GTK_IS_WINDOW(widget) && !GTK_IS_OFFSCREEN_WINDOW(widget);
+ const bool isToplevelWidget = widget && gtk_widget_is_toplevel(widget);
+
+#if USE(GTK4)
+ // A toplevel widget in GTK4 is always a window, there is no need for further checks.
+ return isToplevelWidget;
+#else
+ return isToplevelWidget && GTK_IS_WINDOW(widget) && !GTK_IS_OFFSCREEN_WINDOW(widget);
+#endif // USE(GTK4)
}
template<>
Added: trunk/Source/WebCore/platform/gtk/GtkVersioning.h (0 => 260125)
--- trunk/Source/WebCore/platform/gtk/GtkVersioning.h (rev 0)
+++ trunk/Source/WebCore/platform/gtk/GtkVersioning.h 2020-04-15 14:25:12 UTC (rev 260125)
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2020 Igalia S.L.
+ * All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#pragma once
+
+#include <gtk/gtk.h>
+
+#if USE(GTK4)
+
+static inline gboolean
+gtk_widget_is_toplevel(GtkWidget* widget)
+{
+ // In theory anything which implements GtkRoot can be a toplevel widget,
+ // in practice only the ones which are GtkWindow or derived need to be
+ // considered here.
+ return GTK_IS_WINDOW(widget);
+}
+
+static inline GtkWidget*
+gtk_widget_get_toplevel(GtkWidget* widget)
+{
+ return GTK_WIDGET(gtk_widget_get_root(widget));
+}
+
+static inline void
+gtk_window_get_position(GtkWindow*, int* x, int* y)
+{
+ *x = *y = 0;
+}
+
+#endif // USE(GTK4)
Modified: trunk/Source/WebKit/ChangeLog (260124 => 260125)
--- trunk/Source/WebKit/ChangeLog 2020-04-15 13:50:25 UTC (rev 260124)
+++ trunk/Source/WebKit/ChangeLog 2020-04-15 14:25:12 UTC (rev 260125)
@@ -1,3 +1,13 @@
+2020-04-15 Adrian Perez de Castro <[email protected]>
+
+ [GTK4] Provide an alternative to gtk_widget_{get,is}_toplevel()
+ https://bugs.webkit.org/show_bug.cgi?id=210463
+
+ Reviewed by Carlos Garcia Campos.
+
+ * UIProcess/API/glib/WebKitUIClient.cpp: Adapt to take into account that GTK4 does not
+ provide the GtkWidget.configure-event signal.
+
2020-04-15 Said Abou-Hallawa <[email protected]>
Unreviewed, reverting r259891.
Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp (260124 => 260125)
--- trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp 2020-04-15 13:50:25 UTC (rev 260124)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp 2020-04-15 14:25:12 UTC (rev 260125)
@@ -139,7 +139,7 @@
webkitWindowPropertiesSetResizable(webkit_web_view_get_window_properties(m_webView), resizable);
}
-#if PLATFORM(GTK)
+#if PLATFORM(GTK) && !USE(GTK4)
static gboolean windowConfigureEventCallback(GtkWindow* window, GdkEventConfigure*, GdkRectangle* targetGeometry)
{
GdkRectangle geometry = { 0, 0, 0, 0 };
@@ -165,7 +165,7 @@
{
RunLoop::current().stop();
}
-#endif
+#endif // PLATFORM(GTK) && !USE(GTK4)
void setWindowFrame(WebPageProxy&, const WebCore::FloatRect& frame) final
{
@@ -174,10 +174,12 @@
GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView));
if (webkit_web_view_is_controlled_by_automation(m_webView) && WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) {
bool needsMove = false;
+ // Querying and setting window positions is not supported in GTK4.
+#if !USE(GTK4)
// Position a toplevel window is not supported under wayland.
#if PLATFORM(WAYLAND)
if (WebCore::PlatformDisplay::sharedDisplay().type() != WebCore::PlatformDisplay::Type::Wayland)
-#endif
+#endif // PLATFORM(WAYLAND)
{
if (geometry.x >= 0 && geometry.y >= 0) {
int x, y;
@@ -185,6 +187,7 @@
needsMove = x != geometry.x || y != geometry.y;
}
}
+#endif // !USE(GTK4)
bool needsResize = false;
if (geometry.width > 0 && geometry.height > 0) {
@@ -196,9 +199,12 @@
if (!needsMove && !needsResize)
return;
+ // There is no GtkWidget::configure-event in GTK4, move is not supported.
+#if !USE(GTK4)
auto signalID = g_signal_connect(window, "configure-event", G_CALLBACK(windowConfigureEventCallback), &geometry);
if (needsMove)
gtk_window_move(GTK_WINDOW(window), geometry.x, geometry.y);
+#endif // !USE(GTK4)
if (needsResize)
gtk_window_resize(GTK_WINDOW(window), geometry.width, geometry.height);
@@ -212,7 +218,7 @@
g_signal_handler_disconnect(window, signalID);
} else
webkitWindowPropertiesSetGeometry(webkit_web_view_get_window_properties(m_webView), &geometry);
-#endif
+#endif // PLATFORM(GTK)
}
void windowFrame(WebPageProxy&, Function<void(WebCore::FloatRect)>&& completionHandler) final