| 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" |
| 11 #include "base/task_runner.h" | 11 #include "base/task_runner.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "base/threading/worker_pool.h" | 13 #include "base/threading/worker_pool.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
| 16 #include "ui/events/devices/device_data_manager.h" | 16 #include "ui/events/devices/device_data_manager.h" |
| 17 #include "ui/events/devices/input_device.h" | 17 #include "ui/events/devices/input_device.h" |
| 18 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
| 19 #include "ui/events/ozone/device/device_event.h" | 19 #include "ui/events/ozone/device/device_event.h" |
| 20 #include "ui/events/ozone/device/device_manager.h" | 20 #include "ui/events/ozone/device/device_manager.h" |
| 21 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 21 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| 22 #include "ui/events/ozone/evdev/input_controller_evdev.h" | 22 #include "ui/events/ozone/evdev/input_controller_evdev.h" |
| 23 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" | 23 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" |
| 24 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h" | 24 #include "ui/events/ozone/evdev/input_device_factory_evdev_proxy.h" |
| 25 #include "ui/events/ozone/evdev/input_injector_evdev.h" | 25 #include "ui/events/ozone/evdev/input_injector_evdev.h" |
| 26 #include "ui/events/ozone/evdev/touch_evdev_types.h" | 26 #include "ui/events/ozone/evdev/touch_evdev_types.h" |
| 27 #include "ui/events/ozone/gamepad/gamepad_provider_ozone.h" |
| 27 | 28 |
| 28 namespace ui { | 29 namespace ui { |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 // Thread safe dispatcher proxy for EventFactoryEvdev. | 33 // Thread safe dispatcher proxy for EventFactoryEvdev. |
| 33 // | 34 // |
| 34 // This is used on the device I/O thread for dispatching to UI. | 35 // This is used on the device I/O thread for dispatching to UI. |
| 35 class ProxyDeviceEventDispatcher : public DeviceEventDispatcherEvdev { | 36 class ProxyDeviceEventDispatcher : public DeviceEventDispatcherEvdev { |
| 36 public: | 37 public: |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchScrollEvent, | 78 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchScrollEvent, |
| 78 event_factory_evdev_, params)); | 79 event_factory_evdev_, params)); |
| 79 } | 80 } |
| 80 | 81 |
| 81 void DispatchTouchEvent(const TouchEventParams& params) override { | 82 void DispatchTouchEvent(const TouchEventParams& params) override { |
| 82 ui_thread_runner_->PostTask( | 83 ui_thread_runner_->PostTask( |
| 83 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchTouchEvent, | 84 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchTouchEvent, |
| 84 event_factory_evdev_, params)); | 85 event_factory_evdev_, params)); |
| 85 } | 86 } |
| 86 | 87 |
| 88 void DispatchGamepadEvent(const GamepadEvent& event) override { |
| 89 ui_thread_runner_->PostTask( |
| 90 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchGamepadEvent, |
| 91 event_factory_evdev_, event)); |
| 92 } |
| 93 |
| 87 void DispatchKeyboardDevicesUpdated( | 94 void DispatchKeyboardDevicesUpdated( |
| 88 const std::vector<InputDevice>& devices) override { | 95 const std::vector<InputDevice>& devices) override { |
| 89 ui_thread_runner_->PostTask( | 96 ui_thread_runner_->PostTask( |
| 90 FROM_HERE, | 97 FROM_HERE, |
| 91 base::Bind(&EventFactoryEvdev::DispatchKeyboardDevicesUpdated, | 98 base::Bind(&EventFactoryEvdev::DispatchKeyboardDevicesUpdated, |
| 92 event_factory_evdev_, devices)); | 99 event_factory_evdev_, devices)); |
| 93 } | 100 } |
| 94 void DispatchTouchscreenDevicesUpdated( | 101 void DispatchTouchscreenDevicesUpdated( |
| 95 const std::vector<TouchscreenDevice>& devices) override { | 102 const std::vector<TouchscreenDevice>& devices) override { |
| 96 ui_thread_runner_->PostTask( | 103 ui_thread_runner_->PostTask( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 116 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchDeviceListsComplete, | 123 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchDeviceListsComplete, |
| 117 event_factory_evdev_)); | 124 event_factory_evdev_)); |
| 118 } | 125 } |
| 119 | 126 |
| 120 void DispatchStylusStateChanged(StylusState stylus_state) override { | 127 void DispatchStylusStateChanged(StylusState stylus_state) override { |
| 121 ui_thread_runner_->PostTask( | 128 ui_thread_runner_->PostTask( |
| 122 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchStylusStateChanged, | 129 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchStylusStateChanged, |
| 123 event_factory_evdev_, stylus_state)); | 130 event_factory_evdev_, stylus_state)); |
| 124 } | 131 } |
| 125 | 132 |
| 133 void DispatchGamepadDevicesUpdated( |
| 134 const std::vector<InputDevice>& devices) override { |
| 135 ui_thread_runner_->PostTask( |
| 136 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchGamepadDevicesUpdated, |
| 137 event_factory_evdev_, devices)); |
| 138 } |
| 139 |
| 126 private: | 140 private: |
| 127 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner_; | 141 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner_; |
| 128 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_; | 142 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_; |
| 129 }; | 143 }; |
| 130 | 144 |
| 131 template <typename T> | 145 template <typename T> |
| 132 gfx::PointF GetTransformedEventLocation(const T& params) { | 146 gfx::PointF GetTransformedEventLocation(const T& params) { |
| 133 float x = params.location.x(); | 147 float x = params.location.x(); |
| 134 float y = params.location.y(); | 148 float y = params.location.y(); |
| 135 | 149 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 153 details.radius_y = radius_y; | 167 details.radius_y = radius_y; |
| 154 return details; | 168 return details; |
| 155 } | 169 } |
| 156 | 170 |
| 157 } // namespace | 171 } // namespace |
| 158 | 172 |
| 159 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, | 173 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| 160 DeviceManager* device_manager, | 174 DeviceManager* device_manager, |
| 161 KeyboardLayoutEngine* keyboard_layout) | 175 KeyboardLayoutEngine* keyboard_layout) |
| 162 : device_manager_(device_manager), | 176 : device_manager_(device_manager), |
| 177 gamepad_provider_(GamepadProviderOzone::GetInstance()), |
| 163 keyboard_(&modifiers_, | 178 keyboard_(&modifiers_, |
| 164 keyboard_layout, | 179 keyboard_layout, |
| 165 base::Bind(&EventFactoryEvdev::DispatchUiEvent, | 180 base::Bind(&EventFactoryEvdev::DispatchUiEvent, |
| 166 base::Unretained(this))), | 181 base::Unretained(this))), |
| 167 cursor_(cursor), | 182 cursor_(cursor), |
| 168 input_controller_(&keyboard_, &button_map_), | 183 input_controller_(&keyboard_, &button_map_), |
| 169 touch_id_generator_(0), | 184 touch_id_generator_(0), |
| 170 weak_ptr_factory_(this) { | 185 weak_ptr_factory_(this) { |
| 171 DCHECK(device_manager_); | 186 DCHECK(device_manager_); |
| 172 } | 187 } |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 339 touch_event.set_location_f(location); | 354 touch_event.set_location_f(location); |
| 340 touch_event.set_root_location_f(location); | 355 touch_event.set_root_location_f(location); |
| 341 touch_event.set_source_device_id(params.device_id); | 356 touch_event.set_source_device_id(params.device_id); |
| 342 DispatchUiEvent(&touch_event); | 357 DispatchUiEvent(&touch_event); |
| 343 | 358 |
| 344 if (params.type == ET_TOUCH_RELEASED || params.type == ET_TOUCH_CANCELLED) { | 359 if (params.type == ET_TOUCH_RELEASED || params.type == ET_TOUCH_CANCELLED) { |
| 345 touch_id_generator_.ReleaseGeneratedID(touch_event.pointer_details().id); | 360 touch_id_generator_.ReleaseGeneratedID(touch_event.pointer_details().id); |
| 346 } | 361 } |
| 347 } | 362 } |
| 348 | 363 |
| 364 void EventFactoryEvdev::DispatchGamepadEvent(const GamepadEvent& event) { |
| 365 gamepad_provider_->DispatchGamepadEvent(event); |
| 366 } |
| 367 |
| 349 void EventFactoryEvdev::DispatchUiEvent(Event* event) { | 368 void EventFactoryEvdev::DispatchUiEvent(Event* event) { |
| 350 // DispatchEvent takes PlatformEvent which is void*. This function | 369 // DispatchEvent takes PlatformEvent which is void*. This function |
| 351 // wraps it with the real type. | 370 // wraps it with the real type. |
| 352 DispatchEvent(event); | 371 DispatchEvent(event); |
| 353 } | 372 } |
| 354 | 373 |
| 355 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated( | 374 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated( |
| 356 const std::vector<InputDevice>& devices) { | 375 const std::vector<InputDevice>& devices) { |
| 357 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchKeyboardDevicesUpdated"); | 376 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchKeyboardDevicesUpdated"); |
| 358 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | 377 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | 410 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| 392 observer->OnDeviceListsComplete(); | 411 observer->OnDeviceListsComplete(); |
| 393 } | 412 } |
| 394 | 413 |
| 395 void EventFactoryEvdev::DispatchStylusStateChanged(StylusState stylus_state) { | 414 void EventFactoryEvdev::DispatchStylusStateChanged(StylusState stylus_state) { |
| 396 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchStylusStateChanged"); | 415 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchStylusStateChanged"); |
| 397 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | 416 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| 398 observer->OnStylusStateChanged(stylus_state); | 417 observer->OnStylusStateChanged(stylus_state); |
| 399 }; | 418 }; |
| 400 | 419 |
| 420 void EventFactoryEvdev::DispatchGamepadDevicesUpdated( |
| 421 const std::vector<InputDevice>& devices) { |
| 422 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchGamepadDevicesUpdated"); |
| 423 gamepad_provider_->DispatchGamepadDevicesUpdated(devices); |
| 424 } |
| 425 |
| 401 void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { | 426 void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { |
| 402 if (event.device_type() != DeviceEvent::INPUT) | 427 if (event.device_type() != DeviceEvent::INPUT) |
| 403 return; | 428 return; |
| 404 | 429 |
| 405 switch (event.action_type()) { | 430 switch (event.action_type()) { |
| 406 case DeviceEvent::ADD: | 431 case DeviceEvent::ADD: |
| 407 case DeviceEvent::CHANGE: { | 432 case DeviceEvent::CHANGE: { |
| 408 TRACE_EVENT1("evdev", "EventFactoryEvdev::OnDeviceAdded", "path", | 433 TRACE_EVENT1("evdev", "EventFactoryEvdev::OnDeviceAdded", "path", |
| 409 event.path().value()); | 434 event.path().value()); |
| 410 input_device_factory_proxy_->AddInputDevice(NextDeviceId(), event.path()); | 435 input_device_factory_proxy_->AddInputDevice(NextDeviceId(), event.path()); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 | 490 |
| 466 // Scan & monitor devices. | 491 // Scan & monitor devices. |
| 467 device_manager_->AddObserver(this); | 492 device_manager_->AddObserver(this); |
| 468 device_manager_->ScanDevices(this); | 493 device_manager_->ScanDevices(this); |
| 469 | 494 |
| 470 // Notify device thread that initial scan is done. | 495 // Notify device thread that initial scan is done. |
| 471 input_device_factory_proxy_->OnStartupScanComplete(); | 496 input_device_factory_proxy_->OnStartupScanComplete(); |
| 472 } | 497 } |
| 473 | 498 |
| 474 } // namespace ui | 499 } // namespace ui |
| OLD | NEW |