| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/automation/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" |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 void FakeAMouseMotionEvent(gint x, gint y) { | 81 void FakeAMouseMotionEvent(gint x, gint y) { |
| 82 GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY); | 82 GdkEvent* event = gdk_event_new(GDK_MOTION_NOTIFY); |
| 83 | 83 |
| 84 event->motion.send_event = false; | 84 event->motion.send_event = false; |
| 85 event->motion.time = XTimeNow(); | 85 event->motion.time = XTimeNow(); |
| 86 | 86 |
| 87 GtkWidget* grab_widget = gtk_grab_get_current(); | 87 GtkWidget* grab_widget = gtk_grab_get_current(); |
| 88 if (grab_widget) { | 88 if (grab_widget) { |
| 89 // If there is a grab, we need to target all events at it regardless of | 89 // If there is a grab, we need to target all events at it regardless of |
| 90 // what widget the mouse is over. | 90 // what widget the mouse is over. |
| 91 event->motion.window = grab_widget->window; | 91 event->motion.window = gtk_widget_get_window(grab_widget); |
| 92 } else { | 92 } else { |
| 93 event->motion.window = gdk_window_at_pointer(&x, &y); | 93 event->motion.window = gdk_window_at_pointer(&x, &y); |
| 94 } | 94 } |
| 95 g_object_ref(event->motion.window); | 95 g_object_ref(event->motion.window); |
| 96 gint window_x, window_y; | 96 gint window_x, window_y; |
| 97 gdk_window_get_origin(event->motion.window, &window_x, &window_y); | 97 gdk_window_get_origin(event->motion.window, &window_x, &window_y); |
| 98 event->motion.x = x - window_x; | 98 event->motion.x = x - window_x; |
| 99 event->motion.y = y - window_y; | 99 event->motion.y = y - window_y; |
| 100 event->motion.x_root = x; | 100 event->motion.x_root = x; |
| 101 event->motion.y_root = y; | 101 event->motion.y_root = y; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 115 ui::KeyboardCode key, | 115 ui::KeyboardCode key, |
| 116 bool control, | 116 bool control, |
| 117 bool shift, | 117 bool shift, |
| 118 bool alt, | 118 bool alt, |
| 119 bool command) { | 119 bool command) { |
| 120 DCHECK(!command); // No command key on Linux | 120 DCHECK(!command); // No command key on Linux |
| 121 GdkWindow* event_window = NULL; | 121 GdkWindow* event_window = NULL; |
| 122 GtkWidget* grab_widget = gtk_grab_get_current(); | 122 GtkWidget* grab_widget = gtk_grab_get_current(); |
| 123 if (grab_widget) { | 123 if (grab_widget) { |
| 124 // If there is a grab, send all events to the grabbed widget. | 124 // If there is a grab, send all events to the grabbed widget. |
| 125 event_window = grab_widget->window; | 125 event_window = gtk_widget_get_window(grab_widget); |
| 126 } else if (window) { | 126 } else if (window) { |
| 127 event_window = GTK_WIDGET(window)->window; | 127 event_window = gtk_widget_get_window(GTK_WIDGET(window)); |
| 128 } else { | 128 } else { |
| 129 // No target was specified. Send the events to the active toplevel. | 129 // No target was specified. Send the events to the active toplevel. |
| 130 GList* windows = gtk_window_list_toplevels(); | 130 GList* windows = gtk_window_list_toplevels(); |
| 131 for (GList* element = windows; element; element = g_list_next(element)) { | 131 for (GList* element = windows; element; element = g_list_next(element)) { |
| 132 GtkWindow* this_window = GTK_WINDOW(element->data); | 132 GtkWindow* this_window = GTK_WINDOW(element->data); |
| 133 if (gtk_window_is_active(this_window)) { | 133 if (gtk_window_is_active(this_window)) { |
| 134 event_window = GTK_WIDGET(this_window)->window; | 134 event_window = gtk_widget_get_window(GTK_WIDGET(this_window)); |
| 135 break; | 135 break; |
| 136 } | 136 } |
| 137 } | 137 } |
| 138 g_list_free(windows); | 138 g_list_free(windows); |
| 139 } | 139 } |
| 140 if (!event_window) { | 140 if (!event_window) { |
| 141 NOTREACHED() << "Window not specified and none is active"; | 141 NOTREACHED() << "Window not specified and none is active"; |
| 142 return false; | 142 return false; |
| 143 } | 143 } |
| 144 | 144 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); | 194 GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS); |
| 195 | 195 |
| 196 event->button.send_event = false; | 196 event->button.send_event = false; |
| 197 event->button.time = XTimeNow(); | 197 event->button.time = XTimeNow(); |
| 198 | 198 |
| 199 gint x, y; | 199 gint x, y; |
| 200 GtkWidget* grab_widget = gtk_grab_get_current(); | 200 GtkWidget* grab_widget = gtk_grab_get_current(); |
| 201 if (grab_widget) { | 201 if (grab_widget) { |
| 202 // If there is a grab, we need to target all events at it regardless of | 202 // If there is a grab, we need to target all events at it regardless of |
| 203 // what widget the mouse is over. | 203 // what widget the mouse is over. |
| 204 event->button.window = grab_widget->window; | 204 event->button.window = gtk_widget_get_window(grab_widget); |
| 205 gdk_window_get_pointer(event->button.window, &x, &y, NULL); | 205 gdk_window_get_pointer(event->button.window, &x, &y, NULL); |
| 206 } else { | 206 } else { |
| 207 event->button.window = gdk_window_at_pointer(&x, &y); | 207 event->button.window = gdk_window_at_pointer(&x, &y); |
| 208 CHECK(event->button.window); | 208 CHECK(event->button.window); |
| 209 } | 209 } |
| 210 | 210 |
| 211 g_object_ref(event->button.window); | 211 g_object_ref(event->button.window); |
| 212 event->button.x = x; | 212 event->button.x = x; |
| 213 event->button.y = y; | 213 event->button.y = y; |
| 214 gint origin_x, origin_y; | 214 gint origin_x, origin_y; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 const base::Closure& task) { | 311 const base::Closure& task) { |
| 312 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); | 312 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); |
| 313 SendMouseMoveNotifyWhenDone( | 313 SendMouseMoveNotifyWhenDone( |
| 314 bounds.x() + bounds.width() / 2, | 314 bounds.x() + bounds.width() / 2, |
| 315 bounds.y() + bounds.height() / 2, | 315 bounds.y() + bounds.height() / 2, |
| 316 base::Bind(&ui_controls::ClickTask, button, state, task)); | 316 base::Bind(&ui_controls::ClickTask, button, state, task)); |
| 317 } | 317 } |
| 318 #endif | 318 #endif |
| 319 | 319 |
| 320 } // namespace ui_controls | 320 } // namespace ui_controls |
| OLD | NEW |