| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/automation/ui_controls.h" | 5 #include "ui/ui_controls/ui_controls.h" |
| 6 | 6 |
| 7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
| 8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
| 13 #include "chrome/browser/automation/ui_controls_internal.h" | 13 #include "ui/base/gtk/gtk_screen_util.h" |
| 14 #include "chrome/browser/ui/gtk/gtk_util.h" | |
| 15 #include "chrome/common/automation_constants.h" | |
| 16 #include "ui/base/gtk/event_synthesis_gtk.h" | 14 #include "ui/base/gtk/event_synthesis_gtk.h" |
| 17 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 18 | 16 |
| 19 #if defined(TOOLKIT_VIEWS) | 17 #if defined(TOOLKIT_VIEWS) |
| 20 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 21 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 22 #endif | 20 #endif |
| 23 | 21 |
| 24 namespace { | 22 namespace { |
| 25 | 23 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 } | 245 } |
| 248 new EventWaiter(task, wait_type, 1); | 246 new EventWaiter(task, wait_type, 1); |
| 249 return rv; | 247 return rv; |
| 250 } | 248 } |
| 251 | 249 |
| 252 bool SendMouseClick(MouseButton type) { | 250 bool SendMouseClick(MouseButton type) { |
| 253 return SendMouseEvents(type, UP | DOWN); | 251 return SendMouseEvents(type, UP | DOWN); |
| 254 } | 252 } |
| 255 | 253 |
| 256 #if defined(TOOLKIT_VIEWS) | 254 #if defined(TOOLKIT_VIEWS) |
| 257 | |
| 258 #if defined(OS_LINUX) && !defined(USE_AURA) | |
| 259 void OnConfigure(GtkWidget* gtk_widget, GdkEvent* event, gpointer data) { | |
| 260 views::Widget* widget = static_cast<views::Widget*>(data); | |
| 261 gfx::Rect actual = widget->GetWindowScreenBounds(); | |
| 262 gfx::Rect desired = widget->GetRootView()->bounds(); | |
| 263 if (actual.size() == desired.size()) | |
| 264 MessageLoop::current()->Quit(); | |
| 265 } | |
| 266 | |
| 267 void SynchronizeWidgetSize(views::Widget* widget) { | |
| 268 // If the actual window size and desired window size | |
| 269 // are different, wait until the window is resized | |
| 270 // to desired size. | |
| 271 gfx::Rect actual = widget->GetWindowScreenBounds(); | |
| 272 gfx::Rect desired = widget->GetRootView()->bounds(); | |
| 273 if (actual.size() != desired.size()) { | |
| 274 // Listen to configure-event that is emitted when an window gets | |
| 275 // resized. | |
| 276 GtkWidget* gtk_widget = widget->GetNativeView(); | |
| 277 g_signal_connect(gtk_widget, "configure-event", | |
| 278 G_CALLBACK(&OnConfigure), widget); | |
| 279 MessageLoop::current()->Run(); | |
| 280 } | |
| 281 } | |
| 282 #endif | |
| 283 | |
| 284 void MoveMouseToCenterAndPress(views::View* view, | |
| 285 MouseButton button, | |
| 286 int state, | |
| 287 const base::Closure& task) { | |
| 288 #if defined(OS_LINUX) | |
| 289 // X is asynchronous and we need to wait until the window gets | |
| 290 // resized to desired size. | |
| 291 SynchronizeWidgetSize(view->GetWidget()); | |
| 292 #endif | |
| 293 | |
| 294 gfx::Point view_center(view->width() / 2, view->height() / 2); | |
| 295 views::View::ConvertPointToScreen(view, &view_center); | |
| 296 SendMouseMoveNotifyWhenDone( | |
| 297 view_center.x(), view_center.y(), | |
| 298 base::Bind(&ui_controls::internal::ClickTask, button, state, task)); | |
| 299 } | |
| 300 #else | |
| 301 void MoveMouseToCenterAndPress(GtkWidget* widget, | |
| 302 MouseButton button, | |
| 303 int state, | |
| 304 const base::Closure& task) { | |
| 305 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); | |
| 306 SendMouseMoveNotifyWhenDone( | |
| 307 bounds.x() + bounds.width() / 2, | |
| 308 bounds.y() + bounds.height() / 2, | |
| 309 base::Bind(&ui_controls::internal::ClickTask, button, state, task)); | |
| 310 } | |
| 311 #endif | |
| 312 | |
| 313 #if defined(TOOLKIT_VIEWS) | |
| 314 void RunClosureAfterAllPendingUIEvents(const base::Closure& task) { | 255 void RunClosureAfterAllPendingUIEvents(const base::Closure& task) { |
| 315 // Send noop event and run task. | 256 // Send noop event and run task. |
| 316 int x, y; | 257 int x, y; |
| 317 gdk_window_at_pointer(&x, &y); | 258 gdk_window_at_pointer(&x, &y); |
| 318 SendMouseMoveNotifyWhenDone(x, y, task); | 259 SendMouseMoveNotifyWhenDone(x, y, task); |
| 319 } | 260 } |
| 320 #endif | 261 #endif |
| 321 | 262 |
| 322 } // namespace ui_controls | 263 } // namespace ui_controls |
| OLD | NEW |