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 |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 SetKeycodeAndSendThenMask(dispatcher, &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(dispatcher, &xevent, XK_Shift_L, ShiftMask); | 137 SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Shift_L, ShiftMask); |
138 if (alt) | 138 if (alt) |
139 SetKeycodeAndSendThenMask(dispatcher, &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 dispatcher->PostNativeEvent(&xevent); | 143 dispatcher->host()->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 dispatcher->PostNativeEvent(&xevent); | 147 dispatcher->host()->PostNativeEvent(&xevent); |
148 if (alt) | 148 if (alt) |
149 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, Mod1Mask, XK_Alt_L); | 149 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, Mod1Mask, XK_Alt_L); |
150 if (shift) | 150 if (shift) |
151 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, ShiftMask, XK_Shift_L); | 151 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, ShiftMask, XK_Shift_L); |
152 if (control) { | 152 if (control) { |
153 UnmaskAndSetKeycodeThenSend(dispatcher, &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); |
(...skipping 20 matching lines...) Expand all Loading... |
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->GetDispatcher()->PostNativeEvent(&xevent); | 188 root_window->GetDispatcher()->host()->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 { |
(...skipping 18 matching lines...) Expand all Loading... |
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->GetDispatcher()->PostNativeEvent(&xevent); | 227 root_window->GetDispatcher()->host()->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->GetDispatcher()->PostNativeEvent(&xevent); | 232 root_window->GetDispatcher()->host()->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 { |
(...skipping 30 matching lines...) Expand all Loading... |
273 NOTREACHED() << "Coulding find RW for " << point.ToString() << " among " | 273 NOTREACHED() << "Coulding find RW for " << point.ToString() << " among " |
274 << windows.size() << " RWs."; | 274 << windows.size() << " RWs."; |
275 return NULL; | 275 return NULL; |
276 } | 276 } |
277 | 277 |
278 void SetKeycodeAndSendThenMask(aura::RootWindow* root_window, | 278 void SetKeycodeAndSendThenMask(aura::RootWindow* root_window, |
279 XEvent* xevent, | 279 XEvent* xevent, |
280 KeySym keysym, | 280 KeySym keysym, |
281 unsigned int mask) { | 281 unsigned int mask) { |
282 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); | 282 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); |
283 root_window->PostNativeEvent(xevent); | 283 root_window->host()->PostNativeEvent(xevent); |
284 xevent->xkey.state |= mask; | 284 xevent->xkey.state |= mask; |
285 } | 285 } |
286 | 286 |
287 void UnmaskAndSetKeycodeThenSend(aura::RootWindow* root_window, | 287 void UnmaskAndSetKeycodeThenSend(aura::RootWindow* root_window, |
288 XEvent* xevent, | 288 XEvent* xevent, |
289 unsigned int mask, | 289 unsigned int mask, |
290 KeySym keysym) { | 290 KeySym keysym) { |
291 xevent->xkey.state ^= mask; | 291 xevent->xkey.state ^= mask; |
292 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); | 292 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); |
293 root_window->PostNativeEvent(xevent); | 293 root_window->host()->PostNativeEvent(xevent); |
294 } | 294 } |
295 | 295 |
296 // Our X11 state. | 296 // Our X11 state. |
297 Display* x_display_; | 297 Display* x_display_; |
298 ::Window x_root_window_; | 298 ::Window x_root_window_; |
299 | 299 |
300 // Input-only window used for events. | 300 // Input-only window used for events. |
301 ::Window x_window_; | 301 ::Window x_window_; |
302 | 302 |
303 DISALLOW_COPY_AND_ASSIGN(UIControlsDesktopX11); | 303 DISALLOW_COPY_AND_ASSIGN(UIControlsDesktopX11); |
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 |
OLD | NEW |