| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 virtual ~UIControlsDesktopX11() { | 71 virtual ~UIControlsDesktopX11() { |
| 72 XDestroyWindow(x_display_, x_window_); | 72 XDestroyWindow(x_display_, x_window_); |
| 73 } | 73 } |
| 74 | 74 |
| 75 virtual bool SendKeyPress(gfx::NativeWindow window, | 75 virtual bool SendKeyPress(gfx::NativeWindow window, |
| 76 ui::KeyboardCode key, | 76 ui::KeyboardCode key, |
| 77 bool control, | 77 bool control, |
| 78 bool shift, | 78 bool shift, |
| 79 bool alt, | 79 bool alt, |
| 80 bool command) OVERRIDE { | 80 bool command) override { |
| 81 DCHECK(!command); // No command key on Aura | 81 DCHECK(!command); // No command key on Aura |
| 82 return SendKeyPressNotifyWhenDone( | 82 return SendKeyPressNotifyWhenDone( |
| 83 window, key, control, shift, alt, command, base::Closure()); | 83 window, key, control, shift, alt, command, base::Closure()); |
| 84 } | 84 } |
| 85 | 85 |
| 86 virtual bool SendKeyPressNotifyWhenDone( | 86 virtual bool SendKeyPressNotifyWhenDone( |
| 87 gfx::NativeWindow window, | 87 gfx::NativeWindow window, |
| 88 ui::KeyboardCode key, | 88 ui::KeyboardCode key, |
| 89 bool control, | 89 bool control, |
| 90 bool shift, | 90 bool shift, |
| 91 bool alt, | 91 bool alt, |
| 92 bool command, | 92 bool command, |
| 93 const base::Closure& closure) OVERRIDE { | 93 const base::Closure& closure) override { |
| 94 DCHECK(!command); // No command key on Aura | 94 DCHECK(!command); // No command key on Aura |
| 95 | 95 |
| 96 aura::WindowTreeHost* host = window->GetHost(); | 96 aura::WindowTreeHost* host = window->GetHost(); |
| 97 | 97 |
| 98 XEvent xevent = {0}; | 98 XEvent xevent = {0}; |
| 99 xevent.xkey.type = KeyPress; | 99 xevent.xkey.type = KeyPress; |
| 100 if (control) { | 100 if (control) { |
| 101 SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask); | 101 SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask); |
| 102 } | 102 } |
| 103 if (shift) | 103 if (shift) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 117 if (shift) | 117 if (shift) |
| 118 UnmaskAndSetKeycodeThenSend(host, &xevent, ShiftMask, XK_Shift_L); | 118 UnmaskAndSetKeycodeThenSend(host, &xevent, ShiftMask, XK_Shift_L); |
| 119 if (control) { | 119 if (control) { |
| 120 UnmaskAndSetKeycodeThenSend(host, &xevent, ControlMask, XK_Control_L); | 120 UnmaskAndSetKeycodeThenSend(host, &xevent, ControlMask, XK_Control_L); |
| 121 } | 121 } |
| 122 DCHECK(!xevent.xkey.state); | 122 DCHECK(!xevent.xkey.state); |
| 123 RunClosureAfterAllPendingUIEvents(closure); | 123 RunClosureAfterAllPendingUIEvents(closure); |
| 124 return true; | 124 return true; |
| 125 } | 125 } |
| 126 | 126 |
| 127 virtual bool SendMouseMove(long screen_x, long screen_y) OVERRIDE { | 127 virtual bool SendMouseMove(long screen_x, long screen_y) override { |
| 128 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); | 128 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); |
| 129 } | 129 } |
| 130 virtual bool SendMouseMoveNotifyWhenDone( | 130 virtual bool SendMouseMoveNotifyWhenDone( |
| 131 long screen_x, | 131 long screen_x, |
| 132 long screen_y, | 132 long screen_y, |
| 133 const base::Closure& closure) OVERRIDE { | 133 const base::Closure& closure) override { |
| 134 gfx::Point screen_location(screen_x, screen_y); | 134 gfx::Point screen_location(screen_x, screen_y); |
| 135 gfx::Point root_location = screen_location; | 135 gfx::Point root_location = screen_location; |
| 136 aura::Window* root_window = RootWindowForPoint(screen_location); | 136 aura::Window* root_window = RootWindowForPoint(screen_location); |
| 137 | 137 |
| 138 aura::client::ScreenPositionClient* screen_position_client = | 138 aura::client::ScreenPositionClient* screen_position_client = |
| 139 aura::client::GetScreenPositionClient(root_window); | 139 aura::client::GetScreenPositionClient(root_window); |
| 140 if (screen_position_client) { | 140 if (screen_position_client) { |
| 141 screen_position_client->ConvertPointFromScreen(root_window, | 141 screen_position_client->ConvertPointFromScreen(root_window, |
| 142 &root_location); | 142 &root_location); |
| 143 } | 143 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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 // RootWindow will take care of other necessary fields. | 162 // RootWindow will take care of other necessary fields. |
| 163 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::Window* root_window = RootWindowForPoint(mouse_loc); | 178 aura::Window* root_window = RootWindowForPoint(mouse_loc); |
| 179 aura::client::ScreenPositionClient* screen_position_client = | 179 aura::client::ScreenPositionClient* screen_position_client = |
| 180 aura::client::GetScreenPositionClient(root_window); | 180 aura::client::GetScreenPositionClient(root_window); |
| 181 if (screen_position_client) | 181 if (screen_position_client) |
| 182 screen_position_client->ConvertPointFromScreen(root_window, &mouse_loc); | 182 screen_position_client->ConvertPointFromScreen(root_window, &mouse_loc); |
| 183 xbutton->x = mouse_loc.x(); | 183 xbutton->x = mouse_loc.x(); |
| 184 xbutton->y = mouse_loc.y(); | 184 xbutton->y = mouse_loc.y(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 204 button_down_mask |= xbutton->state; | 204 button_down_mask |= xbutton->state; |
| 205 } | 205 } |
| 206 if (state & UP) { | 206 if (state & UP) { |
| 207 xevent.xbutton.type = ButtonRelease; | 207 xevent.xbutton.type = ButtonRelease; |
| 208 root_window->GetHost()->PostNativeEvent(&xevent); | 208 root_window->GetHost()->PostNativeEvent(&xevent); |
| 209 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; | 209 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; |
| 210 } | 210 } |
| 211 RunClosureAfterAllPendingUIEvents(closure); | 211 RunClosureAfterAllPendingUIEvents(closure); |
| 212 return true; | 212 return true; |
| 213 } | 213 } |
| 214 virtual bool SendMouseClick(MouseButton type) OVERRIDE { | 214 virtual bool SendMouseClick(MouseButton type) override { |
| 215 return SendMouseEvents(type, UP | DOWN); | 215 return SendMouseEvents(type, UP | DOWN); |
| 216 } | 216 } |
| 217 virtual void RunClosureAfterAllPendingUIEvents( | 217 virtual void RunClosureAfterAllPendingUIEvents( |
| 218 const base::Closure& closure) OVERRIDE { | 218 const base::Closure& closure) override { |
| 219 if (closure.is_null()) | 219 if (closure.is_null()) |
| 220 return; | 220 return; |
| 221 static XEvent* marker_event = NULL; | 221 static XEvent* marker_event = NULL; |
| 222 if (!marker_event) { | 222 if (!marker_event) { |
| 223 marker_event = new XEvent(); | 223 marker_event = new XEvent(); |
| 224 marker_event->xclient.type = ClientMessage; | 224 marker_event->xclient.type = ClientMessage; |
| 225 marker_event->xclient.display = x_display_; | 225 marker_event->xclient.display = x_display_; |
| 226 marker_event->xclient.window = x_window_; | 226 marker_event->xclient.window = x_window_; |
| 227 marker_event->xclient.format = 8; | 227 marker_event->xclient.format = 8; |
| 228 } | 228 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 283 |
| 284 UIControlsAura* CreateUIControlsDesktopAura() { | 284 UIControlsAura* CreateUIControlsDesktopAura() { |
| 285 // The constructor of UIControlsDesktopX11 needs X11 connection to be | 285 // The constructor of UIControlsDesktopX11 needs X11 connection to be |
| 286 // initialized. | 286 // initialized. |
| 287 gfx::InitializeThreadedX11(); | 287 gfx::InitializeThreadedX11(); |
| 288 return new UIControlsDesktopX11(); | 288 return new UIControlsDesktopX11(); |
| 289 } | 289 } |
| 290 | 290 |
| 291 } // namespace test | 291 } // namespace test |
| 292 } // namespace views | 292 } // namespace views |
| OLD | NEW |