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

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

Issue 12088015: Add ability for EventGenerator to generate Scroll events asynchronously (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Free any leftover events in destructor Created 7 years, 10 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/base/events/event.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/bind.h"
7 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop_proxy.h"
8 #include "ui/aura/client/screen_position_client.h" 10 #include "ui/aura/client/screen_position_client.h"
9 #include "ui/aura/root_window.h" 11 #include "ui/aura/root_window.h"
10 #include "ui/base/events/event.h" 12 #include "ui/base/events/event.h"
11 #include "ui/base/events/event_utils.h" 13 #include "ui/base/events/event_utils.h"
12 #include "ui/gfx/vector2d_conversions.h" 14 #include "ui/gfx/vector2d_conversions.h"
13 15
14 #if defined(USE_X11) 16 #if defined(USE_X11)
15 #include <X11/Xlib.h> 17 #include <X11/Xlib.h>
16 #include "ui/base/x/x11_util.h" 18 #include "ui/base/x/x11_util.h"
17 #endif 19 #endif
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 }; 70 };
69 71
70 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; 72 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON;
71 73
72 } // namespace 74 } // namespace
73 75
74 EventGenerator::EventGenerator(RootWindow* root_window) 76 EventGenerator::EventGenerator(RootWindow* root_window)
75 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 77 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
76 current_root_window_(delegate_->GetRootWindowAt(current_location_)), 78 current_root_window_(delegate_->GetRootWindowAt(current_location_)),
77 flags_(0), 79 flags_(0),
78 grab_(false) { 80 grab_(false),
81 async_(false) {
79 } 82 }
80 83
81 EventGenerator::EventGenerator(RootWindow* root_window, const gfx::Point& point) 84 EventGenerator::EventGenerator(RootWindow* root_window, const gfx::Point& point)
82 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 85 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
83 current_location_(point), 86 current_location_(point),
84 current_root_window_(delegate_->GetRootWindowAt(current_location_)), 87 current_root_window_(delegate_->GetRootWindowAt(current_location_)),
85 flags_(0), 88 flags_(0),
86 grab_(false) { 89 grab_(false),
90 async_(false) {
87 } 91 }
88 92
89 EventGenerator::EventGenerator(RootWindow* root_window, Window* window) 93 EventGenerator::EventGenerator(RootWindow* root_window, Window* window)
90 : delegate_(new DefaultEventGeneratorDelegate(root_window)), 94 : delegate_(new DefaultEventGeneratorDelegate(root_window)),
91 current_location_(CenterOfWindow(window)), 95 current_location_(CenterOfWindow(window)),
92 current_root_window_(delegate_->GetRootWindowAt(current_location_)), 96 current_root_window_(delegate_->GetRootWindowAt(current_location_)),
93 flags_(0), 97 flags_(0),
94 grab_(false) { 98 grab_(false),
99 async_(false) {
95 } 100 }
96 101
97 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate) 102 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate)
98 : delegate_(delegate), 103 : delegate_(delegate),
99 current_root_window_(delegate_->GetRootWindowAt(current_location_)), 104 current_root_window_(delegate_->GetRootWindowAt(current_location_)),
100 flags_(0), 105 flags_(0),
101 grab_(false) { 106 grab_(false),
107 async_(false) {
102 } 108 }
103 109
104 EventGenerator::~EventGenerator() { 110 EventGenerator::~EventGenerator() {
111 for (std::list<ui::Event*>::iterator i = pending_events_.begin();
112 i != pending_events_.end(); ++i)
113 delete *i;
114 pending_events_.clear();
105 } 115 }
106 116
107 void EventGenerator::PressLeftButton() { 117 void EventGenerator::PressLeftButton() {
108 PressButton(ui::EF_LEFT_MOUSE_BUTTON); 118 PressButton(ui::EF_LEFT_MOUSE_BUTTON);
109 } 119 }
110 120
111 void EventGenerator::ReleaseLeftButton() { 121 void EventGenerator::ReleaseLeftButton() {
112 ReleaseButton(ui::EF_LEFT_MOUSE_BUTTON); 122 ReleaseButton(ui::EF_LEFT_MOUSE_BUTTON);
113 } 123 }
114 124
(...skipping 24 matching lines...) Expand all
139 149
140 gfx::Vector2dF diff(point - current_location_); 150 gfx::Vector2dF diff(point - current_location_);
141 for (float i = 1; i <= count; i++) { 151 for (float i = 1; i <= count; i++) {
142 gfx::Vector2dF step(diff); 152 gfx::Vector2dF step(diff);
143 step.Scale(i / count); 153 step.Scale(i / count);
144 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); 154 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step);
145 if (!grab_) 155 if (!grab_)
146 UpdateCurrentRootWindow(move_point); 156 UpdateCurrentRootWindow(move_point);
147 ConvertPointToTarget(current_root_window_, &move_point); 157 ConvertPointToTarget(current_root_window_, &move_point);
148 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_); 158 ui::MouseEvent mouseev(event_type, move_point, move_point, flags_);
149 Dispatch(mouseev); 159 Dispatch(&mouseev);
150 } 160 }
151 current_location_ = point; 161 current_location_ = point;
152 } 162 }
153 163
154 void EventGenerator::MoveMouseRelativeTo(const Window* window, 164 void EventGenerator::MoveMouseRelativeTo(const Window* window,
155 const gfx::Point& point_in_parent) { 165 const gfx::Point& point_in_parent) {
156 gfx::Point point(point_in_parent); 166 gfx::Point point(point_in_parent);
157 ConvertPointFromTarget(window, &point); 167 ConvertPointFromTarget(window, &point);
158 MoveMouseTo(point); 168 MoveMouseTo(point);
159 } 169 }
160 170
161 void EventGenerator::DragMouseTo(const gfx::Point& point) { 171 void EventGenerator::DragMouseTo(const gfx::Point& point) {
162 PressLeftButton(); 172 PressLeftButton();
163 MoveMouseTo(point); 173 MoveMouseTo(point);
164 ReleaseLeftButton(); 174 ReleaseLeftButton();
165 } 175 }
166 176
167 void EventGenerator::MoveMouseToCenterOf(Window* window) { 177 void EventGenerator::MoveMouseToCenterOf(Window* window) {
168 MoveMouseTo(CenterOfWindow(window)); 178 MoveMouseTo(CenterOfWindow(window));
169 } 179 }
170 180
171 void EventGenerator::PressTouch() { 181 void EventGenerator::PressTouch() {
172 TestTouchEvent touchev( 182 TestTouchEvent touchev(
173 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), flags_); 183 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), flags_);
174 Dispatch(touchev); 184 Dispatch(&touchev);
175 } 185 }
176 186
177 void EventGenerator::MoveTouch(const gfx::Point& point) { 187 void EventGenerator::MoveTouch(const gfx::Point& point) {
178 TestTouchEvent touchev(ui::ET_TOUCH_MOVED, point, flags_); 188 TestTouchEvent touchev(ui::ET_TOUCH_MOVED, point, flags_);
179 Dispatch(touchev); 189 Dispatch(&touchev);
180 190
181 current_location_ = point; 191 current_location_ = point;
182 if (!grab_) 192 if (!grab_)
183 UpdateCurrentRootWindow(point); 193 UpdateCurrentRootWindow(point);
184 } 194 }
185 195
186 void EventGenerator::ReleaseTouch() { 196 void EventGenerator::ReleaseTouch() {
187 TestTouchEvent touchev( 197 TestTouchEvent touchev(
188 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), flags_); 198 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), flags_);
189 Dispatch(touchev); 199 Dispatch(&touchev);
190 } 200 }
191 201
192 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { 202 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) {
193 PressTouch(); 203 PressTouch();
194 MoveTouch(point); 204 MoveTouch(point);
195 ReleaseTouch(); 205 ReleaseTouch();
196 } 206 }
197 207
198 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) { 208 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) {
199 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); 209 PressMoveAndReleaseTouchTo(CenterOfWindow(window));
200 } 210 }
201 211
202 void EventGenerator::GestureTapAt(const gfx::Point& location) { 212 void EventGenerator::GestureTapAt(const gfx::Point& location) {
203 const int kTouchId = 2; 213 const int kTouchId = 2;
204 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 214 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
205 location, 215 location,
206 kTouchId, 216 kTouchId,
207 ui::EventTimeForNow()); 217 ui::EventTimeForNow());
208 Dispatch(press); 218 Dispatch(&press);
209 219
210 ui::TouchEvent release( 220 ui::TouchEvent release(
211 ui::ET_TOUCH_RELEASED, location, kTouchId, 221 ui::ET_TOUCH_RELEASED, location, kTouchId,
212 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); 222 press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
213 Dispatch(release); 223 Dispatch(&release);
214 } 224 }
215 225
216 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { 226 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) {
217 const int kTouchId = 3; 227 const int kTouchId = 3;
218 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 228 ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
219 location, 229 location,
220 kTouchId, 230 kTouchId,
221 ui::EventTimeForNow()); 231 ui::EventTimeForNow());
222 Dispatch(press); 232 Dispatch(&press);
223 233
224 ui::TouchEvent release( 234 ui::TouchEvent release(
225 ui::ET_TOUCH_RELEASED, location, kTouchId, 235 ui::ET_TOUCH_RELEASED, location, kTouchId,
226 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); 236 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000));
227 Dispatch(release); 237 Dispatch(&release);
228 } 238 }
229 239
230 void EventGenerator::GestureScrollSequence(const gfx::Point& start, 240 void EventGenerator::GestureScrollSequence(const gfx::Point& start,
231 const gfx::Point& end, 241 const gfx::Point& end,
232 const base::TimeDelta& step_delay, 242 const base::TimeDelta& step_delay,
233 int steps) { 243 int steps) {
234 const int kTouchId = 5; 244 const int kTouchId = 5;
235 base::TimeDelta timestamp = ui::EventTimeForNow(); 245 base::TimeDelta timestamp = ui::EventTimeForNow();
236 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); 246 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp);
237 Dispatch(press); 247 Dispatch(&press);
238 248
239 int dx = (end.x() - start.x()) / steps; 249 int dx = (end.x() - start.x()) / steps;
240 int dy = (end.y() - start.y()) / steps; 250 int dy = (end.y() - start.y()) / steps;
241 gfx::Point location = start; 251 gfx::Point location = start;
242 for (int i = 0; i < steps; ++i) { 252 for (int i = 0; i < steps; ++i) {
243 location.Offset(dx, dy); 253 location.Offset(dx, dy);
244 timestamp += step_delay; 254 timestamp += step_delay;
245 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); 255 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp);
246 Dispatch(move); 256 Dispatch(&move);
247 } 257 }
248 258
249 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); 259 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp);
250 Dispatch(release); 260 Dispatch(&release);
251 } 261 }
252 262
253 void EventGenerator::GestureMultiFingerScroll(int count, 263 void EventGenerator::GestureMultiFingerScroll(int count,
254 const gfx::Point* start, 264 const gfx::Point* start,
255 int event_separation_time_ms, 265 int event_separation_time_ms,
256 int steps, 266 int steps,
257 int move_x, 267 int move_x,
258 int move_y) { 268 int move_y) {
259 const int kMaxTouchPoints = 10; 269 const int kMaxTouchPoints = 10;
260 gfx::Point points[kMaxTouchPoints]; 270 gfx::Point points[kMaxTouchPoints];
261 CHECK_LE(count, kMaxTouchPoints); 271 CHECK_LE(count, kMaxTouchPoints);
262 CHECK_GT(steps, 0); 272 CHECK_GT(steps, 0);
263 273
264 int delta_x = move_x / steps; 274 int delta_x = move_x / steps;
265 int delta_y = move_y / steps; 275 int delta_y = move_y / steps;
266 276
267 base::TimeDelta press_time = ui::EventTimeForNow(); 277 base::TimeDelta press_time = ui::EventTimeForNow();
268 for (int i = 0; i < count; ++i) { 278 for (int i = 0; i < count; ++i) {
269 points[i] = start[i]; 279 points[i] = start[i];
270 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time); 280 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, points[i], i, press_time);
271 Dispatch(press); 281 Dispatch(&press);
272 } 282 }
273 283
274 for (int step = 0; step < steps; ++step) { 284 for (int step = 0; step < steps; ++step) {
275 base::TimeDelta move_time = press_time + 285 base::TimeDelta move_time = press_time +
276 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step); 286 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step);
277 for (int i = 0; i < count; ++i) { 287 for (int i = 0; i < count; ++i) {
278 points[i].Offset(delta_x, delta_y); 288 points[i].Offset(delta_x, delta_y);
279 ui::TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time); 289 ui::TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time);
280 Dispatch(move); 290 Dispatch(&move);
281 } 291 }
282 } 292 }
283 293
284 base::TimeDelta release_time = press_time + 294 base::TimeDelta release_time = press_time +
285 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps); 295 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps);
286 for (int i = 0; i < count; ++i) { 296 for (int i = 0; i < count; ++i) {
287 ui::TouchEvent release( 297 ui::TouchEvent release(
288 ui::ET_TOUCH_RELEASED, points[i], i, release_time); 298 ui::ET_TOUCH_RELEASED, points[i], i, release_time);
289 Dispatch(release); 299 Dispatch(&release);
290 } 300 }
291 } 301 }
292 302
303 void EventGenerator::ScrollSequence(const gfx::Point& start,
304 const base::TimeDelta& step_delay,
305 float x_offset,
306 float y_offset,
307 int steps,
308 int num_fingers) {
309 base::TimeDelta timestamp = base::TimeDelta::FromInternalValue(
310 base::TimeTicks::Now().ToInternalValue());
311 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
312 start,
313 timestamp,
314 0,
315 0,
316 0,
317 num_fingers);
318 Dispatch(&fling_cancel);
319
320 float dx = x_offset / steps;
321 float dy = y_offset / steps;
322 for (int i = 0; i < steps; ++i) {
323 timestamp += step_delay;
324 ui::ScrollEvent move(ui::ET_SCROLL,
325 start,
326 timestamp,
327 0,
328 dx,
329 dy,
330 num_fingers);
331 Dispatch(&move);
332 }
333
334 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START,
335 start,
336 timestamp,
337 0,
338 x_offset,
339 y_offset,
340 num_fingers);
341 Dispatch(&fling_start);
342 }
343
344 void EventGenerator::ScrollSequence(const gfx::Point& start,
345 const base::TimeDelta& step_delay,
346 const std::vector<gfx::Point>& offsets,
347 int num_fingers) {
348 int steps = offsets.size();
349 base::TimeDelta timestamp = ui::EventTimeForNow();
350 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL,
351 start,
352 timestamp,
353 0,
354 0,
355 0,
356 num_fingers);
357 Dispatch(&fling_cancel);
358
359 for (int i = 0; i < steps; ++i) {
360 timestamp += step_delay;
361 ui::ScrollEvent scroll(ui::ET_SCROLL,
362 start,
363 timestamp,
364 0,
365 offsets[i].x(),
366 offsets[i].y(),
367 num_fingers);
368 Dispatch(&scroll);
369 }
370
371 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START,
372 start,
373 timestamp,
374 0,
375 offsets[steps - 1].x(),
376 offsets[steps - 1].y(),
377 num_fingers);
378 Dispatch(&fling_start);
379 }
380
293 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { 381 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) {
294 DispatchKeyEvent(true, key_code, flags); 382 DispatchKeyEvent(true, key_code, flags);
295 } 383 }
296 384
297 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { 385 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) {
298 DispatchKeyEvent(false, key_code, flags); 386 DispatchKeyEvent(false, key_code, flags);
299 } 387 }
300 388
301 void EventGenerator::Dispatch(ui::Event& event) { 389 void EventGenerator::Dispatch(ui::Event* event) {
302 switch (event.type()) { 390 DoDispatchEvent(event, async_);
303 case ui::ET_KEY_PRESSED:
304 case ui::ET_KEY_RELEASED:
305 current_root_window_->AsRootWindowHostDelegate()->OnHostKeyEvent(
306 static_cast<ui::KeyEvent*>(&event));
307 break;
308 case ui::ET_MOUSE_PRESSED:
309 case ui::ET_MOUSE_DRAGGED:
310 case ui::ET_MOUSE_RELEASED:
311 case ui::ET_MOUSE_MOVED:
312 case ui::ET_MOUSE_ENTERED:
313 case ui::ET_MOUSE_EXITED:
314 case ui::ET_MOUSEWHEEL:
315 current_root_window_->AsRootWindowHostDelegate()->OnHostMouseEvent(
316 static_cast<ui::MouseEvent*>(&event));
317 break;
318 case ui::ET_TOUCH_RELEASED:
319 case ui::ET_TOUCH_PRESSED:
320 case ui::ET_TOUCH_MOVED:
321 case ui::ET_TOUCH_STATIONARY:
322 case ui::ET_TOUCH_CANCELLED:
323 current_root_window_->AsRootWindowHostDelegate()->OnHostTouchEvent(
324 static_cast<ui::TouchEvent*>(&event));
325 break;
326 default:
327 NOTIMPLEMENTED();
328 break;
329 }
330 } 391 }
331 392
332 void EventGenerator::DispatchKeyEvent(bool is_press, 393 void EventGenerator::DispatchKeyEvent(bool is_press,
333 ui::KeyboardCode key_code, 394 ui::KeyboardCode key_code,
334 int flags) { 395 int flags) {
335 #if defined(OS_WIN) 396 #if defined(OS_WIN)
336 UINT key_press = WM_KEYDOWN; 397 UINT key_press = WM_KEYDOWN;
337 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags); 398 uint16 character = ui::GetCharacterFromKeyCode(key_code, flags);
338 if (is_press && character) { 399 if (is_press && character) {
339 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; 400 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 };
340 TestKeyEvent keyev(native_event, flags, false); 401 TestKeyEvent keyev(native_event, flags, false);
341 Dispatch(keyev); 402 Dispatch(&keyev);
342 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character 403 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character
343 // if the key event cooresponds to a real character. 404 // if the key event cooresponds to a real character.
344 key_press = WM_CHAR; 405 key_press = WM_CHAR;
345 key_code = static_cast<ui::KeyboardCode>(character); 406 key_code = static_cast<ui::KeyboardCode>(character);
346 } 407 }
347 MSG native_event = 408 MSG native_event =
348 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; 409 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 };
349 TestKeyEvent keyev(native_event, flags, key_press == WM_CHAR); 410 TestKeyEvent keyev(native_event, flags, key_press == WM_CHAR);
350 #else 411 #else
351 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; 412 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED;
352 #if defined(USE_X11) 413 #if defined(USE_X11)
353 scoped_ptr<XEvent> native_event(new XEvent); 414 scoped_ptr<XEvent> native_event(new XEvent);
354 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get()); 415 ui::InitXKeyEventForTesting(type, key_code, flags, native_event.get());
355 TestKeyEvent keyev(native_event.get(), flags, false); 416 TestKeyEvent keyev(native_event.get(), flags, false);
356 #else 417 #else
357 ui::KeyEvent keyev(type, key_code, flags, false); 418 ui::KeyEvent keyev(type, key_code, flags, false);
358 #endif // USE_X11 419 #endif // USE_X11
359 #endif // OS_WIN 420 #endif // OS_WIN
360 Dispatch(keyev); 421 Dispatch(&keyev);
361 } 422 }
362 423
363 void EventGenerator::UpdateCurrentRootWindow(const gfx::Point& point) { 424 void EventGenerator::UpdateCurrentRootWindow(const gfx::Point& point) {
364 current_root_window_ = delegate_->GetRootWindowAt(point); 425 current_root_window_ = delegate_->GetRootWindowAt(point);
365 } 426 }
366 427
367 void EventGenerator::PressButton(int flag) { 428 void EventGenerator::PressButton(int flag) {
368 if (!(flags_ & flag)) { 429 if (!(flags_ & flag)) {
369 flags_ |= flag; 430 flags_ |= flag;
370 grab_ = flags_ & kAllButtonMask; 431 grab_ = flags_ & kAllButtonMask;
371 gfx::Point location = GetLocationInCurrentRoot(); 432 gfx::Point location = GetLocationInCurrentRoot();
372 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_); 433 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_);
373 Dispatch(mouseev); 434 Dispatch(&mouseev);
374 } 435 }
375 } 436 }
376 437
377 void EventGenerator::ReleaseButton(int flag) { 438 void EventGenerator::ReleaseButton(int flag) {
378 if (flags_ & flag) { 439 if (flags_ & flag) {
379 gfx::Point location = GetLocationInCurrentRoot(); 440 gfx::Point location = GetLocationInCurrentRoot();
380 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, 441 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location,
381 location, flags_); 442 location, flags_);
382 Dispatch(mouseev); 443 Dispatch(&mouseev);
383 flags_ ^= flag; 444 flags_ ^= flag;
384 } 445 }
385 grab_ = flags_ & kAllButtonMask; 446 grab_ = flags_ & kAllButtonMask;
386 } 447 }
387 448
388 void EventGenerator::ConvertPointFromTarget(const aura::Window* target, 449 void EventGenerator::ConvertPointFromTarget(const aura::Window* target,
389 gfx::Point* point) const { 450 gfx::Point* point) const {
390 DCHECK(point); 451 DCHECK(point);
391 aura::client::ScreenPositionClient* client = 452 aura::client::ScreenPositionClient* client =
392 delegate_->GetScreenPositionClient(target); 453 delegate_->GetScreenPositionClient(target);
(...skipping 19 matching lines...) Expand all
412 ConvertPointToTarget(current_root_window_, &p); 473 ConvertPointToTarget(current_root_window_, &p);
413 return p; 474 return p;
414 } 475 }
415 476
416 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const { 477 gfx::Point EventGenerator::CenterOfWindow(const Window* window) const {
417 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint(); 478 gfx::Point center = gfx::Rect(window->bounds().size()).CenterPoint();
418 ConvertPointFromTarget(window, &center); 479 ConvertPointFromTarget(window, &center);
419 return center; 480 return center;
420 } 481 }
421 482
483 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) {
484 if (async) {
485 ui::Event* pending_event;
486 if (event->IsKeyEvent()) {
487 pending_event = new ui::KeyEvent(*static_cast<ui::KeyEvent*>(event));
488 } else if (event->IsMouseEvent()) {
489 pending_event = new ui::MouseEvent(*static_cast<ui::MouseEvent*>(event));
490 } else if (event->IsTouchEvent()) {
491 pending_event = new ui::TouchEvent(*static_cast<ui::TouchEvent*>(event));
492 } else if (event->IsScrollEvent()) {
493 pending_event =
494 new ui::ScrollEvent(*static_cast<ui::ScrollEvent*>(event));
495 } else {
496 NOTREACHED() << "Invalid event type";
497 return;
498 }
499 if (pending_events_.empty()) {
500 base::MessageLoopProxy::current()->PostTask(
501 FROM_HERE,
502 base::Bind(&EventGenerator::DispatchNextPendingEvent,
503 base::Unretained(this)));
504 }
505 pending_events_.push_back(pending_event);
506 } else {
507 RootWindowHostDelegate* root_window_host_delegate =
508 current_root_window_->AsRootWindowHostDelegate();
509 if (event->IsKeyEvent()) {
510 root_window_host_delegate->OnHostKeyEvent(
511 static_cast<ui::KeyEvent*>(event));
512 } else if (event->IsMouseEvent()) {
513 root_window_host_delegate->OnHostMouseEvent(
514 static_cast<ui::MouseEvent*>(event));
515 } else if (event->IsTouchEvent()) {
516 root_window_host_delegate->OnHostTouchEvent(
517 static_cast<ui::TouchEvent*>(event));
518 } else if (event->IsScrollEvent()) {
519 root_window_host_delegate->OnHostScrollEvent(
520 static_cast<ui::ScrollEvent*>(event));
521 } else {
522 NOTREACHED() << "Invalid event type";
523 }
524 }
525 }
526
527 void EventGenerator::DispatchNextPendingEvent() {
528 DCHECK(!pending_events_.empty());
529 ui::Event* event = pending_events_.front();
530 DoDispatchEvent(event, false);
531 pending_events_.pop_front();
532 delete event;
533 if (!pending_events_.empty()) {
534 base::MessageLoopProxy::current()->PostTask(
535 FROM_HERE,
536 base::Bind(&EventGenerator::DispatchNextPendingEvent,
537 base::Unretained(this)));
538 }
539 }
540
541
422 } // namespace test 542 } // namespace test
423 } // namespace aura 543 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/test/event_generator.h ('k') | ui/base/events/event.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698