Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1244)

Side by Side Diff: chrome/browser/automation/ui_controls_linux.cc

Issue 171079: more linux automation porting: SendKeyPressNotifyWhenDone... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/automation/ui_controls.h ('k') | chrome/browser/automation/ui_controls_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/logging.h" 10 #include "base/logging.h"
11 #include "base/message_loop.h"
11 #include "chrome/test/automation/automation_constants.h" 12 #include "chrome/test/automation/automation_constants.h"
12 13
13 namespace { 14 namespace {
14 15
15 int GdkKeycodeForWindowsKeycode(wchar_t windows_keyval) { 16 class EventWaiter : public MessageLoopForUI::Observer {
16 switch (windows_keyval) { 17 public:
17 case VK_SPACE: 18 EventWaiter(Task* task, GdkEventType type) : task_(task), type_(type) {
18 return GDK_space; 19 MessageLoopForUI::current()->AddObserver(this);
19 default:
20 NOTREACHED() << "Unsupported keyval: " << windows_keyval;
21 return 0;
22 } 20 }
21
22 virtual ~EventWaiter() {
23 MessageLoopForUI::current()->RemoveObserver(this);
24 }
25
26 // MessageLoop::Observer implementation:
27 virtual void WillProcessEvent(GdkEvent* event) {
28 // No-op.
29 }
30
31 virtual void DidProcessEvent(GdkEvent* event) {
32 if (event->any.type == type_) {
33 task_->Run();
34 delete this;
35 }
36 }
37
38 private:
39 Task* task_;
40 GdkEventType type_;
41 };
42
23 } 43 }
24 44
25 } // namespace
26
27 namespace ui_controls { 45 namespace ui_controls {
28 46
29 bool SendKeyPress(gfx::NativeWindow window, 47 bool SendKeyPress(gfx::NativeWindow window,
30 wchar_t key, bool control, bool shift, bool alt) { 48 wchar_t key, bool control, bool shift, bool alt) {
49 // TODO(estade): send a release as well?
31 GdkEvent* event = gdk_event_new(GDK_KEY_PRESS); 50 GdkEvent* event = gdk_event_new(GDK_KEY_PRESS);
32 51
33 event->key.type = GDK_KEY_PRESS; 52 event->key.type = GDK_KEY_PRESS;
34 event->key.window = GTK_WIDGET(window)->window; 53 event->key.window = GTK_WIDGET(window)->window;
35 g_object_ref(event->key.window); 54 g_object_ref(event->key.window);
36 event->key.send_event = false; 55 event->key.send_event = false;
37 // TODO(estade): Put the real time? 56 // TODO(estade): Put the real time?
38 event->key.time = GDK_CURRENT_TIME; 57 event->key.time = GDK_CURRENT_TIME;
39 // TODO(estade): handle other state flags besides control, shift, alt? 58 // TODO(estade): handle other state flags besides control, shift, alt?
40 // For example caps lock. 59 // For example caps lock.
41 event->key.state = (control ? GDK_CONTROL_MASK : 0) | 60 event->key.state = (control ? GDK_CONTROL_MASK : 0) |
42 (shift ? GDK_SHIFT_MASK : 0) | 61 (shift ? GDK_SHIFT_MASK : 0) |
43 (alt ? GDK_MOD1_MASK : 0); 62 (alt ? GDK_MOD1_MASK : 0);
44 event->key.keyval = GdkKeycodeForWindowsKeycode(key); 63 event->key.keyval = key;
45 // TODO(estade): fill in the string? 64 // TODO(estade): fill in the string?
46 65
47 GdkKeymapKey* keys; 66 GdkKeymapKey* keys;
48 gint n_keys; 67 gint n_keys;
49 if (!gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(), 68 if (!gdk_keymap_get_entries_for_keyval(gdk_keymap_get_default(),
50 event->key.keyval, &keys, &n_keys)) { 69 event->key.keyval, &keys, &n_keys)) {
51 return false; 70 return false;
52 } 71 }
53 event->key.hardware_keycode = keys[0].keycode; 72 event->key.hardware_keycode = keys[0].keycode;
54 event->key.group = keys[0].group; 73 event->key.group = keys[0].group;
55 g_free(keys); 74 g_free(keys);
56 75
57 gdk_event_put(event); 76 gdk_event_put(event);
58 // gdk_event_put appends a copy of the event. 77 // gdk_event_put appends a copy of the event.
59 gdk_event_free(event); 78 gdk_event_free(event);
60 return true; 79 return true;
61 } 80 }
62 81
63 bool SendKeyPressNotifyWhenDone(wchar_t key, bool control, bool shift, 82 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, wchar_t key,
83 bool control, bool shift,
64 bool alt, Task* task) { 84 bool alt, Task* task) {
65 NOTIMPLEMENTED(); 85 // This object will delete itself after running |task|.
66 return false; 86 new EventWaiter(task, GDK_KEY_PRESS);
87 return SendKeyPress(window, key, control, shift, alt);
67 } 88 }
68 89
69 // TODO(estade): this appears to be unused on Windows. Can we remove it? 90 // TODO(estade): this appears to be unused on Windows. Can we remove it?
70 bool SendKeyDown(wchar_t key) { 91 bool SendKeyDown(wchar_t key) {
71 NOTIMPLEMENTED(); 92 NOTIMPLEMENTED();
72 return false; 93 return false;
73 } 94 }
74 95
75 // TODO(estade): this appears to be unused on Windows. Can we remove it? 96 // TODO(estade): this appears to be unused on Windows. Can we remove it?
76 bool SendKeyUp(wchar_t key) { 97 bool SendKeyUp(wchar_t key) {
(...skipping 18 matching lines...) Expand all
95 116
96 // TODO(estade): need to figure out a better type for this than View. 117 // TODO(estade): need to figure out a better type for this than View.
97 void MoveMouseToCenterAndPress(views::View* view, 118 void MoveMouseToCenterAndPress(views::View* view,
98 MouseButton button, 119 MouseButton button,
99 int state, 120 int state,
100 Task* task) { 121 Task* task) {
101 NOTIMPLEMENTED(); 122 NOTIMPLEMENTED();
102 } 123 }
103 124
104 } // namespace ui_controls 125 } // namespace ui_controls
OLDNEW
« no previous file with comments | « chrome/browser/automation/ui_controls.h ('k') | chrome/browser/automation/ui_controls_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698