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

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

Issue 1372253002: gfx: Make conversions from gfx::Point to PointF explicit. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pointfconvert-gfx: . Created 5 years, 2 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
OLDNEW
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"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 } 55 }
56 }; 56 };
57 57
58 class TestTouchEvent : public ui::TouchEvent { 58 class TestTouchEvent : public ui::TouchEvent {
59 public: 59 public:
60 TestTouchEvent(ui::EventType type, 60 TestTouchEvent(ui::EventType type,
61 const gfx::Point& root_location, 61 const gfx::Point& root_location,
62 int touch_id, 62 int touch_id,
63 int flags, 63 int flags,
64 base::TimeDelta timestamp) 64 base::TimeDelta timestamp)
65 : TouchEvent(type, root_location, flags, touch_id, timestamp, 65 : TouchEvent(type,
66 1.0f, 1.0f, 0.0f, 0.0f) { 66 gfx::PointF(root_location),
67 } 67 flags,
68 touch_id,
69 timestamp,
70 1.0f,
71 1.0f,
72 0.0f,
73 0.0f) {}
68 74
69 private: 75 private:
70 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); 76 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent);
71 }; 77 };
72 78
73 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; 79 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON;
74 80
75 } // namespace 81 } // namespace
76 82
77 EventGeneratorDelegate* EventGenerator::default_delegate = NULL; 83 EventGeneratorDelegate* EventGenerator::default_delegate = NULL;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 157
152 void EventGenerator::PressRightButton() { 158 void EventGenerator::PressRightButton() {
153 PressButton(ui::EF_RIGHT_MOUSE_BUTTON); 159 PressButton(ui::EF_RIGHT_MOUSE_BUTTON);
154 } 160 }
155 161
156 void EventGenerator::ReleaseRightButton() { 162 void EventGenerator::ReleaseRightButton() {
157 ReleaseButton(ui::EF_RIGHT_MOUSE_BUTTON); 163 ReleaseButton(ui::EF_RIGHT_MOUSE_BUTTON);
158 } 164 }
159 165
160 void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) { 166 void EventGenerator::MoveMouseWheel(int delta_x, int delta_y) {
161 gfx::Point location = GetLocationInCurrentRoot(); 167 auto location = gfx::PointF(GetLocationInCurrentRoot());
162 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location, 168 ui::MouseEvent mouseev(ui::ET_MOUSEWHEEL, location, location,
163 ui::EventTimeForNow(), flags_, 0); 169 ui::EventTimeForNow(), flags_, 0);
164 ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y); 170 ui::MouseWheelEvent wheelev(mouseev, delta_x, delta_y);
165 Dispatch(&wheelev); 171 Dispatch(&wheelev);
166 } 172 }
167 173
168 void EventGenerator::SendMouseExit() { 174 void EventGenerator::SendMouseExit() {
169 gfx::Point exit_location(current_location_); 175 gfx::Point exit_location(current_location_);
170 delegate()->ConvertPointToTarget(current_target_, &exit_location); 176 delegate()->ConvertPointToTarget(current_target_, &exit_location);
171 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location, 177 ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, gfx::PointF(exit_location),
172 ui::EventTimeForNow(), flags_, 0); 178 gfx::PointF(exit_location), ui::EventTimeForNow(),
179 flags_, 0);
173 Dispatch(&mouseev); 180 Dispatch(&mouseev);
174 } 181 }
175 182
176 void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host, 183 void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host,
177 const gfx::Point& point_for_native) { 184 const gfx::Point& point_for_native) {
178 #if defined(USE_X11) 185 #if defined(USE_X11)
179 ui::ScopedXI2Event xevent; 186 ui::ScopedXI2Event xevent;
180 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); 187 xevent.InitMotionEvent(point_in_host, point_for_native, flags_);
181 static_cast<XEvent*>(xevent)->xmotion.time = Now().InMicroseconds(); 188 static_cast<XEvent*>(xevent)->xmotion.time = Now().InMicroseconds();
182 ui::MouseEvent mouseev(xevent); 189 ui::MouseEvent mouseev(xevent);
183 #elif defined(USE_OZONE) 190 #elif defined(USE_OZONE)
184 // Ozone uses the location in native event as a system location. 191 // Ozone uses the location in native event as a system location.
185 // Create a fake event with the point in host, which will be passed 192 // Create a fake event with the point in host, which will be passed
186 // to the non native event, then update the native event with the native 193 // to the non native event, then update the native event with the native
187 // (root) one. 194 // (root) one.
188 scoped_ptr<ui::MouseEvent> native_event(new ui::MouseEvent( 195 scoped_ptr<ui::MouseEvent> native_event(
189 ui::ET_MOUSE_MOVED, point_in_host, point_in_host, Now(), flags_, 0)); 196 new ui::MouseEvent(ui::ET_MOUSE_MOVED, gfx::PointF(point_in_host),
197 gfx::PointF(point_in_host), Now(), flags_, 0));
190 ui::MouseEvent mouseev(native_event.get()); 198 ui::MouseEvent mouseev(native_event.get());
191 native_event->set_location(point_for_native); 199 native_event->set_location(point_for_native);
192 #else 200 #else
193 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, point_in_host, point_for_native, 201 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, gfx::PointF(point_in_host),
194 Now(), flags_, 0); 202 gfx::PointF(point_for_native), Now(), flags_, 0);
195 LOG(FATAL) 203 LOG(FATAL)
196 << "Generating a native motion event is not supported on this platform"; 204 << "Generating a native motion event is not supported on this platform";
197 #endif 205 #endif
198 Dispatch(&mouseev); 206 Dispatch(&mouseev);
199 207
200 current_location_ = point_in_host; 208 current_location_ = point_in_host;
201 delegate()->ConvertPointFromHost(current_target_, &current_location_); 209 delegate()->ConvertPointFromHost(current_target_, &current_location_);
202 } 210 }
203 211
204 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { 212 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) {
205 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? 213 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ?
206 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; 214 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED;
207 ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, 215 ui::MouseEvent mouseev(event_type, gfx::PointF(point_in_host),
208 ui::EventTimeForNow(), flags_, 0); 216 gfx::PointF(point_in_host), ui::EventTimeForNow(),
217 flags_, 0);
209 Dispatch(&mouseev); 218 Dispatch(&mouseev);
210 219
211 current_location_ = point_in_host; 220 current_location_ = point_in_host;
212 delegate()->ConvertPointFromHost(current_target_, &current_location_); 221 delegate()->ConvertPointFromHost(current_target_, &current_location_);
213 } 222 }
214 223
215 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen, 224 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
216 int count) { 225 int count) {
217 DCHECK_GT(count, 0); 226 DCHECK_GT(count, 0);
218 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ? 227 const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ?
219 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED; 228 ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED;
220 229
221 gfx::Vector2dF diff(point_in_screen - current_location_); 230 gfx::Vector2dF diff(point_in_screen - current_location_);
222 for (float i = 1; i <= count; i++) { 231 for (float i = 1; i <= count; i++) {
223 gfx::Vector2dF step(diff); 232 gfx::Vector2dF step(diff);
224 step.Scale(i / count); 233 step.Scale(i / count);
225 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step); 234 gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step);
226 if (!grab_) 235 if (!grab_)
227 UpdateCurrentDispatcher(move_point); 236 UpdateCurrentDispatcher(move_point);
228 delegate()->ConvertPointToTarget(current_target_, &move_point); 237 delegate()->ConvertPointToTarget(current_target_, &move_point);
229 ui::MouseEvent mouseev(event_type, move_point, move_point, 238 ui::MouseEvent mouseev(event_type, gfx::PointF(move_point),
230 ui::EventTimeForNow(), flags_, 0); 239 gfx::PointF(move_point), ui::EventTimeForNow(),
240 flags_, 0);
231 Dispatch(&mouseev); 241 Dispatch(&mouseev);
232 } 242 }
233 current_location_ = point_in_screen; 243 current_location_ = point_in_screen;
234 } 244 }
235 245
236 void EventGenerator::MoveMouseRelativeTo(const EventTarget* window, 246 void EventGenerator::MoveMouseRelativeTo(const EventTarget* window,
237 const gfx::Point& point_in_parent) { 247 const gfx::Point& point_in_parent) {
238 gfx::Point point(point_in_parent); 248 gfx::Point point(point_in_parent);
239 delegate()->ConvertPointFromTarget(window, &point); 249 delegate()->ConvertPointFromTarget(window, &point);
240 MoveMouseTo(point); 250 MoveMouseTo(point);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 } 308 }
299 309
300 void EventGenerator::GestureEdgeSwipe() { 310 void EventGenerator::GestureEdgeSwipe() {
301 ui::GestureEvent gesture( 311 ui::GestureEvent gesture(
302 0, 0, 0, Now(), ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE)); 312 0, 0, 0, Now(), ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE));
303 Dispatch(&gesture); 313 Dispatch(&gesture);
304 } 314 }
305 315
306 void EventGenerator::GestureTapAt(const gfx::Point& location) { 316 void EventGenerator::GestureTapAt(const gfx::Point& location) {
307 const int kTouchId = 2; 317 const int kTouchId = 2;
308 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 318 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::PointF(location), kTouchId,
309 location,
310 kTouchId,
311 Now()); 319 Now());
312 Dispatch(&press); 320 Dispatch(&press);
313 321
314 ui::TouchEvent release( 322 ui::TouchEvent release(
315 ui::ET_TOUCH_RELEASED, location, kTouchId, 323 ui::ET_TOUCH_RELEASED, gfx::PointF(location), kTouchId,
316 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); 324 press.time_stamp() + base::TimeDelta::FromMilliseconds(50));
317 Dispatch(&release); 325 Dispatch(&release);
318 } 326 }
319 327
320 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { 328 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) {
321 const int kTouchId = 3; 329 const int kTouchId = 3;
322 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 330 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::PointF(location), kTouchId,
323 location,
324 kTouchId,
325 Now()); 331 Now());
326 Dispatch(&press); 332 Dispatch(&press);
327 333
328 ui::TouchEvent release( 334 ui::TouchEvent release(
329 ui::ET_TOUCH_RELEASED, location, kTouchId, 335 ui::ET_TOUCH_RELEASED, gfx::PointF(location), kTouchId,
330 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); 336 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000));
331 Dispatch(&release); 337 Dispatch(&release);
332 } 338 }
333 339
334 base::TimeDelta EventGenerator::CalculateScrollDurationForFlingVelocity( 340 base::TimeDelta EventGenerator::CalculateScrollDurationForFlingVelocity(
335 const gfx::Point& start, 341 const gfx::Point& start,
336 const gfx::Point& end, 342 const gfx::Point& end,
337 float velocity, 343 float velocity,
338 int steps) { 344 int steps) {
339 const float kGestureDistance = (start - end).Length(); 345 const float kGestureDistance = (start - end).Length();
340 const float kFlingStepDelay = (kGestureDistance / velocity) / steps * 1000000; 346 const float kFlingStepDelay = (kGestureDistance / velocity) / steps * 1000000;
341 return base::TimeDelta::FromMicroseconds(kFlingStepDelay); 347 return base::TimeDelta::FromMicroseconds(kFlingStepDelay);
342 } 348 }
343 349
344 void EventGenerator::GestureScrollSequence(const gfx::Point& start, 350 void EventGenerator::GestureScrollSequence(const gfx::Point& start,
345 const gfx::Point& end, 351 const gfx::Point& end,
346 const base::TimeDelta& step_delay, 352 const base::TimeDelta& step_delay,
347 int steps) { 353 int steps) {
348 GestureScrollSequenceWithCallback(start, end, step_delay, steps, 354 GestureScrollSequenceWithCallback(start, end, step_delay, steps,
349 base::Bind(&DummyCallback)); 355 base::Bind(&DummyCallback));
350 } 356 }
351 357
352 void EventGenerator::GestureScrollSequenceWithCallback( 358 void EventGenerator::GestureScrollSequenceWithCallback(
353 const gfx::Point& start, 359 const gfx::Point& start,
354 const gfx::Point& end, 360 const gfx::Point& end,
355 const base::TimeDelta& step_delay, 361 const base::TimeDelta& step_delay,
356 int steps, 362 int steps,
357 const ScrollStepCallback& callback) { 363 const ScrollStepCallback& callback) {
358 const int kTouchId = 5; 364 const int kTouchId = 5;
365 auto location = gfx::PointF(start);
359 base::TimeDelta timestamp = Now(); 366 base::TimeDelta timestamp = Now();
360 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, kTouchId, timestamp); 367 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId, timestamp);
361 Dispatch(&press); 368 Dispatch(&press);
362 369
363 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF()); 370 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF());
364 371
365 float dx = static_cast<float>(end.x() - start.x()) / steps; 372 float dx = static_cast<float>(end.x() - start.x()) / steps;
366 float dy = static_cast<float>(end.y() - start.y()) / steps; 373 float dy = static_cast<float>(end.y() - start.y()) / steps;
367 gfx::PointF location = start;
368 for (int i = 0; i < steps; ++i) { 374 for (int i = 0; i < steps; ++i) {
369 location.Offset(dx, dy); 375 location.Offset(dx, dy);
370 timestamp += step_delay; 376 timestamp += step_delay;
371 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp); 377 ui::TouchEvent move(ui::ET_TOUCH_MOVED, location, kTouchId, timestamp);
372 Dispatch(&move); 378 Dispatch(&move);
373 callback.Run(ui::ET_GESTURE_SCROLL_UPDATE, gfx::Vector2dF(dx, dy)); 379 callback.Run(ui::ET_GESTURE_SCROLL_UPDATE, gfx::Vector2dF(dx, dy));
374 } 380 }
375 381
376 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, end, kTouchId, timestamp); 382 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::PointF(end), kTouchId,
383 timestamp);
377 Dispatch(&release); 384 Dispatch(&release);
378 385
379 callback.Run(ui::ET_GESTURE_SCROLL_END, gfx::Vector2dF()); 386 callback.Run(ui::ET_GESTURE_SCROLL_END, gfx::Vector2dF());
380 } 387 }
381 388
382 void EventGenerator::GestureMultiFingerScroll(int count, 389 void EventGenerator::GestureMultiFingerScroll(int count,
383 const gfx::Point start[], 390 const gfx::Point start[],
384 int event_separation_time_ms, 391 int event_separation_time_ms,
385 int steps, 392 int steps,
386 int move_x, 393 int move_x,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 } 428 }
422 429
423 int last_id = 0; 430 int last_id = 0;
424 for (int step = 0; step < steps; ++step) { 431 for (int step = 0; step < steps; ++step) {
425 base::TimeDelta move_time = press_time_first + 432 base::TimeDelta move_time = press_time_first +
426 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step); 433 base::TimeDelta::FromMilliseconds(event_separation_time_ms * step);
427 434
428 while (last_id < count && 435 while (last_id < count &&
429 !pressed[last_id] && 436 !pressed[last_id] &&
430 move_time >= press_time[last_id]) { 437 move_time >= press_time[last_id]) {
431 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, 438 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, gfx::PointF(points[last_id]),
432 points[last_id], 439 last_id, press_time[last_id]);
433 last_id,
434 press_time[last_id]);
435 Dispatch(&press); 440 Dispatch(&press);
436 pressed[last_id] = true; 441 pressed[last_id] = true;
437 last_id++; 442 last_id++;
438 } 443 }
439 444
440 for (int i = 0; i < count; ++i) { 445 for (int i = 0; i < count; ++i) {
441 points[i].Offset(delta_x, delta_y); 446 points[i].Offset(delta_x, delta_y);
442 if (i >= last_id) 447 if (i >= last_id)
443 continue; 448 continue;
444 ui::TouchEvent move(ui::ET_TOUCH_MOVED, points[i], i, move_time); 449 ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::PointF(points[i]), i,
450 move_time);
445 Dispatch(&move); 451 Dispatch(&move);
446 } 452 }
447 } 453 }
448 454
449 base::TimeDelta release_time = press_time_first + 455 base::TimeDelta release_time = press_time_first +
450 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps); 456 base::TimeDelta::FromMilliseconds(event_separation_time_ms * steps);
451 for (int i = 0; i < last_id; ++i) { 457 for (int i = 0; i < last_id; ++i) {
452 ui::TouchEvent release( 458 ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::PointF(points[i]), i,
453 ui::ET_TOUCH_RELEASED, points[i], i, release_time); 459 release_time);
454 Dispatch(&release); 460 Dispatch(&release);
455 } 461 }
456 } 462 }
457 463
458 void EventGenerator::ScrollSequence(const gfx::Point& start, 464 void EventGenerator::ScrollSequence(const gfx::Point& start,
459 const base::TimeDelta& step_delay, 465 const base::TimeDelta& step_delay,
460 float x_offset, 466 float x_offset,
461 float y_offset, 467 float y_offset,
462 int steps, 468 int steps,
463 int num_fingers) { 469 int num_fingers) {
464 base::TimeDelta timestamp = Now(); 470 base::TimeDelta timestamp = Now();
465 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, 471 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, gfx::PointF(start),
466 start, 472 timestamp, 0, 0, 0, 0, 0, num_fingers);
467 timestamp,
468 0,
469 0, 0,
470 0, 0,
471 num_fingers);
472 Dispatch(&fling_cancel); 473 Dispatch(&fling_cancel);
473 474
474 float dx = x_offset / steps; 475 float dx = x_offset / steps;
475 float dy = y_offset / steps; 476 float dy = y_offset / steps;
476 for (int i = 0; i < steps; ++i) { 477 for (int i = 0; i < steps; ++i) {
477 timestamp += step_delay; 478 timestamp += step_delay;
478 ui::ScrollEvent move(ui::ET_SCROLL, 479 ui::ScrollEvent move(ui::ET_SCROLL, gfx::PointF(start), timestamp, 0, dx,
479 start, 480 dy, dx, dy, num_fingers);
480 timestamp,
481 0,
482 dx, dy,
483 dx, dy,
484 num_fingers);
485 Dispatch(&move); 481 Dispatch(&move);
486 } 482 }
487 483
488 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, 484 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, gfx::PointF(start),
489 start, 485 timestamp, 0, x_offset, y_offset, x_offset,
490 timestamp, 486 y_offset, num_fingers);
491 0,
492 x_offset, y_offset,
493 x_offset, y_offset,
494 num_fingers);
495 Dispatch(&fling_start); 487 Dispatch(&fling_start);
496 } 488 }
497 489
498 void EventGenerator::ScrollSequence(const gfx::Point& start, 490 void EventGenerator::ScrollSequence(const gfx::Point& start,
499 const base::TimeDelta& step_delay, 491 const base::TimeDelta& step_delay,
500 const std::vector<gfx::PointF>& offsets, 492 const std::vector<gfx::PointF>& offsets,
501 int num_fingers) { 493 int num_fingers) {
502 size_t steps = offsets.size(); 494 size_t steps = offsets.size();
503 base::TimeDelta timestamp = Now(); 495 base::TimeDelta timestamp = Now();
504 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, 496 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, gfx::PointF(start),
505 start, 497 timestamp, 0, 0, 0, 0, 0, num_fingers);
506 timestamp,
507 0,
508 0, 0,
509 0, 0,
510 num_fingers);
511 Dispatch(&fling_cancel); 498 Dispatch(&fling_cancel);
512 499
513 for (size_t i = 0; i < steps; ++i) { 500 for (size_t i = 0; i < steps; ++i) {
514 timestamp += step_delay; 501 timestamp += step_delay;
515 ui::ScrollEvent scroll(ui::ET_SCROLL, 502 ui::ScrollEvent scroll(ui::ET_SCROLL, gfx::PointF(start), timestamp, 0,
516 start, 503 offsets[i].x(), offsets[i].y(), offsets[i].x(),
517 timestamp, 504 offsets[i].y(), num_fingers);
518 0,
519 offsets[i].x(), offsets[i].y(),
520 offsets[i].x(), offsets[i].y(),
521 num_fingers);
522 Dispatch(&scroll); 505 Dispatch(&scroll);
523 } 506 }
524 507
525 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, 508 ui::ScrollEvent fling_start(ui::ET_SCROLL_FLING_START, gfx::PointF(start),
526 start, 509 timestamp, 0, offsets[steps - 1].x(),
527 timestamp, 510 offsets[steps - 1].y(), offsets[steps - 1].x(),
528 0, 511 offsets[steps - 1].y(), num_fingers);
529 offsets[steps - 1].x(), offsets[steps - 1].y(),
530 offsets[steps - 1].x(), offsets[steps - 1].y(),
531 num_fingers);
532 Dispatch(&fling_start); 512 Dispatch(&fling_start);
533 } 513 }
534 514
535 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) { 515 void EventGenerator::PressKey(ui::KeyboardCode key_code, int flags) {
536 DispatchKeyEvent(true, key_code, flags); 516 DispatchKeyEvent(true, key_code, flags);
537 } 517 }
538 518
539 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { 519 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) {
540 DispatchKeyEvent(false, key_code, flags); 520 DispatchKeyEvent(false, key_code, flags);
541 } 521 }
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 } 578 }
599 579
600 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { 580 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) {
601 current_target_ = delegate()->GetTargetAt(point); 581 current_target_ = delegate()->GetTargetAt(point);
602 } 582 }
603 583
604 void EventGenerator::PressButton(int flag) { 584 void EventGenerator::PressButton(int flag) {
605 if (!(flags_ & flag)) { 585 if (!(flags_ & flag)) {
606 flags_ |= flag; 586 flags_ |= flag;
607 grab_ = (flags_ & kAllButtonMask) != 0; 587 grab_ = (flags_ & kAllButtonMask) != 0;
608 gfx::Point location = GetLocationInCurrentRoot(); 588 auto location = gfx::PointF(GetLocationInCurrentRoot());
609 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, 589 ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location,
610 ui::EventTimeForNow(), flags_, flag); 590 ui::EventTimeForNow(), flags_, flag);
611 Dispatch(&mouseev); 591 Dispatch(&mouseev);
612 } 592 }
613 } 593 }
614 594
615 void EventGenerator::ReleaseButton(int flag) { 595 void EventGenerator::ReleaseButton(int flag) {
616 if (flags_ & flag) { 596 if (flags_ & flag) {
617 gfx::Point location = GetLocationInCurrentRoot(); 597 auto location = gfx::PointF(GetLocationInCurrentRoot());
618 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, location, 598 ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location, location,
619 ui::EventTimeForNow(), flags_, flag); 599 ui::EventTimeForNow(), flags_, flag);
620 Dispatch(&mouseev); 600 Dispatch(&mouseev);
621 flags_ ^= flag; 601 flags_ ^= flag;
622 } 602 }
623 grab_ = (flags_ & kAllButtonMask) != 0; 603 grab_ = (flags_ & kAllButtonMask) != 0;
624 } 604 }
625 605
626 gfx::Point EventGenerator::GetLocationInCurrentRoot() const { 606 gfx::Point EventGenerator::GetLocationInCurrentRoot() const {
627 gfx::Point p(current_location_); 607 gfx::Point p(current_location_);
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 return default_delegate; 667 return default_delegate;
688 } 668 }
689 669
690 EventGeneratorDelegate* EventGenerator::delegate() { 670 EventGeneratorDelegate* EventGenerator::delegate() {
691 return const_cast<EventGeneratorDelegate*>( 671 return const_cast<EventGeneratorDelegate*>(
692 const_cast<const EventGenerator*>(this)->delegate()); 672 const_cast<const EventGenerator*>(this)->delegate());
693 } 673 }
694 674
695 } // namespace test 675 } // namespace test
696 } // namespace ui 676 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698