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/ozone/evdev/event_factory_evdev.h" | 5 #include "ui/events/ozone/evdev/event_factory_evdev.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/ptr_util.h" |
10 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
11 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
12 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
13 #include "base/time/time.h" | 14 #include "base/time/time.h" |
14 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
15 #include "ui/events/devices/device_data_manager.h" | 16 #include "ui/events/devices/device_data_manager.h" |
16 #include "ui/events/devices/input_device.h" | 17 #include "ui/events/devices/input_device.h" |
17 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
18 #include "ui/events/ozone/device/device_event.h" | 19 #include "ui/events/ozone/device/device_event.h" |
19 #include "ui/events/ozone/device/device_manager.h" | 20 #include "ui/events/ozone/device/device_manager.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 143 } |
143 | 144 |
144 void EventFactoryEvdev::Init() { | 145 void EventFactoryEvdev::Init() { |
145 DCHECK(!initialized_); | 146 DCHECK(!initialized_); |
146 | 147 |
147 StartThread(); | 148 StartThread(); |
148 | 149 |
149 initialized_ = true; | 150 initialized_ = true; |
150 } | 151 } |
151 | 152 |
152 scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { | 153 std::unique_ptr<SystemInputInjector> |
| 154 EventFactoryEvdev::CreateSystemInputInjector() { |
153 // Use forwarding dispatcher for the injector rather than dispatching | 155 // Use forwarding dispatcher for the injector rather than dispatching |
154 // directly. We cannot assume it is safe to (re-)enter ui::Event dispatch | 156 // directly. We cannot assume it is safe to (re-)enter ui::Event dispatch |
155 // synchronously from the injection point. | 157 // synchronously from the injection point. |
156 scoped_ptr<DeviceEventDispatcherEvdev> proxy_dispatcher( | 158 std::unique_ptr<DeviceEventDispatcherEvdev> proxy_dispatcher( |
157 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), | 159 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), |
158 weak_ptr_factory_.GetWeakPtr())); | 160 weak_ptr_factory_.GetWeakPtr())); |
159 return make_scoped_ptr( | 161 return base::WrapUnique( |
160 new InputInjectorEvdev(std::move(proxy_dispatcher), cursor_)); | 162 new InputInjectorEvdev(std::move(proxy_dispatcher), cursor_)); |
161 } | 163 } |
162 | 164 |
163 void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { | 165 void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { |
164 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchKeyEvent", "device", | 166 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchKeyEvent", "device", |
165 params.device_id); | 167 params.device_id); |
166 keyboard_.OnKeyChange(params.code, params.down, params.suppress_auto_repeat, | 168 keyboard_.OnKeyChange(params.code, params.down, params.suppress_auto_repeat, |
167 params.timestamp, params.device_id); | 169 params.timestamp, params.device_id); |
168 } | 170 } |
169 | 171 |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
397 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), | 399 PointerDetails(EventPointerType::POINTER_TYPE_MOUSE), |
398 EventTimeForNow()))); | 400 EventTimeForNow()))); |
399 } | 401 } |
400 | 402 |
401 int EventFactoryEvdev::NextDeviceId() { | 403 int EventFactoryEvdev::NextDeviceId() { |
402 return ++last_device_id_; | 404 return ++last_device_id_; |
403 } | 405 } |
404 | 406 |
405 void EventFactoryEvdev::StartThread() { | 407 void EventFactoryEvdev::StartThread() { |
406 // Set up device factory. | 408 // Set up device factory. |
407 scoped_ptr<DeviceEventDispatcherEvdev> proxy_dispatcher( | 409 std::unique_ptr<DeviceEventDispatcherEvdev> proxy_dispatcher( |
408 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), | 410 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), |
409 weak_ptr_factory_.GetWeakPtr())); | 411 weak_ptr_factory_.GetWeakPtr())); |
410 thread_.Start(std::move(proxy_dispatcher), cursor_, | 412 thread_.Start(std::move(proxy_dispatcher), cursor_, |
411 base::Bind(&EventFactoryEvdev::OnThreadStarted, | 413 base::Bind(&EventFactoryEvdev::OnThreadStarted, |
412 weak_ptr_factory_.GetWeakPtr())); | 414 weak_ptr_factory_.GetWeakPtr())); |
413 } | 415 } |
414 | 416 |
415 void EventFactoryEvdev::OnThreadStarted( | 417 void EventFactoryEvdev::OnThreadStarted( |
416 scoped_ptr<InputDeviceFactoryEvdevProxy> input_device_factory) { | 418 std::unique_ptr<InputDeviceFactoryEvdevProxy> input_device_factory) { |
417 TRACE_EVENT0("evdev", "EventFactoryEvdev::OnThreadStarted"); | 419 TRACE_EVENT0("evdev", "EventFactoryEvdev::OnThreadStarted"); |
418 input_device_factory_proxy_ = std::move(input_device_factory); | 420 input_device_factory_proxy_ = std::move(input_device_factory); |
419 | 421 |
420 // Hook up device configuration. | 422 // Hook up device configuration. |
421 input_controller_.SetInputDeviceFactory(input_device_factory_proxy_.get()); | 423 input_controller_.SetInputDeviceFactory(input_device_factory_proxy_.get()); |
422 | 424 |
423 // Scan & monitor devices. | 425 // Scan & monitor devices. |
424 device_manager_->AddObserver(this); | 426 device_manager_->AddObserver(this); |
425 device_manager_->ScanDevices(this); | 427 device_manager_->ScanDevices(this); |
426 | 428 |
427 // Notify device thread that initial scan is done. | 429 // Notify device thread that initial scan is done. |
428 input_device_factory_proxy_->OnStartupScanComplete(); | 430 input_device_factory_proxy_->OnStartupScanComplete(); |
429 } | 431 } |
430 | 432 |
431 } // namespace ui | 433 } // namespace ui |
OLD | NEW |