| 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 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "ui/aura/client/screen_position_client.h" | 9 #include "ui/aura/client/screen_position_client.h" |
| 10 #include "ui/aura/env.h" | 10 #include "ui/aura/env.h" |
| 11 #include "ui/aura/test/ui_controls_factory_aura.h" | 11 #include "ui/aura/test/ui_controls_factory_aura.h" |
| 12 #include "ui/aura/window.h" | 12 #include "ui/aura/window.h" |
| 13 #include "ui/aura/window_event_dispatcher.h" | 13 #include "ui/aura/window_tree_host.h" |
| 14 #include "ui/base/test/ui_controls_aura.h" | 14 #include "ui/base/test/ui_controls_aura.h" |
| 15 #include "ui/base/x/x11_util.h" | 15 #include "ui/base/x/x11_util.h" |
| 16 #include "ui/compositor/dip_util.h" | 16 #include "ui/compositor/dip_util.h" |
| 17 #include "ui/events/keycodes/keyboard_code_conversion_x.h" | 17 #include "ui/events/keycodes/keyboard_code_conversion_x.h" |
| 18 | 18 |
| 19 namespace aura { | 19 namespace aura { |
| 20 namespace test { | 20 namespace test { |
| 21 namespace { | 21 namespace { |
| 22 | 22 |
| 23 using ui_controls::DOWN; | 23 using ui_controls::DOWN; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 } | 73 } |
| 74 | 74 |
| 75 // Returns true when the event is a marker event. | 75 // Returns true when the event is a marker event. |
| 76 bool Matcher(const base::NativeEvent& event) { | 76 bool Matcher(const base::NativeEvent& event) { |
| 77 return event->xany.type == ClientMessage && | 77 return event->xany.type == ClientMessage && |
| 78 event->xclient.message_type == MarkerEventAtom(); | 78 event->xclient.message_type == MarkerEventAtom(); |
| 79 } | 79 } |
| 80 | 80 |
| 81 class UIControlsX11 : public UIControlsAura { | 81 class UIControlsX11 : public UIControlsAura { |
| 82 public: | 82 public: |
| 83 UIControlsX11(WindowEventDispatcher* dispatcher) : dispatcher_(dispatcher) { | 83 UIControlsX11(WindowTreeHost* host) : host_(host) { |
| 84 } | 84 } |
| 85 | 85 |
| 86 virtual bool SendKeyPress(gfx::NativeWindow window, | 86 virtual bool SendKeyPress(gfx::NativeWindow window, |
| 87 ui::KeyboardCode key, | 87 ui::KeyboardCode key, |
| 88 bool control, | 88 bool control, |
| 89 bool shift, | 89 bool shift, |
| 90 bool alt, | 90 bool alt, |
| 91 bool command) OVERRIDE { | 91 bool command) OVERRIDE { |
| 92 DCHECK(!command); // No command key on Aura | 92 DCHECK(!command); // No command key on Aura |
| 93 return SendKeyPressNotifyWhenDone( | 93 return SendKeyPressNotifyWhenDone( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 xevent.xkey.type = KeyPress; | 106 xevent.xkey.type = KeyPress; |
| 107 if (control) | 107 if (control) |
| 108 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); | 108 SetKeycodeAndSendThenMask(&xevent, XK_Control_L, ControlMask); |
| 109 if (shift) | 109 if (shift) |
| 110 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); | 110 SetKeycodeAndSendThenMask(&xevent, XK_Shift_L, ShiftMask); |
| 111 if (alt) | 111 if (alt) |
| 112 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); | 112 SetKeycodeAndSendThenMask(&xevent, XK_Alt_L, Mod1Mask); |
| 113 xevent.xkey.keycode = | 113 xevent.xkey.keycode = |
| 114 XKeysymToKeycode(gfx::GetXDisplay(), | 114 XKeysymToKeycode(gfx::GetXDisplay(), |
| 115 ui::XKeysymForWindowsKeyCode(key, shift)); | 115 ui::XKeysymForWindowsKeyCode(key, shift)); |
| 116 dispatcher_->host()->PostNativeEvent(&xevent); | 116 host_->PostNativeEvent(&xevent); |
| 117 | 117 |
| 118 // Send key release events. | 118 // Send key release events. |
| 119 xevent.xkey.type = KeyRelease; | 119 xevent.xkey.type = KeyRelease; |
| 120 dispatcher_->host()->PostNativeEvent(&xevent); | 120 host_->PostNativeEvent(&xevent); |
| 121 if (alt) | 121 if (alt) |
| 122 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); | 122 UnmaskAndSetKeycodeThenSend(&xevent, Mod1Mask, XK_Alt_L); |
| 123 if (shift) | 123 if (shift) |
| 124 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); | 124 UnmaskAndSetKeycodeThenSend(&xevent, ShiftMask, XK_Shift_L); |
| 125 if (control) | 125 if (control) |
| 126 UnmaskAndSetKeycodeThenSend(&xevent, ControlMask, XK_Control_L); | 126 UnmaskAndSetKeycodeThenSend(&xevent, ControlMask, XK_Control_L); |
| 127 DCHECK(!xevent.xkey.state); | 127 DCHECK(!xevent.xkey.state); |
| 128 RunClosureAfterAllPendingUIEvents(closure); | 128 RunClosureAfterAllPendingUIEvents(closure); |
| 129 return true; | 129 return true; |
| 130 } | 130 } |
| 131 | 131 |
| 132 virtual bool SendMouseMove(long screen_x, long screen_y) OVERRIDE { | 132 virtual bool SendMouseMove(long screen_x, long screen_y) OVERRIDE { |
| 133 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); | 133 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); |
| 134 } | 134 } |
| 135 virtual bool SendMouseMoveNotifyWhenDone( | 135 virtual bool SendMouseMoveNotifyWhenDone( |
| 136 long screen_x, | 136 long screen_x, |
| 137 long screen_y, | 137 long screen_y, |
| 138 const base::Closure& closure) OVERRIDE { | 138 const base::Closure& closure) OVERRIDE { |
| 139 gfx::Point root_location(screen_x, screen_y); | 139 gfx::Point root_location(screen_x, screen_y); |
| 140 aura::client::ScreenPositionClient* screen_position_client = | 140 aura::client::ScreenPositionClient* screen_position_client = |
| 141 aura::client::GetScreenPositionClient(dispatcher_->window()); | 141 aura::client::GetScreenPositionClient(host_->window()); |
| 142 if (screen_position_client) { | 142 if (screen_position_client) { |
| 143 screen_position_client->ConvertPointFromScreen(dispatcher_->window(), | 143 screen_position_client->ConvertPointFromScreen(host_->window(), |
| 144 &root_location); | 144 &root_location); |
| 145 } | 145 } |
| 146 gfx::Point root_current_location; | 146 gfx::Point root_current_location; |
| 147 dispatcher_->host()->QueryMouseLocation(&root_current_location); | 147 host_->QueryMouseLocation(&root_current_location); |
| 148 dispatcher_->host()->ConvertPointFromHost(&root_current_location); | 148 host_->ConvertPointFromHost(&root_current_location); |
| 149 | 149 |
| 150 if (root_location != root_current_location && button_down_mask == 0) { | 150 if (root_location != root_current_location && button_down_mask == 0) { |
| 151 // Move the cursor because EnterNotify/LeaveNotify are generated with the | 151 // Move the cursor because EnterNotify/LeaveNotify are generated with the |
| 152 // current mouse position as a result of XGrabPointer() | 152 // current mouse position as a result of XGrabPointer() |
| 153 dispatcher_->window()->MoveCursorTo(root_location); | 153 host_->window()->MoveCursorTo(root_location); |
| 154 } else { | 154 } else { |
| 155 XEvent xevent = {0}; | 155 XEvent xevent = {0}; |
| 156 XMotionEvent* xmotion = &xevent.xmotion; | 156 XMotionEvent* xmotion = &xevent.xmotion; |
| 157 xmotion->type = MotionNotify; | 157 xmotion->type = MotionNotify; |
| 158 xmotion->x = root_location.x(); | 158 xmotion->x = root_location.x(); |
| 159 xmotion->y = root_location.y(); | 159 xmotion->y = root_location.y(); |
| 160 xmotion->state = button_down_mask; | 160 xmotion->state = button_down_mask; |
| 161 xmotion->same_screen = True; | 161 xmotion->same_screen = True; |
| 162 // WindowEventDispatcher will take care of other necessary fields. | 162 // WindowTreeHost will take care of other necessary fields. |
| 163 dispatcher_->host()->PostNativeEvent(&xevent); | 163 host_->PostNativeEvent(&xevent); |
| 164 } | 164 } |
| 165 RunClosureAfterAllPendingUIEvents(closure); | 165 RunClosureAfterAllPendingUIEvents(closure); |
| 166 return true; | 166 return true; |
| 167 } | 167 } |
| 168 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { | 168 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { |
| 169 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 169 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
| 170 } | 170 } |
| 171 virtual bool SendMouseEventsNotifyWhenDone( | 171 virtual bool SendMouseEventsNotifyWhenDone( |
| 172 MouseButton type, | 172 MouseButton type, |
| 173 int state, | 173 int state, |
| 174 const base::Closure& closure) OVERRIDE { | 174 const base::Closure& closure) OVERRIDE { |
| 175 XEvent xevent = {0}; | 175 XEvent xevent = {0}; |
| 176 XButtonEvent* xbutton = &xevent.xbutton; | 176 XButtonEvent* xbutton = &xevent.xbutton; |
| 177 gfx::Point mouse_loc = aura::Env::GetInstance()->last_mouse_location(); | 177 gfx::Point mouse_loc = aura::Env::GetInstance()->last_mouse_location(); |
| 178 aura::client::ScreenPositionClient* screen_position_client = | 178 aura::client::ScreenPositionClient* screen_position_client = |
| 179 aura::client::GetScreenPositionClient(dispatcher_->window()); | 179 aura::client::GetScreenPositionClient(host_->window()); |
| 180 if (screen_position_client) { | 180 if (screen_position_client) { |
| 181 screen_position_client->ConvertPointFromScreen(dispatcher_->window(), | 181 screen_position_client->ConvertPointFromScreen(host_->window(), |
| 182 &mouse_loc); | 182 &mouse_loc); |
| 183 } | 183 } |
| 184 xbutton->x = mouse_loc.x(); | 184 xbutton->x = mouse_loc.x(); |
| 185 xbutton->y = mouse_loc.y(); | 185 xbutton->y = mouse_loc.y(); |
| 186 xbutton->same_screen = True; | 186 xbutton->same_screen = True; |
| 187 switch (type) { | 187 switch (type) { |
| 188 case LEFT: | 188 case LEFT: |
| 189 xbutton->button = Button1; | 189 xbutton->button = Button1; |
| 190 xbutton->state = Button1Mask; | 190 xbutton->state = Button1Mask; |
| 191 break; | 191 break; |
| 192 case MIDDLE: | 192 case MIDDLE: |
| 193 xbutton->button = Button2; | 193 xbutton->button = Button2; |
| 194 xbutton->state = Button2Mask; | 194 xbutton->state = Button2Mask; |
| 195 break; | 195 break; |
| 196 case RIGHT: | 196 case RIGHT: |
| 197 xbutton->button = Button3; | 197 xbutton->button = Button3; |
| 198 xbutton->state = Button3Mask; | 198 xbutton->state = Button3Mask; |
| 199 break; | 199 break; |
| 200 } | 200 } |
| 201 // WindowEventDispatcher will take care of other necessary fields. | 201 // WindowEventDispatcher will take care of other necessary fields. |
| 202 if (state & DOWN) { | 202 if (state & DOWN) { |
| 203 xevent.xbutton.type = ButtonPress; | 203 xevent.xbutton.type = ButtonPress; |
| 204 dispatcher_->host()->PostNativeEvent(&xevent); | 204 host_->PostNativeEvent(&xevent); |
| 205 button_down_mask |= xbutton->state; | 205 button_down_mask |= xbutton->state; |
| 206 } | 206 } |
| 207 if (state & UP) { | 207 if (state & UP) { |
| 208 xevent.xbutton.type = ButtonRelease; | 208 xevent.xbutton.type = ButtonRelease; |
| 209 dispatcher_->host()->PostNativeEvent(&xevent); | 209 host_->PostNativeEvent(&xevent); |
| 210 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; | 210 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; |
| 211 } | 211 } |
| 212 RunClosureAfterAllPendingUIEvents(closure); | 212 RunClosureAfterAllPendingUIEvents(closure); |
| 213 return true; | 213 return true; |
| 214 } | 214 } |
| 215 virtual bool SendMouseClick(MouseButton type) OVERRIDE { | 215 virtual bool SendMouseClick(MouseButton type) OVERRIDE { |
| 216 return SendMouseEvents(type, UP | DOWN); | 216 return SendMouseEvents(type, UP | DOWN); |
| 217 } | 217 } |
| 218 virtual void RunClosureAfterAllPendingUIEvents( | 218 virtual void RunClosureAfterAllPendingUIEvents( |
| 219 const base::Closure& closure) OVERRIDE { | 219 const base::Closure& closure) OVERRIDE { |
| 220 if (closure.is_null()) | 220 if (closure.is_null()) |
| 221 return; | 221 return; |
| 222 static XEvent* marker_event = NULL; | 222 static XEvent* marker_event = NULL; |
| 223 if (!marker_event) { | 223 if (!marker_event) { |
| 224 marker_event = new XEvent(); | 224 marker_event = new XEvent(); |
| 225 marker_event->xclient.type = ClientMessage; | 225 marker_event->xclient.type = ClientMessage; |
| 226 marker_event->xclient.display = NULL; | 226 marker_event->xclient.display = NULL; |
| 227 marker_event->xclient.window = None; | 227 marker_event->xclient.window = None; |
| 228 marker_event->xclient.format = 8; | 228 marker_event->xclient.format = 8; |
| 229 } | 229 } |
| 230 marker_event->xclient.message_type = MarkerEventAtom(); | 230 marker_event->xclient.message_type = MarkerEventAtom(); |
| 231 dispatcher_->host()->PostNativeEvent(marker_event); | 231 host_->PostNativeEvent(marker_event); |
| 232 new EventWaiter(closure, &Matcher); | 232 new EventWaiter(closure, &Matcher); |
| 233 } | 233 } |
| 234 private: | 234 private: |
| 235 void SetKeycodeAndSendThenMask(XEvent* xevent, | 235 void SetKeycodeAndSendThenMask(XEvent* xevent, |
| 236 KeySym keysym, | 236 KeySym keysym, |
| 237 unsigned int mask) { | 237 unsigned int mask) { |
| 238 xevent->xkey.keycode = | 238 xevent->xkey.keycode = |
| 239 XKeysymToKeycode(gfx::GetXDisplay(), keysym); | 239 XKeysymToKeycode(gfx::GetXDisplay(), keysym); |
| 240 dispatcher_->host()->PostNativeEvent(xevent); | 240 host_->PostNativeEvent(xevent); |
| 241 xevent->xkey.state |= mask; | 241 xevent->xkey.state |= mask; |
| 242 } | 242 } |
| 243 | 243 |
| 244 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, | 244 void UnmaskAndSetKeycodeThenSend(XEvent* xevent, |
| 245 unsigned int mask, | 245 unsigned int mask, |
| 246 KeySym keysym) { | 246 KeySym keysym) { |
| 247 xevent->xkey.state ^= mask; | 247 xevent->xkey.state ^= mask; |
| 248 xevent->xkey.keycode = | 248 xevent->xkey.keycode = |
| 249 XKeysymToKeycode(gfx::GetXDisplay(), keysym); | 249 XKeysymToKeycode(gfx::GetXDisplay(), keysym); |
| 250 dispatcher_->host()->PostNativeEvent(xevent); | 250 host_->PostNativeEvent(xevent); |
| 251 } | 251 } |
| 252 | 252 |
| 253 WindowEventDispatcher* dispatcher_; | 253 WindowTreeHost* host_; |
| 254 | 254 |
| 255 DISALLOW_COPY_AND_ASSIGN(UIControlsX11); | 255 DISALLOW_COPY_AND_ASSIGN(UIControlsX11); |
| 256 }; | 256 }; |
| 257 | 257 |
| 258 } // namespace | 258 } // namespace |
| 259 | 259 |
| 260 UIControlsAura* CreateUIControlsAura(WindowEventDispatcher* dispatcher) { | 260 UIControlsAura* CreateUIControlsAura(WindowTreeHost* host) { |
| 261 return new UIControlsX11(dispatcher); | 261 return new UIControlsX11(host); |
| 262 } | 262 } |
| 263 | 263 |
| 264 } // namespace test | 264 } // namespace test |
| 265 } // namespace aura | 265 } // namespace aura |
| OLD | NEW |