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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 DCHECK(!xevent.xkey.state); | 156 DCHECK(!xevent.xkey.state); |
157 RunClosureAfterAllPendingUIEvents(closure); | 157 RunClosureAfterAllPendingUIEvents(closure); |
158 return true; | 158 return true; |
159 } | 159 } |
160 | 160 |
161 // Simulate a mouse move. (x,y) are absolute screen coordinates. | 161 // Simulate a mouse move. (x,y) are absolute screen coordinates. |
162 virtual bool SendMouseMove(long x, long y) OVERRIDE { | 162 virtual bool SendMouseMove(long x, long y) OVERRIDE { |
163 return SendMouseMoveNotifyWhenDone(x, y, base::Closure()); | 163 return SendMouseMoveNotifyWhenDone(x, y, base::Closure()); |
164 } | 164 } |
165 virtual bool SendMouseMoveNotifyWhenDone( | 165 virtual bool SendMouseMoveNotifyWhenDone( |
166 long x, | 166 long screen_x, |
167 long y, | 167 long screen_y, |
168 const base::Closure& closure) OVERRIDE { | 168 const base::Closure& closure) OVERRIDE { |
169 gfx::Point screen_point(x, y); | 169 gfx::Point screen_point(screen_x, screen_y); |
170 gfx::Point window_point = screen_point; | 170 gfx::Point root_point = screen_point; |
171 aura::Window* root_window = RootWindowForPoint(screen_point); | 171 aura::Window* root_window = RootWindowForPoint(screen_point); |
172 | 172 |
173 aura::client::ScreenPositionClient* screen_position_client = | 173 aura::client::ScreenPositionClient* screen_position_client = |
174 aura::client::GetScreenPositionClient(root_window); | 174 aura::client::GetScreenPositionClient(root_window); |
175 if (screen_position_client) { | 175 if (screen_position_client) |
176 screen_position_client->ConvertPointFromScreen(root_window, | 176 screen_position_client->ConvertPointFromScreen(root_window, &root_point); |
177 &window_point); | 177 |
| 178 aura::WindowEventDispatcher* dispatcher = root_window->GetDispatcher(); |
| 179 gfx::Point root_current_location; |
| 180 dispatcher->host()->QueryMouseLocation(&root_current_location); |
| 181 dispatcher->host()->ConvertPointFromHost(&root_current_location); |
| 182 |
| 183 if (root_point != root_current_location && button_down_mask == 0) { |
| 184 // Move the cursor because EnterNotify/LeaveNotify are generated with the |
| 185 // current mouse position as a result of XGrabPointer() |
| 186 dispatcher->MoveCursorTo(root_point); |
| 187 } else { |
| 188 XEvent xevent = {0}; |
| 189 XMotionEvent* xmotion = &xevent.xmotion; |
| 190 xmotion->type = MotionNotify; |
| 191 xmotion->x = root_point.x(); |
| 192 xmotion->y = root_point.y(); |
| 193 xmotion->state = button_down_mask; |
| 194 xmotion->same_screen = True; |
| 195 // RootWindow will take care of other necessary fields. |
| 196 dispatcher->host()->PostNativeEvent(&xevent); |
178 } | 197 } |
179 | |
180 XEvent xevent = {0}; | |
181 XMotionEvent* xmotion = &xevent.xmotion; | |
182 xmotion->type = MotionNotify; | |
183 xmotion->x = window_point.x(); | |
184 xmotion->y = window_point.y(); | |
185 xmotion->state = button_down_mask; | |
186 xmotion->same_screen = True; | |
187 // RootWindow will take care of other necessary fields. | |
188 root_window->GetDispatcher()->host()->PostNativeEvent(&xevent); | |
189 RunClosureAfterAllPendingUIEvents(closure); | 198 RunClosureAfterAllPendingUIEvents(closure); |
190 return true; | 199 return true; |
191 } | 200 } |
192 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { | 201 virtual bool SendMouseEvents(MouseButton type, int state) OVERRIDE { |
193 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); | 202 return SendMouseEventsNotifyWhenDone(type, state, base::Closure()); |
194 } | 203 } |
195 virtual bool SendMouseEventsNotifyWhenDone( | 204 virtual bool SendMouseEventsNotifyWhenDone( |
196 MouseButton type, | 205 MouseButton type, |
197 int state, | 206 int state, |
198 const base::Closure& closure) OVERRIDE { | 207 const base::Closure& closure) OVERRIDE { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 }; | 313 }; |
305 | 314 |
306 } // namespace | 315 } // namespace |
307 | 316 |
308 UIControlsAura* CreateUIControlsDesktopAura() { | 317 UIControlsAura* CreateUIControlsDesktopAura() { |
309 return new UIControlsDesktopX11(); | 318 return new UIControlsDesktopX11(); |
310 } | 319 } |
311 | 320 |
312 } // namespace test | 321 } // namespace test |
313 } // namespace views | 322 } // namespace views |
OLD | NEW |