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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 virtual bool SendKeyPressNotifyWhenDone( | 118 virtual bool SendKeyPressNotifyWhenDone( |
119 gfx::NativeWindow window, | 119 gfx::NativeWindow window, |
120 ui::KeyboardCode key, | 120 ui::KeyboardCode key, |
121 bool control, | 121 bool control, |
122 bool shift, | 122 bool shift, |
123 bool alt, | 123 bool alt, |
124 bool command, | 124 bool command, |
125 const base::Closure& closure) OVERRIDE { | 125 const base::Closure& closure) OVERRIDE { |
126 DCHECK(!command); // No command key on Aura | 126 DCHECK(!command); // No command key on Aura |
127 | 127 |
128 aura::WindowEventDispatcher* dispatcher = window->GetDispatcher(); | 128 aura::WindowTreeHost* host = window->GetHost(); |
129 | 129 |
130 XEvent xevent = {0}; | 130 XEvent xevent = {0}; |
131 xevent.xkey.type = KeyPress; | 131 xevent.xkey.type = KeyPress; |
132 if (control) { | 132 if (control) { |
133 SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Control_L, | 133 SetKeycodeAndSendThenMask(host, &xevent, XK_Control_L, ControlMask); |
134 ControlMask); | |
135 } | 134 } |
136 if (shift) | 135 if (shift) |
137 SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Shift_L, ShiftMask); | 136 SetKeycodeAndSendThenMask(host, &xevent, XK_Shift_L, ShiftMask); |
138 if (alt) | 137 if (alt) |
139 SetKeycodeAndSendThenMask(dispatcher, &xevent, XK_Alt_L, Mod1Mask); | 138 SetKeycodeAndSendThenMask(host, &xevent, XK_Alt_L, Mod1Mask); |
140 xevent.xkey.keycode = | 139 xevent.xkey.keycode = |
141 XKeysymToKeycode(x_display_, | 140 XKeysymToKeycode(x_display_, |
142 ui::XKeysymForWindowsKeyCode(key, shift)); | 141 ui::XKeysymForWindowsKeyCode(key, shift)); |
143 dispatcher->host()->PostNativeEvent(&xevent); | 142 host->PostNativeEvent(&xevent); |
144 | 143 |
145 // Send key release events. | 144 // Send key release events. |
146 xevent.xkey.type = KeyRelease; | 145 xevent.xkey.type = KeyRelease; |
147 dispatcher->host()->PostNativeEvent(&xevent); | 146 host->PostNativeEvent(&xevent); |
148 if (alt) | 147 if (alt) |
149 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, Mod1Mask, XK_Alt_L); | 148 UnmaskAndSetKeycodeThenSend(host, &xevent, Mod1Mask, XK_Alt_L); |
150 if (shift) | 149 if (shift) |
151 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, ShiftMask, XK_Shift_L); | 150 UnmaskAndSetKeycodeThenSend(host, &xevent, ShiftMask, XK_Shift_L); |
152 if (control) { | 151 if (control) { |
153 UnmaskAndSetKeycodeThenSend(dispatcher, &xevent, ControlMask, | 152 UnmaskAndSetKeycodeThenSend(host, &xevent, ControlMask, XK_Control_L); |
154 XK_Control_L); | |
155 } | 153 } |
156 DCHECK(!xevent.xkey.state); | 154 DCHECK(!xevent.xkey.state); |
157 RunClosureAfterAllPendingUIEvents(closure); | 155 RunClosureAfterAllPendingUIEvents(closure); |
158 return true; | 156 return true; |
159 } | 157 } |
160 | 158 |
161 virtual bool SendMouseMove(long screen_x, long screen_y) OVERRIDE { | 159 virtual bool SendMouseMove(long screen_x, long screen_y) OVERRIDE { |
162 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); | 160 return SendMouseMoveNotifyWhenDone(screen_x, screen_y, base::Closure()); |
163 } | 161 } |
164 virtual bool SendMouseMoveNotifyWhenDone( | 162 virtual bool SendMouseMoveNotifyWhenDone( |
165 long screen_x, | 163 long screen_x, |
166 long screen_y, | 164 long screen_y, |
167 const base::Closure& closure) OVERRIDE { | 165 const base::Closure& closure) OVERRIDE { |
168 gfx::Point screen_location(screen_x, screen_y); | 166 gfx::Point screen_location(screen_x, screen_y); |
169 gfx::Point root_location = screen_location; | 167 gfx::Point root_location = screen_location; |
170 aura::Window* root_window = RootWindowForPoint(screen_location); | 168 aura::Window* root_window = RootWindowForPoint(screen_location); |
171 | 169 |
172 aura::client::ScreenPositionClient* screen_position_client = | 170 aura::client::ScreenPositionClient* screen_position_client = |
173 aura::client::GetScreenPositionClient(root_window); | 171 aura::client::GetScreenPositionClient(root_window); |
174 if (screen_position_client) { | 172 if (screen_position_client) { |
175 screen_position_client->ConvertPointFromScreen(root_window, | 173 screen_position_client->ConvertPointFromScreen(root_window, |
176 &root_location); | 174 &root_location); |
177 } | 175 } |
178 | 176 |
179 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); | 177 aura::WindowTreeHost* host = root_window->GetHost(); |
180 gfx::Point root_current_location; | 178 gfx::Point root_current_location; |
181 dispatcher->host()->QueryMouseLocation(&root_current_location); | 179 host->QueryMouseLocation(&root_current_location); |
182 dispatcher->host()->ConvertPointFromHost(&root_current_location); | 180 host->ConvertPointFromHost(&root_current_location); |
183 | 181 |
184 if (root_location != root_current_location && button_down_mask == 0) { | 182 if (root_location != root_current_location && button_down_mask == 0) { |
185 // Move the cursor because EnterNotify/LeaveNotify are generated with the | 183 // Move the cursor because EnterNotify/LeaveNotify are generated with the |
186 // current mouse position as a result of XGrabPointer() | 184 // current mouse position as a result of XGrabPointer() |
187 root_window->MoveCursorTo(root_location); | 185 root_window->MoveCursorTo(root_location); |
188 } else { | 186 } else { |
189 XEvent xevent = {0}; | 187 XEvent xevent = {0}; |
190 XMotionEvent* xmotion = &xevent.xmotion; | 188 XMotionEvent* xmotion = &xevent.xmotion; |
191 xmotion->type = MotionNotify; | 189 xmotion->type = MotionNotify; |
192 xmotion->x = root_location.x(); | 190 xmotion->x = root_location.x(); |
193 xmotion->y = root_location.y(); | 191 xmotion->y = root_location.y(); |
194 xmotion->state = button_down_mask; | 192 xmotion->state = button_down_mask; |
195 xmotion->same_screen = True; | 193 xmotion->same_screen = True; |
196 // RootWindow will take care of other necessary fields. | 194 // RootWindow will take care of other necessary fields. |
197 dispatcher->host()->PostNativeEvent(&xevent); | 195 host->PostNativeEvent(&xevent); |
198 } | 196 } |
199 RunClosureAfterAllPendingUIEvents(closure); | 197 RunClosureAfterAllPendingUIEvents(closure); |
200 return true; | 198 return true; |
201 } | 199 } |
202 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { | 200 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { |
203 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 201 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
204 } | 202 } |
205 virtual bool SendMouseEventsNotifyWhenDone( | 203 virtual bool SendMouseEventsNotifyWhenDone( |
206 MouseButton type, | 204 MouseButton type, |
207 int state, | 205 int state, |
(...skipping 19 matching lines...) Expand all Loading... |
227 xbutton->state = Button2Mask; | 225 xbutton->state = Button2Mask; |
228 break; | 226 break; |
229 case RIGHT: | 227 case RIGHT: |
230 xbutton->button = Button3; | 228 xbutton->button = Button3; |
231 xbutton->state = Button3Mask; | 229 xbutton->state = Button3Mask; |
232 break; | 230 break; |
233 } | 231 } |
234 // RootWindow will take care of other necessary fields. | 232 // RootWindow will take care of other necessary fields. |
235 if (state & DOWN) { | 233 if (state & DOWN) { |
236 xevent.xbutton.type = ButtonPress; | 234 xevent.xbutton.type = ButtonPress; |
237 root_window->GetDispatcher()->host()->PostNativeEvent(&xevent); | 235 root_window->GetHost()->PostNativeEvent(&xevent); |
238 button_down_mask |= xbutton->state; | 236 button_down_mask |= xbutton->state; |
239 } | 237 } |
240 if (state & UP) { | 238 if (state & UP) { |
241 xevent.xbutton.type = ButtonRelease; | 239 xevent.xbutton.type = ButtonRelease; |
242 root_window->GetDispatcher()->host()->PostNativeEvent(&xevent); | 240 root_window->GetHost()->PostNativeEvent(&xevent); |
243 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; | 241 button_down_mask = (button_down_mask | xbutton->state) ^ xbutton->state; |
244 } | 242 } |
245 RunClosureAfterAllPendingUIEvents(closure); | 243 RunClosureAfterAllPendingUIEvents(closure); |
246 return true; | 244 return true; |
247 } | 245 } |
248 virtual bool SendMouseClick(MouseButton type) OVERRIDE { | 246 virtual bool SendMouseClick(MouseButton type) OVERRIDE { |
249 return SendMouseEvents(type, UP | DOWN); | 247 return SendMouseEvents(type, UP | DOWN); |
250 } | 248 } |
251 virtual void RunClosureAfterAllPendingUIEvents( | 249 virtual void RunClosureAfterAllPendingUIEvents( |
252 const base::Closure& closure) OVERRIDE { | 250 const base::Closure& closure) OVERRIDE { |
(...skipping 25 matching lines...) Expand all Loading... |
278 if ((*it)->GetBoundsInScreen().Contains(point)) { | 276 if ((*it)->GetBoundsInScreen().Contains(point)) { |
279 return (*it)->GetRootWindow(); | 277 return (*it)->GetRootWindow(); |
280 } | 278 } |
281 } | 279 } |
282 | 280 |
283 NOTREACHED() << "Coulding find RW for " << point.ToString() << " among " | 281 NOTREACHED() << "Coulding find RW for " << point.ToString() << " among " |
284 << windows.size() << " RWs."; | 282 << windows.size() << " RWs."; |
285 return NULL; | 283 return NULL; |
286 } | 284 } |
287 | 285 |
288 void SetKeycodeAndSendThenMask(aura::WindowEventDispatcher* dispatcher, | 286 void SetKeycodeAndSendThenMask(aura::WindowTreeHost* host, |
289 XEvent* xevent, | 287 XEvent* xevent, |
290 KeySym keysym, | 288 KeySym keysym, |
291 unsigned int mask) { | 289 unsigned int mask) { |
292 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); | 290 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); |
293 dispatcher->host()->PostNativeEvent(xevent); | 291 host->PostNativeEvent(xevent); |
294 xevent->xkey.state |= mask; | 292 xevent->xkey.state |= mask; |
295 } | 293 } |
296 | 294 |
297 void UnmaskAndSetKeycodeThenSend(aura::WindowEventDispatcher* dispatcher, | 295 void UnmaskAndSetKeycodeThenSend(aura::WindowTreeHost* host, |
298 XEvent* xevent, | 296 XEvent* xevent, |
299 unsigned int mask, | 297 unsigned int mask, |
300 KeySym keysym) { | 298 KeySym keysym) { |
301 xevent->xkey.state ^= mask; | 299 xevent->xkey.state ^= mask; |
302 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); | 300 xevent->xkey.keycode = XKeysymToKeycode(x_display_, keysym); |
303 dispatcher->host()->PostNativeEvent(xevent); | 301 host->PostNativeEvent(xevent); |
304 } | 302 } |
305 | 303 |
306 // Our X11 state. | 304 // Our X11 state. |
307 Display* x_display_; | 305 Display* x_display_; |
308 ::Window x_root_window_; | 306 ::Window x_root_window_; |
309 | 307 |
310 // Input-only window used for events. | 308 // Input-only window used for events. |
311 ::Window x_window_; | 309 ::Window x_window_; |
312 | 310 |
313 DISALLOW_COPY_AND_ASSIGN(UIControlsDesktopX11); | 311 DISALLOW_COPY_AND_ASSIGN(UIControlsDesktopX11); |
314 }; | 312 }; |
315 | 313 |
316 } // namespace | 314 } // namespace |
317 | 315 |
318 UIControlsAura* CreateUIControlsDesktopAura() { | 316 UIControlsAura* CreateUIControlsDesktopAura() { |
319 return new UIControlsDesktopX11(); | 317 return new UIControlsDesktopX11(); |
320 } | 318 } |
321 | 319 |
322 } // namespace test | 320 } // namespace test |
323 } // namespace views | 321 } // namespace views |
OLD | NEW |