Title: [260176] trunk
Revision
260176
Author
[email protected]
Date
2020-04-16 04:22:51 -0700 (Thu, 16 Apr 2020)

Log Message

[GTK] MiniBrowser opens new windows too small causing failures on some WPT tests
https://bugs.webkit.org/show_bug.cgi?id=210206

Reviewed by Carlos Garcia Campos.

Source/WebCore:

Some WPT tests (when executed with the WPT runner via WebDriver)
open new browser windows via _javascript_ invoking Window.open()
and then run the test on this new window.
The size of the new window is not specified, and we were failing
to provide a default window size, so it was using the minimum of
100x100 which its just too small for some test that later call
document.elementFromPoint() on some coordinates
that are outside of that size.

To fix that provide the size of the default GTK window to WebCore
if the application sets one via gtk_window_set_default_size().
And if not, then use the size of the previous window.

Also change the way we position the new window to work better when
the system uses more than one monitor. Previously to get the default
coordinates of the new window we were using gdk_display_get_monitor()
with just the first monitor available.
This causes issues in the calculation of the available space when
using several monitors. Instead get the monitor in use by looking
at the current GDK root window.

Tests: TestWebKitAPI/WebKit2Gtk/TestUIClient:/webkit/WebKitWebView/open-window-default-size
and TestWebKitAPI/WebKit2Gtk/TestUIClient:/webkit/WebKitWebView/open-window-no-default-size

* loader/FrameLoader.cpp:
(WebCore::createWindow):
* platform/gtk/PlatformScreenGtk.cpp:
(WebCore::getCurrentScreenMonitor):
(WebCore::screenRect):
(WebCore::screenAvailableRect):

Source/WebKit:

Provide the size of the default window (if is set) when windowRect is called
before the window is shown.

* UIProcess/API/glib/WebKitUIClient.cpp:

Tools:

Add two API test to check that window.open() by default gets a size
request equal to the old window if there is no default window size,
or to the default window if there is a default window size.

A new function helper setCreateNewWebViewsInWindowsWithDefaultSize()
its added to create new webviews in new windows automatically, which
its needed to test the case of having a default window size.

* TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp:
(testWebViewWindowProperties):
(testWebViewOpenWindowDefaultSize):
(testWebViewOpenWindowNoDefaultSize):
(beforeAll):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (260175 => 260176)


--- trunk/Source/WebCore/ChangeLog	2020-04-16 09:19:17 UTC (rev 260175)
+++ trunk/Source/WebCore/ChangeLog	2020-04-16 11:22:51 UTC (rev 260176)
@@ -1,3 +1,41 @@
+2020-04-16  Carlos Alberto Lopez Perez  <[email protected]>
+
+        [GTK] MiniBrowser opens new windows too small causing failures on some WPT tests
+        https://bugs.webkit.org/show_bug.cgi?id=210206
+
+        Reviewed by Carlos Garcia Campos.
+
+        Some WPT tests (when executed with the WPT runner via WebDriver)
+        open new browser windows via _javascript_ invoking Window.open()
+        and then run the test on this new window.
+        The size of the new window is not specified, and we were failing
+        to provide a default window size, so it was using the minimum of
+        100x100 which its just too small for some test that later call
+        document.elementFromPoint() on some coordinates
+        that are outside of that size.
+
+        To fix that provide the size of the default GTK window to WebCore
+        if the application sets one via gtk_window_set_default_size().
+        And if not, then use the size of the previous window.
+
+        Also change the way we position the new window to work better when
+        the system uses more than one monitor. Previously to get the default
+        coordinates of the new window we were using gdk_display_get_monitor()
+        with just the first monitor available.
+        This causes issues in the calculation of the available space when
+        using several monitors. Instead get the monitor in use by looking
+        at the current GDK root window.
+
+        Tests: TestWebKitAPI/WebKit2Gtk/TestUIClient:/webkit/WebKitWebView/open-window-default-size
+        and TestWebKitAPI/WebKit2Gtk/TestUIClient:/webkit/WebKitWebView/open-window-no-default-size
+
+        * loader/FrameLoader.cpp:
+        (WebCore::createWindow):
+        * platform/gtk/PlatformScreenGtk.cpp:
+        (WebCore::getCurrentScreenMonitor):
+        (WebCore::screenRect):
+        (WebCore::screenAvailableRect):
+
 2020-04-16  Tomoki Imai  <[email protected]>
 
         TextureMapper renders video element with "object-fit: cover" incorrectly

