Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(937)

Side by Side Diff: ui/events/ozone/evdev/event_factory_evdev.cc

Issue 2805793002: ozone: evdev: Add gamepad support (Closed)
Patch Set: Support Gamepad in Ozone. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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
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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 touch_event.set_root_location_f(location); 357 touch_event.set_root_location_f(location);
343 touch_event.set_source_device_id(params.device_id); 358 touch_event.set_source_device_id(params.device_id);
344 touch_event.set_pointer_details(details); 359 touch_event.set_pointer_details(details);
345 DispatchUiEvent(&touch_event); 360 DispatchUiEvent(&touch_event);
346 361
347 if (params.type == ET_TOUCH_RELEASED || params.type == ET_TOUCH_CANCELLED) { 362 if (params.type == ET_TOUCH_RELEASED || params.type == ET_TOUCH_CANCELLED) {
348 touch_id_generator_.ReleaseGeneratedID(touch_event.pointer_details().id); 363 touch_id_generator_.ReleaseGeneratedID(touch_event.pointer_details().id);
349 } 364 }
350 } 365 }
351 366
367 void EventFactoryEvdev::DispatchGamepadEvent(const GamepadEvent& event) {
368 gamepad_provider_->DispatchGamepadEvent(event);
369 }
370
352 void EventFactoryEvdev::DispatchUiEvent(Event* event) { 371 void EventFactoryEvdev::DispatchUiEvent(Event* event) {
353 // DispatchEvent takes PlatformEvent which is void*. This function 372 // DispatchEvent takes PlatformEvent which is void*. This function
354 // wraps it with the real type. 373 // wraps it with the real type.
355 DispatchEvent(event); 374 DispatchEvent(event);
356 } 375 }
357 376
358 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated( 377 void EventFactoryEvdev::DispatchKeyboardDevicesUpdated(
359 const std::vector<InputDevice>& devices) { 378 const std::vector<InputDevice>& devices) {
360 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchKeyboardDevicesUpdated"); 379 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchKeyboardDevicesUpdated");
361 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); 380 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); 413 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
395 observer->OnDeviceListsComplete(); 414 observer->OnDeviceListsComplete();
396 } 415 }
397 416
398 void EventFactoryEvdev::DispatchStylusStateChanged(StylusState stylus_state) { 417 void EventFactoryEvdev::DispatchStylusStateChanged(StylusState stylus_state) {
399 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchStylusStateChanged"); 418 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchStylusStateChanged");
400 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); 419 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance();
401 observer->OnStylusStateChanged(stylus_state); 420 observer->OnStylusStateChanged(stylus_state);
402 }; 421 };
403 422
423 void EventFactoryEvdev::DispatchGamepadDevicesUpdated(
424 const std::vector<InputDevice>& devices) {
425 TRACE_EVENT0("evdev", "EventFactoryEvdev::DispatchGamepadDevicesUpdated");
426 gamepad_provider_->DispatchGamepadDevicesUpdated(devices);
427 }
428
404 void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) { 429 void EventFactoryEvdev::OnDeviceEvent(const DeviceEvent& event) {
405 if (event.device_type() != DeviceEvent::INPUT) 430 if (event.device_type() != DeviceEvent::INPUT)
406 return; 431 return;
407 432
408 switch (event.action_type()) { 433 switch (event.action_type()) {
409 case DeviceEvent::ADD: 434 case DeviceEvent::ADD:
410 case DeviceEvent::CHANGE: { 435 case DeviceEvent::CHANGE: {
411 TRACE_EVENT1("evdev", "EventFactoryEvdev::OnDeviceAdded", "path", 436 TRACE_EVENT1("evdev", "EventFactoryEvdev::OnDeviceAdded", "path",
412 event.path().value()); 437 event.path().value());
413 input_device_factory_proxy_->AddInputDevice(NextDeviceId(), event.path()); 438 input_device_factory_proxy_->AddInputDevice(NextDeviceId(), event.path());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 493
469 // Scan & monitor devices. 494 // Scan & monitor devices.
470 device_manager_->AddObserver(this); 495 device_manager_->AddObserver(this);
471 device_manager_->ScanDevices(this); 496 device_manager_->ScanDevices(this);
472 497
473 // Notify device thread that initial scan is done. 498 // Notify device thread that initial scan is done.
474 input_device_factory_proxy_->OnStartupScanComplete(); 499 input_device_factory_proxy_->OnStartupScanComplete();
475 } 500 }
476 501
477 } // namespace ui 502 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698