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

Side by Side Diff: ui/views/test/ui_controls_factory_desktop_aurax11.cc

Issue 37733003: Make GetRootWindow() return a Window instead of a RootWindow. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 1 month 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <X11/keysym.h> 5 #include <X11/keysym.h>
6 #include <X11/Xlib.h> 6 #include <X11/Xlib.h>
7 7
8 // X macro fail. 8 // X macro fail.
9 #if defined(RootWindow) 9 #if defined(RootWindow)
10 #undef RootWindow 10 #undef RootWindow
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 virtual bool SendKeyPressNotifyWhenDone( 118 virtual bool SendKeyPressNotifyWhenDone(
119 gfx::NativeWindow window, 119 gfx::NativeWindow window,
120 ui::KeyboardCode key, 120 ui::KeyboardCode key,
121 bool control, 121 bool control,
122 bool shift, 122 bool shift,
123 bool alt, 123 bool alt,
124 bool command, 124 bool command,
125 const base::Closure& closure) OVERRIDE { 125 const base::Closure& closure) OVERRIDE {
126 DCHECK(!command); // No command key on Aura 126 DCHECK(!command); // No command key on Aura
127 127
128 aura::RootWindow* root_window = window->GetRootWindow(); 128 aura::WindowEventDispatcher* dispatcher = window->GetDispatcher();
129 129
130 XEvent xevent = {0}; 130 XEvent xevent = {0};
131 xevent.xkey.type = KeyPress; 131 xevent.xkey.type = KeyPress;
132 if (control) { 132 if (control) {
133 SetKeycodeAndSendThenMask(root_window, &xevent, XK_Control_L, 133 SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Control_L,
134 ControlMask); 134 ControlMask);
135 } 135 }
136 if (shift) 136 if (shift)
137 SetKeycodeAndSendThenMask(root_window, &xevent, XK_Shift_L, ShiftMask); 137 SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Shift_L, ShiftMask);
138 if (alt) 138 if (alt)
139 SetKeycodeAndSendThenMask(root_window, &xevent, XK_Alt_L, Mod1Mask); 139 SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Alt_L, Mod1Mask);
140 xevent.xkey.keycode = 140 xevent.xkey.keycode =
141 XKeysymToKeycode(x_display_, 141 XKeysymToKeycode(x_display_,
142 ui::XKeysymForWindowsKeyCode(key, shift)); 142 ui::XKeysymForWindowsKeyCode(key, shift));
143 root_window->PostNativeEvent(&xevent); 143 dispatcher->PostNativeEvent(&xevent);
144 144
145 // Send key release events. 145 // Send key release events.
146 xevent.xkey.type = KeyRelease; 146 xevent.xkey.type = KeyRelease;
147 root_window->PostNativeEvent(&xevent); 147 dispatcher->PostNativeEvent(&xevent);
148 if (alt) 148 if (alt)
149 UnmaskAndSetKeycodeThenSend(root_window, &xevent, Mod1Mask, XK_Alt_L); 149 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, Mod1Mask, XK_Alt_L);
150 if (shift) 150 if (shift)
151 UnmaskAndSetKeycodeThenSend(root_window, &xevent, ShiftMask, XK_Shift_L); 151 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, ShiftMask, XK_Shift_L);
152 if (control) { 152 if (control) {
153 UnmaskAndSetKeycodeThenSend(root_window, &xevent, ControlMask, 153 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, ControlMask,
154 XK_Control_L); 154 XK_Control_L);
155 } 155 }
156 DCHECK(!xevent.xkey.state); 156 DCHECK(!xevent.xkey.state);
157 RunClosureAfterAllPendingUIEvents(closure); 157 RunClosureAfterAllPendingUIEvents(closure);
158 return true; 158 return true;
159 } 159 }
160 160
161 // Simulate a mouse move. (x,y) are absolute screen coordinates. 161 // Simulate a mouse move. (x,y) are absolute screen coordinates.
162 virtual bool SendMouseMove(long x, long y) OVERRIDE { 162 virtual bool SendMouseMove(long x, long y) OVERRIDE {
163 return SendMouseMoveNotifyWhenDone(x, y, base::Closure()); 163 return SendMouseMoveNotifyWhenDone(x, y, base::Closure());
164 } 164 }
165 virtual bool SendMouseMoveNotifyWhenDone( 165 virtual bool SendMouseMoveNotifyWhenDone(
166 long x, 166 long x,
167 long y, 167 long y,
168 const base::Closure& closure) OVERRIDE { 168 const base::Closure& closure) OVERRIDE {
169 gfx::Point screen_point(x, y); 169 gfx::Point screen_point(x, y);
170 gfx::Point window_point = screen_point; 170 gfx::Point window_point = screen_point;
171 aura::RootWindow* root_window = RootWindowForPoint(screen_point); 171 aura::Window* root_window = RootWindowForPoint(screen_point);
172 172
173 aura::client::ScreenPositionClient* screen_position_client = 173 aura::client::ScreenPositionClient* screen_position_client =
174 aura::client::GetScreenPositionClient(root_window); 174 aura::client::GetScreenPositionClient(root_window);
175 if (screen_position_client) { 175 if (screen_position_client) {
176 screen_position_client->ConvertPointFromScreen(root_window, 176 screen_position_client->ConvertPointFromScreen(root_window,
177 &window_point); 177 &window_point);
178 } 178 }
179 179
180 XEvent xevent = {0}; 180 XEvent xevent = {0};
181 XMotionEvent* xmotion = &xevent.xmotion; 181 XMotionEvent* xmotion = &xevent.xmotion;
182 xmotion->type = MotionNotify; 182 xmotion->type = MotionNotify;
183 xmotion->x = window_point.x(); 183 xmotion->x = window_point.x();
184 xmotion->y = window_point.y(); 184 xmotion->y = window_point.y();
185 xmotion->state = button_down_mask; 185 xmotion->state = button_down_mask;
186 xmotion->same_screen = True; 186 xmotion->same_screen = True;
187 // RootWindow will take care of other necessary fields. 187 // RootWindow will take care of other necessary fields.
188 root_window->PostNativeEvent(&xevent); 188 root_window->GetDispatcher()->PostNativeEvent(&xevent);
189 RunClosureAfterAllPendingUIEvents(closure); 189 RunClosureAfterAllPendingUIEvents(closure);
190 return true; 190 return true;
191 } 191 }
192 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { 192 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE {
193 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); 193 return SendMouseEventsNotifyWhenDone(type, state, base::Closure());
194 } 194 }
195 virtual bool SendMouseEventsNotifyWhenDone( 195 virtual bool SendMouseEventsNotifyWhenDone(
196 MouseButton type, 196 MouseButton type,
197 int state, 197 int state,
198 const base::Closure& closure) OVERRIDE { 198 const base::Closure& closure) OVERRIDE {
199 XEvent xevent = {0}; 199 XEvent xevent = {0};
200 XButtonEvent* xbutton = &xevent.xbutton; 200 XButtonEvent* xbutton = &xevent.xbutton;
201 gfx::Point mouse_loc = aura::Env::GetInstance()->last_mouse_location(); 201 gfx::Point mouse_loc = aura::Env::GetInstance()->last_mouse_location();
202 aura::RootWindow* root_window = RootWindowForPoint(mouse_loc); 202 aura::Window* root_window = RootWindowForPoint(mouse_loc);
203 aura::client::ScreenPositionClient* screen_position_client = 203 aura::client::ScreenPositionClient* screen_position_client =
204 aura::client::GetScreenPositionClient(root_window); 204 aura::client::GetScreenPositionClient(root_window);
205 if (screen_position_client) 205 if (screen_position_client)
206 screen_position_client->ConvertPointFromScreen(root_window, &mouse_loc); 206 screen_position_client->ConvertPointFromScreen(root_window, &mouse_loc);
207 xbutton->x = mouse_loc.x(); 207 xbutton->x = mouse_loc.x();
208 xbutton->y = mouse_loc.y(); 208 xbutton->y = mouse_loc.y();
209 xbutton->same_screen = True; 209 xbutton->same_screen = True;
210 switch (type) { 210 switch (type) {
211 case LEFT: 211 case LEFT:
212 xbutton->button = Button1; 212 xbutton->button = Button1;
213 xbutton->state = Button1Mask; 213 xbutton->state = Button1Mask;
214 break; 214 break;
215 case MIDDLE: 215 case MIDDLE:
216 xbutton->button = Button2; 216 xbutton->button = Button2;
217 xbutton->state = Button2Mask; 217 xbutton->state = Button2Mask;
218 break; 218 break;
219 case RIGHT: 219 case RIGHT:
220 xbutton->button = Button3; 220 xbutton->button = Button3;
221 xbutton->state = Button3Mask; 221 xbutton->state = Button3Mask;
222 break; 222 break;
223 } 223 }
224 // RootWindow will take care of other necessary fields. 224 // RootWindow will take care of other necessary fields.
225 if (state & DOWN) { 225 if (state & DOWN) {
226 xevent.xbutton.type = ButtonPress; 226 xevent.xbutton.type = ButtonPress;
227 root_window->PostNativeEvent(&xevent); 227 root_window->GetDispatcher()->PostNativeEvent(&xevent);
228 button_down_mask |= xbutton->state; 228 button_down_mask |= xbutton->state;
229 } 229 }
230 if (state & UP) { 230 if (state & UP) {
231 xevent.xbutton.type = ButtonRelease; 231 xevent.xbutton.type = ButtonRelease;
232 root_window->PostNativeEvent(&xevent); 232 root_window->GetDispatcher()->PostNativeEvent(&xevent);
233 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; 233 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state;
234 } 234 }
235 RunClosureAfterAllPendingUIEvents(closure); 235 RunClosureAfterAllPendingUIEvents(closure);
236 return true; 236 return true;
237 } 237 }
238 virtual bool SendMouseClick(MouseButton type) OVERRIDE { 238 virtual bool SendMouseClick(MouseButton type) OVERRIDE {
239 return SendMouseEvents(type, UP | DOWN); 239 return SendMouseEvents(type, UP | DOWN);
240 } 240 }
241 virtual void RunClosureAfterAllPendingUIEvents( 241 virtual void RunClosureAfterAllPendingUIEvents(
242 const base::Closure& closure) OVERRIDE { 242 const base::Closure& closure) OVERRIDE {
243 if (closure.is_null()) 243 if (closure.is_null())
244 return; 244 return;
245 static XEvent* marker_event = NULL; 245 static XEvent* marker_event = NULL;
246 if (!marker_event) { 246 if (!marker_event) {
247 marker_event = new XEvent(); 247 marker_event = new XEvent();
248 marker_event->xclient.type = ClientMessage; 248 marker_event->xclient.type = ClientMessage;
249 marker_event->xclient.display = x_display_; 249 marker_event->xclient.display = x_display_;
250 marker_event->xclient.window = x_window_; 250 marker_event->xclient.window = x_window_;
251 marker_event->xclient.format = 8; 251 marker_event->xclient.format = 8;
252 } 252 }
253 marker_event->xclient.message_type = MarkerEventAtom(); 253 marker_event->xclient.message_type = MarkerEventAtom();
254 XSendEvent(x_display_, x_window_, False, 0, marker_event); 254 XSendEvent(x_display_, x_window_, False, 0, marker_event);
255 new EventWaiter(closure, &Matcher); 255 new EventWaiter(closure, &Matcher);
256 } 256 }
257 private: 257 private:
258 aura::RootWindow* RootWindowForPoint(const gfx::Point& point) { 258 aura::Window* RootWindowForPoint(const gfx::Point& point) {
259 // Most interactive_ui_tests run inside of the aura_test_helper 259 // Most interactive_ui_tests run inside of the aura_test_helper
260 // environment. This means that we can't rely on gfx::Screen and several 260 // environment. This means that we can't rely on gfx::Screen and several
261 // other things to work properly. Therefore we hack around this by 261 // other things to work properly. Therefore we hack around this by
262 // iterating across the windows owned DesktopRootWindowHostX11 since this 262 // iterating across the windows owned DesktopRootWindowHostX11 since this
263 // doesn't rely on having a DesktopScreenX11. 263 // doesn't rely on having a DesktopScreenX11.
264 std::vector<aura::Window*> windows = 264 std::vector<aura::Window*> windows =
265 DesktopRootWindowHostX11::GetAllOpenWindows(); 265 DesktopRootWindowHostX11::GetAllOpenWindows();
266 for (std::vector<aura::Window*>::const_iterator it = windows.begin(); 266 for (std::vector<aura::Window*>::const_iterator it = windows.begin();
267 it != windows.end(); ++it) { 267 it != windows.end(); ++it) {
268 if ((*it)->GetBoundsInScreen().Contains(point)) { 268 if ((*it)->GetBoundsInScreen().Contains(point)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 }; 304 };
305 305
306 } // namespace 306 } // namespace
307 307
308 UIControlsAura* CreateUIControlsDesktopAura() { 308 UIControlsAura* CreateUIControlsDesktopAura() {
309 return new UIControlsDesktopX11(); 309 return new UIControlsDesktopX11();
310 } 310 }
311 311
312 } // namespace test 312 } // namespace test
313 } // namespace views 313 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/event_utils_aura.cc ('k') | ui/views/widget/desktop_aura/desktop_drag_drop_client_aurax11.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698