Modified: trunk/Source/WebCore/loader/FrameLoader.cpp (260175 => 260176)


--- trunk/Source/WebCore/loader/FrameLoader.cpp	2020-04-16 09:19:17 UTC (rev 260175)
+++ trunk/Source/WebCore/loader/FrameLoader.cpp	2020-04-16 11:22:51 UTC (rev 260176)
@@ -4120,12 +4120,21 @@
         windowRect.setX(*features.x);
     if (features.y)
         windowRect.setY(*features.y);
-    // Zero width and height mean using default size, not minumum one.
+    // Zero width and height mean using default size, not minimum one.
     if (features.width && *features.width)
         windowRect.setWidth(*features.width + (windowRect.width() - viewportSize.width()));
     if (features.height && *features.height)
         windowRect.setHeight(*features.height + (windowRect.height() - viewportSize.height()));
 
+#if PLATFORM(GTK)
+    FloatRect oldWindowRect = oldPage->chrome().windowRect();
+    // Use the size of the previous window if there is no default size.
+    if (!windowRect.width())
+        windowRect.setWidth(oldWindowRect.width());
+    if (!windowRect.height())
+        windowRect.setHeight(oldWindowRect.height());
+#endif
+
     // Ensure non-NaN values, minimum size as well as being within valid screen area.
     FloatRect newWindowRect = DOMWindow::adjustWindowRect(*page, windowRect);
 

Modified: trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp (260175 => 260176)


--- trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp	2020-04-16 09:19:17 UTC (rev 260175)
+++ trunk/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp	2020-04-16 11:22:51 UTC (rev 260176)
@@ -164,14 +164,25 @@
     }
 }
 
