diff options
author | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 20:46:59 +0000 |
---|---|---|
committer | evan@chromium.org <evan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-04 20:46:59 +0000 |
commit | 0d89635f0c83a050662d1d60cb88fe3255a20985 (patch) | |
tree | 2c116b5b03093f7fcfbdbdc65ce463fb12471998 /webkit | |
parent | 2815fd215021595d12782cd15bb69d7d03c39618 (diff) | |
download | chromium_src-0d89635f0c83a050662d1d60cb88fe3255a20985.zip chromium_src-0d89635f0c83a050662d1d60cb88fe3255a20985.tar.gz chromium_src-0d89635f0c83a050662d1d60cb88fe3255a20985.tar.bz2 |
linux: SizeTo() must synchronously size the content area.
The old code was wrong and racy and the new message loop really exposed the
bug.
Review URL: http://codereview.chromium.org/119197
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17663 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit')
-rw-r--r-- | webkit/tools/test_shell/test_shell.h | 5 | ||||
-rw-r--r-- | webkit/tools/test_shell/test_shell_gtk.cc | 45 |
2 files changed, 38 insertions, 12 deletions
diff --git a/webkit/tools/test_shell/test_shell.h b/webkit/tools/test_shell/test_shell.h index d6ac049..1de2a9f 100644 --- a/webkit/tools/test_shell/test_shell.h +++ b/webkit/tools/test_shell/test_shell.h @@ -344,11 +344,6 @@ private: // Dump the stats table counters on exit. bool dump_stats_table_on_exit_; - -#if defined(OS_LINUX) - // The height of the non-rendering area of the main window, in pixels. - int top_chrome_height_; -#endif }; #endif // WEBKIT_TOOLS_TEST_SHELL_TEST_SHELL_H_ 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) { |