<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[260125] trunk/Source</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/260125">260125</a></dd>
<dt>Author</dt> <dd>aperez@igalia.com</dd>
<dt>Date</dt> <dd>2020-04-15 07:25:12 -0700 (Wed, 15 Apr 2020)</dd>
</dl>

<h3>Log Message</h3>
<pre>[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.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgtkGtkUtilitiescpp">trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp</a></li>
<li><a href="#trunkSourceWebKitChangeLog">trunk/Source/WebKit/ChangeLog</a></li>
<li><a href="#trunkSourceWebKitUIProcessAPIglibWebKitUIClientcpp">trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreplatformgtkGtkVersioningh">trunk/Source/WebCore/platform/gtk/GtkVersioning.h</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (260124 => 260125)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,5 +1,27 @@
</span><span class="cx"> 2020-04-15  Adrian Perez de Castro  <aperez@igalia.com>
</span><span class="cx"> 
</span><ins>+        [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  <aperez@igalia.com>
+
</ins><span class="cx">         [GTK4] Adapt to cursor API changes
</span><span class="cx">         https://bugs.webkit.org/show_bug.cgi?id=210453
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkGtkUtilitiescpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp (260124 => 260125)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -19,6 +19,7 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "GtkUtilities.h"
</span><span class="cx"> 
</span><ins>+#include "GtkVersioning.h"
</ins><span class="cx"> #include "IntPoint.h"
</span><span class="cx"> #include <gtk/gtk.h>
</span><span class="cx"> #include <wtf/glib/GUniquePtr.h>
</span><span class="lines">@@ -25,6 +26,20 @@
</span><span class="cx"> 
</span><span class="cx"> namespace WebCore {
</span><span class="cx"> 
</span><ins>+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);
+}
+
</ins><span class="cx"> IntPoint convertWidgetPointToScreenPoint(GtkWidget* widget, const IntPoint& point)
</span><span class="cx"> {
</span><span class="cx">     // FIXME: This is actually a very tricky operation and the results of this function should
</span><span class="lines">@@ -35,22 +50,23 @@
</span><span class="cx">     if (!toplevelWidget || !gtk_widget_is_toplevel(toplevelWidget) || !GTK_IS_WINDOW(toplevelWidget))
</span><span class="cx">         return point;
</span><span class="cx"> 
</span><del>-    GdkWindow* gdkWindow = gtk_widget_get_window(toplevelWidget);
-    if (!gdkWindow)
-        return point;
-
</del><span class="cx">     int xInWindow, yInWindow;
</span><span class="cx">     gtk_widget_translate_coordinates(widget, toplevelWidget, point.x(), point.y(), &xInWindow, &yInWindow);
</span><span class="cx"> 
</span><del>-    int windowOriginX, windowOriginY;
-    gdk_window_get_origin(gdkWindow, &windowOriginX, &windowOriginY);
-
-    return IntPoint(windowOriginX + xInWindow, windowOriginY + yInWindow);
</del><ins>+    const auto origin = gtkWindowGetOrigin(toplevelWidget);
+    return IntPoint(origin.x() + xInWindow, origin.y() + yInWindow);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> bool widgetIsOnscreenToplevelWindow(GtkWidget* widget)
</span><span class="cx"> {
</span><del>-    return widget && gtk_widget_is_toplevel(widget) && GTK_IS_WINDOW(widget) && !GTK_IS_OFFSCREEN_WINDOW(widget);
</del><ins>+    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)
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> template<>
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgtkGtkVersioningh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/platform/gtk/GtkVersioning.h (0 => 260125)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -0,0 +1,48 @@
</span><ins>+/*
+ * 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)
</ins></span></pre></div>
<a id="trunkSourceWebKitChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/ChangeLog (260124 => 260125)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -1,3 +1,13 @@
</span><ins>+2020-04-15  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [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.
+
</ins><span class="cx"> 2020-04-15  Said Abou-Hallawa  <sabouhallawa@apple.com>
</span><span class="cx"> 
</span><span class="cx">         Unreviewed, reverting r259891.
</span></span></pre></div>
<a id="trunkSourceWebKitUIProcessAPIglibWebKitUIClientcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp (260124 => 260125)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -139,7 +139,7 @@
</span><span class="cx">         webkitWindowPropertiesSetResizable(webkit_web_view_get_window_properties(m_webView), resizable);
</span><span class="cx">     }
</span><span class="cx"> 
</span><del>-#if PLATFORM(GTK)
</del><ins>+#if PLATFORM(GTK) && !USE(GTK4)
</ins><span class="cx">     static gboolean windowConfigureEventCallback(GtkWindow* window, GdkEventConfigure*, GdkRectangle* targetGeometry)
</span><span class="cx">     {
</span><span class="cx">         GdkRectangle geometry = { 0, 0, 0, 0 };
</span><span class="lines">@@ -165,7 +165,7 @@
</span><span class="cx">     {
</span><span class="cx">         RunLoop::current().stop();
</span><span class="cx">     }
</span><del>-#endif
</del><ins>+#endif // PLATFORM(GTK) && !USE(GTK4)
</ins><span class="cx"> 
</span><span class="cx">     void setWindowFrame(WebPageProxy&, const WebCore::FloatRect& frame) final
</span><span class="cx">     {
</span><span class="lines">@@ -174,10 +174,12 @@
</span><span class="cx">         GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView));
</span><span class="cx">         if (webkit_web_view_is_controlled_by_automation(m_webView) && WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) {
</span><span class="cx">             bool needsMove = false;
</span><ins>+            // Querying and setting window positions is not supported in GTK4.
+#if !USE(GTK4)
</ins><span class="cx">             // Position a toplevel window is not supported under wayland.
</span><span class="cx"> #if PLATFORM(WAYLAND)
</span><span class="cx">             if (WebCore::PlatformDisplay::sharedDisplay().type() != WebCore::PlatformDisplay::Type::Wayland)
</span><del>-#endif
</del><ins>+#endif // PLATFORM(WAYLAND)
</ins><span class="cx">             {
</span><span class="cx">                 if (geometry.x >= 0 && geometry.y >= 0) {
</span><span class="cx">                     int x, y;
</span><span class="lines">@@ -185,6 +187,7 @@
</span><span class="cx">                     needsMove = x != geometry.x || y != geometry.y;
</span><span class="cx">                 }
</span><span class="cx">             }
</span><ins>+#endif // !USE(GTK4)
</ins><span class="cx"> 
</span><span class="cx">             bool needsResize = false;
</span><span class="cx">             if (geometry.width > 0 && geometry.height > 0) {
</span><span class="lines">@@ -196,9 +199,12 @@
</span><span class="cx">             if (!needsMove && !needsResize)
</span><span class="cx">                 return;
</span><span class="cx"> 
</span><ins>+            // There is no GtkWidget::configure-event in GTK4, move is not supported.
+#if !USE(GTK4)
</ins><span class="cx">             auto signalID = g_signal_connect(window, "configure-event", G_CALLBACK(windowConfigureEventCallback), &geometry);
</span><span class="cx">             if (needsMove)
</span><span class="cx">                 gtk_window_move(GTK_WINDOW(window), geometry.x, geometry.y);
</span><ins>+#endif // !USE(GTK4)
</ins><span class="cx">             if (needsResize)
</span><span class="cx">                 gtk_window_resize(GTK_WINDOW(window), geometry.width, geometry.height);
</span><span class="cx"> 
</span><span class="lines">@@ -212,7 +218,7 @@
</span><span class="cx">             g_signal_handler_disconnect(window, signalID);
</span><span class="cx">         } else
</span><span class="cx">             webkitWindowPropertiesSetGeometry(webkit_web_view_get_window_properties(m_webView), &geometry);
</span><del>-#endif
</del><ins>+#endif // PLATFORM(GTK)
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     void windowFrame(WebPageProxy&, Function<void(WebCore::FloatRect)>&& completionHandler) final
</span></span></pre>
</div>
</div>

</body>
</html>