| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/automation/ui_controls.h" | 5 #include "chrome/browser/automation/ui_controls.h" |
| 6 | 6 |
| 7 #include <X11/keysym.h> | 7 #include <X11/keysym.h> |
| 8 #include <X11/Xlib.h> | 8 #include <X11/Xlib.h> |
| 9 | 9 |
| 10 // X macro fail. | 10 // X macro fail. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 ui::KeyboardCode key, | 83 ui::KeyboardCode key, |
| 84 bool control, | 84 bool control, |
| 85 bool shift, | 85 bool shift, |
| 86 bool alt, | 86 bool alt, |
| 87 bool command) { | 87 bool command) { |
| 88 DCHECK(!command); // No command key on Aura | 88 DCHECK(!command); // No command key on Aura |
| 89 return SendKeyPressNotifyWhenDone( | 89 return SendKeyPressNotifyWhenDone( |
| 90 window, key, control, shift, alt, command, base::Closure()); | 90 window, key, control, shift, alt, command, base::Closure()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void SetMaskAndKeycodeThenSend(XEvent* xevent, | 93 void SetKeycodeAndSendThenMask(XEvent* xevent, |
| 94 unsigned int mask, | 94 KeySym keysym, |
| 95 unsigned int keycode) { | 95 unsigned int mask) { |
| 96 xevent->xkey.keycode = |
| 97 XKeysymToKeycode(base::MessagePumpX::GetDefaultXDisplay(), |
| 98 keysym); |
| 99 aura::RootWindow::GetInstance()->PostNativeEvent(xevent); |
| 96 xevent->xkey.state |= mask; | 100 xevent->xkey.state |= mask; |
| 97 xevent->xkey.keycode = keycode; | 101 } |
| 102 |
| 103 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, |
| 104 unsigned int mask, |
| 105 KeySym keysym) { |
| 106 xevent->xkey.state ^= mask; |
| 107 xevent->xkey.keycode = |
| 108 XKeysymToKeycode(base::MessagePumpX::GetDefaultXDisplay(), |
| 109 keysym); |
| 98 aura::RootWindow::GetInstance()->PostNativeEvent(xevent); | 110 aura::RootWindow::GetInstance()->PostNativeEvent(xevent); |
| 99 } | 111 } |
| 100 | 112 |
| 101 void SetKeycodeAndSendThenUnmask(XEvent* xevent, | |
| 102 unsigned int mask, | |
| 103 unsigned int keycode) { | |
| 104 xevent->xkey.keycode = keycode; | |
| 105 aura::RootWindow::GetInstance()->PostNativeEvent(xevent); | |
| 106 xevent->xkey.state ^= mask; | |
| 107 } | |
| 108 | |
| 109 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, | 113 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
| 110 ui::KeyboardCode key, | 114 ui::KeyboardCode key, |
| 111 bool control, | 115 bool control, |
| 112 bool shift, | 116 bool shift, |
| 113 bool alt, | 117 bool alt, |
| 114 bool command, | 118 bool command, |
| 115 const base::Closure& closure) { | 119 const base::Closure& closure) { |
| 116 DCHECK(!command); // No command key on Aura | 120 DCHECK(!command); // No command key on Aura |
| 117 XEvent xevent = {0}; | 121 XEvent xevent = {0}; |
| 118 xevent.xkey.type = KeyPress; | 122 xevent.xkey.type = KeyPress; |
| 119 if (control) | 123 if (control) |
| 120 SetMaskAndKeycodeThenSend(&xevent, ControlMask, XK_Control_L); | 124 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); |
| 121 if (shift) | 125 if (shift) |
| 122 SetMaskAndKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); | 126 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); |
| 123 if (alt) | 127 if (alt) |
| 124 SetMaskAndKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); | 128 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); |
| 125 xevent.xkey.keycode = | 129 xevent.xkey.keycode = |
| 126 XKeysymToKeycode(base::MessagePumpX::GetDefaultXDisplay(), | 130 XKeysymToKeycode(base::MessagePumpX::GetDefaultXDisplay(), |
| 127 ui::XKeysymForWindowsKeyCode(key, shift)); | 131 ui::XKeysymForWindowsKeyCode(key, shift)); |
| 128 aura::RootWindow::GetInstance()->PostNativeEvent(&xevent); | 132 aura::RootWindow::GetInstance()->PostNativeEvent(&xevent); |
| 129 | 133 |
| 130 // Send key release events. | 134 // Send key release events. |
| 131 xevent.xkey.type = KeyRelease; | 135 xevent.xkey.type = KeyRelease; |
| 132 aura::RootWindow::GetInstance()->PostNativeEvent(&xevent); | 136 aura::RootWindow::GetInstance()->PostNativeEvent(&xevent); |
| 133 if (alt) | 137 if (alt) |
| 134 SetKeycodeAndSendThenUnmask(&xevent, Mod1Mask, XK_Alt_L); | 138 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); |
| 135 if (shift) | 139 if (shift) |
| 136 SetKeycodeAndSendThenUnmask(&xevent, ShiftMask, XK_Shift_L); | 140 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); |
| 137 if (control) | 141 if (control) |
| 138 SetKeycodeAndSendThenUnmask(&xevent, ControlMask, XK_Control_L); | 142 UnmaskAndSetKeycodeThenSend(&xevent, ControlMask, XK_Control_L); |
| 139 DCHECK(!xevent.xkey.state); | 143 DCHECK(!xevent.xkey.state); |
| 140 RunClosureAfterAllPendingUIEvents(closure); | 144 RunClosureAfterAllPendingUIEvents(closure); |
| 141 return true; | 145 return true; |
| 142 } | 146 } |
| 143 | 147 |
| 144 bool SendMouseMove(long x, long y) { | 148 bool SendMouseMove(long x, long y) { |
| 145 return SendMouseMoveNotifyWhenDone(x, y, base::Closure()); | 149 return SendMouseMoveNotifyWhenDone(x, y, base::Closure()); |
| 146 } | 150 } |
| 147 | 151 |
| 148 bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& closure) { | 152 bool SendMouseMoveNotifyWhenDone(long x, long y, const base::Closure& closure) { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 marker_event->xclient.display = NULL; | 229 marker_event->xclient.display = NULL; |
| 226 marker_event->xclient.window = None; | 230 marker_event->xclient.window = None; |
| 227 marker_event->xclient.format = 8; | 231 marker_event->xclient.format = 8; |
| 228 } | 232 } |
| 229 marker_event->xclient.message_type = MarkerEventAtom(); | 233 marker_event->xclient.message_type = MarkerEventAtom(); |
| 230 aura::RootWindow::GetInstance()->PostNativeEvent(marker_event); | 234 aura::RootWindow::GetInstance()->PostNativeEvent(marker_event); |
| 231 new EventWaiter(closure, &Matcher); | 235 new EventWaiter(closure, &Matcher); |
| 232 } | 236 } |
| 233 | 237 |
| 234 } // namespace ui_controls | 238 } // namespace ui_controls |
| OLD | NEW |