Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(694)

Side by Side Diff: ui/aura/test/event_generator.cc

Issue 10827145: Convert Aura to use ui::Event. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/aura/test/test_activation_client.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "ui/aura/event.h"
9 #include "ui/aura/root_window.h" 8 #include "ui/aura/root_window.h"
9 #include "ui/base/event.h"
10 10
11 #if defined(USE_X11) 11 #if defined(USE_X11)
12 #include <X11/Xlib.h> 12 #include <X11/Xlib.h>
13 #include "ui/base/x/x11_util.h" 13 #include "ui/base/x/x11_util.h"
14 #endif 14 #endif
15 15
16 namespace { 16 namespace {
17 17
18 class TestKeyEvent : public aura::KeyEvent { 18 class TestKeyEvent : public ui::KeyEvent {
19 public: 19 public:
20 TestKeyEvent(const base::NativeEvent& native_event, int flags) 20 TestKeyEvent(const base::NativeEvent& native_event, int flags)
21 : KeyEvent(native_event, false /* is_char */) { 21 : KeyEvent(native_event, false /* is_char */) {
22 set_flags(flags); 22 set_flags(flags);
23 } 23 }
24 }; 24 };
25 25
26 class TestTouchEvent : public aura::TouchEvent { 26 class TestTouchEvent : public ui::TouchEventImpl {
27 public: 27 public:
28 TestTouchEvent(ui::EventType type, 28 TestTouchEvent(ui::EventType type,
29 const gfx::Point& root_location, 29 const gfx::Point& root_location,
30 int flags) 30 int flags)
31 : TouchEvent(type, root_location, 0, 31 : TouchEventImpl(type, root_location, 0,
32 base::Time::NowFromSystemTime() - base::Time()) { 32 base::Time::NowFromSystemTime() - base::Time()) {
33 set_flags(flags); 33 set_flags(flags);
34 } 34 }
35 35
36 private: 36 private:
37 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); 37 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent);
38 }; 38 };
39 39
40 gfx::Point CenterOfWindowInRootWindowCoordinate(aura::RootWindow* root_window, 40 gfx::Point CenterOfWindowInRootWindowCoordinate(aura::RootWindow* root_window,
41 aura::Window* window) { 41 aura::Window* window) {
42 gfx::Point center = window->bounds().CenterPoint(); 42 gfx::Point center = window->bounds().CenterPoint();
43 aura::Window::ConvertPointToWindow(window->parent(), root_window, &center); 43 aura::Window::ConvertPointToTarget(window->parent(), root_window, &center);
44 return center; 44 return center;
45 } 45 }
46 46
47 } // namespace 47 } // namespace
48 48
49 namespace aura { 49 namespace aura {
50 namespace test { 50 namespace test {
51 51
52 EventGenerator::EventGenerator(RootWindow* root_window) 52 EventGenerator::EventGenerator(RootWindow* root_window)
53 : root_window_(root_window), 53 : root_window_(root_window),
(...skipping 12 matching lines...) Expand all
66 current_location_(CenterOfWindowInRootWindowCoordinate(root_window, 66 current_location_(CenterOfWindowInRootWindowCoordinate(root_window,
67 window)) { 67 window)) {
68 } 68 }
69 69
70 EventGenerator::~EventGenerator() { 70 EventGenerator::~EventGenerator() {
71 } 71 }
72 72
73 void EventGenerator::PressLeftButton() { 73 void EventGenerator::PressLeftButton() {
74 if ((flags_ & ui::EF_LEFT_MOUSE_BUTTON) == 0) { 74 if ((flags_ & ui::EF_LEFT_MOUSE_BUTTON) == 0) {
75 flags_ |= ui::EF_LEFT_MOUSE_BUTTON; 75 flags_ |= ui::EF_LEFT_MOUSE_BUTTON;
76 MouseEvent mouseev( 76 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, current_location_,
77 ui::ET_MOUSE_PRESSED, current_location_, current_location_, flags_); 77 current_location_, flags_);
78 Dispatch(mouseev); 78 Dispatch(mouseev);
79 } 79 }
80 } 80 }
81 81
82 void EventGenerator::ReleaseLeftButton() { 82 void EventGenerator::ReleaseLeftButton() {
83 if (flags_ & ui::EF_LEFT_MOUSE_BUTTON) { 83 if (flags_ & ui::EF_LEFT_MOUSE_BUTTON) {
84 MouseEvent mouseev( 84 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, current_location_,
85 ui::ET_MOUSE_RELEASED, current_location_, current_location_, flags_); 85 current_location_, flags_);
86 Dispatch(mouseev); 86 Dispatch(mouseev);
87 flags_ ^= ui::EF_LEFT_MOUSE_BUTTON; 87 flags_ ^= ui::EF_LEFT_MOUSE_BUTTON;
88 } 88 }
89 } 89 }
90 90
91 void EventGenerator::ClickLeftButton() { 91 void EventGenerator::ClickLeftButton() {
92 PressLeftButton(); 92 PressLeftButton();
93 ReleaseLeftButton(); 93 ReleaseLeftButton();
94 } 94 }
95 95
96 void EventGenerator::DoubleClickLeftButton() { 96 void EventGenerator::DoubleClickLeftButton() {
97 flags_ |= ui::EF_IS_DOUBLE_CLICK; 97 flags_ |= ui::EF_IS_DOUBLE_CLICK;
98 PressLeftButton(); 98 PressLeftButton();
99 flags_ ^= ui::EF_IS_DOUBLE_CLICK; 99 flags_ ^= ui::EF_IS_DOUBLE_CLICK;
100 ReleaseLeftButton(); 100 ReleaseLeftButton();
101 } 101 }
102 102
103 void EventGenerator::MoveMouseTo(const gfx::Point& point, int count) { 103 void EventGenerator::MoveMouseTo(const gfx::Point& point, int count) {
104 DCHECK_GT(count, 0); 104 DCHECK_GT(count, 0);
105 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? 105 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ?
106 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; 106 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED;
107 const gfx::Point diff = point.Subtract(current_location_); 107 const gfx::Point diff = point.Subtract(current_location_);
108 for (int i = 1; i <= count; i++) { 108 for (int i = 1; i <= count; i++) {
109 const gfx::Point move_point = current_location_.Add( 109 const gfx::Point move_point = current_location_.Add(
110 gfx::Point(diff.x() / count * i, diff.y() / count * i)); 110 gfx::Point(diff.x() / count * i, diff.y() / count * i));
111 MouseEvent mouseev(event_type, move_point, move_point, flags_); 111 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_);
112 Dispatch(mouseev); 112 Dispatch(mouseev);
113 } 113 }
114 current_location_ = point; 114 current_location_ = point;
115 } 115 }
116 116
117 void EventGenerator::MoveMouseRelativeTo(const Window* window, 117 void EventGenerator::MoveMouseRelativeTo(const Window* window,
118 const gfx::Point& point) { 118 const gfx::Point& point) {
119 gfx::Point root_point(point); 119 gfx::Point root_point(point);
120 aura::Window::ConvertPointToWindow(window, root_window_, &root_point); 120 Window::ConvertPointToTarget(window, root_window_, &root_point);
121 121
122 MoveMouseTo(root_point); 122 MoveMouseTo(root_point);
123 } 123 }
124 124
125 void EventGenerator::DragMouseTo(const gfx::Point& point) { 125 void EventGenerator::DragMouseTo(const gfx::Point& point) {
126 PressLeftButton(); 126 PressLeftButton();
127 MoveMouseTo(point); 127 MoveMouseTo(point);
128 ReleaseLeftButton(); 128 ReleaseLeftButton();
129 } 129 }
130 130
(...skipping 24 matching lines...) Expand all
155 ReleaseTouch(); 155 ReleaseTouch();
156 } 156 }
157 157
158 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { 158 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) {
159 PressMoveAndReleaseTouchTo(CenterOfWindowInRootWindowCoordinate(root_window_, 159 PressMoveAndReleaseTouchTo(CenterOfWindowInRootWindowCoordinate(root_window_,
160 window)); 160 window));
161 } 161 }
162 162
163 void EventGenerator::GestureTapAt(const gfx::Point& location) { 163 void EventGenerator::GestureTapAt(const gfx::Point& location) {
164 const int kTouchId = 2; 164 const int kTouchId = 2;
165 TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId, 165 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, location, kTouchId,
166 base::Time::NowFromSystemTime() - base::Time()); 166 base::Time::NowFromSystemTime() - base::Time());
167 Dispatch(press); 167 Dispatch(press);
168 168
169 TouchEvent release(ui::ET_TOUCH_RELEASED, location, kTouchId, 169 ui::TouchEventImpl release(
170 ui::ET_TOUCH_RELEASED, location, kTouchId,
170 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); 171 press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
171 Dispatch(release); 172 Dispatch(release);
172 } 173 }
173 174
174 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { 175 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) {
175 const int kTouchId = 3; 176 const int kTouchId = 3;
176 TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId, 177 ui::TouchEventImpl press(
178 ui::ET_TOUCH_PRESSED, location, kTouchId,
177 base::Time::NowFromSystemTime() - base::Time()); 179 base::Time::NowFromSystemTime() - base::Time());
178 Dispatch(press); 180 Dispatch(press);
179 181
180 TouchEvent release(ui::ET_TOUCH_RELEASED, location, kTouchId, 182 ui::TouchEventImpl release(
183 ui::ET_TOUCH_RELEASED, location, kTouchId,
181 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); 184 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000));
182 Dispatch(release); 185 Dispatch(release);
183 } 186 }
184 187
185 void EventGenerator::GestureScrollSequence(const gfx::Point& start, 188 void EventGenerator::GestureScrollSequence(const gfx::Point& start,
186 const gfx::Point& end, 189 const gfx::Point& end,
187 const base::TimeDelta& step_delay, 190 const base::TimeDelta& step_delay,
188 int steps) { 191 int steps) {
189 const int kTouchId = 5; 192 const int kTouchId = 5;
190 base::TimeDelta timestamp = base::Time::NowFromSystemTime() - base::Time(); 193 base::TimeDelta timestamp = base::Time::NowFromSystemTime() - base::Time();
191 TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); 194 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp);
192 Dispatch(press); 195 Dispatch(press);
193 196
194 int dx = (end.x() - start.x()) / steps; 197 int dx = (end.x() - start.x()) / steps;
195 int dy = (end.y() - start.y()) / steps; 198 int dy = (end.y() - start.y()) / steps;
196 gfx::Point location = start; 199 gfx::Point location = start;
197 for (int i = 0; i < steps; ++i) { 200 for (int i = 0; i < steps; ++i) {
198 location.Offset(dx, dy); 201 location.Offset(dx, dy);
199 timestamp += step_delay; 202 timestamp += step_delay;
200 TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); 203 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp);
201 Dispatch(move); 204 Dispatch(move);
202 } 205 }
203 206
204 TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); 207 ui::TouchEventImpl release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp);
205 Dispatch(release); 208 Dispatch(release);
206 } 209 }
207 210
208 void EventGenerator::GestureMultiFingerScroll(int count, 211 void EventGenerator::GestureMultiFingerScroll(int count,
209 const gfx::Point* start, 212 const gfx::Point* start,
210 int event_separation_time_ms, 213 int event_separation_time_ms,
211 int steps, 214 int steps,
212 int move_x, 215 int move_x,
213 int move_y) { 216 int move_y) {
214 const int kMaxTouchPoints = 10; 217 const int kMaxTouchPoints = 10;
215 gfx::Point points[kMaxTouchPoints]; 218 gfx::Point points[kMaxTouchPoints];
216 CHECK_LE(count, kMaxTouchPoints); 219 CHECK_LE(count, kMaxTouchPoints);
217 CHECK_GT(steps, 0); 220 CHECK_GT(steps, 0);
218 221
219 int delta_x = move_x / steps; 222 int delta_x = move_x / steps;
220 int delta_y = move_y / steps; 223 int delta_y = move_y / steps;
221 224
222 base::TimeDelta press_time = base::Time::NowFromSystemTime() - base::Time(); 225 base::TimeDelta press_time = base::Time::NowFromSystemTime() - base::Time();
223 for (int i = 0; i < count; ++i) { 226 for (int i = 0; i < count; ++i) {
224 points[i] = start[i]; 227 points[i] = start[i];
225 TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time); 228 ui::TouchEventImpl press(ui::ET_TOUCH_PRESSED, points[i], i, press_time);
226 Dispatch(press); 229 Dispatch(press);
227 } 230 }
228 231
229 for (int step = 0; step < steps; ++step) { 232 for (int step = 0; step < steps; ++step) {
230 base::TimeDelta move_time = press_time + 233 base::TimeDelta move_time = press_time +
231 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step); 234 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step);
232 for (int i = 0; i < count; ++i) { 235 for (int i = 0; i < count; ++i) {
233 points[i].Offset(delta_x, delta_y); 236 points[i].Offset(delta_x, delta_y);
234 TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time); 237 ui::TouchEventImpl move(ui::ET_TOUCH_MOVED, points[i], i, move_time);
235 Dispatch(move); 238 Dispatch(move);
236 } 239 }
237 } 240 }
238 241
239 base::TimeDelta release_time = press_time + 242 base::TimeDelta release_time = press_time +
240 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps); 243 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps);
241 for (int i = 0; i < count; ++i) { 244 for (int i = 0; i < count; ++i) {
242 TouchEvent release(ui::ET_TOUCH_RELEASED, points[i], i, release_time); 245 ui::TouchEventImpl release(
246 ui::ET_TOUCH_RELEASED, points[i], i, release_time);
243 Dispatch(release); 247 Dispatch(release);
244 } 248 }
245 } 249 }
246 250
247 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { 251 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) {
248 DispatchKeyEvent(true, key_code, flags); 252 DispatchKeyEvent(true, key_code, flags);
249 } 253 }
250 254
251 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { 255 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) {
252 DispatchKeyEvent(false, key_code, flags); 256 DispatchKeyEvent(false, key_code, flags);
253 } 257 }
254 258
255 void EventGenerator::Dispatch(Event& event) { 259 void EventGenerator::Dispatch(ui::Event& event) {
256 switch (event.type()) { 260 switch (event.type()) {
257 case ui::ET_KEY_PRESSED: 261 case ui::ET_KEY_PRESSED:
258 case ui::ET_KEY_RELEASED: 262 case ui::ET_KEY_RELEASED:
259 root_window_->AsRootWindowHostDelegate()->OnHostKeyEvent( 263 root_window_->AsRootWindowHostDelegate()->OnHostKeyEvent(
260 static_cast<KeyEvent*>(&event)); 264 static_cast<ui::KeyEvent*>(&event));
261 break; 265 break;
262 case ui::ET_MOUSE_PRESSED: 266 case ui::ET_MOUSE_PRESSED:
263 case ui::ET_MOUSE_DRAGGED: 267 case ui::ET_MOUSE_DRAGGED:
264 case ui::ET_MOUSE_RELEASED: 268 case ui::ET_MOUSE_RELEASED:
265 case ui::ET_MOUSE_MOVED: 269 case ui::ET_MOUSE_MOVED:
266 case ui::ET_MOUSE_ENTERED: 270 case ui::ET_MOUSE_ENTERED:
267 case ui::ET_MOUSE_EXITED: 271 case ui::ET_MOUSE_EXITED:
268 case ui::ET_MOUSEWHEEL: 272 case ui::ET_MOUSEWHEEL:
269 root_window_->AsRootWindowHostDelegate()->OnHostMouseEvent( 273 root_window_->AsRootWindowHostDelegate()->OnHostMouseEvent(
270 static_cast<MouseEvent*>(&event)); 274 static_cast<ui::MouseEvent*>(&event));
271 break; 275 break;
272 case ui::ET_TOUCH_RELEASED: 276 case ui::ET_TOUCH_RELEASED:
273 case ui::ET_TOUCH_PRESSED: 277 case ui::ET_TOUCH_PRESSED:
274 case ui::ET_TOUCH_MOVED: 278 case ui::ET_TOUCH_MOVED:
275 case ui::ET_TOUCH_STATIONARY: 279 case ui::ET_TOUCH_STATIONARY:
276 case ui::ET_TOUCH_CANCELLED: 280 case ui::ET_TOUCH_CANCELLED:
277 root_window_->AsRootWindowHostDelegate()->OnHostTouchEvent( 281 root_window_->AsRootWindowHostDelegate()->OnHostTouchEvent(
278 static_cast<TouchEvent*>(&event)); 282 static_cast<ui::TouchEventImpl*>(&event));
279 break; 283 break;
280 default: 284 default:
281 NOTIMPLEMENTED(); 285 NOTIMPLEMENTED();
282 break; 286 break;
283 } 287 }
284 } 288 }
285 289
286 void EventGenerator::DispatchKeyEvent(bool is_press, 290 void EventGenerator::DispatchKeyEvent(bool is_press,
287 ui::KeyboardCode key_code, 291 ui::KeyboardCode key_code,
288 int flags) { 292 int flags) {
289 #if defined(OS_WIN) 293 #if defined(OS_WIN)
290 MSG native_event = 294 MSG native_event =
291 { NULL, (is_press ? WM_KEYDOWN : WM_KEYUP), key_code, 0 }; 295 { NULL, (is_press ? WM_KEYDOWN : WM_KEYUP), key_code, 0 };
292 TestKeyEvent keyev(native_event, flags); 296 TestKeyEvent keyev(native_event, flags);
293 #else 297 #else
294 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; 298 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED;
295 #if defined(USE_X11) 299 #if defined(USE_X11)
296 scoped_ptr<XEvent> native_event(new XEvent); 300 scoped_ptr<XEvent> native_event(new XEvent);
297 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); 301 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get());
298 TestKeyEvent keyev(native_event.get(), flags); 302 TestKeyEvent keyev(native_event.get(), flags);
299 #else 303 #else
300 KeyEvent keyev(type, key_code, flags); 304 ui::KeyEvent keyev(type, key_code, flags);
301 #endif // USE_X11 305 #endif // USE_X11
302 #endif // OS_WIN 306 #endif // OS_WIN
303 Dispatch(keyev); 307 Dispatch(keyev);
304 } 308 }
305 309
306 } // namespace test 310 } // namespace test
307 } // namespace aura 311 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/aura/test/test_activation_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698