summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-18 01:13:30 +0000
committeroshima@google.com <oshima@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2011-05-18 01:13:30 +0000
commitee64fc06a4c0730cbea8a855c8efd8ca771810d8 (patch)
tree7b1f1670833a54e6ac5dbd7b03f893fd482a76ea
parent32b7454c2705bd4071e35d2a636ed15b54c5863d (diff)
downloadchromium_src-ee64fc06a4c0730cbea8a855c8efd8ca771810d8.zip
chromium_src-ee64fc06a4c0730cbea8a855c8efd8ca771810d8.tar.gz
chromium_src-ee64fc06a4c0730cbea8a855c8efd8ca771810d8.tar.bz2
Synchronize window resize in MoveMouseToCenterAndPress on linux.
I tried to synchronize it in Show methods (in test mode), but it didn't work because next task is posted before show and running message loop executes the task before the window gets resized. For now, I decided to put the code in ui_controls. Let me know if you have suggestion where to put this code. BUG=82219 TEST=bookmark test and menu_item_view tests are no longer flaky without gtk hack. Review URL: http://codereview.chromium.org/6982031 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85711 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/ui_controls_linux.cc36
-rw-r--r--chrome/browser/ui/views/menu_item_view_test.cc29
-rw-r--r--views/widget/widget_gtk.cc2
3 files changed, 38 insertions, 29 deletions
diff --git a/chrome/browser/automation/ui_controls_linux.cc b/chrome/browser/automation/ui_controls_linux.cc
index d63501a..1c5a631 100644
--- a/chrome/browser/automation/ui_controls_linux.cc
+++ b/chrome/browser/automation/ui_controls_linux.cc
@@ -17,6 +17,7 @@
#if defined(TOOLKIT_VIEWS)
#include "views/view.h"
+#include "views/widget/root_view.h"
#include "views/widget/widget.h"
#endif
@@ -165,7 +166,6 @@ bool SendMouseMove(long x, long y) {
// the move, even though it succesfully moves the server cursor. We fake it in
// order to get drags to work.
FakeAMouseMotionEvent(x, y);
-
return true;
}
@@ -194,6 +194,7 @@ bool SendMouseEvents(MouseButton type, int state) {
gdk_window_get_pointer(event->button.window, &x, &y, NULL);
} else {
event->button.window = gdk_window_at_pointer(&x, &y);
+ CHECK(event->button.window);
}
g_object_ref(event->button.window);
@@ -250,8 +251,41 @@ bool SendMouseClick(MouseButton type) {
}
#if defined(TOOLKIT_VIEWS)
+
+#if defined(OS_LINUX)
+void OnConfigure(GtkWidget* gtk_widget, GdkEvent* event, gpointer data) {
+ views::Widget* widget = static_cast<views::Widget*>(data);
+ gfx::Rect actual = widget->GetWindowScreenBounds();
+ gfx::Rect desired = widget->GetRootView()->bounds();
+ if (actual.size() == desired.size())
+ MessageLoop::current()->Quit();
+}
+
+void SynchronizeWidgetSize(views::Widget* widget) {
+ // If the actual window size and desired window size
+ // are different, wait until the window is resized
+ // to desired size.
+ gfx::Rect actual = widget->GetWindowScreenBounds();
+ gfx::Rect desired = widget->GetRootView()->bounds();
+ if (actual.size() != desired.size()) {
+ // Listen to configure-event that is emitted when an window gets
+ // resized.
+ GtkWidget* gtk_widget = widget->GetNativeView();
+ g_signal_connect(gtk_widget, "configure-event",
+ G_CALLBACK(&OnConfigure), widget);
+ MessageLoop::current()->Run();
+ }
+}
+#endif
+
void MoveMouseToCenterAndPress(views::View* view, MouseButton button,
int state, Task* task) {
+#if defined(OS_LINUX)
+ // X is asynchronous and we need to wait until the window gets
+ // resized to desired size.
+ SynchronizeWidgetSize(view->GetWidget());
+#endif
+
gfx::Point view_center(view->width() / 2, view->height() / 2);
views::View::ConvertPointToScreen(view, &view_center);
SendMouseMoveNotifyWhenDone(view_center.x(), view_center.y(),
diff --git a/chrome/browser/ui/views/menu_item_view_test.cc b/chrome/browser/ui/views/menu_item_view_test.cc
index 6b8bb20..33ce6b6 100644
--- a/chrome/browser/ui/views/menu_item_view_test.cc
+++ b/chrome/browser/ui/views/menu_item_view_test.cc
@@ -73,7 +73,7 @@ class MenuItemViewTestBase : public ViewEventTestBase,
bounds,
views::MenuItemView::TOPLEFT,
true);
- }
+ }
protected:
// Generate a mouse click on the specified view and post a new task.
@@ -88,21 +88,6 @@ class MenuItemViewTestBase : public ViewEventTestBase,
virtual void BuildMenu(views::MenuItemView* menu) {
}
-#if defined(TOOLKIT_USES_GTK)
- // GTK processes widget size changes with an idle task so RootView
- // sizes are not updated reliably before an automation mouse click.
- // This can result in the event being marked outside the menu
- // bounds. To work around this issue for testing, this code short
- // circuits the RootView size update by setting it directly.
- void WorkaroundGTKRace() {
- views::Widget* widget = menu_->GetSubmenu()->GetWidget();
- if (widget) {
- widget->GetRootView()->SetSize(
- widget->GetClientAreaScreenBounds().size());
- }
- }
-#endif
-
views::MenuButton* button_;
scoped_ptr<views::MenuItemView> menu_;
};
@@ -214,9 +199,6 @@ class MenuItemViewTestInsert : public MenuItemViewTestBase {
views::MenuItemView::NORMAL);
ASSERT_TRUE(inserted_item_);
menu_->ChildrenChanged();
-#if defined(TOOLKIT_USES_GTK)
- WorkaroundGTKRace();
-#endif
// click an item and pass control to the next step
views::MenuItemView* item = submenu->GetMenuItemAt(SELECT_INDEX);
@@ -310,9 +292,6 @@ class MenuItemViewTestInsertWithSubmenu : public MenuItemViewTestBase {
views::MenuItemView::NORMAL);
ASSERT_TRUE(inserted_item_);
menu_->ChildrenChanged();
-#if defined(TOOLKIT_USES_GTK)
- WorkaroundGTKRace();
-#endif
Click(inserted_item_,
CreateEventTask(this, &MenuItemViewTestInsertWithSubmenu::Step3));
@@ -375,9 +354,6 @@ class MenuItemViewTestRemove : public MenuItemViewTestBase {
// remove
menu_->RemoveMenuItemAt(REMOVE_INDEX);
menu_->ChildrenChanged();
-#if defined(TOOLKIT_USES_GTK)
- WorkaroundGTKRace();
-#endif
// click
views::MenuItemView* item = submenu->GetMenuItemAt(SELECT_INDEX);
@@ -474,9 +450,6 @@ class MenuItemViewTestRemoveWithSubmenu : public MenuItemViewTestBase {
// remove
menu_->RemoveMenuItemAt(REMOVE_INDEX);
menu_->ChildrenChanged();
-#if defined(TOOLKIT_USES_GTK)
- WorkaroundGTKRace();
-#endif
// click
Click(button_,
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index 164c692..0e693d8 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -726,6 +726,8 @@ void WidgetGtk::InitNativeWidget(const Widget::InitParams& params) {
if (parent)
SetBounds(params.bounds);
} else {
+ gtk_widget_add_events(widget_,
+ GDK_STRUCTURE_MASK);
if (params.bounds.width() > 0 && params.bounds.height() > 0)
gtk_window_resize(GTK_WINDOW(widget_), params.bounds.width(),
params.bounds.height());