OLD | NEW |
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 |
11 #endif | 11 #endif |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "ui/aura/client/screen_position_client.h" | 15 #include "ui/aura/client/screen_position_client.h" |
16 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
17 #include "ui/aura/test/aura_test_utils.h" | 17 #include "ui/aura/test/aura_test_utils.h" |
18 #include "ui/aura/test/ui_controls_factory_aura.h" | 18 #include "ui/aura/test/ui_controls_factory_aura.h" |
| 19 #include "ui/aura/test/x11_event_sender.h" |
19 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
20 #include "ui/base/test/ui_controls_aura.h" | 21 #include "ui/base/test/ui_controls_aura.h" |
21 #include "ui/base/x/x11_util.h" | 22 #include "ui/base/x/x11_util.h" |
22 #include "ui/compositor/dip_util.h" | 23 #include "ui/compositor/dip_util.h" |
23 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 24 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
24 #include "ui/events/test/platform_event_waiter.h" | 25 #include "ui/events/test/platform_event_waiter.h" |
25 #include "ui/gfx/x/x11_connection.h" | 26 #include "ui/gfx/x/x11_connection.h" |
26 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" | 27 #include "ui/views/widget/desktop_aura/desktop_window_tree_host_x11.h" |
27 | 28 |
28 namespace views { | 29 namespace views { |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 if (control) { | 98 if (control) { |
98 SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask); | 99 SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask); |
99 } | 100 } |
100 if (shift) | 101 if (shift) |
101 SetKeycodeAndSendThenMask(host, &xevent, XK_Shift_L, ShiftMask); | 102 SetKeycodeAndSendThenMask(host, &xevent, XK_Shift_L, ShiftMask); |
102 if (alt) | 103 if (alt) |
103 SetKeycodeAndSendThenMask(host, &xevent, XK_Alt_L, Mod1Mask); | 104 SetKeycodeAndSendThenMask(host, &xevent, XK_Alt_L, Mod1Mask); |
104 xevent.xkey.keycode = | 105 xevent.xkey.keycode = |
105 XKeysymToKeycode(x_display_, | 106 XKeysymToKeycode(x_display_, |
106 ui::XKeysymForWindowsKeyCode(key, shift)); | 107 ui::XKeysymForWindowsKeyCode(key, shift)); |
107 host->PostNativeEvent(&xevent); | 108 aura::test::PostEventToWindowTreeHost(xevent, host); |
108 | 109 |
109 // Send key release events. | 110 // Send key release events. |
110 xevent.xkey.type = KeyRelease; | 111 xevent.xkey.type = KeyRelease; |
111 host->PostNativeEvent(&xevent); | 112 aura::test::PostEventToWindowTreeHost(xevent, host); |
112 if (alt) | 113 if (alt) |
113 UnmaskAndSetKeycodeThenSend(host, &xevent, Mod1Mask, XK_Alt_L); | 114 UnmaskAndSetKeycodeThenSend(host, &xevent, Mod1Mask, XK_Alt_L); |
114 if (shift) | 115 if (shift) |
115 UnmaskAndSetKeycodeThenSend(host, &xevent, ShiftMask, XK_Shift_L); | 116 UnmaskAndSetKeycodeThenSend(host, &xevent, ShiftMask, XK_Shift_L); |
116 if (control) { | 117 if (control) { |
117 UnmaskAndSetKeycodeThenSend(host, &xevent, ControlMask, XK_Control_L); | 118 UnmaskAndSetKeycodeThenSend(host, &xevent, ControlMask, XK_Control_L); |
118 } | 119 } |
119 DCHECK(!xevent.xkey.state); | 120 DCHECK(!xevent.xkey.state); |
120 RunClosureAfterAllPendingUIEvents(closure); | 121 RunClosureAfterAllPendingUIEvents(closure); |
121 return true; | 122 return true; |
(...skipping 27 matching lines...) Expand all Loading... |
149 root_window->MoveCursorTo(root_location); | 150 root_window->MoveCursorTo(root_location); |
150 } else { | 151 } else { |
151 XEvent xevent = {0}; | 152 XEvent xevent = {0}; |
152 XMotionEvent* xmotion = &xevent.xmotion; | 153 XMotionEvent* xmotion = &xevent.xmotion; |
153 xmotion->type = MotionNotify; | 154 xmotion->type = MotionNotify; |
154 xmotion->x = root_location.x(); | 155 xmotion->x = root_location.x(); |
155 xmotion->y = root_location.y(); | 156 xmotion->y = root_location.y(); |
156 xmotion->state = button_down_mask; | 157 xmotion->state = button_down_mask; |
157 xmotion->same_screen = True; | 158 xmotion->same_screen = True; |
158 // RootWindow will take care of other necessary fields. | 159 // RootWindow will take care of other necessary fields. |
159 host->PostNativeEvent(&xevent); | 160 aura::test::PostEventToWindowTreeHost(xevent, host); |
160 } | 161 } |
161 RunClosureAfterAllPendingUIEvents(closure); | 162 RunClosureAfterAllPendingUIEvents(closure); |
162 return true; | 163 return true; |
163 } | 164 } |
164 bool SendMouseEvents(MouseButton type, int state) override { | 165 bool SendMouseEvents(MouseButton type, int state) override { |
165 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 166 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
166 } | 167 } |
167 bool SendMouseEventsNotifyWhenDone(MouseButton type, | 168 bool SendMouseEventsNotifyWhenDone(MouseButton type, |
168 int state, | 169 int state, |
169 const base::Closure& closure) override { | 170 const base::Closure& closure) override { |
(...skipping 18 matching lines...) Expand all Loading... |
188 xbutton->state = Button2Mask; | 189 xbutton->state = Button2Mask; |
189 break; | 190 break; |
190 case RIGHT: | 191 case RIGHT: |
191 xbutton->button = Button3; | 192 xbutton->button = Button3; |
192 xbutton->state = Button3Mask; | 193 xbutton->state = Button3Mask; |
193 break; | 194 break; |
194 } | 195 } |
195 // RootWindow will take care of other necessary fields. | 196 // RootWindow will take care of other necessary fields. |
196 if (state & DOWN) { | 197 if (state & DOWN) { |
197 xevent.xbutton.type = ButtonPress; | 198 xevent.xbutton.type = ButtonPress; |
198 root_window->GetHost()->PostNativeEvent(&xevent); | 199 aura::test::PostEventToWindowTreeHost(xevent, root_window->GetHost()); |
199 button_down_mask |= xbutton->state; | 200 button_down_mask |= xbutton->state; |
200 } | 201 } |
201 if (state & UP) { | 202 if (state & UP) { |
202 xevent.xbutton.type = ButtonRelease; | 203 xevent.xbutton.type = ButtonRelease; |
203 root_window->GetHost()->PostNativeEvent(&xevent); | 204 aura::test::PostEventToWindowTreeHost(xevent, root_window->GetHost()); |
204 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; | 205 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; |
205 } | 206 } |
206 RunClosureAfterAllPendingUIEvents(closure); | 207 RunClosureAfterAllPendingUIEvents(closure); |
207 return true; | 208 return true; |
208 } | 209 } |
209 bool SendMouseClick(MouseButton type) override { | 210 bool SendMouseClick(MouseButton type) override { |
210 return SendMouseEvents(type, UP | DOWN); | 211 return SendMouseEvents(type, UP | DOWN); |
211 } | 212 } |
212 void RunClosureAfterAllPendingUIEvents( | 213 void RunClosureAfterAllPendingUIEvents( |
213 const base::Closure& closure) override { | 214 const base::Closure& closure) override { |
(...skipping 30 matching lines...) Expand all Loading... |
244 NOTREACHED() << "Coulding find RW for " << point.ToString() << " among " | 245 NOTREACHED() << "Coulding find RW for " << point.ToString() << " among " |
245 << windows.size() << " RWs."; | 246 << windows.size() << " RWs."; |
246 return NULL; | 247 return NULL; |
247 } | 248 } |
248 | 249 |
249 void SetKeycodeAndSendThenMask(aura::WindowTreeHost* host, | 250 void SetKeycodeAndSendThenMask(aura::WindowTreeHost* host, |
250 XEvent* xevent, | 251 XEvent* xevent, |
251 KeySym keysym, | 252 KeySym keysym, |
252 unsigned int mask) { | 253 unsigned int mask) { |
253 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); | 254 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); |
254 host->PostNativeEvent(xevent); | 255 aura::test::PostEventToWindowTreeHost(*xevent, host); |
255 xevent->xkey.state |= mask; | 256 xevent->xkey.state |= mask; |
256 } | 257 } |
257 | 258 |
258 void UnmaskAndSetKeycodeThenSend(aura::WindowTreeHost* host, | 259 void UnmaskAndSetKeycodeThenSend(aura::WindowTreeHost* host, |
259 XEvent* xevent, | 260 XEvent* xevent, |
260 unsigned int mask, | 261 unsigned int mask, |
261 KeySym keysym) { | 262 KeySym keysym) { |
262 xevent->xkey.state ^= mask; | 263 xevent->xkey.state ^= mask; |
263 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); | 264 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); |
264 host->PostNativeEvent(xevent); | 265 aura::test::PostEventToWindowTreeHost(*xevent, host); |
265 } | 266 } |
266 | 267 |
267 // Our X11 state. | 268 // Our X11 state. |
268 Display* x_display_; | 269 Display* x_display_; |
269 ::Window x_root_window_; | 270 ::Window x_root_window_; |
270 | 271 |
271 // Input-only window used for events. | 272 // Input-only window used for events. |
272 ::Window x_window_; | 273 ::Window x_window_; |
273 | 274 |
274 DISALLOW_COPY_AND_ASSIGN(UIControlsDesktopX11); | 275 DISALLOW_COPY_AND_ASSIGN(UIControlsDesktopX11); |
275 }; | 276 }; |
276 | 277 |
277 } // namespace | 278 } // namespace |
278 | 279 |
279 UIControlsAura* CreateUIControlsDesktopAura() { | 280 UIControlsAura* CreateUIControlsDesktopAura() { |
280 // The constructor of UIControlsDesktopX11 needs X11 connection to be | 281 // The constructor of UIControlsDesktopX11 needs X11 connection to be |
281 // initialized. | 282 // initialized. |
282 gfx::InitializeThreadedX11(); | 283 gfx::InitializeThreadedX11(); |
283 return new UIControlsDesktopX11(); | 284 return new UIControlsDesktopX11(); |
284 } | 285 } |
285 | 286 |
286 } // namespace test | 287 } // namespace test |
287 } // namespace views | 288 } // namespace views |
OLD | NEW |