| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 1.0f, | 72 1.0f, |
| 73 0.0f, | 73 0.0f, |
| 74 0.0f) {} | 74 0.0f) {} |
| 75 | 75 |
| 76 private: | 76 private: |
| 77 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); | 77 DISALLOW_COPY_AND_ASSIGN(TestTouchEvent); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; | 80 const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON; |
| 81 | 81 |
| 82 void ConvertToPenPointerEvent(ui::TouchEvent* event) { | |
| 83 auto details = event->pointer_details(); | |
| 84 details.pointer_type = ui::EventPointerType::POINTER_TYPE_PEN; | |
| 85 event->set_pointer_details(details); | |
| 86 } | |
| 87 | |
| 88 } // namespace | 82 } // namespace |
| 89 | 83 |
| 90 EventGeneratorDelegate* EventGenerator::default_delegate = NULL; | 84 EventGeneratorDelegate* EventGenerator::default_delegate = NULL; |
| 91 | 85 |
| 92 EventGenerator::EventGenerator(gfx::NativeWindow root_window) | 86 EventGenerator::EventGenerator(gfx::NativeWindow root_window) |
| 93 : current_target_(NULL), | 87 : current_target_(NULL), |
| 94 flags_(0), | 88 flags_(0), |
| 95 grab_(false), | 89 grab_(false), |
| 96 async_(false), | 90 async_(false), |
| 97 target_(Target::WIDGET) { | 91 target_(Target::WIDGET) { |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 PressLeftButton(); | 254 PressLeftButton(); |
| 261 MoveMouseTo(point); | 255 MoveMouseTo(point); |
| 262 ReleaseLeftButton(); | 256 ReleaseLeftButton(); |
| 263 } | 257 } |
| 264 | 258 |
| 265 void EventGenerator::MoveMouseToCenterOf(EventTarget* window) { | 259 void EventGenerator::MoveMouseToCenterOf(EventTarget* window) { |
| 266 MoveMouseTo(CenterOfWindow(window)); | 260 MoveMouseTo(CenterOfWindow(window)); |
| 267 } | 261 } |
| 268 | 262 |
| 269 void EventGenerator::EnterPenPointerMode() { | 263 void EventGenerator::EnterPenPointerMode() { |
| 270 pen_pointer_mode_ = true; | 264 touch_pointer_details_.pointer_type = ui::EventPointerType::POINTER_TYPE_PEN; |
| 271 } | 265 } |
| 272 | 266 |
| 273 void EventGenerator::ExitPenPointerMode() { | 267 void EventGenerator::ExitPenPointerMode() { |
| 274 pen_pointer_mode_ = false; | 268 touch_pointer_details_.pointer_type = |
| 269 ui::EventPointerType::POINTER_TYPE_TOUCH; |
| 270 } |
| 271 |
| 272 void EventGenerator::SetTouchRadius(float x, float y) { |
| 273 touch_pointer_details_.radius_x = x; |
| 274 touch_pointer_details_.radius_y = y; |
| 275 } | 275 } |
| 276 | 276 |
| 277 void EventGenerator::PressTouch() { | 277 void EventGenerator::PressTouch() { |
| 278 PressTouchId(0); | 278 PressTouchId(0); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void EventGenerator::PressTouchId(int touch_id) { | 281 void EventGenerator::PressTouchId(int touch_id) { |
| 282 TestTouchEvent touchev(ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), | 282 TestTouchEvent touchev(ui::ET_TOUCH_PRESSED, GetLocationInCurrentRoot(), |
| 283 touch_id, flags_, ui::EventTimeForNow()); | 283 touch_id, flags_, ui::EventTimeForNow()); |
| 284 Dispatch(&touchev); | 284 Dispatch(&touchev); |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 DoDispatchEvent(event, async_); | 578 DoDispatchEvent(event, async_); |
| 579 } | 579 } |
| 580 | 580 |
| 581 void EventGenerator::Init(gfx::NativeWindow root_window, | 581 void EventGenerator::Init(gfx::NativeWindow root_window, |
| 582 gfx::NativeWindow window_context) { | 582 gfx::NativeWindow window_context) { |
| 583 ui::SetEventTickClockForTesting(base::MakeUnique<TestTickClock>()); | 583 ui::SetEventTickClockForTesting(base::MakeUnique<TestTickClock>()); |
| 584 delegate()->SetContext(this, root_window, window_context); | 584 delegate()->SetContext(this, root_window, window_context); |
| 585 if (window_context) | 585 if (window_context) |
| 586 current_location_ = delegate()->CenterOfWindow(window_context); | 586 current_location_ = delegate()->CenterOfWindow(window_context); |
| 587 current_target_ = delegate()->GetTargetAt(current_location_); | 587 current_target_ = delegate()->GetTargetAt(current_location_); |
| 588 touch_pointer_details_ = |
| 589 PointerDetails(ui::EventPointerType::POINTER_TYPE_TOUCH, 1.0, 1.0, |
| 590 std::numeric_limits<float>::quiet_NaN(), 0.0, 0.0); |
| 588 } | 591 } |
| 589 | 592 |
| 590 void EventGenerator::DispatchKeyEvent(bool is_press, | 593 void EventGenerator::DispatchKeyEvent(bool is_press, |
| 591 ui::KeyboardCode key_code, | 594 ui::KeyboardCode key_code, |
| 592 int flags) { | 595 int flags) { |
| 593 #if defined(OS_WIN) | 596 #if defined(OS_WIN) |
| 594 UINT key_press = WM_KEYDOWN; | 597 UINT key_press = WM_KEYDOWN; |
| 595 uint16_t character = ui::DomCodeToUsLayoutCharacter( | 598 uint16_t character = ui::DomCodeToUsLayoutCharacter( |
| 596 ui::UsLayoutKeyboardCodeToDomCode(key_code), flags); | 599 ui::UsLayoutKeyboardCodeToDomCode(key_code), flags); |
| 597 if (is_press && character) { | 600 if (is_press && character) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 gfx::Point p(current_location_); | 656 gfx::Point p(current_location_); |
| 654 delegate()->ConvertPointToTarget(current_target_, &p); | 657 delegate()->ConvertPointToTarget(current_target_, &p); |
| 655 return p; | 658 return p; |
| 656 } | 659 } |
| 657 | 660 |
| 658 gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const { | 661 gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const { |
| 659 return delegate()->CenterOfTarget(window); | 662 return delegate()->CenterOfTarget(window); |
| 660 } | 663 } |
| 661 | 664 |
| 662 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { | 665 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { |
| 663 if (pen_pointer_mode_ && event->IsTouchEvent()) | 666 if (event->IsTouchEvent()) { |
| 664 ConvertToPenPointerEvent(static_cast<ui::TouchEvent*>(event)); | 667 static_cast<ui::TouchEvent*>(event)->set_pointer_details( |
| 668 touch_pointer_details_); |
| 669 } |
| 665 | 670 |
| 666 if (async) { | 671 if (async) { |
| 667 std::unique_ptr<ui::Event> pending_event = ui::Event::Clone(*event); | 672 std::unique_ptr<ui::Event> pending_event = ui::Event::Clone(*event); |
| 668 if (pending_events_.empty()) { | 673 if (pending_events_.empty()) { |
| 669 base::ThreadTaskRunnerHandle::Get()->PostTask( | 674 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 670 FROM_HERE, | 675 FROM_HERE, |
| 671 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 676 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
| 672 base::Unretained(this))); | 677 base::Unretained(this))); |
| 673 } | 678 } |
| 674 pending_events_.push_back(std::move(pending_event)); | 679 pending_events_.push_back(std::move(pending_event)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 707 return default_delegate; | 712 return default_delegate; |
| 708 } | 713 } |
| 709 | 714 |
| 710 EventGeneratorDelegate* EventGenerator::delegate() { | 715 EventGeneratorDelegate* EventGenerator::delegate() { |
| 711 return const_cast<EventGeneratorDelegate*>( | 716 return const_cast<EventGeneratorDelegate*>( |
| 712 const_cast<const EventGenerator*>(this)->delegate()); | 717 const_cast<const EventGenerator*>(this)->delegate()); |
| 713 } | 718 } |
| 714 | 719 |
| 715 } // namespace test | 720 } // namespace test |
| 716 } // namespace ui | 721 } // namespace ui |
| OLD | NEW |