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 "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/debug/trace_event.h" | 8 #include "base/debug/trace_event.h" |
9 #include "base/task_runner.h" | 9 #include "base/task_runner.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
11 #include "base/threading/worker_pool.h" | 11 #include "base/threading/worker_pool.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "ui/events/devices/device_data_manager.h" | 13 #include "ui/events/devices/device_data_manager.h" |
14 #include "ui/events/devices/input_device.h" | 14 #include "ui/events/devices/input_device.h" |
15 #include "ui/events/ozone/device/device_event.h" | 15 #include "ui/events/ozone/device/device_event.h" |
16 #include "ui/events/ozone/device/device_manager.h" | 16 #include "ui/events/ozone/device/device_manager.h" |
17 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 17 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
18 #include "ui/events/ozone/evdev/input_controller_evdev.h" | 18 #include "ui/events/ozone/evdev/input_controller_evdev.h" |
19 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" | 19 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" |
20 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h" | 20 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h" |
21 #include "ui/events/ozone/evdev/input_injector_evdev.h" | 21 #include "ui/events/ozone/evdev/input_injector_evdev.h" |
22 | 22 |
23 namespace ui { | 23 namespace ui { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Thread safe dispatcher proxy for EventFactoryEvdev. | 27 // Thread safe dispatcher proxy for EventFactoryEvdev. |
| 28 // |
| 29 // This is used on the device I/O thread for dispatching to UI. |
28 class ProxyDeviceEventDispatcher : public DeviceEventDispatcherEvdev { | 30 class ProxyDeviceEventDispatcher : public DeviceEventDispatcherEvdev { |
29 public: | 31 public: |
30 ProxyDeviceEventDispatcher( | 32 ProxyDeviceEventDispatcher( |
31 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner, | 33 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner, |
32 base::WeakPtr<EventFactoryEvdev> event_factory_evdev) | 34 base::WeakPtr<EventFactoryEvdev> event_factory_evdev) |
33 : ui_thread_runner_(ui_thread_runner), | 35 : ui_thread_runner_(ui_thread_runner), |
34 event_factory_evdev_(event_factory_evdev) {} | 36 event_factory_evdev_(event_factory_evdev) {} |
35 ~ProxyDeviceEventDispatcher() override {} | 37 ~ProxyDeviceEventDispatcher() override {} |
36 | 38 |
37 // DeviceEventDispatcher: | 39 // DeviceEventDispatcher: |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 weak_ptr_factory_(this) { | 123 weak_ptr_factory_(this) { |
122 DCHECK(device_manager_); | 124 DCHECK(device_manager_); |
123 } | 125 } |
124 | 126 |
125 EventFactoryEvdev::~EventFactoryEvdev() { | 127 EventFactoryEvdev::~EventFactoryEvdev() { |
126 } | 128 } |
127 | 129 |
128 void EventFactoryEvdev::Init() { | 130 void EventFactoryEvdev::Init() { |
129 DCHECK(!initialized_); | 131 DCHECK(!initialized_); |
130 | 132 |
131 // Set up device factory. | 133 StartThread(); |
132 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher( | |
133 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), | |
134 weak_ptr_factory_.GetWeakPtr())); | |
135 input_device_factory_.reset( | |
136 new InputDeviceFactoryEvdev(dispatcher.Pass(), cursor_)); | |
137 input_device_factory_proxy_.reset( | |
138 new InputDeviceFactoryEvdevProxy(base::ThreadTaskRunnerHandle::Get(), | |
139 input_device_factory_->GetWeakPtr())); | |
140 | |
141 // TODO(spang): This settings interface is really broken. crbug.com/450899 | |
142 input_controller_.SetInputDeviceFactory(input_device_factory_proxy_.get()); | |
143 | |
144 // Scan & monitor devices. | |
145 device_manager_->AddObserver(this); | |
146 device_manager_->ScanDevices(this); | |
147 | 134 |
148 initialized_ = true; | 135 initialized_ = true; |
149 } | 136 } |
150 | 137 |
151 scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { | 138 scoped_ptr<SystemInputInjector> EventFactoryEvdev::CreateSystemInputInjector() { |
152 // Use forwarding dispatcher for the injector rather than dispatching | 139 // Use forwarding dispatcher for the injector rather than dispatching |
153 // directly. We cannot assume it is safe to (re-)enter ui::Event dispatch | 140 // directly. We cannot assume it is safe to (re-)enter ui::Event dispatch |
154 // synchronously from the injection point. | 141 // synchronously from the injection point. |
155 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher( | 142 scoped_ptr<DeviceEventDispatcherEvdev> proxy_dispatcher( |
156 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), | 143 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), |
157 weak_ptr_factory_.GetWeakPtr())); | 144 weak_ptr_factory_.GetWeakPtr())); |
158 return make_scoped_ptr(new InputInjectorEvdev(dispatcher.Pass(), cursor_)); | 145 return make_scoped_ptr( |
| 146 new InputInjectorEvdev(proxy_dispatcher.Pass(), cursor_)); |
159 } | 147 } |
160 | 148 |
161 void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { | 149 void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { |
162 keyboard_.OnKeyChange(params.code, params.down); | 150 keyboard_.OnKeyChange(params.code, params.down); |
163 } | 151 } |
164 | 152 |
165 void EventFactoryEvdev::DispatchMouseMoveEvent( | 153 void EventFactoryEvdev::DispatchMouseMoveEvent( |
166 const MouseMoveEventParams& params) { | 154 const MouseMoveEventParams& params) { |
167 MouseEvent event(ui::ET_MOUSE_MOVED, params.location, params.location, | 155 MouseEvent event(ui::ET_MOUSE_MOVED, params.location, params.location, |
168 modifiers_.GetModifierFlags(), | 156 modifiers_.GetModifierFlags(), |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent, | 298 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent, |
311 weak_ptr_factory_.GetWeakPtr(), | 299 weak_ptr_factory_.GetWeakPtr(), |
312 MouseMoveEventParams(-1 /* device_id */, | 300 MouseMoveEventParams(-1 /* device_id */, |
313 cursor_->GetLocation()))); | 301 cursor_->GetLocation()))); |
314 } | 302 } |
315 | 303 |
316 int EventFactoryEvdev::NextDeviceId() { | 304 int EventFactoryEvdev::NextDeviceId() { |
317 return ++last_device_id_; | 305 return ++last_device_id_; |
318 } | 306 } |
319 | 307 |
| 308 void EventFactoryEvdev::StartThread() { |
| 309 // Set up device factory. |
| 310 scoped_ptr<DeviceEventDispatcherEvdev> proxy_dispatcher( |
| 311 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), |
| 312 weak_ptr_factory_.GetWeakPtr())); |
| 313 thread_.Start(proxy_dispatcher.Pass(), cursor_, |
| 314 base::Bind(&EventFactoryEvdev::OnThreadStarted, |
| 315 weak_ptr_factory_.GetWeakPtr())); |
| 316 } |
| 317 |
| 318 void EventFactoryEvdev::OnThreadStarted( |
| 319 scoped_ptr<InputDeviceFactoryEvdevProxy> input_device_factory) { |
| 320 input_device_factory_proxy_ = input_device_factory.Pass(); |
| 321 |
| 322 // TODO(spang): This settings interface is really broken. crbug.com/450899 |
| 323 input_controller_.SetInputDeviceFactory(input_device_factory_proxy_.get()); |
| 324 |
| 325 // Scan & monitor devices. |
| 326 device_manager_->AddObserver(this); |
| 327 device_manager_->ScanDevices(this); |
| 328 } |
| 329 |
320 } // namespace ui | 330 } // namespace ui |
OLD | NEW |