OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
9 | 9 |
10 #include "gfx/rect.h" | 10 #include "gfx/rect.h" |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 | 137 |
138 gdk_event_put(event); | 138 gdk_event_put(event); |
139 gdk_event_free(event); | 139 gdk_event_free(event); |
140 } | 140 } |
141 | 141 |
142 } // namespace | 142 } // namespace |
143 | 143 |
144 namespace ui_controls { | 144 namespace ui_controls { |
145 | 145 |
146 bool SendKeyPress(gfx::NativeWindow window, | 146 bool SendKeyPress(gfx::NativeWindow window, |
147 base::KeyboardCode key, bool control, bool shift, bool alt) { | 147 base::KeyboardCode key, |
| 148 bool control, bool shift, bool alt, bool command) { |
| 149 DCHECK(command == false); // No command key on Linux |
148 GdkWindow* event_window = NULL; | 150 GdkWindow* event_window = NULL; |
149 GtkWidget* grab_widget = gtk_grab_get_current(); | 151 GtkWidget* grab_widget = gtk_grab_get_current(); |
150 if (grab_widget) { | 152 if (grab_widget) { |
151 // If there is a grab, send all events to the grabbed widget. | 153 // If there is a grab, send all events to the grabbed widget. |
152 event_window = grab_widget->window; | 154 event_window = grab_widget->window; |
153 } else if (window) { | 155 } else if (window) { |
154 event_window = GTK_WIDGET(window)->window; | 156 event_window = GTK_WIDGET(window)->window; |
155 } else { | 157 } else { |
156 // No target was specified. Send the events to the active toplevel. | 158 // No target was specified. Send the events to the active toplevel. |
157 GList* windows = gtk_window_list_toplevels(); | 159 GList* windows = gtk_window_list_toplevels(); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 | 210 |
209 if (control) | 211 if (control) |
210 rv = rv && SendKeyEvent(event_window, false, GDK_Control_L, | 212 rv = rv && SendKeyEvent(event_window, false, GDK_Control_L, |
211 GDK_CONTROL_MASK); | 213 GDK_CONTROL_MASK); |
212 | 214 |
213 return rv; | 215 return rv; |
214 } | 216 } |
215 | 217 |
216 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, | 218 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
217 base::KeyboardCode key, | 219 base::KeyboardCode key, |
218 bool control, bool shift, bool alt, | 220 bool control, bool shift, |
| 221 bool alt, bool command, |
219 Task* task) { | 222 Task* task) { |
| 223 DCHECK(command == false); // No command key on Linux |
220 int release_count = 1; | 224 int release_count = 1; |
221 if (control) | 225 if (control) |
222 release_count++; | 226 release_count++; |
223 if (shift) | 227 if (shift) |
224 release_count++; | 228 release_count++; |
225 if (alt) | 229 if (alt) |
226 release_count++; | 230 release_count++; |
227 // This object will delete itself after running |task|. | 231 // This object will delete itself after running |task|. |
228 new EventWaiter(task, GDK_KEY_RELEASE, release_count); | 232 new EventWaiter(task, GDK_KEY_RELEASE, release_count); |
229 return SendKeyPress(window, key, control, shift, alt); | 233 return SendKeyPress(window, key, control, shift, alt, command); |
230 } | 234 } |
231 | 235 |
232 bool SendMouseMove(long x, long y) { | 236 bool SendMouseMove(long x, long y) { |
233 gdk_display_warp_pointer(gdk_display_get_default(), gdk_screen_get_default(), | 237 gdk_display_warp_pointer(gdk_display_get_default(), gdk_screen_get_default(), |
234 x, y); | 238 x, y); |
235 // Sometimes gdk_display_warp_pointer fails to send back any indication of | 239 // Sometimes gdk_display_warp_pointer fails to send back any indication of |
236 // the move, even though it succesfully moves the server cursor. We fake it in | 240 // the move, even though it succesfully moves the server cursor. We fake it in |
237 // order to get drags to work. | 241 // order to get drags to work. |
238 FakeAMouseMotionEvent(x, y); | 242 FakeAMouseMotionEvent(x, y); |
239 | 243 |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 int state, | 338 int state, |
335 Task* task) { | 339 Task* task) { |
336 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); | 340 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); |
337 SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2, | 341 SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2, |
338 bounds.y() + bounds.height() / 2, | 342 bounds.y() + bounds.height() / 2, |
339 new ClickTask(button, state, task)); | 343 new ClickTask(button, state, task)); |
340 } | 344 } |
341 #endif | 345 #endif |
342 | 346 |
343 } // namespace ui_controls | 347 } // namespace ui_controls |
OLD | NEW |