| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 -100, -100, 10, 10, // x, y, width, height | 61 -100, -100, 10, 10, // x, y, width, height |
| 62 0, // border width | 62 0, // border width |
| 63 CopyFromParent, // depth | 63 CopyFromParent, // depth |
| 64 InputOnly, | 64 InputOnly, |
| 65 CopyFromParent, // visual | 65 CopyFromParent, // visual |
| 66 0, | 66 0, |
| 67 NULL)) { | 67 NULL)) { |
| 68 XStoreName(x_display_, x_window_, "Chromium UIControlsDesktopX11 Window"); | 68 XStoreName(x_display_, x_window_, "Chromium UIControlsDesktopX11 Window"); |
| 69 } | 69 } |
| 70 | 70 |
| 71 virtual ~UIControlsDesktopX11() { | 71 ~UIControlsDesktopX11() override { XDestroyWindow(x_display_, x_window_); } |
| 72 XDestroyWindow(x_display_, x_window_); | |
| 73 } | |
| 74 | 72 |
| 75 virtual bool SendKeyPress(gfx::NativeWindow window, | 73 bool SendKeyPress(gfx::NativeWindow window, |
| 76 ui::KeyboardCode key, | 74 ui::KeyboardCode key, |
| 77 bool control, | 75 bool control, |
| 78 bool shift, | 76 bool shift, |
| 79 bool alt, | 77 bool alt, |
| 80 bool command) override { | 78 bool command) override { |
| 81 DCHECK(!command); // No command key on Aura | 79 DCHECK(!command); // No command key on Aura |
| 82 return SendKeyPressNotifyWhenDone( | 80 return SendKeyPressNotifyWhenDone( |
| 83 window, key, control, shift, alt, command, base::Closure()); | 81 window, key, control, shift, alt, command, base::Closure()); |
| 84 } | 82 } |
| 85 | 83 |
| 86 virtual bool SendKeyPressNotifyWhenDone( | 84 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
| 87 gfx::NativeWindow window, | 85 ui::KeyboardCode key, |
| 88 ui::KeyboardCode key, | 86 bool control, |
| 89 bool control, | 87 bool shift, |
| 90 bool shift, | 88 bool alt, |
| 91 bool alt, | 89 bool command, |
| 92 bool command, | 90 const base::Closure& closure) override { |
| 93 const base::Closure& closure) override { | |
| 94 DCHECK(!command); // No command key on Aura | 91 DCHECK(!command); // No command key on Aura |
| 95 | 92 |
| 96 aura::WindowTreeHost* host = window->GetHost(); | 93 aura::WindowTreeHost* host = window->GetHost(); |
| 97 | 94 |
| 98 XEvent xevent = {0}; | 95 XEvent xevent = {0}; |
| 99 xevent.xkey.type = KeyPress; | 96 xevent.xkey.type = KeyPress; |
| 100 if (control) { | 97 if (control) { |
| 101 SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask); | 98 SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask); |
| 102 } | 99 } |
| 103 if (shift) | 100 if (shift) |
| (...skipping 13 matching lines...) Expand all Loading... |
| 117 if (shift) | 114 if (shift) |
| 118 UnmaskAndSetKeycodeThenSend(host, &xevent, ShiftMask, XK_Shift_L); | 115 UnmaskAndSetKeycodeThenSend(host, &xevent, ShiftMask, XK_Shift_L); |
| 119 if (control) { | 116 if (control) { |
| 120 UnmaskAndSetKeycodeThenSend(host, &xevent, ControlMask, XK_Control_L); | 117 UnmaskAndSetKeycodeThenSend(host, &xevent, ControlMask, XK_Control_L); |
| 121 } | 118 } |
| 122 DCHECK(!xevent.xkey.state); | 119 DCHECK(!xevent.xkey.state); |
| 123 RunClosureAfterAllPendingUIEvents(closure); | 120 RunClosureAfterAllPendingUIEvents(closure); |
| 124 return true; | 121 return true; |
| 125 } | 122 } |
| 126 | 123 |
| 127 virtual bool SendMouseMove(long screen_x, long screen_y) override { | 124 bool SendMouseMove(long screen_x, long screen_y) override { |
| 128 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); | 125 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); |
| 129 } | 126 } |
| 130 virtual bool SendMouseMoveNotifyWhenDone( | 127 bool SendMouseMoveNotifyWhenDone(long screen_x, |
| 131 long screen_x, | 128 long screen_y, |
| 132 long screen_y, | 129 const base::Closure& closure) override { |
| 133 const base::Closure& closure) override { | |
| 134 gfx::Point screen_location(screen_x, screen_y); | 130 gfx::Point screen_location(screen_x, screen_y); |
| 135 gfx::Point root_location = screen_location; | 131 gfx::Point root_location = screen_location; |
| 136 aura::Window* root_window = RootWindowForPoint(screen_location); | 132 aura::Window* root_window = RootWindowForPoint(screen_location); |
| 137 | 133 |
| 138 aura::client::ScreenPositionClient* screen_position_client = | 134 aura::client::ScreenPositionClient* screen_position_client = |
| 139 aura::client::GetScreenPositionClient(root_window); | 135 aura::client::GetScreenPositionClient(root_window); |
| 140 if (screen_position_client) { | 136 if (screen_position_client) { |
| 141 screen_position_client->ConvertPointFromScreen(root_window, | 137 screen_position_client->ConvertPointFromScreen(root_window, |
| 142 &root_location); | 138 &root_location); |
| 143 } | 139 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 158 xmotion->x = root_location.x(); | 154 xmotion->x = root_location.x(); |
| 159 xmotion->y = root_location.y(); | 155 xmotion->y = root_location.y(); |
| 160 xmotion->state = button_down_mask; | 156 xmotion->state = button_down_mask; |
| 161 xmotion->same_screen = True; | 157 xmotion->same_screen = True; |
| 162 // RootWindow will take care of other necessary fields. | 158 // RootWindow will take care of other necessary fields. |
| 163 host->PostNativeEvent(&xevent); | 159 host->PostNativeEvent(&xevent); |
| 164 } | 160 } |
| 165 RunClosureAfterAllPendingUIEvents(closure); | 161 RunClosureAfterAllPendingUIEvents(closure); |
| 166 return true; | 162 return true; |
| 167 } | 163 } |
| 168 virtual bool SendMouseEvents(MouseButton type, int state) override { | 164 bool SendMouseEvents(MouseButton type, int state) override { |
| 169 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 165 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
| 170 } | 166 } |
| 171 virtual bool SendMouseEventsNotifyWhenDone( | 167 bool SendMouseEventsNotifyWhenDone(MouseButton type, |
| 172 MouseButton type, | 168 int state, |
| 173 int state, | 169 const base::Closure& closure) override { |
| 174 const base::Closure& closure) override { | |
| 175 XEvent xevent = {0}; | 170 XEvent xevent = {0}; |
| 176 XButtonEvent* xbutton = &xevent.xbutton; | 171 XButtonEvent* xbutton = &xevent.xbutton; |
| 177 gfx::Point mouse_loc = aura::Env::GetInstance()->last_mouse_location(); | 172 gfx::Point mouse_loc = aura::Env::GetInstance()->last_mouse_location(); |
| 178 aura::Window* root_window = RootWindowForPoint(mouse_loc); | 173 aura::Window* root_window = RootWindowForPoint(mouse_loc); |
| 179 aura::client::ScreenPositionClient* screen_position_client = | 174 aura::client::ScreenPositionClient* screen_position_client = |
| 180 aura::client::GetScreenPositionClient(root_window); | 175 aura::client::GetScreenPositionClient(root_window); |
| 181 if (screen_position_client) | 176 if (screen_position_client) |
| 182 screen_position_client->ConvertPointFromScreen(root_window, &mouse_loc); | 177 screen_position_client->ConvertPointFromScreen(root_window, &mouse_loc); |
| 183 xbutton->x = mouse_loc.x(); | 178 xbutton->x = mouse_loc.x(); |
| 184 xbutton->y = mouse_loc.y(); | 179 xbutton->y = mouse_loc.y(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 204 button_down_mask |= xbutton->state; | 199 button_down_mask |= xbutton->state; |
| 205 } | 200 } |
| 206 if (state & UP) { | 201 if (state & UP) { |
| 207 xevent.xbutton.type = ButtonRelease; | 202 xevent.xbutton.type = ButtonRelease; |
| 208 root_window->GetHost()->PostNativeEvent(&xevent); | 203 root_window->GetHost()->PostNativeEvent(&xevent); |
| 209 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; | 204 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; |
| 210 } | 205 } |
| 211 RunClosureAfterAllPendingUIEvents(closure); | 206 RunClosureAfterAllPendingUIEvents(closure); |
| 212 return true; | 207 return true; |
| 213 } | 208 } |
| 214 virtual bool SendMouseClick(MouseButton type) override { | 209 bool SendMouseClick(MouseButton type) override { |
| 215 return SendMouseEvents(type, UP | DOWN); | 210 return SendMouseEvents(type, UP | DOWN); |
| 216 } | 211 } |
| 217 virtual void RunClosureAfterAllPendingUIEvents( | 212 void RunClosureAfterAllPendingUIEvents( |
| 218 const base::Closure& closure) override { | 213 const base::Closure& closure) override { |
| 219 if (closure.is_null()) | 214 if (closure.is_null()) |
| 220 return; | 215 return; |
| 221 static XEvent* marker_event = NULL; | 216 static XEvent* marker_event = NULL; |
| 222 if (!marker_event) { | 217 if (!marker_event) { |
| 223 marker_event = new XEvent(); | 218 marker_event = new XEvent(); |
| 224 marker_event->xclient.type = ClientMessage; | 219 marker_event->xclient.type = ClientMessage; |
| 225 marker_event->xclient.display = x_display_; | 220 marker_event->xclient.display = x_display_; |
| 226 marker_event->xclient.window = x_window_; | 221 marker_event->xclient.window = x_window_; |
| 227 marker_event->xclient.format = 8; | 222 marker_event->xclient.format = 8; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 283 | 278 |
| 284 UIControlsAura* CreateUIControlsDesktopAura() { | 279 UIControlsAura* CreateUIControlsDesktopAura() { |
| 285 // The constructor of UIControlsDesktopX11 needs X11 connection to be | 280 // The constructor of UIControlsDesktopX11 needs X11 connection to be |
| 286 // initialized. | 281 // initialized. |
| 287 gfx::InitializeThreadedX11(); | 282 gfx::InitializeThreadedX11(); |
| 288 return new UIControlsDesktopX11(); | 283 return new UIControlsDesktopX11(); |
| 289 } | 284 } |
| 290 | 285 |
| 291 } // namespace test | 286 } // namespace test |
| 292 } // namespace views | 287 } // namespace views |
| OLD | NEW |