OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/events/test/event_generator.h" | 5 #include "ui/events/test/event_generator.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 const base::TimeDelta& step_delay, | 294 const base::TimeDelta& step_delay, |
295 int steps, | 295 int steps, |
296 const ScrollStepCallback& callback) { | 296 const ScrollStepCallback& callback) { |
297 const int kTouchId = 5; | 297 const int kTouchId = 5; |
298 base::TimeDelta timestamp = Now(); | 298 base::TimeDelta timestamp = Now(); |
299 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); | 299 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); |
300 Dispatch(&press); | 300 Dispatch(&press); |
301 | 301 |
302 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF()); | 302 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF()); |
303 | 303 |
304 int dx = (end.x() - start.x()) / steps; | 304 float dx = static_cast<float>(end.x() - start.x()) / steps; |
305 int dy = (end.y() - start.y()) / steps; | 305 float dy = static_cast<float>(end.y() - start.y()) / steps; |
306 gfx::Point location = start; | 306 gfx::PointF location = start; |
307 for (int i = 0; i < steps; ++i) { | 307 for (int i = 0; i < steps; ++i) { |
308 location.Offset(dx, dy); | 308 location.Offset(dx, dy); |
309 timestamp += step_delay; | 309 timestamp += step_delay; |
310 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); | 310 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); |
311 Dispatch(&move); | 311 Dispatch(&move); |
312 callback.Run(ui::ET_GESTURE_SCROLL_UPDATE, gfx::Vector2dF(dx, dy)); | 312 callback.Run(ui::ET_GESTURE_SCROLL_UPDATE, gfx::Vector2dF(dx, dy)); |
313 } | 313 } |
314 | 314 |
315 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); | 315 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); |
316 Dispatch(&release); | 316 Dispatch(&release); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 timestamp, | 429 timestamp, |
430 0, | 430 0, |
431 x_offset, y_offset, | 431 x_offset, y_offset, |
432 x_offset, y_offset, | 432 x_offset, y_offset, |
433 num_fingers); | 433 num_fingers); |
434 Dispatch(&fling_start); | 434 Dispatch(&fling_start); |
435 } | 435 } |
436 | 436 |
437 void EventGenerator::ScrollSequence(const gfx::Point& start, | 437 void EventGenerator::ScrollSequence(const gfx::Point& start, |
438 const base::TimeDelta& step_delay, | 438 const base::TimeDelta& step_delay, |
439 const std::vector<gfx::Point>& offsets, | 439 const std::vector<gfx::PointF>& offsets, |
440 int num_fingers) { | 440 int num_fingers) { |
441 size_t steps = offsets.size(); | 441 size_t steps = offsets.size(); |
442 base::TimeDelta timestamp = Now(); | 442 base::TimeDelta timestamp = Now(); |
443 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 443 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
444 start, | 444 start, |
445 timestamp, | 445 timestamp, |
446 0, | 446 0, |
447 0, 0, | 447 0, 0, |
448 0, 0, | 448 0, 0, |
449 num_fingers); | 449 num_fingers); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 return default_delegate; | 623 return default_delegate; |
624 } | 624 } |
625 | 625 |
626 EventGeneratorDelegate* EventGenerator::delegate() { | 626 EventGeneratorDelegate* EventGenerator::delegate() { |
627 return const_cast<EventGeneratorDelegate*>( | 627 return const_cast<EventGeneratorDelegate*>( |
628 const_cast<const EventGenerator*>(this)->delegate()); | 628 const_cast<const EventGenerator*>(this)->delegate()); |
629 } | 629 } |
630 | 630 |
631 } // namespace test | 631 } // namespace test |
632 } // namespace ui | 632 } // namespace ui |
OLD | NEW |