Changeset 250707 in webkit


Ignore:
Timestamp:
Oct 3, 2019 11:15:39 PM (4 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] WebAutomation: make setWindowRect synchronous
https://bugs.webkit.org/show_bug.cgi?id=202530

Reviewed by Carlos Alberto Lopez Perez.

Move/resize window is asynchronous in GTK, but automation expects it to be synchronous so that get window rect
after setting it always returns the value set. Use a nested run loop to wait for the configure events after the
move/resize.

  • UIProcess/API/glib/WebKitUIClient.cpp:

(UIClient::windowConfigureEventCallback):
(UIClient::setWindowFrameTimerFired):

Location:
trunk/Source/WebKit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/ChangeLog

    r250706 r250707  
     12019-10-03  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] WebAutomation: make setWindowRect synchronous
     4        https://bugs.webkit.org/show_bug.cgi?id=202530
     5
     6        Reviewed by Carlos Alberto Lopez Perez.
     7
     8        Move/resize window is asynchronous in GTK, but automation expects it to be synchronous so that get window rect
     9        after setting it always returns the value set. Use a nested run loop to wait for the configure events after the
     10        move/resize.
     11
     12        * UIProcess/API/glib/WebKitUIClient.cpp:
     13        (UIClient::windowConfigureEventCallback):
     14        (UIClient::setWindowFrameTimerFired):
     15
    1162019-10-03  Carlos Garcia Campos  <cgarcia@igalia.com>
    217
  • trunk/Source/WebKit/UIProcess/API/glib/WebKitUIClient.cpp

    r248846 r250707  
    3636#include "WebsiteDataStore.h"
    3737#include <wtf/glib/GRefPtr.h>
     38#include <wtf/glib/RunLoopSourcePriority.h>
    3839
    3940#if PLATFORM(GTK)
     
    129130    }
    130131
     132#if PLATFORM(GTK)
     133    static void windowConfigureEventCallback(GtkWindow* window, GdkEventConfigure*, GdkRectangle* targetGeometry)
     134    {
     135        GdkRectangle geometry = { 0, 0, 0, 0 };
     136        gtk_window_get_position(window, &geometry.x, &geometry.y);
     137        gtk_window_get_size(window, &geometry.width, &geometry.height);
     138        if (geometry.x == targetGeometry->x && geometry.y == targetGeometry->y && geometry.width == targetGeometry->width && geometry.height == targetGeometry->height)
     139            RunLoop::current().stop();
     140    }
     141
     142    void setWindowFrameTimerFired()
     143    {
     144        RunLoop::current().stop();
     145    }
     146#endif
     147
    131148    void setWindowFrame(WebPageProxy&, const WebCore::FloatRect& frame) final
    132149    {
     
    135152        GtkWidget* window = gtk_widget_get_toplevel(GTK_WIDGET(m_webView));
    136153        if (webkit_web_view_is_controlled_by_automation(m_webView) && WebCore::widgetIsOnscreenToplevelWindow(window) && gtk_widget_get_visible(window)) {
     154            if ((geometry.x < 0 || geometry.y < 0) && (geometry.width <= 0 || geometry.height <= 0))
     155                return;
     156
     157            auto signalID = g_signal_connect(window, "configure-event", G_CALLBACK(windowConfigureEventCallback), &geometry);
    137158            if (geometry.x >= 0 && geometry.y >= 0)
    138159                gtk_window_move(GTK_WINDOW(window), geometry.x, geometry.y);
    139160            if (geometry.width > 0 && geometry.height > 0)
    140161                gtk_window_resize(GTK_WINDOW(window), geometry.width, geometry.height);
     162
     163            // We need the move/resize to happen synchronously in automation mode, so we use a nested RunLoop
     164            // to wait, up top 1 second, for the configure events.
     165            auto timer = makeUnique<RunLoop::Timer<UIClient>>(RunLoop::main(), this, &UIClient::setWindowFrameTimerFired);
     166            timer->setPriority(RunLoopSourcePriority::RunLoopTimer);
     167            timer->startOneShot(1_s);
     168            RunLoop::run();
     169            timer = nullptr;
     170            g_signal_handler_disconnect(window, signalID);
    141171        } else
    142172            webkitWindowPropertiesSetGeometry(webkit_web_view_get_window_properties(m_webView), &geometry);
Note: See TracChangeset for help on using the changeset viewer.