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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 260 PressLeftButton(); | 260 PressLeftButton(); |
| 261 MoveMouseTo(point); | 261 MoveMouseTo(point); |
| 262 ReleaseLeftButton(); | 262 ReleaseLeftButton(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void EventGenerator::MoveMouseToCenterOf(EventTarget* window) { | 265 void EventGenerator::MoveMouseToCenterOf(EventTarget* window) { |
| 266 MoveMouseTo(CenterOfWindow(window)); | 266 MoveMouseTo(CenterOfWindow(window)); |
| 267 } | 267 } |
| 268 | 268 |
| 269 void EventGenerator::EnterPenPointerMode() { | 269 void EventGenerator::EnterPenPointerMode() { |
| 270 pen_pointer_mode_ = true; | 270 pen_pointer_mode_ = true; |
|
sadrul
2016/12/07 18:00:19
Should these be updated?
denniskempin
2016/12/07 18:32:18
These are used on mouse pen events only, so they a
| |
| 271 } | 271 } |
| 272 | 272 |
| 273 void EventGenerator::ExitPenPointerMode() { | 273 void EventGenerator::ExitPenPointerMode() { |
| 274 pen_pointer_mode_ = false; | 274 pen_pointer_mode_ = false; |
| 275 } | 275 } |
| 276 | 276 |
| 277 void EventGenerator::SetTouchRadius(float x, float y) { | |
| 278 touch_pointer_details_.radius_x = x; | |
| 279 touch_pointer_details_.radius_y = y; | |
| 280 } | |
| 281 | |
| 277 void EventGenerator::PressTouch() { | 282 void EventGenerator::PressTouch() { |
| 278 PressTouchId(0); | 283 PressTouchId(0); |
| 279 } | 284 } |
| 280 | 285 |
| 281 void EventGenerator::PressTouchId(int touch_id) { | 286 void EventGenerator::PressTouchId(int touch_id) { |
| 282 TestTouchEvent touchev(ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), | 287 TestTouchEvent touchev(ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), |
| 283 touch_id, flags_, ui::EventTimeForNow()); | 288 touch_id, flags_, ui::EventTimeForNow()); |
| 284 Dispatch(&touchev); | 289 Dispatch(&touchev); |
| 285 } | 290 } |
| 286 | 291 |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 578 DoDispatchEvent(event, async_); | 583 DoDispatchEvent(event, async_); |
| 579 } | 584 } |
| 580 | 585 |
| 581 void EventGenerator::Init(gfx::NativeWindow root_window, | 586 void EventGenerator::Init(gfx::NativeWindow root_window, |
| 582 gfx::NativeWindow window_context) { | 587 gfx::NativeWindow window_context) { |
| 583 ui::SetEventTickClockForTesting(base::MakeUnique<TestTickClock>()); | 588 ui::SetEventTickClockForTesting(base::MakeUnique<TestTickClock>()); |
| 584 delegate()->SetContext(this, root_window, window_context); | 589 delegate()->SetContext(this, root_window, window_context); |
| 585 if (window_context) | 590 if (window_context) |
| 586 current_location_ = delegate()->CenterOfWindow(window_context); | 591 current_location_ = delegate()->CenterOfWindow(window_context); |
| 587 current_target_ = delegate()->GetTargetAt(current_location_); | 592 current_target_ = delegate()->GetTargetAt(current_location_); |
| 593 touch_pointer_details_ = | |
| 594 PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1.0, 1.0, | |
| 595 std::numeric_limits<float>::quiet_NaN(), 0.0, 0.0); | |
| 588 } | 596 } |
| 589 | 597 |
| 590 void EventGenerator::DispatchKeyEvent(bool is_press, | 598 void EventGenerator::DispatchKeyEvent(bool is_press, |
| 591 ui::KeyboardCode key_code, | 599 ui::KeyboardCode key_code, |
| 592 int flags) { | 600 int flags) { |
| 593 #if defined(OS_WIN) | 601 #if defined(OS_WIN) |
| 594 UINT key_press = WM_KEYDOWN; | 602 UINT key_press = WM_KEYDOWN; |
| 595 uint16_t character = ui::DomCodeToUsLayoutCharacter( | 603 uint16_t character = ui::DomCodeToUsLayoutCharacter( |
| 596 ui::UsLayoutKeyboardCodeToDomCode(key_code), flags); | 604 ui::UsLayoutKeyboardCodeToDomCode(key_code), flags); |
| 597 if (is_press && character) { | 605 if (is_press && character) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 656 } | 664 } |
| 657 | 665 |
| 658 gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const { | 666 gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const { |
| 659 return delegate()->CenterOfTarget(window); | 667 return delegate()->CenterOfTarget(window); |
| 660 } | 668 } |
| 661 | 669 |
| 662 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { | 670 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { |
| 663 if (pen_pointer_mode_ && event->IsMouseEvent()) | 671 if (pen_pointer_mode_ && event->IsMouseEvent()) |
| 664 ConvertToPenPointerEvent(static_cast<ui::MouseEvent*>(event)); | 672 ConvertToPenPointerEvent(static_cast<ui::MouseEvent*>(event)); |
| 665 | 673 |
| 674 if (event->IsTouchEvent()) { | |
| 675 static_cast<ui::TouchEvent*>(event)->set_pointer_details( | |
| 676 touch_pointer_details_); | |
| 677 } | |
| 678 | |
| 666 if (async) { | 679 if (async) { |
| 667 std::unique_ptr<ui::Event> pending_event = ui::Event::Clone(*event); | 680 std::unique_ptr<ui::Event> pending_event = ui::Event::Clone(*event); |
| 668 if (pending_events_.empty()) { | 681 if (pending_events_.empty()) { |
| 669 base::ThreadTaskRunnerHandle::Get()->PostTask( | 682 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 670 FROM_HERE, | 683 FROM_HERE, |
| 671 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 684 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 672 base::Unretained(this))); | 685 base::Unretained(this))); |
| 673 } | 686 } |
| 674 pending_events_.push_back(std::move(pending_event)); | 687 pending_events_.push_back(std::move(pending_event)); |
| 675 } else { | 688 } else { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 707 return default_delegate; | 720 return default_delegate; |
| 708 } | 721 } |
| 709 | 722 |
| 710 EventGeneratorDelegate* EventGenerator::delegate() { | 723 EventGeneratorDelegate* EventGenerator::delegate() { |
| 711 return const_cast<EventGeneratorDelegate*>( | 724 return const_cast<EventGeneratorDelegate*>( |
| 712 const_cast<const EventGenerator*>(this)->delegate()); | 725 const_cast<const EventGenerator*>(this)->delegate()); |
| 713 } | 726 } |
| 714 | 727 |
| 715 } // namespace test | 728 } // namespace test |
| 716 } // namespace ui | 729 } // namespace ui |
| OLD | NEW |