| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 xevent.xkey.type = KeyPress; | 111 xevent.xkey.type = KeyPress; |
| 112 if (control) | 112 if (control) |
| 113 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); | 113 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); |
| 114 if (shift) | 114 if (shift) |
| 115 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); | 115 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); |
| 116 if (alt) | 116 if (alt) |
| 117 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); | 117 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); |
| 118 xevent.xkey.keycode = | 118 xevent.xkey.keycode = |
| 119 XKeysymToKeycode(gfx::GetXDisplay(), | 119 XKeysymToKeycode(gfx::GetXDisplay(), |
| 120 ui::XKeysymForWindowsKeyCode(key, shift)); | 120 ui::XKeysymForWindowsKeyCode(key, shift)); |
| 121 root_window_->PostNativeEvent(&xevent); | 121 root_window_->host()->PostNativeEvent(&xevent); |
| 122 | 122 |
| 123 // Send key release events. | 123 // Send key release events. |
| 124 xevent.xkey.type = KeyRelease; | 124 xevent.xkey.type = KeyRelease; |
| 125 root_window_->PostNativeEvent(&xevent); | 125 root_window_->host()->PostNativeEvent(&xevent); |
| 126 if (alt) | 126 if (alt) |
| 127 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); | 127 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); |
| 128 if (shift) | 128 if (shift) |
| 129 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); | 129 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); |
| 130 if (control) | 130 if (control) |
| 131 UnmaskAndSetKeycodeThenSend(&xevent, ControlMask, XK_Control_L); | 131 UnmaskAndSetKeycodeThenSend(&xevent, ControlMask, XK_Control_L); |
| 132 DCHECK(!xevent.xkey.state); | 132 DCHECK(!xevent.xkey.state); |
| 133 RunClosureAfterAllPendingUIEvents(closure); | 133 RunClosureAfterAllPendingUIEvents(closure); |
| 134 return true; | 134 return true; |
| 135 } | 135 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 146 XMotionEvent* xmotion = &xevent.xmotion; | 146 XMotionEvent* xmotion = &xevent.xmotion; |
| 147 xmotion->type = MotionNotify; | 147 xmotion->type = MotionNotify; |
| 148 gfx::Point point = ui::ConvertPointToPixel( | 148 gfx::Point point = ui::ConvertPointToPixel( |
| 149 root_window_->window()->layer(), | 149 root_window_->window()->layer(), |
| 150 gfx::Point(static_cast<int>(x), static_cast<int>(y))); | 150 gfx::Point(static_cast<int>(x), static_cast<int>(y))); |
| 151 xmotion->x = point.x(); | 151 xmotion->x = point.x(); |
| 152 xmotion->y = point.y(); | 152 xmotion->y = point.y(); |
| 153 xmotion->state = button_down_mask; | 153 xmotion->state = button_down_mask; |
| 154 xmotion->same_screen = True; | 154 xmotion->same_screen = True; |
| 155 // RootWindow will take care of other necessary fields. | 155 // RootWindow will take care of other necessary fields. |
| 156 root_window_->PostNativeEvent(&xevent); | 156 root_window_->host()->PostNativeEvent(&xevent); |
| 157 RunClosureAfterAllPendingUIEvents(closure); | 157 RunClosureAfterAllPendingUIEvents(closure); |
| 158 return true; | 158 return true; |
| 159 } | 159 } |
| 160 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { | 160 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { |
| 161 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 161 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
| 162 } | 162 } |
| 163 virtual bool SendMouseEventsNotifyWhenDone( | 163 virtual bool SendMouseEventsNotifyWhenDone( |
| 164 MouseButton type, | 164 MouseButton type, |
| 165 int state, | 165 int state, |
| 166 const base::Closure& closure) OVERRIDE { | 166 const base::Closure& closure) OVERRIDE { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 186 xbutton->state = Button2Mask; | 186 xbutton->state = Button2Mask; |
| 187 break; | 187 break; |
| 188 case RIGHT: | 188 case RIGHT: |
| 189 xbutton->button = Button3; | 189 xbutton->button = Button3; |
| 190 xbutton->state = Button3Mask; | 190 xbutton->state = Button3Mask; |
| 191 break; | 191 break; |
| 192 } | 192 } |
| 193 // RootWindow will take care of other necessary fields. | 193 // RootWindow will take care of other necessary fields. |
| 194 if (state & DOWN) { | 194 if (state & DOWN) { |
| 195 xevent.xbutton.type = ButtonPress; | 195 xevent.xbutton.type = ButtonPress; |
| 196 root_window_->PostNativeEvent(&xevent); | 196 root_window_->host()->PostNativeEvent(&xevent); |
| 197 button_down_mask |= xbutton->state; | 197 button_down_mask |= xbutton->state; |
| 198 } | 198 } |
| 199 if (state & UP) { | 199 if (state & UP) { |
| 200 xevent.xbutton.type = ButtonRelease; | 200 xevent.xbutton.type = ButtonRelease; |
| 201 root_window_->PostNativeEvent(&xevent); | 201 root_window_->host()->PostNativeEvent(&xevent); |
| 202 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; | 202 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; |
| 203 } | 203 } |
| 204 RunClosureAfterAllPendingUIEvents(closure); | 204 RunClosureAfterAllPendingUIEvents(closure); |
| 205 return true; | 205 return true; |
| 206 } | 206 } |
| 207 virtual bool SendMouseClick(MouseButton type) OVERRIDE { | 207 virtual bool SendMouseClick(MouseButton type) OVERRIDE { |
| 208 return SendMouseEvents(type, UP | DOWN); | 208 return SendMouseEvents(type, UP | DOWN); |
| 209 } | 209 } |
| 210 virtual void RunClosureAfterAllPendingUIEvents( | 210 virtual void RunClosureAfterAllPendingUIEvents( |
| 211 const base::Closure& closure) OVERRIDE { | 211 const base::Closure& closure) OVERRIDE { |
| 212 if (closure.is_null()) | 212 if (closure.is_null()) |
| 213 return; | 213 return; |
| 214 static XEvent* marker_event = NULL; | 214 static XEvent* marker_event = NULL; |
| 215 if (!marker_event) { | 215 if (!marker_event) { |
| 216 marker_event = new XEvent(); | 216 marker_event = new XEvent(); |
| 217 marker_event->xclient.type = ClientMessage; | 217 marker_event->xclient.type = ClientMessage; |
| 218 marker_event->xclient.display = NULL; | 218 marker_event->xclient.display = NULL; |
| 219 marker_event->xclient.window = None; | 219 marker_event->xclient.window = None; |
| 220 marker_event->xclient.format = 8; | 220 marker_event->xclient.format = 8; |
| 221 } | 221 } |
| 222 marker_event->xclient.message_type = MarkerEventAtom(); | 222 marker_event->xclient.message_type = MarkerEventAtom(); |
| 223 root_window_->PostNativeEvent(marker_event); | 223 root_window_->host()->PostNativeEvent(marker_event); |
| 224 new EventWaiter(closure, &Matcher); | 224 new EventWaiter(closure, &Matcher); |
| 225 } | 225 } |
| 226 private: | 226 private: |
| 227 void SetKeycodeAndSendThenMask(XEvent* xevent, | 227 void SetKeycodeAndSendThenMask(XEvent* xevent, |
| 228 KeySym keysym, | 228 KeySym keysym, |
| 229 unsigned int mask) { | 229 unsigned int mask) { |
| 230 xevent->xkey.keycode = | 230 xevent->xkey.keycode = |
| 231 XKeysymToKeycode(gfx::GetXDisplay(), keysym); | 231 XKeysymToKeycode(gfx::GetXDisplay(), keysym); |
| 232 root_window_->PostNativeEvent(xevent); | 232 root_window_->host()->PostNativeEvent(xevent); |
| 233 xevent->xkey.state |= mask; | 233 xevent->xkey.state |= mask; |
| 234 } | 234 } |
| 235 | 235 |
| 236 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, | 236 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, |
| 237 unsigned int mask, | 237 unsigned int mask, |
| 238 KeySym keysym) { | 238 KeySym keysym) { |
| 239 xevent->xkey.state ^= mask; | 239 xevent->xkey.state ^= mask; |
| 240 xevent->xkey.keycode = | 240 xevent->xkey.keycode = |
| 241 XKeysymToKeycode(gfx::GetXDisplay(), keysym); | 241 XKeysymToKeycode(gfx::GetXDisplay(), keysym); |
| 242 root_window_->PostNativeEvent(xevent); | 242 root_window_->host()->PostNativeEvent(xevent); |
| 243 } | 243 } |
| 244 | 244 |
| 245 aura::RootWindow* root_window_; | 245 aura::RootWindow* root_window_; |
| 246 | 246 |
| 247 DISALLOW_COPY_AND_ASSIGN(UIControlsX11); | 247 DISALLOW_COPY_AND_ASSIGN(UIControlsX11); |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 } // namespace | 250 } // namespace |
| 251 | 251 |
| 252 UIControlsAura* CreateUIControlsAura(aura::RootWindow* root_window) { | 252 UIControlsAura* CreateUIControlsAura(aura::RootWindow* root_window) { |
| 253 return new UIControlsX11(root_window); | 253 return new UIControlsX11(root_window); |
| 254 } | 254 } |
| 255 | 255 |
| 256 } // namespace test | 256 } // namespace test |
| 257 } // namespace aura | 257 } // namespace aura |
| OLD | NEW |