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 "app/event_synthesis_gtk.h" |
10 #include "gfx/rect.h" | 11 #include "gfx/rect.h" |
11 #include "base/event_synthesis_gtk.h" | |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "chrome/browser/automation/ui_controls_internal.h" | 14 #include "chrome/browser/automation/ui_controls_internal.h" |
15 #include "chrome/browser/gtk/gtk_util.h" | 15 #include "chrome/browser/gtk/gtk_util.h" |
16 #include "chrome/test/automation/automation_constants.h" | 16 #include "chrome/test/automation/automation_constants.h" |
17 | 17 |
18 #if defined(TOOLKIT_VIEWS) | 18 #if defined(TOOLKIT_VIEWS) |
19 #include "views/view.h" | 19 #include "views/view.h" |
20 #include "views/widget/widget.h" | 20 #include "views/widget/widget.h" |
21 #endif | 21 #endif |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 | 89 |
90 gdk_event_put(event); | 90 gdk_event_put(event); |
91 gdk_event_free(event); | 91 gdk_event_free(event); |
92 } | 92 } |
93 | 93 |
94 } // namespace | 94 } // namespace |
95 | 95 |
96 namespace ui_controls { | 96 namespace ui_controls { |
97 | 97 |
98 bool SendKeyPress(gfx::NativeWindow window, | 98 bool SendKeyPress(gfx::NativeWindow window, |
99 base::KeyboardCode key, | 99 app::KeyboardCode key, |
100 bool control, bool shift, bool alt, bool command) { | 100 bool control, bool shift, bool alt, bool command) { |
101 DCHECK(command == false); // No command key on Linux | 101 DCHECK(command == false); // No command key on Linux |
102 GdkWindow* event_window = NULL; | 102 GdkWindow* event_window = NULL; |
103 GtkWidget* grab_widget = gtk_grab_get_current(); | 103 GtkWidget* grab_widget = gtk_grab_get_current(); |
104 if (grab_widget) { | 104 if (grab_widget) { |
105 // If there is a grab, send all events to the grabbed widget. | 105 // If there is a grab, send all events to the grabbed widget. |
106 event_window = grab_widget->window; | 106 event_window = grab_widget->window; |
107 } else if (window) { | 107 } else if (window) { |
108 event_window = GTK_WIDGET(window)->window; | 108 event_window = GTK_WIDGET(window)->window; |
109 } else { | 109 } else { |
110 // No target was specified. Send the events to the active toplevel. | 110 // No target was specified. Send the events to the active toplevel. |
111 GList* windows = gtk_window_list_toplevels(); | 111 GList* windows = gtk_window_list_toplevels(); |
112 for (GList* element = windows; element; element = g_list_next(element)) { | 112 for (GList* element = windows; element; element = g_list_next(element)) { |
113 GtkWindow* this_window = GTK_WINDOW(element->data); | 113 GtkWindow* this_window = GTK_WINDOW(element->data); |
114 if (gtk_window_is_active(this_window)) { | 114 if (gtk_window_is_active(this_window)) { |
115 event_window = GTK_WIDGET(this_window)->window; | 115 event_window = GTK_WIDGET(this_window)->window; |
116 break; | 116 break; |
117 } | 117 } |
118 } | 118 } |
119 g_list_free(windows); | 119 g_list_free(windows); |
120 } | 120 } |
121 if (!event_window) { | 121 if (!event_window) { |
122 NOTREACHED() << "Window not specified and none is active"; | 122 NOTREACHED() << "Window not specified and none is active"; |
123 return false; | 123 return false; |
124 } | 124 } |
125 | 125 |
126 std::vector<GdkEvent*> events; | 126 std::vector<GdkEvent*> events; |
127 base::SynthesizeKeyPressEvents(event_window, key, control, shift, alt, | 127 app::SynthesizeKeyPressEvents(event_window, key, control, shift, alt, |
128 &events); | 128 &events); |
129 for (std::vector<GdkEvent*>::iterator iter = events.begin(); | 129 for (std::vector<GdkEvent*>::iterator iter = events.begin(); |
130 iter != events.end(); ++iter) { | 130 iter != events.end(); ++iter) { |
131 gdk_event_put(*iter); | 131 gdk_event_put(*iter); |
132 // gdk_event_put appends a copy of the event. | 132 // gdk_event_put appends a copy of the event. |
133 gdk_event_free(*iter); | 133 gdk_event_free(*iter); |
134 } | 134 } |
135 | 135 |
136 return true; | 136 return true; |
137 } | 137 } |
138 | 138 |
139 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, | 139 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
140 base::KeyboardCode key, | 140 app::KeyboardCode key, |
141 bool control, bool shift, | 141 bool control, bool shift, |
142 bool alt, bool command, | 142 bool alt, bool command, |
143 Task* task) { | 143 Task* task) { |
144 DCHECK(command == false); // No command key on Linux | 144 DCHECK(command == false); // No command key on Linux |
145 int release_count = 1; | 145 int release_count = 1; |
146 if (control) | 146 if (control) |
147 release_count++; | 147 release_count++; |
148 if (shift) | 148 if (shift) |
149 release_count++; | 149 release_count++; |
150 if (alt) | 150 if (alt) |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 int state, | 259 int state, |
260 Task* task) { | 260 Task* task) { |
261 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); | 261 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); |
262 SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2, | 262 SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2, |
263 bounds.y() + bounds.height() / 2, | 263 bounds.y() + bounds.height() / 2, |
264 new ClickTask(button, state, task)); | 264 new ClickTask(button, state, task)); |
265 } | 265 } |
266 #endif | 266 #endif |
267 | 267 |
268 } // namespace ui_controls | 268 } // namespace ui_controls |
OLD | NEW |