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

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

Issue 8821012: Revert 113177 - process all ui events before posting closure because menu depends on ui events to... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years 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
OLDNEW
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 <X11/keysym.h> 7 #include <X11/keysym.h>
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 9
10 #include "base/callback.h" 10 #include "base/callback.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 "marker_event", 63 "marker_event",
64 False); 64 False);
65 } 65 }
66 66
67 // Returns true when the event is a marker event. 67 // Returns true when the event is a marker event.
68 bool Matcher(const base::NativeEvent& event) { 68 bool Matcher(const base::NativeEvent& event) {
69 return event->xany.type == ClientMessage && 69 return event->xany.type == ClientMessage &&
70 event->xclient.message_type == MarkerEventAtom(); 70 event->xclient.message_type == MarkerEventAtom();
71 } 71 }
72 72
73 void RunClosureAfterEvents(const base::Closure closure) {
74 if (closure.is_null())
75 return;
76 static XEvent* marker_event = NULL;
77 if (!marker_event) {
78 marker_event = new XEvent();
79 marker_event->xclient.type = ClientMessage;
80 marker_event->xclient.display = NULL;
81 marker_event->xclient.window = None;
82 marker_event->xclient.format = 8;
83 }
84 marker_event->xclient.message_type = MarkerEventAtom();
85 aura::Desktop::GetInstance()->PostNativeEvent(marker_event);
86 new EventWaiter(closure, &Matcher);
87 }
88
73 } // namespace 89 } // namespace
74 90
75 namespace ui_controls { 91 namespace ui_controls {
76 92
77 bool SendKeyPress(gfx::NativeWindow window, 93 bool SendKeyPress(gfx::NativeWindow window,
78 ui::KeyboardCode key, 94 ui::KeyboardCode key,
79 bool control, 95 bool control,
80 bool shift, 96 bool shift,
81 bool alt, 97 bool alt,
82 bool command) { 98 bool command) {
(...skipping 27 matching lines...) Expand all
110 const base::Closure& closure) { 126 const base::Closure& closure) {
111 DCHECK(!command); // No command key on Aura 127 DCHECK(!command); // No command key on Aura
112 XEvent xevent = {0}; 128 XEvent xevent = {0};
113 xevent.xkey.type = KeyPress; 129 xevent.xkey.type = KeyPress;
114 if (control) 130 if (control)
115 SetMaskAndKeycodeThenSend(&xevent, ControlMask, XK_Control_L); 131 SetMaskAndKeycodeThenSend(&xevent, ControlMask, XK_Control_L);
116 if (shift) 132 if (shift)
117 SetMaskAndKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); 133 SetMaskAndKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L);
118 if (alt) 134 if (alt)
119 SetMaskAndKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); 135 SetMaskAndKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L);
120 xevent.xkey.keycode = ui::XKeysymForWindowsKeyCode(key, shift); 136 xevent.xkey.keycode =
137 XKeysymToKeycode(base::MessagePumpX::GetDefaultXDisplay(),
138 ui::XKeysymForWindowsKeyCode(key, shift));
121 aura::Desktop::GetInstance()->PostNativeEvent(&xevent); 139 aura::Desktop::GetInstance()->PostNativeEvent(&xevent);
122 140
123 // Send key release events. 141 // Send key release events.
124 xevent.xkey.type = KeyRelease; 142 xevent.xkey.type = KeyRelease;
125 aura::Desktop::GetInstance()->PostNativeEvent(&xevent); 143 aura::Desktop::GetInstance()->PostNativeEvent(&xevent);
126 if (alt) 144 if (alt)
127 SetKeycodeAndSendThenUnmask(&xevent, Mod1Mask, XK_Alt_L); 145 SetKeycodeAndSendThenUnmask(&xevent, Mod1Mask, XK_Alt_L);
128 if (shift) 146 if (shift)
129 SetKeycodeAndSendThenUnmask(&xevent, ShiftMask, XK_Shift_L); 147 SetKeycodeAndSendThenUnmask(&xevent, ShiftMask, XK_Shift_L);
130 if (control) 148 if (control)
131 SetKeycodeAndSendThenUnmask(&xevent, ControlMask, XK_Control_L); 149 SetKeycodeAndSendThenUnmask(&xevent, ControlMask, XK_Control_L);
132 DCHECK(!xevent.xkey.state); 150 DCHECK(!xevent.xkey.state);
133 RunClosureAfterAllPendingUIEvents(closure); 151 RunClosureAfterEvents(closure);
134 return true; 152 return true;
135 } 153 }
136 154
137 bool SendMouseMove(long x, long y) { 155 bool SendMouseMove(long x, long y) {
138 return SendMouseMoveNotifyWhenDone(x, y, base::Closure()); 156 return SendMouseMoveNotifyWhenDone(x, y, base::Closure());
139 } 157 }
140 158
141 bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& closure) { 159 bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& closure) {
142 XEvent xevent = {0}; 160 XEvent xevent = {0};
143 XMotionEvent* xmotion = &xevent.xmotion; 161 XMotionEvent* xmotion = &xevent.xmotion;
144 xmotion->type = MotionNotify; 162 xmotion->type = MotionNotify;
145 g_current_x = xmotion->x = x; 163 g_current_x = xmotion->x = x;
146 g_current_y = xmotion->y = y; 164 g_current_y = xmotion->y = y;
147 xmotion->same_screen = True; 165 xmotion->same_screen = True;
148 // Desktop will take care of other necessary fields. 166 // Desktop will take care of other necessary fields.
149 aura::Desktop::GetInstance()->PostNativeEvent(&xevent); 167 aura::Desktop::GetInstance()->PostNativeEvent(&xevent);
150 RunClosureAfterAllPendingUIEvents(closure); 168 RunClosureAfterEvents(closure);
151 return false; 169 return false;
152 } 170 }
153 171
154 bool SendMouseEvents(MouseButton type, int state) { 172 bool SendMouseEvents(MouseButton type, int state) {
155 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); 173 return SendMouseEventsNotifyWhenDone(type, state, base::Closure());
156 } 174 }
157 175
158 bool SendMouseEventsNotifyWhenDone(MouseButton type, 176 bool SendMouseEventsNotifyWhenDone(MouseButton type,
159 int state, 177 int state,
160 const base::Closure& closure) { 178 const base::Closure& closure) {
(...skipping 22 matching lines...) Expand all
183 201
184 aura::Desktop* desktop = aura::Desktop::GetInstance(); 202 aura::Desktop* desktop = aura::Desktop::GetInstance();
185 if (state & DOWN) { 203 if (state & DOWN) {
186 xevent.xbutton.type = ButtonPress; 204 xevent.xbutton.type = ButtonPress;
187 desktop->PostNativeEvent(&xevent); 205 desktop->PostNativeEvent(&xevent);
188 } 206 }
189 if (state & UP) { 207 if (state & UP) {
190 xevent.xbutton.type = ButtonRelease; 208 xevent.xbutton.type = ButtonRelease;
191 desktop->PostNativeEvent(&xevent); 209 desktop->PostNativeEvent(&xevent);
192 } 210 }
193 RunClosureAfterAllPendingUIEvents(closure); 211 RunClosureAfterEvents(closure);
194 return false; 212 return false;
195 } 213 }
196 214
197 bool SendMouseClick(MouseButton type) { 215 bool SendMouseClick(MouseButton type) {
198 return SendMouseEvents(type, UP | DOWN); 216 return SendMouseEvents(type, UP | DOWN);
199 } 217 }
200 218
201 void MoveMouseToCenterAndPress(views::View* view, MouseButton button, 219 void MoveMouseToCenterAndPress(views::View* view, MouseButton button,
202 int state, const base::Closure& closure) { 220 int state, const base::Closure& closure) {
203 DCHECK(view); 221 DCHECK(view);
204 DCHECK(view->GetWidget()); 222 DCHECK(view->GetWidget());
205 gfx::Point view_center(view->width() / 2, view->height() / 2); 223 gfx::Point view_center(view->width() / 2, view->height() / 2);
206 views::View::ConvertPointToScreen(view, &view_center); 224 views::View::ConvertPointToScreen(view, &view_center);
207 SendMouseMove(view_center.x(), view_center.y()); 225 SendMouseMove(view_center.x(), view_center.y());
208 SendMouseEventsNotifyWhenDone(button, state, closure); 226 SendMouseEventsNotifyWhenDone(button, state, closure);
209 } 227 }
210 228
211 void RunClosureAfterAllPendingUIEvents(const base::Closure& closure) {
212 if (closure.is_null())
213 return;
214 static XEvent* marker_event = NULL;
215 if (!marker_event) {
216 marker_event = new XEvent();
217 marker_event->xclient.type = ClientMessage;
218 marker_event->xclient.display = NULL;
219 marker_event->xclient.window = None;
220 marker_event->xclient.format = 8;
221 }
222 marker_event->xclient.message_type = MarkerEventAtom();
223 aura::Desktop::GetInstance()->PostNativeEvent(marker_event);
224 new EventWaiter(closure, &Matcher);
225 }
226
227 } // namespace ui_controls 229 } // namespace ui_controls
OLDNEW
« no previous file with comments | « chrome/browser/automation/ui_controls_aurawin.cc ('k') | chrome/browser/automation/ui_controls_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698