| 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/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 "ui/aura/client/screen_position_client.h" | 10 #include "ui/aura/client/screen_position_client.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 : KeyEvent(native_event, is_char) { | 62 : KeyEvent(native_event, is_char) { |
| 63 set_flags(flags); | 63 set_flags(flags); |
| 64 } | 64 } |
| 65 }; | 65 }; |
| 66 | 66 |
| 67 class TestTouchEvent : public ui::TouchEvent { | 67 class TestTouchEvent : public ui::TouchEvent { |
| 68 public: | 68 public: |
| 69 TestTouchEvent(ui::EventType type, | 69 TestTouchEvent(ui::EventType type, |
| 70 const gfx::Point& root_location, | 70 const gfx::Point& root_location, |
| 71 int touch_id, | 71 int touch_id, |
| 72 int flags) | 72 int flags, |
| 73 : TouchEvent(type, root_location, flags, touch_id, ui::EventTimeForNow(), | 73 base::TimeDelta timestamp) |
| 74 : TouchEvent(type, root_location, flags, touch_id, timestamp, |
| 74 1.0f, 1.0f, 1.0f, 1.0f) { | 75 1.0f, 1.0f, 1.0f, 1.0f) { |
| 75 } | 76 } |
| 76 | 77 |
| 77 private: | 78 private: |
| 78 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); | 79 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); |
| 79 }; | 80 }; |
| 80 | 81 |
| 81 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; | 82 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; |
| 82 | 83 |
| 83 } // namespace | 84 } // namespace |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 void EventGenerator::MoveMouseToCenterOf(Window* window) { | 213 void EventGenerator::MoveMouseToCenterOf(Window* window) { |
| 213 MoveMouseTo(CenterOfWindow(window)); | 214 MoveMouseTo(CenterOfWindow(window)); |
| 214 } | 215 } |
| 215 | 216 |
| 216 void EventGenerator::PressTouch() { | 217 void EventGenerator::PressTouch() { |
| 217 PressTouchId(0); | 218 PressTouchId(0); |
| 218 } | 219 } |
| 219 | 220 |
| 220 void EventGenerator::PressTouchId(int touch_id) { | 221 void EventGenerator::PressTouchId(int touch_id) { |
| 221 TestTouchEvent touchev( | 222 TestTouchEvent touchev( |
| 222 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_); | 223 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_, |
| 224 Now()); |
| 223 Dispatch(&touchev); | 225 Dispatch(&touchev); |
| 224 } | 226 } |
| 225 | 227 |
| 226 void EventGenerator::MoveTouch(const gfx::Point& point) { | 228 void EventGenerator::MoveTouch(const gfx::Point& point) { |
| 227 MoveTouchId(point, 0); | 229 MoveTouchId(point, 0); |
| 228 } | 230 } |
| 229 | 231 |
| 230 void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) { | 232 void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) { |
| 231 current_location_ = point; | 233 current_location_ = point; |
| 232 TestTouchEvent touchev( | 234 TestTouchEvent touchev( |
| 233 ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), touch_id, flags_); | 235 ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), touch_id, flags_, Now()); |
| 234 Dispatch(&touchev); | 236 Dispatch(&touchev); |
| 235 | 237 |
| 236 if (!grab_) | 238 if (!grab_) |
| 237 UpdateCurrentDispatcher(point); | 239 UpdateCurrentDispatcher(point); |
| 238 } | 240 } |
| 239 | 241 |
| 240 void EventGenerator::ReleaseTouch() { | 242 void EventGenerator::ReleaseTouch() { |
| 241 ReleaseTouchId(0); | 243 ReleaseTouchId(0); |
| 242 } | 244 } |
| 243 | 245 |
| 244 void EventGenerator::ReleaseTouchId(int touch_id) { | 246 void EventGenerator::ReleaseTouchId(int touch_id) { |
| 245 TestTouchEvent touchev( | 247 TestTouchEvent touchev( |
| 246 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), touch_id, flags_); | 248 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), touch_id, flags_, |
| 249 Now()); |
| 247 Dispatch(&touchev); | 250 Dispatch(&touchev); |
| 248 } | 251 } |
| 249 | 252 |
| 250 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { | 253 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { |
| 251 PressTouch(); | 254 PressTouch(); |
| 252 MoveTouch(point); | 255 MoveTouch(point); |
| 253 ReleaseTouch(); | 256 ReleaseTouch(); |
| 254 } | 257 } |
| 255 | 258 |
| 256 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { | 259 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { |
| 257 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); | 260 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); |
| 258 } | 261 } |
| 259 | 262 |
| 260 void EventGenerator::GestureEdgeSwipe() { | 263 void EventGenerator::GestureEdgeSwipe() { |
| 261 ui::GestureEvent gesture( | 264 ui::GestureEvent gesture( |
| 262 ui::ET_GESTURE_WIN8_EDGE_SWIPE, | 265 ui::ET_GESTURE_WIN8_EDGE_SWIPE, |
| 263 0, | 266 0, |
| 264 0, | 267 0, |
| 265 0, | 268 0, |
| 266 ui::EventTimeForNow(), | 269 Now(), |
| 267 ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0), | 270 ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0), |
| 268 0); | 271 0); |
| 269 Dispatch(&gesture); | 272 Dispatch(&gesture); |
| 270 } | 273 } |
| 271 | 274 |
| 272 void EventGenerator::GestureTapAt(const gfx::Point& location) { | 275 void EventGenerator::GestureTapAt(const gfx::Point& location) { |
| 273 const int kTouchId = 2; | 276 const int kTouchId = 2; |
| 274 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 277 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
| 275 location, | 278 location, |
| 276 kTouchId, | 279 kTouchId, |
| 277 ui::EventTimeForNow()); | 280 Now()); |
| 278 Dispatch(&press); | 281 Dispatch(&press); |
| 279 | 282 |
| 280 ui::TouchEvent release( | 283 ui::TouchEvent release( |
| 281 ui::ET_TOUCH_RELEASED, location, kTouchId, | 284 ui::ET_TOUCH_RELEASED, location, kTouchId, |
| 282 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); | 285 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); |
| 283 Dispatch(&release); | 286 Dispatch(&release); |
| 284 } | 287 } |
| 285 | 288 |
| 286 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { | 289 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { |
| 287 const int kTouchId = 3; | 290 const int kTouchId = 3; |
| 288 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 291 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, |
| 289 location, | 292 location, |
| 290 kTouchId, | 293 kTouchId, |
| 291 ui::EventTimeForNow()); | 294 Now()); |
| 292 Dispatch(&press); | 295 Dispatch(&press); |
| 293 | 296 |
| 294 ui::TouchEvent release( | 297 ui::TouchEvent release( |
| 295 ui::ET_TOUCH_RELEASED, location, kTouchId, | 298 ui::ET_TOUCH_RELEASED, location, kTouchId, |
| 296 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); | 299 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); |
| 297 Dispatch(&release); | 300 Dispatch(&release); |
| 298 } | 301 } |
| 299 | 302 |
| 300 void EventGenerator::GestureScrollSequence(const gfx::Point& start, | 303 void EventGenerator::GestureScrollSequence(const gfx::Point& start, |
| 301 const gfx::Point& end, | 304 const gfx::Point& end, |
| 302 const base::TimeDelta& step_delay, | 305 const base::TimeDelta& step_delay, |
| 303 int steps) { | 306 int steps) { |
| 304 GestureScrollSequenceWithCallback(start, end, step_delay, steps, | 307 GestureScrollSequenceWithCallback(start, end, step_delay, steps, |
| 305 base::Bind(&DummyCallback)); | 308 base::Bind(&DummyCallback)); |
| 306 } | 309 } |
| 307 | 310 |
| 308 void EventGenerator::GestureScrollSequenceWithCallback( | 311 void EventGenerator::GestureScrollSequenceWithCallback( |
| 309 const gfx::Point& start, | 312 const gfx::Point& start, |
| 310 const gfx::Point& end, | 313 const gfx::Point& end, |
| 311 const base::TimeDelta& step_delay, | 314 const base::TimeDelta& step_delay, |
| 312 int steps, | 315 int steps, |
| 313 const ScrollStepCallback& callback) { | 316 const ScrollStepCallback& callback) { |
| 314 const int kTouchId = 5; | 317 const int kTouchId = 5; |
| 315 base::TimeDelta timestamp = ui::EventTimeForNow(); | 318 base::TimeDelta timestamp = Now(); |
| 316 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); | 319 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); |
| 317 Dispatch(&press); | 320 Dispatch(&press); |
| 318 | 321 |
| 319 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF()); | 322 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF()); |
| 320 | 323 |
| 321 int dx = (end.x() - start.x()) / steps; | 324 int dx = (end.x() - start.x()) / steps; |
| 322 int dy = (end.y() - start.y()) / steps; | 325 int dy = (end.y() - start.y()) / steps; |
| 323 gfx::Point location = start; | 326 gfx::Point location = start; |
| 324 for (int i = 0; i < steps; ++i) { | 327 for (int i = 0; i < steps; ++i) { |
| 325 location.Offset(dx, dy); | 328 location.Offset(dx, dy); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 CHECK_LE(count, kMaxTouchPoints); | 363 CHECK_LE(count, kMaxTouchPoints); |
| 361 CHECK_GT(steps, 0); | 364 CHECK_GT(steps, 0); |
| 362 | 365 |
| 363 int delta_x = move_x / steps; | 366 int delta_x = move_x / steps; |
| 364 int delta_y = move_y / steps; | 367 int delta_y = move_y / steps; |
| 365 | 368 |
| 366 for (int i = 0; i < count; ++i) { | 369 for (int i = 0; i < count; ++i) { |
| 367 points[i] = start[i]; | 370 points[i] = start[i]; |
| 368 } | 371 } |
| 369 | 372 |
| 370 base::TimeDelta press_time_first = ui::EventTimeForNow(); | 373 base::TimeDelta press_time_first = Now(); |
| 371 base::TimeDelta press_time[kMaxTouchPoints]; | 374 base::TimeDelta press_time[kMaxTouchPoints]; |
| 372 bool pressed[kMaxTouchPoints]; | 375 bool pressed[kMaxTouchPoints]; |
| 373 for (int i = 0; i < count; ++i) { | 376 for (int i = 0; i < count; ++i) { |
| 374 pressed[i] = false; | 377 pressed[i] = false; |
| 375 press_time[i] = press_time_first + | 378 press_time[i] = press_time_first + |
| 376 base::TimeDelta::FromMilliseconds(delay_adding_finger_ms[i]); | 379 base::TimeDelta::FromMilliseconds(delay_adding_finger_ms[i]); |
| 377 } | 380 } |
| 378 | 381 |
| 379 int last_id = 0; | 382 int last_id = 0; |
| 380 for (int step = 0; step < steps; ++step) { | 383 for (int step = 0; step < steps; ++step) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 410 Dispatch(&release); | 413 Dispatch(&release); |
| 411 } | 414 } |
| 412 } | 415 } |
| 413 | 416 |
| 414 void EventGenerator::ScrollSequence(const gfx::Point& start, | 417 void EventGenerator::ScrollSequence(const gfx::Point& start, |
| 415 const base::TimeDelta& step_delay, | 418 const base::TimeDelta& step_delay, |
| 416 float x_offset, | 419 float x_offset, |
| 417 float y_offset, | 420 float y_offset, |
| 418 int steps, | 421 int steps, |
| 419 int num_fingers) { | 422 int num_fingers) { |
| 420 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( | 423 base::TimeDelta timestamp = Now(); |
| 421 base::TimeTicks::Now().ToInternalValue()); | |
| 422 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 424 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| 423 start, | 425 start, |
| 424 timestamp, | 426 timestamp, |
| 425 0, | 427 0, |
| 426 0, 0, | 428 0, 0, |
| 427 0, 0, | 429 0, 0, |
| 428 num_fingers); | 430 num_fingers); |
| 429 Dispatch(&fling_cancel); | 431 Dispatch(&fling_cancel); |
| 430 | 432 |
| 431 float dx = x_offset / steps; | 433 float dx = x_offset / steps; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 450 x_offset, y_offset, | 452 x_offset, y_offset, |
| 451 num_fingers); | 453 num_fingers); |
| 452 Dispatch(&fling_start); | 454 Dispatch(&fling_start); |
| 453 } | 455 } |
| 454 | 456 |
| 455 void EventGenerator::ScrollSequence(const gfx::Point& start, | 457 void EventGenerator::ScrollSequence(const gfx::Point& start, |
| 456 const base::TimeDelta& step_delay, | 458 const base::TimeDelta& step_delay, |
| 457 const std::vector<gfx::Point>& offsets, | 459 const std::vector<gfx::Point>& offsets, |
| 458 int num_fingers) { | 460 int num_fingers) { |
| 459 int steps = offsets.size(); | 461 int steps = offsets.size(); |
| 460 base::TimeDelta timestamp = ui::EventTimeForNow(); | 462 base::TimeDelta timestamp = Now(); |
| 461 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 463 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| 462 start, | 464 start, |
| 463 timestamp, | 465 timestamp, |
| 464 0, | 466 0, |
| 465 0, 0, | 467 0, 0, |
| 466 0, 0, | 468 0, 0, |
| 467 num_fingers); | 469 num_fingers); |
| 468 Dispatch(&fling_cancel); | 470 Dispatch(&fling_cancel); |
| 469 | 471 |
| 470 for (int i = 0; i < steps; ++i) { | 472 for (int i = 0; i < steps; ++i) { |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 pending_events_.pop_front(); | 633 pending_events_.pop_front(); |
| 632 delete event; | 634 delete event; |
| 633 if (!pending_events_.empty()) { | 635 if (!pending_events_.empty()) { |
| 634 base::MessageLoopProxy::current()->PostTask( | 636 base::MessageLoopProxy::current()->PostTask( |
| 635 FROM_HERE, | 637 FROM_HERE, |
| 636 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 638 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 637 base::Unretained(this))); | 639 base::Unretained(this))); |
| 638 } | 640 } |
| 639 } | 641 } |
| 640 | 642 |
| 643 base::TimeDelta EventGenerator::Now() { |
| 644 if (simulated_time_ != base::TimeDelta()) |
| 645 return simulated_time_; |
| 646 return ui::EventTimeForNow(); |
| 647 } |
| 641 | 648 |
| 642 } // namespace test | 649 } // namespace test |
| 643 } // namespace aura | 650 } // namespace aura |
| OLD | NEW |