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_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "ui/aura/client/screen_position_client.h" | 10 #include "ui/aura/client/screen_position_client.h" |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 float x_offset, | 305 float x_offset, |
306 float y_offset, | 306 float y_offset, |
307 int steps, | 307 int steps, |
308 int num_fingers) { | 308 int num_fingers) { |
309 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( | 309 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue( |
310 base::TimeTicks::Now().ToInternalValue()); | 310 base::TimeTicks::Now().ToInternalValue()); |
311 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 311 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
312 start, | 312 start, |
313 timestamp, | 313 timestamp, |
314 0, | 314 0, |
315 0, | 315 0, 0, |
316 0, | 316 0, 0, |
317 num_fingers); | 317 num_fingers); |
318 Dispatch(&fling_cancel); | 318 Dispatch(&fling_cancel); |
319 | 319 |
320 float dx = x_offset / steps; | 320 float dx = x_offset / steps; |
321 float dy = y_offset / steps; | 321 float dy = y_offset / steps; |
322 for (int i = 0; i < steps; ++i) { | 322 for (int i = 0; i < steps; ++i) { |
323 timestamp += step_delay; | 323 timestamp += step_delay; |
324 ui::ScrollEvent move(ui::ET_SCROLL, | 324 ui::ScrollEvent move(ui::ET_SCROLL, |
325 start, | 325 start, |
326 timestamp, | 326 timestamp, |
327 0, | 327 0, |
328 dx, | 328 dx, dy, |
329 dy, | 329 dx, dy, |
330 num_fingers); | 330 num_fingers); |
331 Dispatch(&move); | 331 Dispatch(&move); |
332 } | 332 } |
333 | 333 |
334 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, | 334 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, |
335 start, | 335 start, |
336 timestamp, | 336 timestamp, |
337 0, | 337 0, |
338 x_offset, | 338 x_offset, y_offset, |
339 y_offset, | 339 x_offset, y_offset, |
340 num_fingers); | 340 num_fingers); |
341 Dispatch(&fling_start); | 341 Dispatch(&fling_start); |
342 } | 342 } |
343 | 343 |
344 void EventGenerator::ScrollSequence(const gfx::Point& start, | 344 void EventGenerator::ScrollSequence(const gfx::Point& start, |
345 const base::TimeDelta& step_delay, | 345 const base::TimeDelta& step_delay, |
346 const std::vector<gfx::Point>& offsets, | 346 const std::vector<gfx::Point>& offsets, |
347 int num_fingers) { | 347 int num_fingers) { |
348 int steps = offsets.size(); | 348 int steps = offsets.size(); |
349 base::TimeDelta timestamp = ui::EventTimeForNow(); | 349 base::TimeDelta timestamp = ui::EventTimeForNow(); |
350 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 350 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
351 start, | 351 start, |
352 timestamp, | 352 timestamp, |
353 0, | 353 0, |
354 0, | 354 0, 0, |
355 0, | 355 0, 0, |
356 num_fingers); | 356 num_fingers); |
357 Dispatch(&fling_cancel); | 357 Dispatch(&fling_cancel); |
358 | 358 |
359 for (int i = 0; i < steps; ++i) { | 359 for (int i = 0; i < steps; ++i) { |
360 timestamp += step_delay; | 360 timestamp += step_delay; |
361 ui::ScrollEvent scroll(ui::ET_SCROLL, | 361 ui::ScrollEvent scroll(ui::ET_SCROLL, |
362 start, | 362 start, |
363 timestamp, | 363 timestamp, |
364 0, | 364 0, |
365 offsets[i].x(), | 365 offsets[i].x(), offsets[i].y(), |
366 offsets[i].y(), | 366 offsets[i].x(), offsets[i].y(), |
367 num_fingers); | 367 num_fingers); |
368 Dispatch(&scroll); | 368 Dispatch(&scroll); |
369 } | 369 } |
370 | 370 |
371 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, | 371 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, |
372 start, | 372 start, |
373 timestamp, | 373 timestamp, |
374 0, | 374 0, |
375 offsets[steps - 1].x(), | 375 offsets[steps - 1].x(), offsets[steps - 1].y(), |
376 offsets[steps - 1].y(), | 376 offsets[steps - 1].x(), offsets[steps - 1].y(), |
377 num_fingers); | 377 num_fingers); |
378 Dispatch(&fling_start); | 378 Dispatch(&fling_start); |
379 } | 379 } |
380 | 380 |
381 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { | 381 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { |
382 DispatchKeyEvent(true, key_code, flags); | 382 DispatchKeyEvent(true, key_code, flags); |
383 } | 383 } |
384 | 384 |
385 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { | 385 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { |
386 DispatchKeyEvent(false, key_code, flags); | 386 DispatchKeyEvent(false, key_code, flags); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
534 base::MessageLoopProxy::current()->PostTask( | 534 base::MessageLoopProxy::current()->PostTask( |
535 FROM_HERE, | 535 FROM_HERE, |
536 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 536 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
537 base::Unretained(this))); | 537 base::Unretained(this))); |
538 } | 538 } |
539 } | 539 } |
540 | 540 |
541 | 541 |
542 } // namespace test | 542 } // namespace test |
543 } // namespace aura | 543 } // namespace aura |
OLD | NEW |