-FloatRect screenRect(Widget*)
+GdkMonitor* getCurrentScreenMonitor()
 {
-    GdkRectangle geometry;
     GdkDisplay* display = gdk_display_get_default();
     if (!display)
-        return { };
+        return nullptr;
 
-    auto* monitor = gdk_display_get_monitor(display, 0);
+    auto* rootWindow = gdk_get_default_root_window();
+    if (!rootWindow)
+        return nullptr;
+
+    return gdk_display_get_monitor_at_window(display, rootWindow);
+}
+
+
+FloatRect screenRect(Widget*)
+{
+    GdkRectangle geometry;
+
+    auto* monitor = getCurrentScreenMonitor();
     if (!monitor)
         return { };
 
@@ -183,11 +194,8 @@
 FloatRect screenAvailableRect(Widget*)
 {
     GdkRectangle workArea;
-    GdkDisplay* display = gdk_display_get_default();
-    if (!display)
-        return { };
 
-    auto* monitor = gdk_display_get_monitor(display, 0);
+    auto* monitor = getCurrentScreenMonitor();
     if (!monitor)
         return { };
 

Modified: trunk/Source/WebKit/ChangeLog (260175 => 260176)


--- trunk/Source/WebKit/ChangeLog	2020-04-16 09:19:17 UTC (rev 260175)
+++ trunk/Source/WebKit/ChangeLog	2020-04-16 11:22:51 UTC (rev 260176)
@@ -1,3 +1,15 @@
+2020-04-16  Carlos Alberto Lopez Perez  <[email protected]>
+
+        [GTK] MiniBrowser opens new windows too small causing failures on some WPT tests
+        https://bugs.webkit.org/show_bug.cgi?id=210206
+
+        Reviewed by Carlos Garcia Campos.
+
+        Provide the size of the default window (if is set) when windowRect is called
+        before the window is shown.
+
+        * UIProcess/API/glib/WebKitUIClient.cpp:
+
 2020-04-16  Tomoki Imai  <[email protected]>
 
         TextureMapper renders video element with "object-fit: cover" incorrectly

Modified: trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp (260175 => 260176)


--- trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp	2020-04-16 09:19:17 UTC (rev 260175)
+++ trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp	2020-04-16 11:22:51 UTC (rev 260176)
@@ -229,6 +229,17 @@
         if (WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) {
             gtk_window_get_position(GTK_WINDOW(window), &geometry.x, &geometry.y);
             gtk_window_get_size(GTK_WINDOW(window), &geometry.width, &geometry.height);
+        } else {
+            GdkRectangle defaultGeometry;
+            webkit_window_properties_get_geometry(webkit_web_view_get_window_properties(m_webView), &defaultGeometry);
+            if ((!defaultGeometry.width || !defaultGeometry.height) && WebCore::widgetIsOnscreenToplevelWindow(window)) {
+                int defaultWidth, defaultHeight;
+                gtk_window_get_default_size(GTK_WINDOW(window), &defaultWidth, &defaultHeight);
+                if (!defaultGeometry.width && defaultWidth != -1)
+                    geometry.width = defaultWidth;
+                if (!defaultGeometry.height && defaultHeight != -1)
+                    geometry.height = defaultHeight;
+            }
         }
         completionHandler(WebCore::FloatRect(geometry));
 #elif PLATFORM(WPE)

Modified: trunk/Tools/ChangeLog (260175 => 260176)


--- trunk/Tools/ChangeLog	2020-04-16 09:19:17 UTC (rev 260175)
+++ trunk/Tools/ChangeLog	2020-04-16 11:22:51 UTC (rev 260176)
@@ -1,3 +1,24 @@
+2020-04-16  Carlos Alberto Lopez Perez  <[email protected]>
+
+        [GTK] MiniBrowser opens new windows too small causing failures on some WPT tests
+        https://bugs.webkit.org/show_bug.cgi?id=210206
+
+        Reviewed by Carlos Garcia Campos.
+
+        Add two API test to check that window.open() by default gets a size
+        request equal to the old window if there is no default window size,
+        or to the default window if there is a default window size.
+
+        A new function helper setCreateNewWebViewsInWindowsWithDefaultSize()
+        its added to create new webviews in new windows automatically, which
+        its needed to test the case of having a default window size.
+
+        * TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp:
+        (testWebViewWindowProperties):
+        (testWebViewOpenWindowDefaultSize):
+        (testWebViewOpenWindowNoDefaultSize):
+        (beforeAll):
+
 2020-04-15  Tim Horton  <[email protected]>
 
         REGRESSION (r258337): Crash when right clicking on link that uses the system UI font with optimizeLegibility on Mojave

Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp (260175 => 260176)


--- trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp	2020-04-16 09:19:17 UTC (rev 260175)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitGLib/TestUIClient.cpp	2020-04-16 11:22:51 UTC (rev 260176)
@@ -307,6 +307,15 @@
         m_windowProperties = windowProperties;
     }
 
+#if PLATFORM(GTK)
+    void setCreateNewWebViewsInWindowsWithDefaultSize(int width = 800, int height = 600)
+    {
+        m_shouldCreateWebViewsInNewWindowsAutomatically = true;
+        m_DefaultGeometryNewWindows.width = width;
+        m_DefaultGeometryNewWindows.height = height;
+    }
+#endif
+
     WebKitHitTestResult* moveMouseAndWaitUntilMouseTargetChanged(int x, int y, unsigned mouseModifiers = 0)
     {
         m_waitingForMouseTargetChange = true;
@@ -349,6 +358,16 @@
         g_signal_connect(newWebView, "ready-to-show", G_CALLBACK(viewReadyToShowCallback), this);
         g_signal_connect(newWebView, "close", G_CALLBACK(viewCloseCallback), this);
 
+#if PLATFORM(GTK)
+        if (m_shouldCreateWebViewsInNewWindowsAutomatically) {
+            g_assert_null(m_parentWindow);
+            m_parentWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+            gtk_window_set_default_size(GTK_WINDOW(m_parentWindow), m_DefaultGeometryNewWindows.width, m_DefaultGeometryNewWindows.height);
+            gtk_container_add(GTK_CONTAINER(m_parentWindow), GTK_WIDGET(newWebView));
+            gtk_widget_show(GTK_WIDGET(newWebView));
+            gtk_widget_show(m_parentWindow);
+        }
+#endif
         return WEBKIT_WEB_VIEW(newWebView);
     }
 
@@ -388,6 +407,11 @@
     unsigned m_mouseTargetModifiers;
     GUniquePtr<char> m_permissionResult;
     bool m_waitingForMouseTargetChange { false };
+
+#if PLATFORM(GTK)
+    bool m_shouldCreateWebViewsInNewWindowsAutomatically { false };
+    cairo_rectangle_int_t m_DefaultGeometryNewWindows;
+#endif
 };
 
 static void testWebViewCreateReadyClose(UIClientTest* test, gconstpointer)
