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 "base/time/time.h" |
15 #include "ui/base/test/event_generator_base.h" | |
15 #include "ui/events/event_constants.h" | 16 #include "ui/events/event_constants.h" |
16 #include "ui/events/keycodes/keyboard_codes.h" | 17 #include "ui/events/keycodes/keyboard_codes.h" |
17 #include "ui/gfx/point.h" | 18 #include "ui/gfx/point.h" |
18 | 19 |
19 namespace base { | 20 namespace base { |
20 class TickClock; | 21 class TickClock; |
21 } | 22 } |
22 | 23 |
23 namespace ui { | 24 namespace ui { |
24 class Event; | 25 class Event; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
73 // handled in the nested message loop. | 74 // handled in the nested message loop. |
74 // 3) Similarly, |base::MessagePumpObserver| will not be invoked. | 75 // 3) Similarly, |base::MessagePumpObserver| will not be invoked. |
75 // 4) Any other code that requires native events, such as | 76 // 4) Any other code that requires native events, such as |
76 // tests for WindowTreeHostWin/WindowTreeHostX11. | 77 // tests for WindowTreeHostWin/WindowTreeHostX11. |
77 // | 78 // |
78 // If one of these applies to your test, please use |ui_controls| | 79 // If one of these applies to your test, please use |ui_controls| |
79 // package instead. | 80 // package instead. |
80 // | 81 // |
81 // Note: The coordinates of the points in API is determined by the | 82 // Note: The coordinates of the points in API is determined by the |
82 // EventGeneratorDelegate. | 83 // EventGeneratorDelegate. |
83 class EventGenerator { | 84 class EventGenerator : public ui::test::EventGeneratorBase { |
84 public: | 85 public: |
85 // Creates an EventGenerator with the mouse/touch location (0,0), | 86 // Creates an EventGenerator with the mouse/touch location (0,0), |
86 // which uses the |root_window|'s coordinates. | 87 // which uses the |root_window|'s coordinates. |
87 explicit EventGenerator(Window* root_window); | 88 explicit EventGenerator(Window* root_window); |
88 | 89 |
89 // Create an EventGenerator with EventGeneratorDelegate, | 90 // Create an EventGenerator with EventGeneratorDelegate, |
90 // which uses the coordinates used by |delegate|. | 91 // which uses the coordinates used by |delegate|. |
91 explicit EventGenerator(EventGeneratorDelegate* delegate); | 92 explicit EventGenerator(EventGeneratorDelegate* delegate); |
92 | 93 |
93 // Creates an EventGenerator with the mouse/touch location | 94 // Creates an EventGenerator with the mouse/touch location |
94 // at |initial_location|, which uses the |root_window|'s coordinates. | 95 // at |initial_location|, which uses the |root_window|'s coordinates. |
95 EventGenerator(Window* root_window, const gfx::Point& initial_location); | 96 EventGenerator(Window* root_window, const gfx::Point& initial_location); |
96 | 97 |
97 // Creates an EventGenerator with the mouse/touch location | 98 // Creates an EventGenerator with the mouse/touch location |
98 // centered over |window|, which uses the |root_window|'s coordinates. | 99 // centered over |window|, which uses the |root_window|'s coordinates. |
99 EventGenerator(Window* root_window, Window* window); | 100 EventGenerator(Window* root_window, Window* window); |
100 | 101 |
101 virtual ~EventGenerator(); | 102 virtual ~EventGenerator(); |
102 | 103 |
103 // Explicitly sets the location used by mouse/touch events. This is set by the | |
104 // various methods that take a location but can be manipulated directly, | |
105 // typically for touch. | |
106 void set_current_location(const gfx::Point& location) { | |
107 current_location_ = location; | |
108 } | |
109 const gfx::Point& current_location() const { return current_location_; } | |
110 | |
111 void set_async(bool async) { async_ = async; } | 104 void set_async(bool async) { async_ = async; } |
112 bool async() const { return async_; } | 105 bool async() const { return async_; } |
113 | 106 |
114 // Resets the event flags bitmask. | |
115 void set_flags(int flags) { flags_ = flags; } | |
116 | |
117 // Generates a left button press event. | |
118 void PressLeftButton(); | |
119 | |
120 // Generates a left button release event. | |
121 void ReleaseLeftButton(); | |
122 | |
123 // Generates events to click (press, release) left button. | |
124 void ClickLeftButton(); | |
125 | |
126 // Generates a double click event using the left button. | |
127 void DoubleClickLeftButton(); | |
128 | |
129 // Generates a right button press event. | |
130 void PressRightButton(); | |
131 | |
132 // Generates a right button release event. | |
133 void ReleaseRightButton(); | |
134 | |
135 // Moves the mouse wheel by |delta_x|, |delta_y|. | 107 // Moves the mouse wheel by |delta_x|, |delta_y|. |
136 void MoveMouseWheel(int delta_x, int delta_y); | 108 void MoveMouseWheel(int delta_x, int delta_y); |
137 | 109 |
138 // Generates a mouse exit. | 110 // Generates a mouse exit. |
139 void SendMouseExit(); | 111 void SendMouseExit(); |
140 | 112 |
141 // Generates events to move mouse to be the given |point| in the | 113 // Generates events to move mouse to be the given |point| in the |
142 // |current_root_window_|'s host window coordinates. | 114 // |current_root_window_|'s host window coordinates. |
143 void MoveMouseToInHost(const gfx::Point& point_in_host); | 115 void MoveMouseToInHost(const gfx::Point& point_in_host); |
144 void MoveMouseToInHost(int x, int y) { | 116 void MoveMouseToInHost(int x, int y) { |
145 MoveMouseToInHost(gfx::Point(x, y)); | 117 MoveMouseToInHost(gfx::Point(x, y)); |
146 } | 118 } |
147 | 119 |
148 // Generates events to move mouse to be the given |point| in screen | |
149 // coordinates. | |
150 void MoveMouseTo(const gfx::Point& point_in_screen, int count); | |
151 void MoveMouseTo(const gfx::Point& point_in_screen) { | |
152 MoveMouseTo(point_in_screen, 1); | |
153 } | |
154 void MoveMouseTo(int x, int y) { | |
155 MoveMouseTo(gfx::Point(x, y)); | |
156 } | |
157 | |
158 // Generates events to move mouse to be the given |point| in |window|'s | 120 // Generates events to move mouse to be the given |point| in |window|'s |
159 // coordinates. | 121 // coordinates. |
160 void MoveMouseRelativeTo(const Window* window, const gfx::Point& point); | 122 void MoveMouseRelativeTo(const Window* window, const gfx::Point& point); |
161 void MoveMouseRelativeTo(const Window* window, int x, int y) { | 123 void MoveMouseRelativeTo(const Window* window, int x, int y) { |
162 MoveMouseRelativeTo(window, gfx::Point(x, y)); | 124 MoveMouseRelativeTo(window, gfx::Point(x, y)); |
163 } | 125 } |
164 | 126 |
165 void MoveMouseBy(int x, int y) { | 127 void MoveMouseBy(int x, int y) { |
166 MoveMouseTo(current_location_ + gfx::Vector2d(x, y)); | 128 MoveMouseTo(current_location() + gfx::Vector2d(x, y)); |
167 } | |
168 | |
169 // Generates events to drag mouse to given |point|. | |
170 void DragMouseTo(const gfx::Point& point); | |
171 | |
172 void DragMouseTo(int x, int y) { | |
173 DragMouseTo(gfx::Point(x, y)); | |
174 } | |
175 | |
176 void DragMouseBy(int dx, int dy) { | |
177 DragMouseTo(current_location_ + gfx::Vector2d(dx, dy)); | |
178 } | 129 } |
179 | 130 |
180 // Generates events to move the mouse to the center of the window. | 131 // Generates events to move the mouse to the center of the window. |
181 void MoveMouseToCenterOf(Window* window); | 132 void MoveMouseToCenterOf(Window* window); |
182 | 133 |
183 // Generates a touch press event. | 134 // Generates a touch press event. |
184 void PressTouch(); | 135 void PressTouch(); |
185 | 136 |
186 // Generates a touch press event with |touch_id|. | 137 // Generates a touch press event with |touch_id|. |
187 void PressTouchId(int touch_id); | 138 void PressTouchId(int touch_id); |
(...skipping 12 matching lines...) Expand all Loading... | |
200 | 151 |
201 // Generates press, move and release event to move touch | 152 // Generates press, move and release event to move touch |
202 // to be the given |point|. | 153 // to be the given |point|. |
203 void PressMoveAndReleaseTouchTo(const gfx::Point& point); | 154 void PressMoveAndReleaseTouchTo(const gfx::Point& point); |
204 | 155 |
205 void PressMoveAndReleaseTouchTo(int x, int y) { | 156 void PressMoveAndReleaseTouchTo(int x, int y) { |
206 PressMoveAndReleaseTouchTo(gfx::Point(x, y)); | 157 PressMoveAndReleaseTouchTo(gfx::Point(x, y)); |
207 } | 158 } |
208 | 159 |
209 void PressMoveAndReleaseTouchBy(int x, int y) { | 160 void PressMoveAndReleaseTouchBy(int x, int y) { |
210 PressMoveAndReleaseTouchTo(current_location_ + gfx::Vector2d(x, y)); | 161 PressMoveAndReleaseTouchTo(current_location() + gfx::Vector2d(x, y)); |
211 } | 162 } |
212 | 163 |
213 // Generates press, move and release events to move touch | 164 // Generates press, move and release events to move touch |
214 // to the center of the window. | 165 // to the center of the window. |
215 void PressMoveAndReleaseTouchToCenterOf(Window* window); | 166 void PressMoveAndReleaseTouchToCenterOf(Window* window); |
216 | 167 |
217 // Generates and dispatches a Win8 edge-swipe event (swipe up from bottom or | 168 // Generates and dispatches a Win8 edge-swipe event (swipe up from bottom or |
218 // swipe down from top). Note that it is not possible to distinguish between | 169 // swipe down from top). Note that it is not possible to distinguish between |
219 // the two edges with this event. | 170 // the two edges with this event. |
220 void GestureEdgeSwipe(); | 171 void GestureEdgeSwipe(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
317 void set_current_host(WindowTreeHost* host) { | 268 void set_current_host(WindowTreeHost* host) { |
318 current_host_ = host; | 269 current_host_ = host; |
319 } | 270 } |
320 | 271 |
321 // Specify an alternative tick clock to be used for simulating time in tests. | 272 // Specify an alternative tick clock to be used for simulating time in tests. |
322 void SetTickClock(scoped_ptr<base::TickClock> tick_clock); | 273 void SetTickClock(scoped_ptr<base::TickClock> tick_clock); |
323 | 274 |
324 // Get the current time from the tick clock. | 275 // Get the current time from the tick clock. |
325 base::TimeDelta Now(); | 276 base::TimeDelta Now(); |
326 | 277 |
278 protected: | |
279 // Overridden from EventGeneratorBase: | |
280 virtual gfx::Point GetLocationInCurrentRoot() const OVERRIDE; | |
281 virtual void DoMoveMouseTo(const gfx::Point& point_in_screen, | |
282 int count) OVERRIDE; | |
283 virtual void DispatchMouseEvent(ui::EventType type, | |
284 const gfx::Point& location_in_root, | |
285 int flags, | |
286 int changed_button_flags) OVERRIDE; | |
287 | |
327 private: | 288 private: |
328 // Dispatch a key event to the WindowEventDispatcher. | 289 // Dispatch a key event to the WindowEventDispatcher. |
329 void DispatchKeyEvent(bool is_press, ui::KeyboardCode key_code, int flags); | 290 void DispatchKeyEvent(bool is_press, ui::KeyboardCode key_code, int flags); |
330 | 291 |
331 void UpdateCurrentDispatcher(const gfx::Point& point); | 292 void UpdateCurrentDispatcher(const gfx::Point& point); |
332 void PressButton(int flag); | |
333 void ReleaseButton(int flag); | |
334 | 293 |
335 // Convert a point between API's coordinates and | 294 // Convert a point between API's coordinates and |
336 // |target|'s coordinates. | 295 // |target|'s coordinates. |
337 void ConvertPointFromTarget(const aura::Window* target, | 296 void ConvertPointFromTarget(const aura::Window* target, |
338 gfx::Point* point) const; | 297 gfx::Point* point) const; |
339 void ConvertPointToTarget(const aura::Window* target, | 298 void ConvertPointToTarget(const aura::Window* target, |
340 gfx::Point* point) const; | 299 gfx::Point* point) const; |
341 | 300 |
342 gfx::Point GetLocationInCurrentRoot() const; | |
343 gfx::Point CenterOfWindow(const Window* window) const; | 301 gfx::Point CenterOfWindow(const Window* window) const; |
344 | 302 |
345 void DispatchNextPendingEvent(); | 303 void DispatchNextPendingEvent(); |
346 void DoDispatchEvent(ui::Event* event, bool async); | 304 void DoDispatchEvent(ui::Event* event, bool async); |
347 | 305 |
348 scoped_ptr<EventGeneratorDelegate> delegate_; | 306 scoped_ptr<EventGeneratorDelegate> delegate_; |
349 gfx::Point current_location_; | |
350 WindowTreeHost* current_host_; | 307 WindowTreeHost* current_host_; |
Ben Goodger (Google)
2014/07/11 18:26:49
so if I understand this correctly the issue you're
sadrul
2014/07/12 07:10:53
I think this is a good idea! Having a generic Even
tapted
2014/07/14 11:37:47
Done.
| |
351 int flags_; | |
352 bool grab_; | |
353 std::list<ui::Event*> pending_events_; | 308 std::list<ui::Event*> pending_events_; |
354 // Set to true to cause events to be posted asynchronously. | 309 // Set to true to cause events to be posted asynchronously. |
355 bool async_; | 310 bool async_; |
356 scoped_ptr<base::TickClock> tick_clock_; | 311 scoped_ptr<base::TickClock> tick_clock_; |
357 | 312 |
358 DISALLOW_COPY_AND_ASSIGN(EventGenerator); | 313 DISALLOW_COPY_AND_ASSIGN(EventGenerator); |
359 }; | 314 }; |
360 | 315 |
361 } // namespace test | 316 } // namespace test |
362 } // namespace aura | 317 } // namespace aura |
363 | 318 |
364 #endif // UI_AURA_TEST_EVENT_GENERATOR_H_ | 319 #endif // UI_AURA_TEST_EVENT_GENERATOR_H_ |
OLD | NEW |