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 #ifndef UI_AURA_TEST_EVENT_GENERATOR_H_ | 5 #ifndef UI_AURA_TEST_EVENT_GENERATOR_H_ |
6 #define UI_AURA_TEST_EVENT_GENERATOR_H_ | 6 #define UI_AURA_TEST_EVENT_GENERATOR_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time/time.h" |
14 #include "ui/events/event_constants.h" | 15 #include "ui/events/event_constants.h" |
15 #include "ui/events/keycodes/keyboard_codes.h" | 16 #include "ui/events/keycodes/keyboard_codes.h" |
16 #include "ui/gfx/point.h" | 17 #include "ui/gfx/point.h" |
17 | 18 |
18 namespace base { | 19 namespace base { |
19 class TimeDelta; | 20 class TickClock; |
20 } | 21 } |
21 | 22 |
22 namespace ui { | 23 namespace ui { |
23 class Event; | 24 class Event; |
24 class EventProcessor; | 25 class EventProcessor; |
25 class KeyEvent; | 26 class KeyEvent; |
26 class MouseEvent; | 27 class MouseEvent; |
27 class ScrollEvent; | 28 class ScrollEvent; |
28 class TouchEvent; | 29 class TouchEvent; |
29 } | 30 } |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 // TODO(yusukes): Support native_event() on all platforms. | 311 // TODO(yusukes): Support native_event() on all platforms. |
311 void ReleaseKey(ui::KeyboardCode key_code, int flags); | 312 void ReleaseKey(ui::KeyboardCode key_code, int flags); |
312 | 313 |
313 // Dispatch the event to the WindowEventDispatcher. | 314 // Dispatch the event to the WindowEventDispatcher. |
314 void Dispatch(ui::Event* event); | 315 void Dispatch(ui::Event* event); |
315 | 316 |
316 void set_current_host(WindowTreeHost* host) { | 317 void set_current_host(WindowTreeHost* host) { |
317 current_host_ = host; | 318 current_host_ = host; |
318 } | 319 } |
319 | 320 |
| 321 // Specify an alternative tick clock to be used for simulating time in tests. |
| 322 void SetTickClock(scoped_ptr<base::TickClock> tick_clock); |
| 323 |
| 324 // Get the current time from the tick clock. |
| 325 base::TimeDelta Now(); |
| 326 |
320 private: | 327 private: |
321 // Dispatch a key event to the WindowEventDispatcher. | 328 // Dispatch a key event to the WindowEventDispatcher. |
322 void DispatchKeyEvent(bool is_press, ui::KeyboardCode key_code, int flags); | 329 void DispatchKeyEvent(bool is_press, ui::KeyboardCode key_code, int flags); |
323 | 330 |
324 void UpdateCurrentDispatcher(const gfx::Point& point); | 331 void UpdateCurrentDispatcher(const gfx::Point& point); |
325 void PressButton(int flag); | 332 void PressButton(int flag); |
326 void ReleaseButton(int flag); | 333 void ReleaseButton(int flag); |
327 | 334 |
328 // Convert a point between API's coordinates and | 335 // Convert a point between API's coordinates and |
329 // |target|'s coordinates. | 336 // |target|'s coordinates. |
330 void ConvertPointFromTarget(const aura::Window* target, | 337 void ConvertPointFromTarget(const aura::Window* target, |
331 gfx::Point* point) const; | 338 gfx::Point* point) const; |
332 void ConvertPointToTarget(const aura::Window* target, | 339 void ConvertPointToTarget(const aura::Window* target, |
333 gfx::Point* point) const; | 340 gfx::Point* point) const; |
334 | 341 |
335 gfx::Point GetLocationInCurrentRoot() const; | 342 gfx::Point GetLocationInCurrentRoot() const; |
336 gfx::Point CenterOfWindow(const Window* window) const; | 343 gfx::Point CenterOfWindow(const Window* window) const; |
337 | 344 |
338 void DispatchNextPendingEvent(); | 345 void DispatchNextPendingEvent(); |
339 void DoDispatchEvent(ui::Event* event, bool async); | 346 void DoDispatchEvent(ui::Event* event, bool async); |
340 | 347 |
341 scoped_ptr<EventGeneratorDelegate> delegate_; | 348 scoped_ptr<EventGeneratorDelegate> delegate_; |
342 gfx::Point current_location_; | 349 gfx::Point current_location_; |
343 WindowTreeHost* current_host_; | 350 WindowTreeHost* current_host_; |
344 int flags_; | 351 int flags_; |
345 bool grab_; | 352 bool grab_; |
346 std::list<ui::Event*> pending_events_; | 353 std::list<ui::Event*> pending_events_; |
347 // Set to true to cause events to be posted asynchronously. | 354 // Set to true to cause events to be posted asynchronously. |
348 bool async_; | 355 bool async_; |
| 356 scoped_ptr<base::TickClock> tick_clock_; |
349 | 357 |
350 DISALLOW_COPY_AND_ASSIGN(EventGenerator); | 358 DISALLOW_COPY_AND_ASSIGN(EventGenerator); |
351 }; | 359 }; |
352 | 360 |
353 } // namespace test | 361 } // namespace test |
354 } // namespace aura | 362 } // namespace aura |
355 | 363 |
356 #endif // UI_AURA_TEST_EVENT_GENERATOR_H_ | 364 #endif // UI_AURA_TEST_EVENT_GENERATOR_H_ |
OLD | NEW |