summaryrefslogtreecommitdiffstats
path: root/webkit/tools/test_shell/test_shell_gtk.cc
diff options
context:
space:
mode:
Diffstat (limited to 'webkit/tools/test_shell/test_shell_gtk.cc')
-rw-r--r--webkit/tools/test_shell/test_shell_gtk.cc45
1 files changed, 38 insertions, 7 deletions
diff --git a/webkit/tools/test_shell/test_shell_gtk.cc b/webkit/tools/test_shell/test_shell_gtk.cc
index 6971a57..8543664 100644
--- a/webkit/tools/test_shell/test_shell_gtk.cc
+++ b/webkit/tools/test_shell/test_shell_gtk.cc
@@ -314,7 +314,6 @@ GtkWidget* CreateMenuBar(TestShell* shell) {
bool TestShell::Initialize(const std::wstring& startingURL) {
m_mainWnd = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
gtk_window_set_title(m_mainWnd, "Test Shell");
- gtk_window_set_default_size(m_mainWnd, 640, 480);
g_signal_connect(G_OBJECT(m_mainWnd), "destroy",
G_CALLBACK(MainWindowDestroyed), this);
g_signal_connect(G_OBJECT(m_mainWnd), "focus-out-event",
@@ -370,11 +369,9 @@ bool TestShell::Initialize(const std::wstring& startingURL) {
gtk_container_add(GTK_CONTAINER(m_mainWnd), vbox);
gtk_widget_show_all(GTK_WIDGET(m_mainWnd));
- top_chrome_height_ = toolbar->allocation.height +
- menu_bar->allocation.height + 2 * gtk_box_get_spacing(GTK_BOX(vbox));
- // LoadURL will do a resize (which uses top_chrome_height_), so make
- // sure we don't call LoadURL until we've completed all of our GTK setup.
+ // LoadURL will do a resize, so make sure we don't call LoadURL
+ // until we've completed all of our GTK setup.
if (!startingURL.empty())
LoadURL(startingURL.c_str());
@@ -399,9 +396,43 @@ void TestShell::TestFinished() {
MessageLoop::current()->Quit();
}
+// Quit the current message loop. Used as a callback below.
+static void QuitMessageLoop() {
+ MessageLoop::current()->Quit();
+}
+
void TestShell::SizeTo(int width, int height) {
- gtk_window_resize(GTK_WINDOW(m_mainWnd), width,
- height + top_chrome_height_);
+ // We've been asked to size the content area to a particular size.
+ // GTK works asynchronously: you request a size and then it eventually
+ // becomes that size. But for this request we need to be sure the resize
+ // has completed by the time SizeTo() returns.
+ //
+ // The fix is to attach to the actual sizing event, resize the widget,
+ // then block the message loop until that event comes through.
+
+ GtkWidget* widget = m_webViewHost->view_handle();
+ if (widget->allocation.width == width &&
+ widget->allocation.height == height) {
+ // Nothing to do.
+ return;
+ }
+
+ gulong handler =
+ g_signal_connect(G_OBJECT(widget), "size-allocate",
+ G_CALLBACK(QuitMessageLoop), NULL);
+ gtk_widget_set_size_request(m_webViewHost->view_handle(), width, height);
+
+ if (widget->allocation.width > width ||
+ widget->allocation.height > height) {
+ // We've been sized smaller. Shrink the window so it snaps back to the
+ // appropriate size.
+ gtk_window_resize(GTK_WINDOW(m_mainWnd), 1, 1);
+ }
+
+ MessageLoop::current()->Run();
+
+ // Clean up our handler.
+ g_signal_handler_disconnect(G_OBJECT(m_webViewHost->view_handle()), handler);
}
static void AlarmHandler(int signatl) {