Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: ui/aura/test/event_generator.cc

Issue 296403011: Support double-tap to click in touch accessibility controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update browser test for touch exploration too Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/chromeos/touch_exploration_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop_proxy.h" 9 #include "base/message_loop/message_loop_proxy.h"
10 #include "base/time/default_tick_clock.h"
10 #include "ui/aura/client/screen_position_client.h" 11 #include "ui/aura/client/screen_position_client.h"
11 #include "ui/aura/window_event_dispatcher.h" 12 #include "ui/aura/window_event_dispatcher.h"
12 #include "ui/aura/window_tree_host.h" 13 #include "ui/aura/window_tree_host.h"
13 #include "ui/events/event.h" 14 #include "ui/events/event.h"
14 #include "ui/events/event_source.h" 15 #include "ui/events/event_source.h"
15 #include "ui/events/event_utils.h" 16 #include "ui/events/event_utils.h"
16 #include "ui/events/test/events_test_utils.h" 17 #include "ui/events/test/events_test_utils.h"
17 #include "ui/gfx/vector2d_conversions.h" 18 #include "ui/gfx/vector2d_conversions.h"
18 19
19 #if defined(USE_X11) 20 #if defined(USE_X11)
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 : KeyEvent(native_event, is_char) { 63 : KeyEvent(native_event, is_char) {
63 set_flags(flags); 64 set_flags(flags);
64 } 65 }
65 }; 66 };
66 67
67 class TestTouchEvent : public ui::TouchEvent { 68 class TestTouchEvent : public ui::TouchEvent {
68 public: 69 public:
69 TestTouchEvent(ui::EventType type, 70 TestTouchEvent(ui::EventType type,
70 const gfx::Point& root_location, 71 const gfx::Point& root_location,
71 int touch_id, 72 int touch_id,
72 int flags) 73 int flags,
73 : TouchEvent(type, root_location, flags, touch_id, ui::EventTimeForNow(), 74 base::TimeDelta timestamp)
75 : TouchEvent(type, root_location, flags, touch_id, timestamp,
74 1.0f, 1.0f, 1.0f, 1.0f) { 76 1.0f, 1.0f, 1.0f, 1.0f) {
75 } 77 }
76 78
77 private: 79 private:
78 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); 80 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent);
79 }; 81 };
80 82
81 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; 83 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON;
82 84
83 } // namespace 85 } // namespace
84 86
85 EventGenerator::EventGenerator(Window* root_window) 87 EventGenerator::EventGenerator(Window* root_window)
86 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 88 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
87 current_host_(delegate_->GetHostAt(current_location_)), 89 current_host_(delegate_->GetHostAt(current_location_)),
88 flags_(0), 90 flags_(0),
89 grab_(false), 91 grab_(false),
90 async_(false) { 92 async_(false),
93 tick_clock_(new base::DefaultTickClock()) {
91 } 94 }
92 95
93 EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point) 96 EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point)
94 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 97 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
95 current_location_(point), 98 current_location_(point),
96 current_host_(delegate_->GetHostAt(current_location_)), 99 current_host_(delegate_->GetHostAt(current_location_)),
97 flags_(0), 100 flags_(0),
98 grab_(false), 101 grab_(false),
99 async_(false) { 102 async_(false),
103 tick_clock_(new base::DefaultTickClock()) {
100 } 104 }
101 105
102 EventGenerator::EventGenerator(Window* root_window, Window* window) 106 EventGenerator::EventGenerator(Window* root_window, Window* window)
103 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 107 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
104 current_location_(CenterOfWindow(window)), 108 current_location_(CenterOfWindow(window)),
105 current_host_(delegate_->GetHostAt(current_location_)), 109 current_host_(delegate_->GetHostAt(current_location_)),
106 flags_(0), 110 flags_(0),
107 grab_(false), 111 grab_(false),
108 async_(false) { 112 async_(false),
113 tick_clock_(new base::DefaultTickClock()) {
109 } 114 }
110 115
111 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) 116 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate)
112 : delegate_(delegate), 117 : delegate_(delegate),
113 current_host_(delegate_->GetHostAt(current_location_)), 118 current_host_(delegate_->GetHostAt(current_location_)),
114 flags_(0), 119 flags_(0),
115 grab_(false), 120 grab_(false),
116 async_(false) { 121 async_(false),
122 tick_clock_(new base::DefaultTickClock()) {
117 } 123 }
118 124
119 EventGenerator::~EventGenerator() { 125 EventGenerator::~EventGenerator() {
120 for (std::list<ui::Event*>::iterator i = pending_events_.begin(); 126 for (std::list<ui::Event*>::iterator i = pending_events_.begin();
121 i != pending_events_.end(); ++i) 127 i != pending_events_.end(); ++i)
122 delete *i; 128 delete *i;
123 pending_events_.clear(); 129 pending_events_.clear();
124 } 130 }
125 131
126 void EventGenerator::PressLeftButton() { 132 void EventGenerator::PressLeftButton() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 void EventGenerator::MoveMouseToCenterOf(Window* window) { 218 void EventGenerator::MoveMouseToCenterOf(Window* window) {
213 MoveMouseTo(CenterOfWindow(window)); 219 MoveMouseTo(CenterOfWindow(window));
214 } 220 }
215 221
216 void EventGenerator::PressTouch() { 222 void EventGenerator::PressTouch() {
217 PressTouchId(0); 223 PressTouchId(0);
218 } 224 }
219 225
220 void EventGenerator::PressTouchId(int touch_id) { 226 void EventGenerator::PressTouchId(int touch_id) {
221 TestTouchEvent touchev( 227 TestTouchEvent touchev(
222 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_); 228 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_,
229 Now());
223 Dispatch(&touchev); 230 Dispatch(&touchev);
224 } 231 }
225 232
226 void EventGenerator::MoveTouch(const gfx::Point& point) { 233 void EventGenerator::MoveTouch(const gfx::Point& point) {
227 MoveTouchId(point, 0); 234 MoveTouchId(point, 0);
228 } 235 }
229 236
230 void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) { 237 void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) {
231 current_location_ = point; 238 current_location_ = point;
232 TestTouchEvent touchev( 239 TestTouchEvent touchev(
233 ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), touch_id, flags_); 240 ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), touch_id, flags_,
241 Now());
234 Dispatch(&touchev); 242 Dispatch(&touchev);
235 243
236 if (!grab_) 244 if (!grab_)
237 UpdateCurrentDispatcher(point); 245 UpdateCurrentDispatcher(point);
238 } 246 }
239 247
240 void EventGenerator::ReleaseTouch() { 248 void EventGenerator::ReleaseTouch() {
241 ReleaseTouchId(0); 249 ReleaseTouchId(0);
242 } 250 }
243 251
244 void EventGenerator::ReleaseTouchId(int touch_id) { 252 void EventGenerator::ReleaseTouchId(int touch_id) {
245 TestTouchEvent touchev( 253 TestTouchEvent touchev(
246 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), touch_id, flags_); 254 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), touch_id, flags_,
255 Now());
247 Dispatch(&touchev); 256 Dispatch(&touchev);
248 } 257 }
249 258
250 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { 259 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) {
251 PressTouch(); 260 PressTouch();
252 MoveTouch(point); 261 MoveTouch(point);
253 ReleaseTouch(); 262 ReleaseTouch();
254 } 263 }
255 264
256 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { 265 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) {
257 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); 266 PressMoveAndReleaseTouchTo(CenterOfWindow(window));
258 } 267 }
259 268
260 void EventGenerator::GestureEdgeSwipe() { 269 void EventGenerator::GestureEdgeSwipe() {
261 ui::GestureEvent gesture( 270 ui::GestureEvent gesture(
262 ui::ET_GESTURE_WIN8_EDGE_SWIPE, 271 ui::ET_GESTURE_WIN8_EDGE_SWIPE,
263 0, 272 0,
264 0, 273 0,
265 0, 274 0,
266 ui::EventTimeForNow(), 275 Now(),
267 ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0), 276 ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0),
268 0); 277 0);
269 Dispatch(&gesture); 278 Dispatch(&gesture);
270 } 279 }
271 280
272 void EventGenerator::GestureTapAt(const gfx::Point& location) { 281 void EventGenerator::GestureTapAt(const gfx::Point& location) {
273 const int kTouchId = 2; 282 const int kTouchId = 2;
274 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 283 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
275 location, 284 location,
276 kTouchId, 285 kTouchId,
277 ui::EventTimeForNow()); 286 Now());
278 Dispatch(&press); 287 Dispatch(&press);
279 288
280 ui::TouchEvent release( 289 ui::TouchEvent release(
281 ui::ET_TOUCH_RELEASED, location, kTouchId, 290 ui::ET_TOUCH_RELEASED, location, kTouchId,
282 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); 291 press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
283 Dispatch(&release); 292 Dispatch(&release);
284 } 293 }
285 294
286 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { 295 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) {
287 const int kTouchId = 3; 296 const int kTouchId = 3;
288 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 297 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
289 location, 298 location,
290 kTouchId, 299 kTouchId,
291 ui::EventTimeForNow()); 300 Now());
292 Dispatch(&press); 301 Dispatch(&press);
293 302
294 ui::TouchEvent release( 303 ui::TouchEvent release(
295 ui::ET_TOUCH_RELEASED, location, kTouchId, 304 ui::ET_TOUCH_RELEASED, location, kTouchId,
296 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); 305 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000));
297 Dispatch(&release); 306 Dispatch(&release);
298 } 307 }
299 308
300 void EventGenerator::GestureScrollSequence(const gfx::Point& start, 309 void EventGenerator::GestureScrollSequence(const gfx::Point& start,
301 const gfx::Point& end, 310 const gfx::Point& end,
302 const base::TimeDelta& step_delay, 311 const base::TimeDelta& step_delay,
303 int steps) { 312 int steps) {
304 GestureScrollSequenceWithCallback(start, end, step_delay, steps, 313 GestureScrollSequenceWithCallback(start, end, step_delay, steps,
305 base::Bind(&DummyCallback)); 314 base::Bind(&DummyCallback));
306 } 315 }
307 316
308 void EventGenerator::GestureScrollSequenceWithCallback( 317 void EventGenerator::GestureScrollSequenceWithCallback(
309 const gfx::Point& start, 318 const gfx::Point& start,
310 const gfx::Point& end, 319 const gfx::Point& end,
311 const base::TimeDelta& step_delay, 320 const base::TimeDelta& step_delay,
312 int steps, 321 int steps,
313 const ScrollStepCallback& callback) { 322 const ScrollStepCallback& callback) {
314 const int kTouchId = 5; 323 const int kTouchId = 5;
315 base::TimeDelta timestamp = ui::EventTimeForNow(); 324 base::TimeDelta timestamp = Now();
316 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); 325 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp);
317 Dispatch(&press); 326 Dispatch(&press);
318 327
319 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF()); 328 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF());
320 329
321 int dx = (end.x() - start.x()) / steps; 330 int dx = (end.x() - start.x()) / steps;
322 int dy = (end.y() - start.y()) / steps; 331 int dy = (end.y() - start.y()) / steps;
323 gfx::Point location = start; 332 gfx::Point location = start;
324 for (int i = 0; i < steps; ++i) { 333 for (int i = 0; i < steps; ++i) {
325 location.Offset(dx, dy); 334 location.Offset(dx, dy);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 CHECK_LE(count, kMaxTouchPoints); 369 CHECK_LE(count, kMaxTouchPoints);
361 CHECK_GT(steps, 0); 370 CHECK_GT(steps, 0);
362 371
363 int delta_x = move_x / steps; 372 int delta_x = move_x / steps;
364 int delta_y = move_y / steps; 373 int delta_y = move_y / steps;
365 374
366 for (int i = 0; i < count; ++i) { 375 for (int i = 0; i < count; ++i) {
367 points[i] = start[i]; 376 points[i] = start[i];
368 } 377 }
369 378
370 base::TimeDelta press_time_first = ui::EventTimeForNow(); 379 base::TimeDelta press_time_first = Now();
371 base::TimeDelta press_time[kMaxTouchPoints]; 380 base::TimeDelta press_time[kMaxTouchPoints];
372 bool pressed[kMaxTouchPoints]; 381 bool pressed[kMaxTouchPoints];
373 for (int i = 0; i < count; ++i) { 382 for (int i = 0; i < count; ++i) {
374 pressed[i] = false; 383 pressed[i] = false;
375 press_time[i] = press_time_first + 384 press_time[i] = press_time_first +
376 base::TimeDelta::FromMilliseconds(delay_adding_finger_ms[i]); 385 base::TimeDelta::FromMilliseconds(delay_adding_finger_ms[i]);
377 } 386 }
378 387
379 int last_id = 0; 388 int last_id = 0;
380 for (int step = 0; step < steps; ++step) { 389 for (int step = 0; step < steps; ++step) {
(...skipping 29 matching lines...) Expand all
410 Dispatch(&release); 419 Dispatch(&release);
411 } 420 }
412 } 421 }
413 422
414 void EventGenerator::ScrollSequence(const gfx::Point& start, 423 void EventGenerator::ScrollSequence(const gfx::Point& start,
415 const base::TimeDelta& step_delay, 424 const base::TimeDelta& step_delay,
416 float x_offset, 425 float x_offset,
417 float y_offset, 426 float y_offset,
418 int steps, 427 int steps,
419 int num_fingers) { 428 int num_fingers) {
420 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( 429 base::TimeDelta timestamp = Now();
421 base::TimeTicks::Now().ToInternalValue());
422 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, 430 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
423 start, 431 start,
424 timestamp, 432 timestamp,
425 0, 433 0,
426 0, 0, 434 0, 0,
427 0, 0, 435 0, 0,
428 num_fingers); 436 num_fingers);
429 Dispatch(&fling_cancel); 437 Dispatch(&fling_cancel);
430 438
431 float dx = x_offset / steps; 439 float dx = x_offset / steps;
(...skipping 18 matching lines...) Expand all
450 x_offset, y_offset, 458 x_offset, y_offset,
451 num_fingers); 459 num_fingers);
452 Dispatch(&fling_start); 460 Dispatch(&fling_start);
453 } 461 }
454 462
455 void EventGenerator::ScrollSequence(const gfx::Point& start, 463 void EventGenerator::ScrollSequence(const gfx::Point& start,
456 const base::TimeDelta& step_delay, 464 const base::TimeDelta& step_delay,
457 const std::vector<gfx::Point>& offsets, 465 const std::vector<gfx::Point>& offsets,
458 int num_fingers) { 466 int num_fingers) {
459 int steps = offsets.size(); 467 int steps = offsets.size();
460 base::TimeDelta timestamp = ui::EventTimeForNow(); 468 base::TimeDelta timestamp = Now();
461 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, 469 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
462 start, 470 start,
463 timestamp, 471 timestamp,
464 0, 472 0,
465 0, 0, 473 0, 0,
466 0, 0, 474 0, 0,
467 num_fingers); 475 num_fingers);
468 Dispatch(&fling_cancel); 476 Dispatch(&fling_cancel);
469 477
470 for (int i = 0; i < steps; ++i) { 478 for (int i = 0; i < steps; ++i) {
(...skipping 23 matching lines...) Expand all
494 } 502 }
495 503
496 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { 504 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) {
497 DispatchKeyEvent(false, key_code, flags); 505 DispatchKeyEvent(false, key_code, flags);
498 } 506 }
499 507
500 void EventGenerator::Dispatch(ui::Event* event) { 508 void EventGenerator::Dispatch(ui::Event* event) {
501 DoDispatchEvent(event, async_); 509 DoDispatchEvent(event, async_);
502 } 510 }
503 511
512 void EventGenerator::SetTickClock(scoped_ptr<base::TickClock> tick_clock) {
513 tick_clock_ = tick_clock.Pass();
514 }
515
516 base::TimeDelta EventGenerator::Now() {
517 // This is the same as what EventTimeForNow() does, but here we do it
518 // with a tick clock that can be replaced with a simulated clock for tests.
519 return base::TimeDelta::FromInternalValue(
520 tick_clock_->NowTicks().ToInternalValue());
521 }
522
504 void EventGenerator::DispatchKeyEvent(bool is_press, 523 void EventGenerator::DispatchKeyEvent(bool is_press,
505 ui::KeyboardCode key_code, 524 ui::KeyboardCode key_code,
506 int flags) { 525 int flags) {
507 #if defined(OS_WIN) 526 #if defined(OS_WIN)
508 UINT key_press = WM_KEYDOWN; 527 UINT key_press = WM_KEYDOWN;
509 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); 528 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags);
510 if (is_press && character) { 529 if (is_press && character) {
511 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; 530 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 };
512 TestKeyEvent keyev(native_event, flags, false); 531 TestKeyEvent keyev(native_event, flags, false);
513 Dispatch(&keyev); 532 Dispatch(&keyev);
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 pending_events_.pop_front(); 650 pending_events_.pop_front();
632 delete event; 651 delete event;
633 if (!pending_events_.empty()) { 652 if (!pending_events_.empty()) {
634 base::MessageLoopProxy::current()->PostTask( 653 base::MessageLoopProxy::current()->PostTask(
635 FROM_HERE, 654 FROM_HERE,
636 base::Bind(&EventGenerator::DispatchNextPendingEvent, 655 base::Bind(&EventGenerator::DispatchNextPendingEvent,
637 base::Unretained(this))); 656 base::Unretained(this)));
638 } 657 }
639 } 658 }
640 659
641
642 } // namespace test 660 } // namespace test
643 } // namespace aura 661 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/chromeos/touch_exploration_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698