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 "base/gfx/rect.h" | 10 #include "base/gfx/rect.h" |
| 11 #include "base/keyboard_code_conversion_gtk.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
13 #include "chrome/common/gtk_util.h" | 14 #include "chrome/common/gtk_util.h" |
14 #include "chrome/test/automation/automation_constants.h" | 15 #include "chrome/test/automation/automation_constants.h" |
15 | 16 |
16 #if defined(TOOLKIT_VIEWS) | 17 #if defined(TOOLKIT_VIEWS) |
17 #include "views/view.h" | 18 #include "views/view.h" |
18 #include "views/widget/widget.h" | 19 #include "views/widget/widget.h" |
19 #endif | 20 #endif |
20 | 21 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 else | 81 else |
81 ui_controls::SendMouseEvents(button_, state_); | 82 ui_controls::SendMouseEvents(button_, state_); |
82 } | 83 } |
83 | 84 |
84 private: | 85 private: |
85 ui_controls::MouseButton button_; | 86 ui_controls::MouseButton button_; |
86 int state_; | 87 int state_; |
87 Task* followup_; | 88 Task* followup_; |
88 }; | 89 }; |
89 | 90 |
90 bool SendKeyEvent(GdkWindow* window, bool press, guint key, guint state) { | 91 bool SendKeyEvent(GdkWindow* window, bool press, guint gdk_key, guint state) { |
91 GdkEvent* event = gdk_event_new(press ? GDK_KEY_PRESS : GDK_KEY_RELEASE); | 92 GdkEvent* event = gdk_event_new(press ? GDK_KEY_PRESS : GDK_KEY_RELEASE); |
92 | 93 |
93 event->key.type = press ? GDK_KEY_PRESS : GDK_KEY_RELEASE; | 94 event->key.type = press ? GDK_KEY_PRESS : GDK_KEY_RELEASE; |
94 event->key.window = window; | 95 event->key.window = window; |
95 g_object_ref(event->key.window); | 96 g_object_ref(event->key.window); |
96 event->key.send_event = false; | 97 event->key.send_event = false; |
97 event->key.time = EventTimeNow(); | 98 event->key.time = EventTimeNow(); |
98 | 99 |
99 event->key.state = state; | 100 event->key.state = state; |
100 event->key.keyval = key; | 101 event->key.keyval = gdk_key; |
101 | 102 |
102 GdkKeymapKey* keys; | 103 GdkKeymapKey* keys; |
103 gint n_keys; | 104 gint n_keys; |
104 if (!gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), | 105 if (!gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), |
105 event->key.keyval, &keys, &n_keys)) { | 106 event->key.keyval, &keys, &n_keys)) { |
106 return false; | 107 return false; |
107 } | 108 } |
108 event->key.hardware_keycode = keys[0].keycode; | 109 event->key.hardware_keycode = keys[0].keycode; |
109 event->key.group = keys[0].group; | 110 event->key.group = keys[0].group; |
110 g_free(keys); | 111 g_free(keys); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 guint state = (control ? GDK_CONTROL_MASK : 0) | | 189 guint state = (control ? GDK_CONTROL_MASK : 0) | |
189 (shift ? GDK_SHIFT_MASK : 0); | 190 (shift ? GDK_SHIFT_MASK : 0); |
190 rv = rv && SendKeyEvent(event_window, true, GDK_Alt_L, state); | 191 rv = rv && SendKeyEvent(event_window, true, GDK_Alt_L, state); |
191 } | 192 } |
192 | 193 |
193 // TODO(estade): handle other state flags besides control, shift, alt? | 194 // TODO(estade): handle other state flags besides control, shift, alt? |
194 // For example caps lock. | 195 // For example caps lock. |
195 guint state = (control ? GDK_CONTROL_MASK : 0) | | 196 guint state = (control ? GDK_CONTROL_MASK : 0) | |
196 (shift ? GDK_SHIFT_MASK : 0) | | 197 (shift ? GDK_SHIFT_MASK : 0) | |
197 (alt ? GDK_MOD1_MASK : 0); | 198 (alt ? GDK_MOD1_MASK : 0); |
| 199 |
| 200 key = base::GdkKeyCodeForWindowsKeyCode(key); |
198 rv = rv && SendKeyEvent(event_window, true, key, state); | 201 rv = rv && SendKeyEvent(event_window, true, key, state); |
199 rv = rv && SendKeyEvent(event_window, false, key, state); | 202 rv = rv && SendKeyEvent(event_window, false, key, state); |
200 | 203 |
201 if (alt) { | 204 if (alt) { |
202 guint state = (control ? GDK_CONTROL_MASK : 0) | | 205 guint state = (control ? GDK_CONTROL_MASK : 0) | |
203 (shift ? GDK_SHIFT_MASK : 0); | 206 (shift ? GDK_SHIFT_MASK : 0); |
204 rv = rv && SendKeyEvent(event_window, false, GDK_Alt_L, state); | 207 rv = rv && SendKeyEvent(event_window, false, GDK_Alt_L, state); |
205 } | 208 } |
206 | 209 |
207 if (shift) { | 210 if (shift) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 int state, | 338 int state, |
336 Task* task) { | 339 Task* task) { |
337 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); | 340 gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget); |
338 SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2, | 341 SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2, |
339 bounds.y() + bounds.height() / 2, | 342 bounds.y() + bounds.height() / 2, |
340 new ClickTask(button, state, task)); | 343 new ClickTask(button, state, task)); |
341 } | 344 } |
342 #endif | 345 #endif |
343 | 346 |
344 } // namespace ui_controls | 347 } // namespace ui_controls |
OLD | NEW |