| 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/memory/ptr_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 class ProxyDeviceEventDispatcher : public DeviceEventDispatcherEvdev { | 35 class ProxyDeviceEventDispatcher : public DeviceEventDispatcherEvdev { |
| 36 public: | 36 public: |
| 37 ProxyDeviceEventDispatcher( | 37 ProxyDeviceEventDispatcher( |
| 38 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner, | 38 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner, |
| 39 base::WeakPtr<EventFactoryEvdev> event_factory_evdev) | 39 base::WeakPtr<EventFactoryEvdev> event_factory_evdev) |
| 40 : ui_thread_runner_(ui_thread_runner), | 40 : ui_thread_runner_(ui_thread_runner), |
| 41 event_factory_evdev_(event_factory_evdev) {} | 41 event_factory_evdev_(event_factory_evdev) {} |
| 42 ~ProxyDeviceEventDispatcher() override {} | 42 ~ProxyDeviceEventDispatcher() override {} |
| 43 | 43 |
| 44 // DeviceEventDispatcher: | 44 // DeviceEventDispatcher: |
| 45 void DispatchGamepadEvent(const GamepadEventParams& params) override { |
| 46 ui_thread_runner_->PostTask( |
| 47 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchGamepadEvent, |
| 48 event_factory_evdev_, params)); |
| 49 } |
| 45 void DispatchKeyEvent(const KeyEventParams& params) override { | 50 void DispatchKeyEvent(const KeyEventParams& params) override { |
| 46 ui_thread_runner_->PostTask(FROM_HERE, | 51 ui_thread_runner_->PostTask(FROM_HERE, |
| 47 base::Bind(&EventFactoryEvdev::DispatchKeyEvent, | 52 base::Bind(&EventFactoryEvdev::DispatchKeyEvent, |
| 48 event_factory_evdev_, params)); | 53 event_factory_evdev_, params)); |
| 49 } | 54 } |
| 50 | 55 |
| 51 void DispatchMouseMoveEvent(const MouseMoveEventParams& params) override { | 56 void DispatchMouseMoveEvent(const MouseMoveEventParams& params) override { |
| 52 ui_thread_runner_->PostTask( | 57 ui_thread_runner_->PostTask( |
| 53 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent, | 58 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent, |
| 54 event_factory_evdev_, params)); | 59 event_factory_evdev_, params)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 77 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchScrollEvent, | 82 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchScrollEvent, |
| 78 event_factory_evdev_, params)); | 83 event_factory_evdev_, params)); |
| 79 } | 84 } |
| 80 | 85 |
| 81 void DispatchTouchEvent(const TouchEventParams& params) override { | 86 void DispatchTouchEvent(const TouchEventParams& params) override { |
| 82 ui_thread_runner_->PostTask( | 87 ui_thread_runner_->PostTask( |
| 83 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchTouchEvent, | 88 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchTouchEvent, |
| 84 event_factory_evdev_, params)); | 89 event_factory_evdev_, params)); |
| 85 } | 90 } |
| 86 | 91 |
| 92 void DispatchGamepadDevicesUpdated( |
| 93 const std::vector<InputDevice>& devices) override { |
| 94 ui_thread_runner_->PostTask( |
| 95 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchGamepadDevicesUpdated, |
| 96 event_factory_evdev_, devices)); |
| 97 } |
| 98 |
| 87 void DispatchKeyboardDevicesUpdated( | 99 void DispatchKeyboardDevicesUpdated( |
| 88 const std::vector<InputDevice>& devices) override { | 100 const std::vector<InputDevice>& devices) override { |
| 89 ui_thread_runner_->PostTask( | 101 ui_thread_runner_->PostTask( |
| 90 FROM_HERE, | 102 FROM_HERE, |
| 91 base::Bind(&EventFactoryEvdev::DispatchKeyboardDevicesUpdated, | 103 base::Bind(&EventFactoryEvdev::DispatchKeyboardDevicesUpdated, |
| 92 event_factory_evdev_, devices)); | 104 event_factory_evdev_, devices)); |
| 93 } | 105 } |
| 94 void DispatchTouchscreenDevicesUpdated( | 106 void DispatchTouchscreenDevicesUpdated( |
| 95 const std::vector<TouchscreenDevice>& devices) override { | 107 const std::vector<TouchscreenDevice>& devices) override { |
| 96 ui_thread_runner_->PostTask( | 108 ui_thread_runner_->PostTask( |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // Use forwarding dispatcher for the injector rather than dispatching | 199 // Use forwarding dispatcher for the injector rather than dispatching |
| 188 // directly. We cannot assume it is safe to (re-)enter ui::Event dispatch | 200 // directly. We cannot assume it is safe to (re-)enter ui::Event dispatch |
| 189 // synchronously from the injection point. | 201 // synchronously from the injection point. |
| 190 std::unique_ptr<DeviceEventDispatcherEvdev> proxy_dispatcher( | 202 std::unique_ptr<DeviceEventDispatcherEvdev> proxy_dispatcher( |
| 191 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), | 203 new ProxyDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), |
| 192 weak_ptr_factory_.GetWeakPtr())); | 204 weak_ptr_factory_.GetWeakPtr())); |
| 193 return base::MakeUnique<InputInjectorEvdev>(std::move(proxy_dispatcher), | 205 return base::MakeUnique<InputInjectorEvdev>(std::move(proxy_dispatcher), |
| 194 cursor_); | 206 cursor_); |
| 195 } | 207 } |
| 196 | 208 |
| 209 void EventFactoryEvdev::DispatchGamepadEvent(const GamepadEventParams& params) { |
| 210 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchGamepadEvent", "device", |
| 211 params.device_id); |
| 212 GamepadEvent event(params.type, params.value, params.code, params.timestamp); |
| 213 event.set_source_device_id(params.device_id); |
| 214 DispatchUiEvent(&event); |
| 215 } |
| 216 |
| 197 void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { | 217 void EventFactoryEvdev::DispatchKeyEvent(const KeyEventParams& params) { |
| 198 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchKeyEvent", "device", | 218 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchKeyEvent", "device", |
| 199 params.device_id); | 219 params.device_id); |
| 200 keyboard_.OnKeyChange(params.code, params.down, params.suppress_auto_repeat, | 220 keyboard_.OnKeyChange(params.code, params.down, params.suppress_auto_repeat, |
| 201 params.timestamp, params.device_id); | 221 params.timestamp, params.device_id); |
| 202 } | 222 } |
| 203 | 223 |
| 204 void EventFactoryEvdev::DispatchMouseMoveEvent( | 224 void EventFactoryEvdev::DispatchMouseMoveEvent( |
| 205 const MouseMoveEventParams& params) { | 225 const MouseMoveEventParams& params) { |
| 206 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchMouseMoveEvent", "device", | 226 TRACE_EVENT1("evdev", "EventFactoryEvdev::DispatchMouseMoveEvent", "device", |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 touch_id_generator_.ReleaseGeneratedID(touch_event.pointer_details().id); | 368 touch_id_generator_.ReleaseGeneratedID(touch_event.pointer_details().id); |
| 349 } | 369 } |
| 350 } | 370 } |
| 351 | 371 |
| 352 void EventFactoryEvdev::DispatchUiEvent(Event* event) { | 372 void EventFactoryEvdev::DispatchUiEvent(Event* event) { |
| 353 // DispatchEvent takes PlatformEvent which is void*. This function | 373 // DispatchEvent takes PlatformEvent which is void*. This function |
| 354 // wraps it with the real type. | 374 // wraps it with the real type. |
| 355 DispatchEvent(event); | 375 DispatchEvent(event); |
| 356 } | 376 } |
| 357 | 377 |
| 378 void EventFactoryEvdev::DispatchGamepadDevicesUpdated( |
| 379 const std::vector<InputDevice>& devices) { |
| 380 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchGamepadDevicesUpdated"); |
| 381 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| 382 observer->OnGamepadDevicesUpdated(devices); |
| 383 } |
| 384 |
| 358 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated( | 385 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated( |
| 359 const std::vector<InputDevice>& devices) { | 386 const std::vector<InputDevice>& devices) { |
| 360 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchKeyboardDevicesUpdated"); | 387 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchKeyboardDevicesUpdated"); |
| 361 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | 388 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| 362 observer->OnKeyboardDevicesUpdated(devices); | 389 observer->OnKeyboardDevicesUpdated(devices); |
| 363 } | 390 } |
| 364 | 391 |
| 365 void EventFactoryEvdev::DispatchTouchscreenDevicesUpdated( | 392 void EventFactoryEvdev::DispatchTouchscreenDevicesUpdated( |
| 366 const std::vector<TouchscreenDevice>& devices) { | 393 const std::vector<TouchscreenDevice>& devices) { |
| 367 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchTouchscreenDevicesUpdated"); | 394 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchTouchscreenDevicesUpdated"); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 | 495 |
| 469 // Scan & monitor devices. | 496 // Scan & monitor devices. |
| 470 device_manager_->AddObserver(this); | 497 device_manager_->AddObserver(this); |
| 471 device_manager_->ScanDevices(this); | 498 device_manager_->ScanDevices(this); |
| 472 | 499 |
| 473 // Notify device thread that initial scan is done. | 500 // Notify device thread that initial scan is done. |
| 474 input_device_factory_proxy_->OnStartupScanComplete(); | 501 input_device_factory_proxy_->OnStartupScanComplete(); |
| 475 } | 502 } |
| 476 | 503 |
| 477 } // namespace ui | 504 } // namespace ui |
| OLD | NEW |