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 <utility> | 11 #include <utility> |
11 | 12 |
12 #include "base/bind.h" | 13 #include "base/bind.h" |
13 #include "base/location.h" | 14 #include "base/location.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/scoped_ptr.h" | |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
18 #include "base/time/tick_clock.h" | 18 #include "base/time/tick_clock.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
21 #include "ui/events/event_source.h" | 21 #include "ui/events/event_source.h" |
22 #include "ui/events/event_utils.h" | 22 #include "ui/events/event_utils.h" |
23 #include "ui/events/test/events_test_utils.h" | 23 #include "ui/events/test/events_test_utils.h" |
24 #include "ui/gfx/geometry/vector2d_conversions.h" | 24 #include "ui/gfx/geometry/vector2d_conversions.h" |
25 | 25 |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 #if defined(USE_X11) | 188 #if defined(USE_X11) |
189 ui::ScopedXI2Event xevent; | 189 ui::ScopedXI2Event xevent; |
190 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); | 190 xevent.InitMotionEvent(point_in_host, point_for_native, flags_); |
191 static_cast<XEvent*>(xevent)->xmotion.time = Now().InMicroseconds(); | 191 static_cast<XEvent*>(xevent)->xmotion.time = Now().InMicroseconds(); |
192 ui::MouseEvent mouseev(xevent); | 192 ui::MouseEvent mouseev(xevent); |
193 #elif defined(USE_OZONE) | 193 #elif defined(USE_OZONE) |
194 // Ozone uses the location in native event as a system location. | 194 // Ozone uses the location in native event as a system location. |
195 // Create a fake event with the point in host, which will be passed | 195 // Create a fake event with the point in host, which will be passed |
196 // to the non native event, then update the native event with the native | 196 // to the non native event, then update the native event with the native |
197 // (root) one. | 197 // (root) one. |
198 scoped_ptr<ui::MouseEvent> native_event(new ui::MouseEvent( | 198 std::unique_ptr<ui::MouseEvent> native_event(new ui::MouseEvent( |
199 ui::ET_MOUSE_MOVED, point_in_host, point_in_host, Now(), flags_, 0)); | 199 ui::ET_MOUSE_MOVED, point_in_host, point_in_host, Now(), flags_, 0)); |
200 ui::MouseEvent mouseev(native_event.get()); | 200 ui::MouseEvent mouseev(native_event.get()); |
201 native_event->set_location(point_for_native); | 201 native_event->set_location(point_for_native); |
202 #else | 202 #else |
203 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, point_in_host, point_for_native, | 203 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, point_in_host, point_for_native, |
204 Now(), flags_, 0); | 204 Now(), flags_, 0); |
205 LOG(FATAL) | 205 LOG(FATAL) |
206 << "Generating a native motion event is not supported on this platform"; | 206 << "Generating a native motion event is not supported on this platform"; |
207 #endif | 207 #endif |
208 Dispatch(&mouseev); | 208 Dispatch(&mouseev); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 } | 552 } |
553 | 553 |
554 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { | 554 void EventGenerator::ReleaseKey(ui::KeyboardCode key_code, int flags) { |
555 DispatchKeyEvent(false, key_code, flags); | 555 DispatchKeyEvent(false, key_code, flags); |
556 } | 556 } |
557 | 557 |
558 void EventGenerator::Dispatch(ui::Event* event) { | 558 void EventGenerator::Dispatch(ui::Event* event) { |
559 DoDispatchEvent(event, async_); | 559 DoDispatchEvent(event, async_); |
560 } | 560 } |
561 | 561 |
562 void EventGenerator::SetTickClock(scoped_ptr<base::TickClock> tick_clock) { | 562 void EventGenerator::SetTickClock(std::unique_ptr<base::TickClock> tick_clock) { |
563 tick_clock_ = std::move(tick_clock); | 563 tick_clock_ = std::move(tick_clock); |
564 } | 564 } |
565 | 565 |
566 base::TimeDelta EventGenerator::Now() { | 566 base::TimeDelta EventGenerator::Now() { |
567 // This is the same as what EventTimeForNow() does, but here we do it | 567 // This is the same as what EventTimeForNow() does, but here we do it |
568 // with a tick clock that can be replaced with a simulated clock for tests. | 568 // with a tick clock that can be replaced with a simulated clock for tests. |
569 return base::TimeDelta::FromInternalValue( | 569 return base::TimeDelta::FromInternalValue( |
570 tick_clock_->NowTicks().ToInternalValue()); | 570 tick_clock_->NowTicks().ToInternalValue()); |
571 } | 571 } |
572 | 572 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 delegate()->ConvertPointToTarget(current_target_, &p); | 643 delegate()->ConvertPointToTarget(current_target_, &p); |
644 return p; | 644 return p; |
645 } | 645 } |
646 | 646 |
647 gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const { | 647 gfx::Point EventGenerator::CenterOfWindow(const EventTarget* window) const { |
648 return delegate()->CenterOfTarget(window); | 648 return delegate()->CenterOfTarget(window); |
649 } | 649 } |
650 | 650 |
651 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { | 651 void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) { |
652 if (async) { | 652 if (async) { |
653 scoped_ptr<ui::Event> pending_event = ui::Event::Clone(*event); | 653 std::unique_ptr<ui::Event> pending_event = ui::Event::Clone(*event); |
654 if (pending_events_.empty()) { | 654 if (pending_events_.empty()) { |
655 base::ThreadTaskRunnerHandle::Get()->PostTask( | 655 base::ThreadTaskRunnerHandle::Get()->PostTask( |
656 FROM_HERE, | 656 FROM_HERE, |
657 base::Bind(&EventGenerator::DispatchNextPendingEvent, | 657 base::Bind(&EventGenerator::DispatchNextPendingEvent, |
658 base::Unretained(this))); | 658 base::Unretained(this))); |
659 } | 659 } |
660 pending_events_.push_back(std::move(pending_event)); | 660 pending_events_.push_back(std::move(pending_event)); |
661 } else { | 661 } else { |
662 if (event->IsKeyEvent()) | 662 if (event->IsKeyEvent()) |
663 delegate()->DispatchKeyEventToIME(current_target_, event->AsKeyEvent()); | 663 delegate()->DispatchKeyEventToIME(current_target_, event->AsKeyEvent()); |
(...skipping 29 matching lines...) Expand all Loading... |
693 return default_delegate; | 693 return default_delegate; |
694 } | 694 } |
695 | 695 |
696 EventGeneratorDelegate* EventGenerator::delegate() { | 696 EventGeneratorDelegate* EventGenerator::delegate() { |
697 return const_cast<EventGeneratorDelegate*>( | 697 return const_cast<EventGeneratorDelegate*>( |
698 const_cast<const EventGenerator*>(this)->delegate()); | 698 const_cast<const EventGenerator*>(this)->delegate()); |
699 } | 699 } |
700 | 700 |
701 } // namespace test | 701 } // namespace test |
702 } // namespace ui | 702 } // namespace ui |
OLD | NEW |