OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/aura/test/event_generator.h" | 5 #include "ui/aura/test/event_generator.h" |
6 | 6 |
| 7 #include "base/bind.h" |
7 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/message_loop_proxy.h" |
8 #include "ui/aura/client/screen_position_client.h" | 10 #include "ui/aura/client/screen_position_client.h" |
9 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
10 #include "ui/base/events/event.h" | 12 #include "ui/base/events/event.h" |
11 #include "ui/base/events/event_utils.h" | 13 #include "ui/base/events/event_utils.h" |
12 #include "ui/gfx/vector2d_conversions.h" | 14 #include "ui/gfx/vector2d_conversions.h" |
13 | 15 |
14 #if defined(USE_X11) | 16 #if defined(USE_X11) |
15 #include <X11/Xlib.h> | 17 #include <X11/Xlib.h> |
16 #include "ui/base/x/x11_util.h" | 18 #include "ui/base/x/x11_util.h" |
17 #endif | 19 #endif |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 }; | 70 }; |
69 | 71 |
70 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; | 72 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; |
71 | 73 |
72 } // namespace | 74 } // namespace |
73 | 75 |
74 EventGenerator::EventGenerator(RootWindow* root_window) | 76 EventGenerator::EventGenerator(RootWindow* root_window) |
75 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 77 : delegate_(new DefaultEventGeneratorDelegate(root_window)), |
76 current_root_window_(delegate_->GetRootWindowAt(current_location_)), | 78 current_root_window_(delegate_->GetRootWindowAt(current_location_)), |
77 flags_(0), | 79 flags_(0), |
78 grab_(false) { | 80 grab_(false), |
| 81 post_events_(false) { |
79 } | 82 } |
80 | 83 |
81 EventGenerator::EventGenerator(RootWindow* root_window, const gfx::Point& point) | 84 EventGenerator::EventGenerator(RootWindow* root_window, const gfx::Point& point) |
82 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 85 : delegate_(new DefaultEventGeneratorDelegate(root_window)), |
83 current_location_(point), | 86 current_location_(point), |
84 current_root_window_(delegate_->GetRootWindowAt(current_location_)), | 87 current_root_window_(delegate_->GetRootWindowAt(current_location_)), |
85 flags_(0), | 88 flags_(0), |
86 grab_(false) { | 89 grab_(false), |
| 90 post_events_(false) { |
87 } | 91 } |
88 | 92 |
89 EventGenerator::EventGenerator(RootWindow* root_window, Window* window) | 93 EventGenerator::EventGenerator(RootWindow* root_window, Window* window) |
90 : delegate_(new DefaultEventGeneratorDelegate(root_window)), | 94 : delegate_(new DefaultEventGeneratorDelegate(root_window)), |
91 current_location_(CenterOfWindow(window)), | 95 current_location_(CenterOfWindow(window)), |
92 current_root_window_(delegate_->GetRootWindowAt(current_location_)), | 96 current_root_window_(delegate_->GetRootWindowAt(current_location_)), |
93 flags_(0), | 97 flags_(0), |
94 grab_(false) { | 98 grab_(false), |
| 99 post_events_(false) { |
95 } | 100 } |
96 | 101 |
97 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) | 102 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) |
98 : delegate_(delegate), | 103 : delegate_(delegate), |
99 current_root_window_(delegate_->GetRootWindowAt(current_location_)), | 104 current_root_window_(delegate_->GetRootWindowAt(current_location_)), |
100 flags_(0), | 105 flags_(0), |
101 grab_(false) { | 106 grab_(false), |
| 107 post_events_(false) { |
102 } | 108 } |
103 | 109 |
104 EventGenerator::~EventGenerator() { | 110 EventGenerator::~EventGenerator() { |
105 } | 111 } |
106 | 112 |
107 void EventGenerator::PressLeftButton() { | 113 void EventGenerator::PressLeftButton() { |
108 PressButton(ui::EF_LEFT_MOUSE_BUTTON); | 114 PressButton(ui::EF_LEFT_MOUSE_BUTTON); |
109 } | 115 } |
110 | 116 |
111 void EventGenerator::ReleaseLeftButton() { | 117 void EventGenerator::ReleaseLeftButton() { |
(...skipping 27 matching lines...) Expand all Loading... |
139 | 145 |
140 gfx::Vector2dF diff(point - current_location_); | 146 gfx::Vector2dF diff(point - current_location_); |
141 for (float i = 1; i <= count; i++) { | 147 for (float i = 1; i <= count; i++) { |
142 gfx::Vector2dF step(diff); | 148 gfx::Vector2dF step(diff); |
143 step.Scale(i / count); | 149 step.Scale(i / count); |
144 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); | 150 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); |
145 if (!grab_) | 151 if (!grab_) |
146 UpdateCurrentRootWindow(move_point); | 152 UpdateCurrentRootWindow(move_point); |
147 ConvertPointToTarget(current_root_window_, &move_point); | 153 ConvertPointToTarget(current_root_window_, &move_point); |
148 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); | 154 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); |
149 Dispatch(mouseev); | 155 Dispatch(&mouseev); |
150 } | 156 } |
151 current_location_ = point; | 157 current_location_ = point; |
152 } | 158 } |
153 | 159 |
154 void EventGenerator::MoveMouseRelativeTo(const Window* window, | 160 void EventGenerator::MoveMouseRelativeTo(const Window* window, |
155 const gfx::Point& point_in_parent) { | 161 const gfx::Point& point_in_parent) { |
156 gfx::Point point(point_in_parent); | 162 gfx::Point point(point_in_parent); |
157 ConvertPointFromTarget(window, &point); | 163 ConvertPointFromTarget(window, &point); |
158 MoveMouseTo(point); | 164 MoveMouseTo(point); |
159 } | 165 } |
160 | 166 |
161 void EventGenerator::DragMouseTo(const gfx::Point& point) { | 167 void EventGenerator::DragMouseTo(const gfx::Point& point) { |
162 PressLeftButton(); | 168 PressLeftButton(); |
163 MoveMouseTo(point); | 169 MoveMouseTo(point); |
164 ReleaseLeftButton(); | 170 ReleaseLeftButton(); |
165 } | 171 } |
166 | 172 |
167 void EventGenerator::MoveMouseToCenterOf(Window* window) { | 173 void EventGenerator::MoveMouseToCenterOf(Window* window) { |
168 MoveMouseTo(CenterOfWindow(window)); | 174 MoveMouseTo(CenterOfWindow(window)); |
169 } | 175 } |
170 | 176 |
171 void EventGenerator::PressTouch() { | 177 void EventGenerator::PressTouch() { |
172 TestTouchEvent touchev( | 178 TestTouchEvent touchev( |
173 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), flags_); | 179 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), flags_); |
174 Dispatch(touchev); | 180 Dispatch(&touchev); |
175 } | 181 } |
176 | 182 |
177 void EventGenerator::MoveTouch(const gfx::Point& point) { | 183 void EventGenerator::MoveTouch(const gfx::Point& point) { |
178 TestTouchEvent touchev(ui::ET_TOUCH_MOVED, point, flags_); | 184 TestTouchEvent touchev(ui::ET_TOUCH_MOVED, point, flags_); |
179 Dispatch(touchev); | 185 Dispatch(&touchev); |
180 | 186 |
181 current_location_ = point; | 187 current_location_ = point; |
182 if (!grab_) | 188 if (!grab_) |
183 UpdateCurrentRootWindow(point); | 189 UpdateCurrentRootWindow(point); |
184 } | 190 } |
185 | 191 |
186 void EventGenerator::ReleaseTouch() { | 192 void EventGenerator::ReleaseTouch() { |
187 TestTouchEvent touchev( | 193 TestTouchEvent touchev( |
188 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), flags_); | 194 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), flags_); |
189 Dispatch(touchev); | 195 Dispatch(&touchev); |
190 } | 196 } |
191 | 197 |
192 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { | 198 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { |
193 PressTouch(); | 199 PressTouch(); |
194 MoveTouch(point); | 200 MoveTouch(point); |
195 ReleaseTouch(); | 201 ReleaseTouch(); |
196 } | 202 } |
197 | 203 |
198 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { | 204 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { |
199 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); | 205 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); |
200 } | 206 } |
201 | 207 |
202 void EventGenerator::GestureTapAt(const gfx::Point& location) { | 208 void EventGenerator::GestureTapAt(const gfx::Point& location) { |
203 const int kTouchId = 2; | 209 const int kTouchId = 2; |
204 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 210 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
205 location, | 211 location, |
206 kTouchId, | 212 kTouchId, |
207 ui::EventTimeForNow()); | 213 ui::EventTimeForNow()); |
208 Dispatch(press); | 214 Dispatch(&press); |
209 | 215 |
210 ui::TouchEvent release( | 216 ui::TouchEvent release( |
211 ui::ET_TOUCH_RELEASED, location, kTouchId, | 217 ui::ET_TOUCH_RELEASED, location, kTouchId, |
212 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); | 218 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); |
213 Dispatch(release); | 219 Dispatch(&release); |
214 } | 220 } |
215 | 221 |
216 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { | 222 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { |
217 const int kTouchId = 3; | 223 const int kTouchId = 3; |
218 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 224 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
219 location, | 225 location, |
220 kTouchId, | 226 kTouchId, |
221 ui::EventTimeForNow()); | 227 ui::EventTimeForNow()); |
222 Dispatch(press); | 228 Dispatch(&press); |
223 | 229 |
224 ui::TouchEvent release( | 230 ui::TouchEvent release( |
225 ui::ET_TOUCH_RELEASED, location, kTouchId, | 231 ui::ET_TOUCH_RELEASED, location, kTouchId, |
226 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); | 232 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); |
227 Dispatch(release); | 233 Dispatch(&release); |
228 } | 234 } |
229 | 235 |
230 void EventGenerator::GestureScrollSequence(const gfx::Point& start, | 236 void EventGenerator::GestureScrollSequence(const gfx::Point& start, |
231 const gfx::Point& end, | 237 const gfx::Point& end, |
232 const base::TimeDelta& step_delay, | 238 const base::TimeDelta& step_delay, |
233 int steps) { | 239 int steps) { |
234 const int kTouchId = 5; | 240 const int kTouchId = 5; |
235 base::TimeDelta timestamp = ui::EventTimeForNow(); | 241 base::TimeDelta timestamp = ui::EventTimeForNow(); |
236 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); | 242 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); |
237 Dispatch(press); | 243 Dispatch(&press); |
238 | 244 |
239 int dx = (end.x() - start.x()) / steps; | 245 int dx = (end.x() - start.x()) / steps; |
240 int dy = (end.y() - start.y()) / steps; | 246 int dy = (end.y() - start.y()) / steps; |
241 gfx::Point location = start; | 247 gfx::Point location = start; |
242 for (int i = 0; i < steps; ++i) { | 248 for (int i = 0; i < steps; ++i) { |
243 location.Offset(dx, dy); | 249 location.Offset(dx, dy); |
244 timestamp += step_delay; | 250 timestamp += step_delay; |
245 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); | 251 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); |
246 Dispatch(move); | 252 Dispatch(&move); |
247 } | 253 } |
248 | 254 |
249 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); | 255 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); |
250 Dispatch(release); | 256 Dispatch(&release); |
251 } | 257 } |
252 | 258 |
253 void EventGenerator::GestureMultiFingerScroll(int count, | 259 void EventGenerator::GestureMultiFingerScroll(int count, |
254 const gfx::Point* start, | 260 const gfx::Point* start, |
255 int event_separation_time_ms, | 261 int event_separation_time_ms, |
256 int steps, | 262 int steps, |
257 int move_x, | 263 int move_x, |
258 int move_y) { | 264 int move_y) { |
259 const int kMaxTouchPoints = 10; | 265 const int kMaxTouchPoints = 10; |
260 gfx::Point points[kMaxTouchPoints]; | 266 gfx::Point points[kMaxTouchPoints]; |
261 CHECK_LE(count, kMaxTouchPoints); | 267 CHECK_LE(count, kMaxTouchPoints); |
262 CHECK_GT(steps, 0); | 268 CHECK_GT(steps, 0); |
263 | 269 |
264 int delta_x = move_x / steps; | 270 int delta_x = move_x / steps; |
265 int delta_y = move_y / steps; | 271 int delta_y = move_y / steps; |
266 | 272 |
267 base::TimeDelta press_time = ui::EventTimeForNow(); | 273 base::TimeDelta press_time = ui::EventTimeForNow(); |
268 for (int i = 0; i < count; ++i) { | 274 for (int i = 0; i < count; ++i) { |
269 points[i] = start[i]; | 275 points[i] = start[i]; |
270 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time); | 276 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time); |
271 Dispatch(press); | 277 Dispatch(&press); |
272 } | 278 } |
273 | 279 |
274 for (int step = 0; step < steps; ++step) { | 280 for (int step = 0; step < steps; ++step) { |
275 base::TimeDelta move_time = press_time + | 281 base::TimeDelta move_time = press_time + |
276 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step); | 282 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step); |
277 for (int i = 0; i < count; ++i) { | 283 for (int i = 0; i < count; ++i) { |
278 points[i].Offset(delta_x, delta_y); | 284 points[i].Offset(delta_x, delta_y); |
279 ui::TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time); | 285 ui::TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time); |
280 Dispatch(move); | 286 Dispatch(&move); |
281 } | 287 } |
282 } | 288 } |
283 | 289 |
284 base::TimeDelta release_time = press_time + | 290 base::TimeDelta release_time = press_time + |
285 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps); | 291 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps); |
286 for (int i = 0; i < count; ++i) { | 292 for (int i = 0; i < count; ++i) { |
287 ui::TouchEvent release( | 293 ui::TouchEvent release( |
288 ui::ET_TOUCH_RELEASED, points[i], i, release_time); | 294 ui::ET_TOUCH_RELEASED, points[i], i, release_time); |
289 Dispatch(release); | 295 Dispatch(&release); |
290 } | 296 } |
291 } | 297 } |
292 | 298 |
| 299 void EventGenerator::ScrollSequence(const gfx::Point& start, |
| 300 const base::TimeDelta& step_delay, |
| 301 float x_offset, |
| 302 float y_offset, |
| 303 int steps, |
| 304 int num_fingers) { |
| 305 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( |
| 306 base::TimeTicks::Now().ToInternalValue()); |
| 307 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| 308 start, |
| 309 timestamp, |
| 310 0, |
| 311 0, |
| 312 0, |
| 313 num_fingers); |
| 314 Dispatch(&fling_cancel); |
| 315 |
| 316 float dx = x_offset / steps; |
| 317 float dy = y_offset / steps; |
| 318 for (int i = 0; i < steps; ++i) { |
| 319 timestamp += step_delay; |
| 320 ui::ScrollEvent move(ui::ET_SCROLL, |
| 321 start, |
| 322 timestamp, |
| 323 0, |
| 324 dx, |
| 325 dy, |
| 326 num_fingers); |
| 327 Dispatch(&move); |
| 328 } |
| 329 |
| 330 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, |
| 331 start, |
| 332 timestamp, |
| 333 0, |
| 334 x_offset, |
| 335 y_offset, |
| 336 num_fingers); |
| 337 Dispatch(&fling_start); |
| 338 } |
| 339 |
| 340 void EventGenerator::ScrollSequence(const gfx::Point& start, |
| 341 const base::TimeDelta& step_delay, |
| 342 const std::vector<gfx::Point>& offsets, |
| 343 int num_fingers) { |
| 344 int steps = offsets.size(); |
| 345 base::TimeDelta timestamp = ui::EventTimeForNow(); |
| 346 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| 347 start, |
| 348 timestamp, |
| 349 0, |
| 350 0, |
| 351 0, |
| 352 num_fingers); |
| 353 Dispatch(&fling_cancel); |
| 354 |
| 355 for (int i = 0; i < steps; ++i) { |
| 356 timestamp += step_delay; |
| 357 ui::ScrollEvent scroll(ui::ET_SCROLL, |
| 358 start, |
| 359 timestamp, |
| 360 0, |
| 361 offsets[i].x(), |
| 362 offsets[i].y(), |
| 363 num_fingers); |
| 364 Dispatch(&scroll); |
| 365 } |
| 366 |
| 367 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, |
| 368 start, |
| 369 timestamp, |
| 370 0, |
| 371 offsets[steps - 1].x(), |
| 372 offsets[steps - 1].y(), |
| 373 num_fingers); |
| 374 Dispatch(&fling_start); |
| 375 } |
| 376 |
293 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { | 377 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { |
294 DispatchKeyEvent(true, key_code, flags); | 378 DispatchKeyEvent(true, key_code, flags); |
295 } | 379 } |
296 | 380 |
297 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { | 381 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { |
298 DispatchKeyEvent(false, key_code, flags); | 382 DispatchKeyEvent(false, key_code, flags); |
299 } | 383 } |
300 | 384 |
301 void EventGenerator::Dispatch(ui::Event& event) { | 385 void EventGenerator::Dispatch(ui::Event* event) { |
302 switch (event.type()) { | 386 DoDispatchEvent(event, post_events_); |
303 case ui::ET_KEY_PRESSED: | |
304 case ui::ET_KEY_RELEASED: | |
305 current_root_window_->AsRootWindowHostDelegate()->OnHostKeyEvent( | |
306 static_cast<ui::KeyEvent*>(&event)); | |
307 break; | |
308 case ui::ET_MOUSE_PRESSED: | |
309 case ui::ET_MOUSE_DRAGGED: | |
310 case ui::ET_MOUSE_RELEASED: | |
311 case ui::ET_MOUSE_MOVED: | |
312 case ui::ET_MOUSE_ENTERED: | |
313 case ui::ET_MOUSE_EXITED: | |
314 case ui::ET_MOUSEWHEEL: | |
315 current_root_window_->AsRootWindowHostDelegate()->OnHostMouseEvent( | |
316 static_cast<ui::MouseEvent*>(&event)); | |
317 break; | |
318 case ui::ET_TOUCH_RELEASED: | |
319 case ui::ET_TOUCH_PRESSED: | |
320 case ui::ET_TOUCH_MOVED: | |
321 case ui::ET_TOUCH_STATIONARY: | |
322 case ui::ET_TOUCH_CANCELLED: | |
323 current_root_window_->AsRootWindowHostDelegate()->OnHostTouchEvent( | |
324 static_cast<ui::TouchEvent*>(&event)); | |
325 break; | |
326 default: | |
327 NOTIMPLEMENTED(); | |
328 break; | |
329 } | |
330 } | 387 } |
331 | 388 |
332 void EventGenerator::DispatchKeyEvent(bool is_press, | 389 void EventGenerator::DispatchKeyEvent(bool is_press, |
333 ui::KeyboardCode key_code, | 390 ui::KeyboardCode key_code, |
334 int flags) { | 391 int flags) { |
335 #if defined(OS_WIN) | 392 #if defined(OS_WIN) |
336 UINT key_press = WM_KEYDOWN; | 393 UINT key_press = WM_KEYDOWN; |
337 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); | 394 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); |
338 if (is_press && character) { | 395 if (is_press && character) { |
339 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; | 396 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; |
340 TestKeyEvent keyev(native_event, flags, false); | 397 TestKeyEvent keyev(native_event, flags, false); |
341 Dispatch(keyev); | 398 DispatchKeyEvent(keyev); |
342 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character | 399 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character |
343 // if the key event cooresponds to a real character. | 400 // if the key event cooresponds to a real character. |
344 key_press = WM_CHAR; | 401 key_press = WM_CHAR; |
345 key_code = static_cast<ui::KeyboardCode>(character); | 402 key_code = static_cast<ui::KeyboardCode>(character); |
346 } | 403 } |
347 MSG native_event = | 404 MSG native_event = |
348 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; | 405 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; |
349 TestKeyEvent keyev(native_event, flags, key_press == WM_CHAR); | 406 TestKeyEvent keyev(native_event, flags, key_press == WM_CHAR); |
350 #else | 407 #else |
351 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; | 408 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
352 #if defined(USE_X11) | 409 #if defined(USE_X11) |
353 scoped_ptr<XEvent> native_event(new XEvent); | 410 scoped_ptr<XEvent> native_event(new XEvent); |
354 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); | 411 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); |
355 TestKeyEvent keyev(native_event.get(), flags, false); | 412 TestKeyEvent keyev(native_event.get(), flags, false); |
356 #else | 413 #else |
357 ui::KeyEvent keyev(type, key_code, flags, false); | 414 ui::KeyEvent keyev(type, key_code, flags, false); |
358 #endif // USE_X11 | 415 #endif // USE_X11 |
359 #endif // OS_WIN | 416 #endif // OS_WIN |
360 Dispatch(keyev); | 417 Dispatch(&keyev); |
361 } | 418 } |
362 | 419 |
363 void EventGenerator::UpdateCurrentRootWindow(const gfx::Point& point) { | 420 void EventGenerator::UpdateCurrentRootWindow(const gfx::Point& point) { |
364 current_root_window_ = delegate_->GetRootWindowAt(point); | 421 current_root_window_ = delegate_->GetRootWindowAt(point); |
365 } | 422 } |
366 | 423 |
367 void EventGenerator::PressButton(int flag) { | 424 void EventGenerator::PressButton(int flag) { |
368 if (!(flags_ & flag)) { | 425 if (!(flags_ & flag)) { |
369 flags_ |= flag; | 426 flags_ |= flag; |
370 grab_ = flags_ & kAllButtonMask; | 427 grab_ = flags_ & kAllButtonMask; |
371 gfx::Point location = GetLocationInCurrentRoot(); | 428 gfx::Point location = GetLocationInCurrentRoot(); |
372 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_); | 429 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_); |
373 Dispatch(mouseev); | 430 Dispatch(&mouseev); |
374 } | 431 } |
375 } | 432 } |
376 | 433 |
377 void EventGenerator::ReleaseButton(int flag) { | 434 void EventGenerator::ReleaseButton(int flag) { |
378 if (flags_ & flag) { | 435 if (flags_ & flag) { |
379 gfx::Point location = GetLocationInCurrentRoot(); | 436 gfx::Point location = GetLocationInCurrentRoot(); |
380 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, | 437 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, |
381 location, flags_); | 438 location, flags_); |
382 Dispatch(mouseev); | 439 Dispatch(&mouseev); |
383 flags_ ^= flag; | 440 flags_ ^= flag; |
384 } | 441 } |
385 grab_ = flags_ & kAllButtonMask; | 442 grab_ = flags_ & kAllButtonMask; |
386 } | 443 } |
387 | 444 |
388 void EventGenerator::ConvertPointFromTarget(const aura::Window* target, | 445 void EventGenerator::ConvertPointFromTarget(const aura::Window* target, |
389 gfx::Point* point) const { | 446 gfx::Point* point) const { |
390 DCHECK(point); | 447 DCHECK(point); |
391 aura::client::ScreenPositionClient* client = | 448 aura::client::ScreenPositionClient* client = |
392 delegate_->GetScreenPositionClient(target); | 449 delegate_->GetScreenPositionClient(target); |
(...skipping 19 matching lines...) Expand all Loading... |
412 ConvertPointToTarget(current_root_window_, &p); | 469 ConvertPointToTarget(current_root_window_, &p); |
413 return p; | 470 return p; |
414 } | 471 } |
415 | 472 |
416 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const { | 473 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const { |
417 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint(); | 474 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint(); |
418 ConvertPointFromTarget(window, ¢er); | 475 ConvertPointFromTarget(window, ¢er); |
419 return center; | 476 return center; |
420 } | 477 } |
421 | 478 |
| 479 void EventGenerator::DoDispatchEvent(ui::Event* event, bool post_event) { |
| 480 if (post_event) { |
| 481 ui::Event* pending_event; |
| 482 if (event->IsKeyEvent()) { |
| 483 pending_event = new ui::KeyEvent(*static_cast<ui::KeyEvent*>(event)); |
| 484 } else if (event->IsMouseEvent()) { |
| 485 pending_event = new ui::MouseEvent(*static_cast<ui::MouseEvent*>(event)); |
| 486 } else if (event->IsTouchEvent()) { |
| 487 pending_event = new ui::TouchEvent(*static_cast<ui::TouchEvent*>(event)); |
| 488 } else if (event->IsScrollEvent()) { |
| 489 pending_event = |
| 490 new ui::ScrollEvent(*static_cast<ui::ScrollEvent*>(event)); |
| 491 } else { |
| 492 NOTREACHED() << "Invalid event type"; |
| 493 return; |
| 494 } |
| 495 if (pending_events_.empty()) { |
| 496 base::MessageLoopProxy::current()->PostTask( |
| 497 FROM_HERE, |
| 498 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 499 base::Unretained(this))); |
| 500 } |
| 501 pending_events_.push_back(pending_event); |
| 502 } else { |
| 503 RootWindowHostDelegate* root_window_host_delegate = |
| 504 current_root_window_->AsRootWindowHostDelegate(); |
| 505 if (event->IsKeyEvent()) { |
| 506 root_window_host_delegate->OnHostKeyEvent( |
| 507 static_cast<ui::KeyEvent*>(event)); |
| 508 } else if (event->IsMouseEvent()) { |
| 509 root_window_host_delegate->OnHostMouseEvent( |
| 510 static_cast<ui::MouseEvent*>(event)); |
| 511 } else if (event->IsTouchEvent()) { |
| 512 root_window_host_delegate->OnHostTouchEvent( |
| 513 static_cast<ui::TouchEvent*>(event)); |
| 514 } else if (event->IsScrollEvent()) { |
| 515 root_window_host_delegate->OnHostScrollEvent( |
| 516 static_cast<ui::ScrollEvent*>(event)); |
| 517 } else { |
| 518 NOTREACHED() << "Invalid event type"; |
| 519 } |
| 520 } |
| 521 } |
| 522 |
| 523 void EventGenerator::DispatchNextPendingEvent() { |
| 524 DCHECK(!pending_events_.empty()); |
| 525 ui::Event* event = pending_events_.front(); |
| 526 DoDispatchEvent(event, false); |
| 527 pending_events_.pop_front(); |
| 528 delete event; |
| 529 if (!pending_events_.empty()) { |
| 530 base::MessageLoopProxy::current()->PostTask( |
| 531 FROM_HERE, |
| 532 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 533 base::Unretained(this))); |
| 534 } |
| 535 } |
| 536 |
| 537 |
422 } // namespace test | 538 } // namespace test |
423 } // namespace aura | 539 } // namespace aura |
OLD | NEW |