@@ -651,12 +675,12 @@
 
 static void testWebViewWindowProperties(UIClientTest* test, gconstpointer)
 {
-    static const char* windowProrpertiesString = "left=100,top=150,width=400,height=400,location=no,menubar=no,status=no,toolbar=no,scrollbars=no";
+    static const char* windowPropertiesString = "left=100,top=150,width=400,height=400,location=no,menubar=no,status=no,toolbar=no,scrollbars=no";
     cairo_rectangle_int_t geometry = { 100, 150, 400, 400 };
     test->setExpectedWindowProperties(UIClientTest::WindowProperties(&geometry, false, false, false, false, false, true, false));
 
-    GUniquePtr<char> htmlString(g_strdup_printf("<html><body _onLoad_=\"window.open('', '', '%s').close();\"></body></html>", windowProrpertiesString));
-    test->loadHtml(htmlString.get(), 0);
+    GUniquePtr<char> htmlString(g_strdup_printf("<html><body _onLoad_=\"window.open('', '', '%s').close();\"></body></html>", windowPropertiesString));
+    test->loadHtml(htmlString.get(), nullptr);
     test->waitUntilMainLoopFinishes();
 
     static const char* propertiesChanged[] = {
@@ -676,6 +700,29 @@
 }
 
 #if PLATFORM(GTK)
+static void testWebViewOpenWindowDefaultSize(UIClientTest* test, gconstpointer)
+{
+    // If no size specified for window.open(), then new windows open with the default window size.
+    cairo_rectangle_int_t expectedGeometry = { 0, 0, 623, 715 };
+    test->setCreateNewWebViewsInWindowsWithDefaultSize(expectedGeometry.width, expectedGeometry.height);
+    test->setExpectedWindowProperties(UIClientTest::WindowProperties(&expectedGeometry, false, false, false, false, false, true, false));
+    test->loadHtml("<html><body _onLoad_=\"window.open('', '', 'left=0,top=0,location=no,menubar=no,status=no,toolbar=no,scrollbars=no').close();\"></body></html>", nullptr);
+    test->waitUntilMainLoopFinishes();
+}
+
+static void testWebViewOpenWindowNoDefaultSize(UIClientTest* test, gconstpointer)
+{
+    // If no size specified for window.open(), and new windows are not set to a specific default size with gtk_window_set_default_size()
+    // on the create signal, then new windows open with the size of the previous window.
+    cairo_rectangle_int_t expectedGeometry = { 0, 0, 527, 671 };
+    test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL, expectedGeometry.width, expectedGeometry.height);
+    test->setExpectedWindowProperties(UIClientTest::WindowProperties(&expectedGeometry, false, false, false, false, false, true, false));
+    test->loadHtml("<html><body _onLoad_=\"window.open('', '', 'left=0,top=0,location=no,menubar=no,status=no,toolbar=no,scrollbars=no').close();\"></body></html>", nullptr);
+    test->waitUntilMainLoopFinishes();
+}
+#endif
+
+#if PLATFORM(GTK)
 static void testWebViewMouseTarget(UIClientTest* test, gconstpointer)
 {
     test->showInWindowAndWaitUntilMapped(GTK_WINDOW_TOPLEVEL);
@@ -1230,6 +1277,11 @@
     ModalDialogsTest::add("WebKitWebView", "disallow-modal-dialogs", testWebViewDisallowModalDialogs);
     UIClientTest::add("WebKitWebView", "_javascript_-dialogs", testWebViewJavaScriptDialogs);
     UIClientTest::add("WebKitWebView", "window-properties", testWebViewWindowProperties);
+#if PLATFORM(GTK)
+    // FIXME: Implement webkit_window_properties_get_geometry() in WPE.
+    UIClientTest::add("WebKitWebView", "open-window-default-size", testWebViewOpenWindowDefaultSize);
+    UIClientTest::add("WebKitWebView", "open-window-no-default-size", testWebViewOpenWindowNoDefaultSize);
+#endif
     // FIXME: Implement mouse move in WPE.
 #if PLATFORM(GTK)
     UIClientTest::add("WebKitWebView", "mouse-target", testWebViewMouseTarget);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to