| 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/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop/message_pump_x11.h" | |
| 15 #include "ui/aura/client/screen_position_client.h" | 14 #include "ui/aura/client/screen_position_client.h" |
| 16 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 17 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
| 18 #include "ui/aura/test/ui_controls_factory_aura.h" | 17 #include "ui/aura/test/ui_controls_factory_aura.h" |
| 19 #include "ui/base/keycodes/keyboard_code_conversion_x.h" | 18 #include "ui/base/keycodes/keyboard_code_conversion_x.h" |
| 20 #include "ui/base/test/ui_controls_aura.h" | 19 #include "ui/base/test/ui_controls_aura.h" |
| 20 #include "ui/base/x/x11_util.h" |
| 21 #include "ui/compositor/dip_util.h" | 21 #include "ui/compositor/dip_util.h" |
| 22 | 22 |
| 23 namespace aura { | 23 namespace aura { |
| 24 namespace test { | 24 namespace test { |
| 25 namespace { | 25 namespace { |
| 26 | 26 |
| 27 using ui_controls::DOWN; | 27 using ui_controls::DOWN; |
| 28 using ui_controls::LEFT; | 28 using ui_controls::LEFT; |
| 29 using ui_controls::MIDDLE; | 29 using ui_controls::MIDDLE; |
| 30 using ui_controls::MouseButton; | 30 using ui_controls::MouseButton; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 base::Closure closure_; | 69 base::Closure closure_; |
| 70 EventWaiterMatcher matcher_; | 70 EventWaiterMatcher matcher_; |
| 71 DISALLOW_COPY_AND_ASSIGN(EventWaiter); | 71 DISALLOW_COPY_AND_ASSIGN(EventWaiter); |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // Returns atom that indidates that the XEvent is marker event. | 74 // Returns atom that indidates that the XEvent is marker event. |
| 75 Atom MarkerEventAtom() { | 75 Atom MarkerEventAtom() { |
| 76 return XInternAtom(base::MessagePumpX11::GetDefaultXDisplay(), | 76 return XInternAtom(ui::GetXDisplay(), "marker_event", False); |
| 77 "marker_event", | |
| 78 False); | |
| 79 } | 77 } |
| 80 | 78 |
| 81 // Returns true when the event is a marker event. | 79 // Returns true when the event is a marker event. |
| 82 bool Matcher(const base::NativeEvent& event) { | 80 bool Matcher(const base::NativeEvent& event) { |
| 83 return event->xany.type == ClientMessage && | 81 return event->xany.type == ClientMessage && |
| 84 event->xclient.message_type == MarkerEventAtom(); | 82 event->xclient.message_type == MarkerEventAtom(); |
| 85 } | 83 } |
| 86 | 84 |
| 87 class UIControlsX11 : public UIControlsAura { | 85 class UIControlsX11 : public UIControlsAura { |
| 88 public: | 86 public: |
| (...skipping 21 matching lines...) Expand all Loading... |
| 110 DCHECK(!command); // No command key on Aura | 108 DCHECK(!command); // No command key on Aura |
| 111 XEvent xevent = {0}; | 109 XEvent xevent = {0}; |
| 112 xevent.xkey.type = KeyPress; | 110 xevent.xkey.type = KeyPress; |
| 113 if (control) | 111 if (control) |
| 114 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); | 112 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); |
| 115 if (shift) | 113 if (shift) |
| 116 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); | 114 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); |
| 117 if (alt) | 115 if (alt) |
| 118 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); | 116 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); |
| 119 xevent.xkey.keycode = | 117 xevent.xkey.keycode = |
| 120 XKeysymToKeycode(base::MessagePumpX11::GetDefaultXDisplay(), | 118 XKeysymToKeycode(ui::GetXDisplay(), |
| 121 ui::XKeysymForWindowsKeyCode(key, shift)); | 119 ui::XKeysymForWindowsKeyCode(key, shift)); |
| 122 root_window_->PostNativeEvent(&xevent); | 120 root_window_->PostNativeEvent(&xevent); |
| 123 | 121 |
| 124 // Send key release events. | 122 // Send key release events. |
| 125 xevent.xkey.type = KeyRelease; | 123 xevent.xkey.type = KeyRelease; |
| 126 root_window_->PostNativeEvent(&xevent); | 124 root_window_->PostNativeEvent(&xevent); |
| 127 if (alt) | 125 if (alt) |
| 128 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); | 126 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); |
| 129 if (shift) | 127 if (shift) |
| 130 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); | 128 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 } | 218 } |
| 221 marker_event->xclient.message_type = MarkerEventAtom(); | 219 marker_event->xclient.message_type = MarkerEventAtom(); |
| 222 root_window_->PostNativeEvent(marker_event); | 220 root_window_->PostNativeEvent(marker_event); |
| 223 new EventWaiter(closure, &Matcher); | 221 new EventWaiter(closure, &Matcher); |
| 224 } | 222 } |
| 225 private: | 223 private: |
| 226 void SetKeycodeAndSendThenMask(XEvent* xevent, | 224 void SetKeycodeAndSendThenMask(XEvent* xevent, |
| 227 KeySym keysym, | 225 KeySym keysym, |
| 228 unsigned int mask) { | 226 unsigned int mask) { |
| 229 xevent->xkey.keycode = | 227 xevent->xkey.keycode = |
| 230 XKeysymToKeycode(base::MessagePumpX11::GetDefaultXDisplay(), | 228 XKeysymToKeycode(ui::GetXDisplay(), keysym); |
| 231 keysym); | |
| 232 root_window_->PostNativeEvent(xevent); | 229 root_window_->PostNativeEvent(xevent); |
| 233 xevent->xkey.state |= mask; | 230 xevent->xkey.state |= mask; |
| 234 } | 231 } |
| 235 | 232 |
| 236 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, | 233 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, |
| 237 unsigned int mask, | 234 unsigned int mask, |
| 238 KeySym keysym) { | 235 KeySym keysym) { |
| 239 xevent->xkey.state ^= mask; | 236 xevent->xkey.state ^= mask; |
| 240 xevent->xkey.keycode = | 237 xevent->xkey.keycode = |
| 241 XKeysymToKeycode(base::MessagePumpX11::GetDefaultXDisplay(), | 238 XKeysymToKeycode(ui::GetXDisplay(), keysym); |
| 242 keysym); | |
| 243 root_window_->PostNativeEvent(xevent); | 239 root_window_->PostNativeEvent(xevent); |
| 244 } | 240 } |
| 245 | 241 |
| 246 aura::RootWindow* root_window_; | 242 aura::RootWindow* root_window_; |
| 247 | 243 |
| 248 DISALLOW_COPY_AND_ASSIGN(UIControlsX11); | 244 DISALLOW_COPY_AND_ASSIGN(UIControlsX11); |
| 249 }; | 245 }; |
| 250 | 246 |
| 251 } // namespace | 247 } // namespace |
| 252 | 248 |
| 253 UIControlsAura* CreateUIControlsAura(aura::RootWindow* root_window) { | 249 UIControlsAura* CreateUIControlsAura(aura::RootWindow* root_window) { |
| 254 return new UIControlsX11(root_window); | 250 return new UIControlsX11(root_window); |
| 255 } | 251 } |
| 256 | 252 |
| 257 } // namespace test | 253 } // namespace test |
| 258 } // namespace aura | 254 } // namespace aura |
| OLD | NEW |