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" |
11 #include "base/thread_task_runner_handle.h" | 11 #include "base/thread_task_runner_handle.h" |
12 #include "base/time/default_tick_clock.h" | 12 #include "base/time/tick_clock.h" |
13 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
14 #include "ui/events/event_source.h" | 14 #include "ui/events/event_source.h" |
15 #include "ui/events/event_utils.h" | 15 #include "ui/events/event_utils.h" |
16 #include "ui/events/test/events_test_utils.h" | 16 #include "ui/events/test/events_test_utils.h" |
17 #include "ui/gfx/geometry/vector2d_conversions.h" | 17 #include "ui/gfx/geometry/vector2d_conversions.h" |
18 | 18 |
19 #if defined(USE_X11) | 19 #if defined(USE_X11) |
20 #include <X11/Xlib.h> | 20 #include <X11/Xlib.h> |
21 #include "ui/events/test/events_test_utils_x11.h" | 21 #include "ui/events/test/events_test_utils_x11.h" |
22 #endif | 22 #endif |
23 | 23 |
24 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
25 #include "ui/events/keycodes/keyboard_code_conversion.h" | 25 #include "ui/events/keycodes/keyboard_code_conversion.h" |
26 #endif | 26 #endif |
27 | 27 |
28 namespace ui { | 28 namespace ui { |
29 namespace test { | 29 namespace test { |
30 namespace { | 30 namespace { |
31 | 31 |
32 void DummyCallback(EventType, const gfx::Vector2dF&) { | 32 void DummyCallback(EventType, const gfx::Vector2dF&) { |
33 } | 33 } |
34 | 34 |
35 class TestTickClock : public base::TickClock { | |
36 public: | |
37 // Starts off with a clock set to TimeTicks(). | |
38 TestTickClock() {} | |
39 | |
40 base::TimeTicks NowTicks() override { | |
41 return base::TimeTicks::FromInternalValue(ticks_++ * 1000); | |
42 } | |
43 | |
44 private: | |
45 int64 ticks_ = 1; | |
sadrul
2015/03/19 10:36:53
Oh, does the style guide allow this?
oshima
2015/03/19 16:41:57
Yep, see "Non-Static Class Member Initializers" in
| |
46 | |
47 DISALLOW_COPY_AND_ASSIGN(TestTickClock); | |
48 }; | |
49 | |
35 class TestKeyEvent : public ui::KeyEvent { | 50 class TestKeyEvent : public ui::KeyEvent { |
36 public: | 51 public: |
37 TestKeyEvent(const base::NativeEvent& native_event, int flags) | 52 TestKeyEvent(const base::NativeEvent& native_event, int flags) |
38 : KeyEvent(native_event) { | 53 : KeyEvent(native_event) { |
39 set_flags(flags); | 54 set_flags(flags); |
40 } | 55 } |
41 }; | 56 }; |
42 | 57 |
43 class TestTouchEvent : public ui::TouchEvent { | 58 class TestTouchEvent : public ui::TouchEvent { |
44 public: | 59 public: |
(...skipping 15 matching lines...) Expand all Loading... | |
60 } // namespace | 75 } // namespace |
61 | 76 |
62 EventGeneratorDelegate* EventGenerator::default_delegate = NULL; | 77 EventGeneratorDelegate* EventGenerator::default_delegate = NULL; |
63 | 78 |
64 EventGenerator::EventGenerator(gfx::NativeWindow root_window) | 79 EventGenerator::EventGenerator(gfx::NativeWindow root_window) |
65 : current_target_(NULL), | 80 : current_target_(NULL), |
66 flags_(0), | 81 flags_(0), |
67 grab_(false), | 82 grab_(false), |
68 async_(false), | 83 async_(false), |
69 targeting_application_(false), | 84 targeting_application_(false), |
70 tick_clock_(new base::DefaultTickClock()) { | 85 tick_clock_(new TestTickClock()) { |
71 Init(root_window, NULL); | 86 Init(root_window, NULL); |
72 } | 87 } |
73 | 88 |
74 EventGenerator::EventGenerator(gfx::NativeWindow root_window, | 89 EventGenerator::EventGenerator(gfx::NativeWindow root_window, |
75 const gfx::Point& point) | 90 const gfx::Point& point) |
76 : current_location_(point), | 91 : current_location_(point), |
77 current_target_(NULL), | 92 current_target_(NULL), |
78 flags_(0), | 93 flags_(0), |
79 grab_(false), | 94 grab_(false), |
80 async_(false), | 95 async_(false), |
81 targeting_application_(false), | 96 targeting_application_(false), |
82 tick_clock_(new base::DefaultTickClock()) { | 97 tick_clock_(new TestTickClock()) { |
83 Init(root_window, NULL); | 98 Init(root_window, NULL); |
84 } | 99 } |
85 | 100 |
86 EventGenerator::EventGenerator(gfx::NativeWindow root_window, | 101 EventGenerator::EventGenerator(gfx::NativeWindow root_window, |
87 gfx::NativeWindow window) | 102 gfx::NativeWindow window) |
88 : current_target_(NULL), | 103 : current_target_(NULL), |
89 flags_(0), | 104 flags_(0), |
90 grab_(false), | 105 grab_(false), |
91 async_(false), | 106 async_(false), |
92 targeting_application_(false), | 107 targeting_application_(false), |
93 tick_clock_(new base::DefaultTickClock()) { | 108 tick_clock_(new TestTickClock()) { |
94 Init(root_window, window); | 109 Init(root_window, window); |
95 } | 110 } |
96 | 111 |
97 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) | 112 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) |
98 : delegate_(delegate), | 113 : delegate_(delegate), |
99 current_target_(NULL), | 114 current_target_(NULL), |
100 flags_(0), | 115 flags_(0), |
101 grab_(false), | 116 grab_(false), |
102 async_(false), | 117 async_(false), |
103 targeting_application_(false), | 118 targeting_application_(false), |
104 tick_clock_(new base::DefaultTickClock()) { | 119 tick_clock_(new TestTickClock()) { |
105 Init(NULL, NULL); | 120 Init(NULL, NULL); |
106 } | 121 } |
107 | 122 |
108 EventGenerator::~EventGenerator() { | 123 EventGenerator::~EventGenerator() { |
109 for (std::list<ui::Event*>::iterator i = pending_events_.begin(); | 124 for (std::list<ui::Event*>::iterator i = pending_events_.begin(); |
110 i != pending_events_.end(); ++i) | 125 i != pending_events_.end(); ++i) |
111 delete *i; | 126 delete *i; |
112 pending_events_.clear(); | 127 pending_events_.clear(); |
113 delegate()->SetContext(NULL, NULL, NULL); | 128 delegate()->SetContext(NULL, NULL, NULL); |
114 } | 129 } |
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; | 545 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; |
531 TestKeyEvent keyev(native_event, flags); | 546 TestKeyEvent keyev(native_event, flags); |
532 Dispatch(&keyev); | 547 Dispatch(&keyev); |
533 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character | 548 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character |
534 // if the key event cooresponds to a real character. | 549 // if the key event cooresponds to a real character. |
535 key_press = WM_CHAR; | 550 key_press = WM_CHAR; |
536 key_code = static_cast<ui::KeyboardCode>(character); | 551 key_code = static_cast<ui::KeyboardCode>(character); |
537 } | 552 } |
538 MSG native_event = | 553 MSG native_event = |
539 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; | 554 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; |
555 native_event.time = Now().InMicroseconds(); | |
540 TestKeyEvent keyev(native_event, flags); | 556 TestKeyEvent keyev(native_event, flags); |
541 #elif defined(USE_X11) | 557 #elif defined(USE_X11) |
542 ui::ScopedXI2Event xevent; | 558 ui::ScopedXI2Event xevent; |
543 xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, | 559 xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, |
544 key_code, | 560 key_code, |
545 flags); | 561 flags); |
562 static_cast<XEvent*>(xevent)->xkey.time = Now().InMicroseconds(); | |
546 ui::KeyEvent keyev(xevent); | 563 ui::KeyEvent keyev(xevent); |
547 #else | 564 #else |
548 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; | 565 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
549 ui::KeyEvent keyev(type, key_code, flags); | 566 ui::KeyEvent keyev(type, key_code, flags); |
550 #endif // OS_WIN | 567 #endif // OS_WIN |
551 Dispatch(&keyev); | 568 Dispatch(&keyev); |
552 } | 569 } |
553 | 570 |
554 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { | 571 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { |
555 current_target_ = delegate()->GetTargetAt(point); | 572 current_target_ = delegate()->GetTargetAt(point); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
641 return default_delegate; | 658 return default_delegate; |
642 } | 659 } |
643 | 660 |
644 EventGeneratorDelegate* EventGenerator::delegate() { | 661 EventGeneratorDelegate* EventGenerator::delegate() { |
645 return const_cast<EventGeneratorDelegate*>( | 662 return const_cast<EventGeneratorDelegate*>( |
646 const_cast<const EventGenerator*>(this)->delegate()); | 663 const_cast<const EventGenerator*>(this)->delegate()); |
647 } | 664 } |
648 | 665 |
649 } // namespace test | 666 } // namespace test |
650 } // namespace ui | 667 } // namespace ui |
OLD | NEW |