Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 34 #include "ui/events/keycodes/keyboard_code_conversion.h" | 34 #include "ui/events/keycodes/keyboard_code_conversion.h" |
| 35 #endif | 35 #endif |
| 36 | 36 |
| 37 namespace ui { | 37 namespace ui { |
| 38 namespace test { | 38 namespace test { |
| 39 namespace { | 39 namespace { |
| 40 | 40 |
| 41 void DummyCallback(EventType, const gfx::Vector2dF&) { | 41 void DummyCallback(EventType, const gfx::Vector2dF&) { |
| 42 } | 42 } |
| 43 | 43 |
| 44 // A proxy for TickClock that allows passing the same underlying clock | |
| 45 // to multiple consumers, each retaining a unique_ptr to their own | |
| 46 // instance of TickClock proxy. | |
| 47 class ClonableTickClock : public base::TickClock, | |
| 48 public base::RefCounted<ClonableTickClock> { | |
| 49 private: | |
| 50 class TickClockProxy : public base::TickClock { | |
| 51 public: | |
| 52 explicit TickClockProxy(ClonableTickClock* tick_clock) | |
| 53 : tick_clock_(tick_clock) {} | |
| 54 | |
| 55 private: | |
| 56 base::TimeTicks NowTicks() override { return tick_clock_->NowTicks(); } | |
| 57 | |
| 58 scoped_refptr<ClonableTickClock> tick_clock_; | |
| 59 DISALLOW_COPY_AND_ASSIGN(TickClockProxy); | |
| 60 }; | |
| 61 | |
| 62 public: | |
| 63 explicit ClonableTickClock(std::unique_ptr<base::TickClock> tick_clock) | |
| 64 : tick_clock_(std::move(tick_clock)) {} | |
| 65 | |
| 66 base::TimeTicks NowTicks() override { return tick_clock_->NowTicks(); } | |
| 67 std::unique_ptr<TickClock> Clone() { | |
| 68 return WrapUnique(new TickClockProxy(this)); | |
| 69 } | |
| 70 | |
| 71 private: | |
| 72 friend class base::RefCounted<ClonableTickClock>; | |
| 73 ~ClonableTickClock() override = default; | |
| 74 std::unique_ptr<TickClock> tick_clock_; | |
| 75 | |
| 76 DISALLOW_COPY_AND_ASSIGN(ClonableTickClock); | |
| 77 }; | |
| 78 | |
| 79 class TestTickClock : public base::TickClock { | 44 class TestTickClock : public base::TickClock { |
| 80 public: | 45 public: |
| 81 // Starts off with a clock set to TimeTicks(). | 46 // Starts off with a clock set to TimeTicks(). |
| 82 TestTickClock() {} | 47 TestTickClock() {} |
| 83 | 48 |
| 84 base::TimeTicks NowTicks() override { | 49 base::TimeTicks NowTicks() override { |
| 85 return base::TimeTicks::FromInternalValue(ticks_++ * 1000); | 50 return base::TimeTicks::FromInternalValue(ticks_++ * 1000); |
| 86 } | 51 } |
| 87 | 52 |
| 88 private: | 53 private: |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 ui::EventTimeForNow(), flags_, 0); | 172 ui::EventTimeForNow(), flags_, 0); |
| 208 Dispatch(&mouseev); | 173 Dispatch(&mouseev); |
| 209 } | 174 } |
| 210 | 175 |
| 211 void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host, | 176 void EventGenerator::MoveMouseToWithNative(const gfx::Point& point_in_host, |
| 212 const gfx::Point& point_for_native) { | 177 const gfx::Point& point_for_native) { |
| 213 #if defined(USE_X11) | 178 #if defined(USE_X11) |
| 214 ui::ScopedXI2Event xevent; | 179 ui::ScopedXI2Event xevent; |
| 215 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); | 180 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); |
| 216 static_cast<XEvent*>(xevent)->xmotion.time = | 181 static_cast<XEvent*>(xevent)->xmotion.time = |
| 217 (Now() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; | 182 (ui::EventTimeForNow() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; |
| 218 ui::MouseEvent mouseev(xevent); | 183 ui::MouseEvent mouseev(xevent); |
| 219 #elif defined(USE_OZONE) | 184 #elif defined(USE_OZONE) |
| 220 // Ozone uses the location in native event as a system location. | 185 // Ozone uses the location in native event as a system location. |
| 221 // Create a fake event with the point in host, which will be passed | 186 // Create a fake event with the point in host, which will be passed |
| 222 // to the non native event, then update the native event with the native | 187 // to the non native event, then update the native event with the native |
| 223 // (root) one. | 188 // (root) one. |
| 224 std::unique_ptr<ui::MouseEvent> native_event(new ui::MouseEvent( | 189 std::unique_ptr<ui::MouseEvent> native_event( |
| 225 ui::ET_MOUSE_MOVED, point_in_host, point_in_host, Now(), flags_, 0)); | 190 new ui::MouseEvent(ui::ET_MOUSE_MOVED, point_in_host, point_in_host, |
| 191 ui::EventTimeForNow(), flags_, 0)); | |
| 226 ui::MouseEvent mouseev(native_event.get()); | 192 ui::MouseEvent mouseev(native_event.get()); |
| 227 native_event->set_location(point_for_native); | 193 native_event->set_location(point_for_native); |
| 228 #else | 194 #else |
| 229 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, point_in_host, point_for_native, | 195 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, point_in_host, point_for_native, |
| 230 Now(), flags_, 0); | 196 ui::EventTimeForNow(), flags_, 0); |
| 231 LOG(FATAL) | 197 LOG(FATAL) |
| 232 << "Generating a native motion event is not supported on this platform"; | 198 << "Generating a native motion event is not supported on this platform"; |
| 233 #endif | 199 #endif |
| 234 Dispatch(&mouseev); | 200 Dispatch(&mouseev); |
| 235 | 201 |
| 236 current_location_ = point_in_host; | 202 current_location_ = point_in_host; |
| 237 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); | 203 delegate()->ConvertPointFromHost(current_target_, ¤t_location_); |
| 238 } | 204 } |
| 239 | 205 |
| 240 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { | 206 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 284 | 250 |
| 285 void EventGenerator::MoveMouseToCenterOf(EventTarget* window) { | 251 void EventGenerator::MoveMouseToCenterOf(EventTarget* window) { |
| 286 MoveMouseTo(CenterOfWindow(window)); | 252 MoveMouseTo(CenterOfWindow(window)); |
| 287 } | 253 } |
| 288 | 254 |
| 289 void EventGenerator::PressTouch() { | 255 void EventGenerator::PressTouch() { |
| 290 PressTouchId(0); | 256 PressTouchId(0); |
| 291 } | 257 } |
| 292 | 258 |
| 293 void EventGenerator::PressTouchId(int touch_id) { | 259 void EventGenerator::PressTouchId(int touch_id) { |
| 294 TestTouchEvent touchev( | 260 TestTouchEvent touchev(ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), |
| 295 ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), touch_id, flags_, | 261 touch_id, flags_, ui::EventTimeForNow()); |
| 296 Now()); | |
| 297 Dispatch(&touchev); | 262 Dispatch(&touchev); |
| 298 } | 263 } |
| 299 | 264 |
| 300 void EventGenerator::MoveTouch(const gfx::Point& point) { | 265 void EventGenerator::MoveTouch(const gfx::Point& point) { |
| 301 MoveTouchId(point, 0); | 266 MoveTouchId(point, 0); |
| 302 } | 267 } |
| 303 | 268 |
| 304 void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) { | 269 void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) { |
| 305 current_location_ = point; | 270 current_location_ = point; |
| 306 TestTouchEvent touchev( | 271 TestTouchEvent touchev(ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), |
| 307 ui::ET_TOUCH_MOVED, GetLocationInCurrentRoot(), touch_id, flags_, | 272 touch_id, flags_, ui::EventTimeForNow()); |
| 308 Now()); | |
| 309 Dispatch(&touchev); | 273 Dispatch(&touchev); |
| 310 | 274 |
| 311 if (!grab_) | 275 if (!grab_) |
| 312 UpdateCurrentDispatcher(point); | 276 UpdateCurrentDispatcher(point); |
| 313 } | 277 } |
| 314 | 278 |
| 315 void EventGenerator::ReleaseTouch() { | 279 void EventGenerator::ReleaseTouch() { |
| 316 ReleaseTouchId(0); | 280 ReleaseTouchId(0); |
| 317 } | 281 } |
| 318 | 282 |
| 319 void EventGenerator::ReleaseTouchId(int touch_id) { | 283 void EventGenerator::ReleaseTouchId(int touch_id) { |
| 320 TestTouchEvent touchev( | 284 TestTouchEvent touchev(ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), |
| 321 ui::ET_TOUCH_RELEASED, GetLocationInCurrentRoot(), touch_id, flags_, | 285 touch_id, flags_, ui::EventTimeForNow()); |
| 322 Now()); | |
| 323 Dispatch(&touchev); | 286 Dispatch(&touchev); |
| 324 } | 287 } |
| 325 | 288 |
| 326 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { | 289 void EventGenerator::PressMoveAndReleaseTouchTo(const gfx::Point& point) { |
| 327 PressTouch(); | 290 PressTouch(); |
| 328 MoveTouch(point); | 291 MoveTouch(point); |
| 329 ReleaseTouch(); | 292 ReleaseTouch(); |
| 330 } | 293 } |
| 331 | 294 |
| 332 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(EventTarget* window) { | 295 void EventGenerator::PressMoveAndReleaseTouchToCenterOf(EventTarget* window) { |
| 333 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); | 296 PressMoveAndReleaseTouchTo(CenterOfWindow(window)); |
| 334 } | 297 } |
| 335 | 298 |
| 336 void EventGenerator::GestureEdgeSwipe() { | 299 void EventGenerator::GestureEdgeSwipe() { |
| 337 GestureEventDetails details(ET_GESTURE_WIN8_EDGE_SWIPE); | 300 GestureEventDetails details(ET_GESTURE_WIN8_EDGE_SWIPE); |
| 338 details.set_device_type(GestureDeviceType::DEVICE_TOUCHSCREEN); | 301 details.set_device_type(GestureDeviceType::DEVICE_TOUCHSCREEN); |
| 339 GestureEvent gesture(0, 0, 0, Now(), details); | 302 GestureEvent gesture(0, 0, 0, ui::EventTimeForNow(), details); |
| 340 Dispatch(&gesture); | 303 Dispatch(&gesture); |
| 341 } | 304 } |
| 342 | 305 |
| 343 void EventGenerator::GestureTapAt(const gfx::Point& location) { | 306 void EventGenerator::GestureTapAt(const gfx::Point& location) { |
| 344 const int kTouchId = 2; | 307 const int kTouchId = 2; |
| 345 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 308 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId, |
| 346 location, | 309 ui::EventTimeForNow()); |
| 347 kTouchId, | |
| 348 Now()); | |
| 349 Dispatch(&press); | 310 Dispatch(&press); |
| 350 | 311 |
| 351 ui::TouchEvent release( | 312 ui::TouchEvent release( |
| 352 ui::ET_TOUCH_RELEASED, location, kTouchId, | 313 ui::ET_TOUCH_RELEASED, location, kTouchId, |
| 353 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); | 314 press.time_stamp() + base::TimeDelta::FromMilliseconds(50)); |
| 354 Dispatch(&release); | 315 Dispatch(&release); |
| 355 } | 316 } |
| 356 | 317 |
| 357 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { | 318 void EventGenerator::GestureTapDownAndUp(const gfx::Point& location) { |
| 358 const int kTouchId = 3; | 319 const int kTouchId = 3; |
| 359 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, | 320 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, location, kTouchId, |
| 360 location, | 321 ui::EventTimeForNow()); |
| 361 kTouchId, | |
| 362 Now()); | |
| 363 Dispatch(&press); | 322 Dispatch(&press); |
| 364 | 323 |
| 365 ui::TouchEvent release( | 324 ui::TouchEvent release( |
| 366 ui::ET_TOUCH_RELEASED, location, kTouchId, | 325 ui::ET_TOUCH_RELEASED, location, kTouchId, |
| 367 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); | 326 press.time_stamp() + base::TimeDelta::FromMilliseconds(1000)); |
| 368 Dispatch(&release); | 327 Dispatch(&release); |
| 369 } | 328 } |
| 370 | 329 |
| 371 base::TimeDelta EventGenerator::CalculateScrollDurationForFlingVelocity( | 330 base::TimeDelta EventGenerator::CalculateScrollDurationForFlingVelocity( |
| 372 const gfx::Point& start, | 331 const gfx::Point& start, |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 386 base::Bind(&DummyCallback)); | 345 base::Bind(&DummyCallback)); |
| 387 } | 346 } |
| 388 | 347 |
| 389 void EventGenerator::GestureScrollSequenceWithCallback( | 348 void EventGenerator::GestureScrollSequenceWithCallback( |
| 390 const gfx::Point& start, | 349 const gfx::Point& start, |
| 391 const gfx::Point& end, | 350 const gfx::Point& end, |
| 392 const base::TimeDelta& step_delay, | 351 const base::TimeDelta& step_delay, |
| 393 int steps, | 352 int steps, |
| 394 const ScrollStepCallback& callback) { | 353 const ScrollStepCallback& callback) { |
| 395 const int kTouchId = 5; | 354 const int kTouchId = 5; |
| 396 base::TimeTicks timestamp = Now(); | 355 base::TimeTicks timestamp = ui::EventTimeForNow(); |
| 397 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, 0, kTouchId, | 356 ui::TouchEvent press(ui::ET_TOUCH_PRESSED, start, 0, kTouchId, |
| 398 timestamp, 5.0f, 5.0f, 0.0f, 1.0f); | 357 timestamp, 5.0f, 5.0f, 0.0f, 1.0f); |
| 399 Dispatch(&press); | 358 Dispatch(&press); |
| 400 | 359 |
| 401 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF()); | 360 callback.Run(ui::ET_GESTURE_SCROLL_BEGIN, gfx::Vector2dF()); |
| 402 | 361 |
| 403 float dx = static_cast<float>(end.x() - start.x()) / steps; | 362 float dx = static_cast<float>(end.x() - start.x()) / steps; |
| 404 float dy = static_cast<float>(end.y() - start.y()) / steps; | 363 float dy = static_cast<float>(end.y() - start.y()) / steps; |
| 405 gfx::PointF location(start); | 364 gfx::PointF location(start); |
| 406 for (int i = 0; i < steps; ++i) { | 365 for (int i = 0; i < steps; ++i) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 446 CHECK_LE(count, kMaxTouchPoints); | 405 CHECK_LE(count, kMaxTouchPoints); |
| 447 CHECK_GT(steps, 0); | 406 CHECK_GT(steps, 0); |
| 448 | 407 |
| 449 int delta_x = move_x / steps; | 408 int delta_x = move_x / steps; |
| 450 int delta_y = move_y / steps; | 409 int delta_y = move_y / steps; |
| 451 | 410 |
| 452 for (int i = 0; i < count; ++i) { | 411 for (int i = 0; i < count; ++i) { |
| 453 points[i] = start[i]; | 412 points[i] = start[i]; |
| 454 } | 413 } |
| 455 | 414 |
| 456 base::TimeTicks press_time_first = Now(); | 415 base::TimeTicks press_time_first = ui::EventTimeForNow(); |
| 457 base::TimeTicks press_time[kMaxTouchPoints]; | 416 base::TimeTicks press_time[kMaxTouchPoints]; |
| 458 bool pressed[kMaxTouchPoints]; | 417 bool pressed[kMaxTouchPoints]; |
| 459 for (int i = 0; i < count; ++i) { | 418 for (int i = 0; i < count; ++i) { |
| 460 pressed[i] = false; | 419 pressed[i] = false; |
| 461 press_time[i] = press_time_first + | 420 press_time[i] = press_time_first + |
| 462 base::TimeDelta::FromMilliseconds(delay_adding_finger_ms[i]); | 421 base::TimeDelta::FromMilliseconds(delay_adding_finger_ms[i]); |
| 463 } | 422 } |
| 464 | 423 |
| 465 int last_id = 0; | 424 int last_id = 0; |
| 466 for (int step = 0; step < steps; ++step) { | 425 for (int step = 0; step < steps; ++step) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 498 Dispatch(&release); | 457 Dispatch(&release); |
| 499 } | 458 } |
| 500 } | 459 } |
| 501 | 460 |
| 502 void EventGenerator::ScrollSequence(const gfx::Point& start, | 461 void EventGenerator::ScrollSequence(const gfx::Point& start, |
| 503 const base::TimeDelta& step_delay, | 462 const base::TimeDelta& step_delay, |
| 504 float x_offset, | 463 float x_offset, |
| 505 float y_offset, | 464 float y_offset, |
| 506 int steps, | 465 int steps, |
| 507 int num_fingers) { | 466 int num_fingers) { |
| 508 base::TimeTicks timestamp = Now(); | 467 base::TimeTicks timestamp = ui::EventTimeForNow(); |
| 509 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 468 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| 510 start, | 469 start, |
| 511 timestamp, | 470 timestamp, |
| 512 0, | 471 0, |
| 513 0, 0, | 472 0, 0, |
| 514 0, 0, | 473 0, 0, |
| 515 num_fingers); | 474 num_fingers); |
| 516 Dispatch(&fling_cancel); | 475 Dispatch(&fling_cancel); |
| 517 | 476 |
| 518 float dx = x_offset / steps; | 477 float dx = x_offset / steps; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 537 x_offset, y_offset, | 496 x_offset, y_offset, |
| 538 num_fingers); | 497 num_fingers); |
| 539 Dispatch(&fling_start); | 498 Dispatch(&fling_start); |
| 540 } | 499 } |
| 541 | 500 |
| 542 void EventGenerator::ScrollSequence(const gfx::Point& start, | 501 void EventGenerator::ScrollSequence(const gfx::Point& start, |
| 543 const base::TimeDelta& step_delay, | 502 const base::TimeDelta& step_delay, |
| 544 const std::vector<gfx::PointF>& offsets, | 503 const std::vector<gfx::PointF>& offsets, |
| 545 int num_fingers) { | 504 int num_fingers) { |
| 546 size_t steps = offsets.size(); | 505 size_t steps = offsets.size(); |
| 547 base::TimeTicks timestamp = Now(); | 506 base::TimeTicks timestamp = ui::EventTimeForNow(); |
| 548 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, | 507 ui::ScrollEvent fling_cancel(ui::ET_SCROLL_FLING_CANCEL, |
| 549 start, | 508 start, |
| 550 timestamp, | 509 timestamp, |
| 551 0, | 510 0, |
| 552 0, 0, | 511 0, 0, |
| 553 0, 0, | 512 0, 0, |
| 554 num_fingers); | 513 num_fingers); |
| 555 Dispatch(&fling_cancel); | 514 Dispatch(&fling_cancel); |
| 556 | 515 |
| 557 for (size_t i = 0; i < steps; ++i) { | 516 for (size_t i = 0; i < steps; ++i) { |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 581 } | 540 } |
| 582 | 541 |
| 583 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { | 542 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { |
| 584 DispatchKeyEvent(false, key_code, flags); | 543 DispatchKeyEvent(false, key_code, flags); |
| 585 } | 544 } |
| 586 | 545 |
| 587 void EventGenerator::Dispatch(ui::Event* event) { | 546 void EventGenerator::Dispatch(ui::Event* event) { |
| 588 DoDispatchEvent(event, async_); | 547 DoDispatchEvent(event, async_); |
| 589 } | 548 } |
| 590 | 549 |
| 591 void EventGenerator::SetTickClock(std::unique_ptr<base::TickClock> tick_clock) { | |
| 592 scoped_refptr<ClonableTickClock> clonable = | |
| 593 new ClonableTickClock(std::move(tick_clock)); | |
| 594 ui::SetEventTickClockForTesting(clonable->Clone()); | |
| 595 tick_clock_ = clonable->Clone(); | |
| 596 } | |
| 597 | |
| 598 base::TimeTicks EventGenerator::Now() { | |
| 599 // This is the same as what EventTimeForNow() does, but here we do it | |
| 600 // with a tick clock that can be replaced with a simulated clock for tests. | |
| 601 // TODO(majidvp): The tick clock used by |ui::EventTimeForNow()| is now | |
| 602 // mockable so we no longer need this. | |
| 603 return tick_clock_->NowTicks(); | |
| 604 } | |
| 605 | |
| 606 void EventGenerator::Init(gfx::NativeWindow root_window, | 550 void EventGenerator::Init(gfx::NativeWindow root_window, |
| 607 gfx::NativeWindow window_context) { | 551 gfx::NativeWindow window_context) { |
| 608 SetTickClock(WrapUnique(new TestTickClock())); | 552 ui::SetEventTickClockForTesting(WrapUnique(new TestTickClock())); |
|
sadrul
2016/06/30 14:30:11
Should you unset it from the dtor? (see https://co
majidvp
2016/07/05 01:59:47
Yes it should be. It is actually unset from dtor i
| |
| 609 delegate()->SetContext(this, root_window, window_context); | 553 delegate()->SetContext(this, root_window, window_context); |
| 610 if (window_context) | 554 if (window_context) |
| 611 current_location_ = delegate()->CenterOfWindow(window_context); | 555 current_location_ = delegate()->CenterOfWindow(window_context); |
| 612 current_target_ = delegate()->GetTargetAt(current_location_); | 556 current_target_ = delegate()->GetTargetAt(current_location_); |
| 613 } | 557 } |
| 614 | 558 |
| 615 void EventGenerator::DispatchKeyEvent(bool is_press, | 559 void EventGenerator::DispatchKeyEvent(bool is_press, |
| 616 ui::KeyboardCode key_code, | 560 ui::KeyboardCode key_code, |
| 617 int flags) { | 561 int flags) { |
| 618 #if defined(OS_WIN) | 562 #if defined(OS_WIN) |
| 619 UINT key_press = WM_KEYDOWN; | 563 UINT key_press = WM_KEYDOWN; |
| 620 uint16_t character = ui::DomCodeToUsLayoutCharacter( | 564 uint16_t character = ui::DomCodeToUsLayoutCharacter( |
| 621 ui::UsLayoutKeyboardCodeToDomCode(key_code), flags); | 565 ui::UsLayoutKeyboardCodeToDomCode(key_code), flags); |
| 622 if (is_press && character) { | 566 if (is_press && character) { |
| 623 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; | 567 MSG native_event = { NULL, WM_KEYDOWN, key_code, 0 }; |
| 624 ui::KeyEvent keyev(native_event, flags); | 568 ui::KeyEvent keyev(native_event, flags); |
| 625 Dispatch(&keyev); | 569 Dispatch(&keyev); |
| 626 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character | 570 // On Windows, WM_KEYDOWN event is followed by WM_CHAR with a character |
| 627 // if the key event cooresponds to a real character. | 571 // if the key event cooresponds to a real character. |
| 628 key_press = WM_CHAR; | 572 key_press = WM_CHAR; |
| 629 key_code = static_cast<ui::KeyboardCode>(character); | 573 key_code = static_cast<ui::KeyboardCode>(character); |
| 630 } | 574 } |
| 631 MSG native_event = | 575 MSG native_event = |
| 632 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; | 576 { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 }; |
| 633 native_event.time = (Now() - base::TimeTicks()).InMicroseconds(); | 577 native_event.time = |
| 578 (ui::EventTimeForNow() - base::TimeTicks()).InMicroseconds(); | |
| 634 ui::KeyEvent keyev(native_event, flags); | 579 ui::KeyEvent keyev(native_event, flags); |
| 635 #elif defined(USE_X11) | 580 #elif defined(USE_X11) |
| 636 ui::ScopedXI2Event xevent; | 581 ui::ScopedXI2Event xevent; |
| 637 xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, | 582 xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED, |
| 638 key_code, | 583 key_code, |
| 639 flags); | 584 flags); |
| 640 static_cast<XEvent*>(xevent)->xkey.time = | 585 static_cast<XEvent*>(xevent)->xkey.time = |
| 641 (Now() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; | 586 (ui::EventTimeForNow() - base::TimeTicks()).InMilliseconds() & UINT32_MAX; |
| 642 ui::KeyEvent keyev(xevent); | 587 ui::KeyEvent keyev(xevent); |
| 643 #else | 588 #else |
| 644 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; | 589 ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED; |
| 645 ui::KeyEvent keyev(type, key_code, flags); | 590 ui::KeyEvent keyev(type, key_code, flags); |
| 646 #endif // OS_WIN | 591 #endif // OS_WIN |
| 647 Dispatch(&keyev); | 592 Dispatch(&keyev); |
| 648 } | 593 } |
| 649 | 594 |
| 650 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { | 595 void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) { |
| 651 current_target_ = delegate()->GetTargetAt(point); | 596 current_target_ = delegate()->GetTargetAt(point); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 return default_delegate; | 673 return default_delegate; |
| 729 } | 674 } |
| 730 | 675 |
| 731 EventGeneratorDelegate* EventGenerator::delegate() { | 676 EventGeneratorDelegate* EventGenerator::delegate() { |
| 732 return const_cast<EventGeneratorDelegate*>( | 677 return const_cast<EventGeneratorDelegate*>( |
| 733 const_cast<const EventGenerator*>(this)->delegate()); | 678 const_cast<const EventGenerator*>(this)->delegate()); |
| 734 } | 679 } |
| 735 | 680 |
| 736 } // namespace test | 681 } // namespace test |
| 737 } // namespace ui | 682 } // namespace ui |
| OLD | NEW |