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 "ui/events/devices/device_data_manager.h" | 12 #include "ui/events/devices/device_data_manager.h" |
13 #include "ui/events/devices/input_device.h" | 13 #include "ui/events/devices/input_device.h" |
14 #include "ui/events/ozone/device/device_event.h" | 14 #include "ui/events/ozone/device/device_event.h" |
15 #include "ui/events/ozone/device/device_manager.h" | 15 #include "ui/events/ozone/device/device_manager.h" |
16 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 16 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
17 #include "ui/events/ozone/evdev/input_controller_evdev.h" | 17 #include "ui/events/ozone/evdev/input_controller_evdev.h" |
18 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" | 18 #include "ui/events/ozone/evdev/input_device_factory_evdev.h" |
19 #include "ui/events/ozone/evdev/input_injector_evdev.h" | 19 #include "ui/events/ozone/evdev/input_injector_evdev.h" |
20 | 20 |
21 namespace ui { | 21 namespace ui { |
22 | 22 |
23 namespace { | |
24 | |
25 class ForwardingDeviceEventDispatcher : public DeviceEventDispatcherEvdev { | |
alexst (slow to review)
2015/01/28 18:35:30
DeviceEventDispatcherProxy?
| |
26 public: | |
27 ForwardingDeviceEventDispatcher( | |
28 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner, | |
29 base::WeakPtr<EventFactoryEvdev> event_factory_evdev) | |
30 : ui_thread_runner_(ui_thread_runner), | |
31 event_factory_evdev_(event_factory_evdev) {} | |
32 ~ForwardingDeviceEventDispatcher() override {} | |
33 | |
34 // DeviceEventDispatcher: | |
35 void DispatchKeyEvent(int device_id, unsigned int code, bool down) override { | |
36 ui_thread_runner_->PostTask( | |
37 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchKeyEvent, | |
38 event_factory_evdev_, device_id, code, down)); | |
39 } | |
40 | |
41 void DispatchMouseMoveEvent(int device_id, | |
42 const gfx::PointF& location) override { | |
43 ui_thread_runner_->PostTask( | |
44 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseMoveEvent, | |
45 event_factory_evdev_, device_id, location)); | |
46 } | |
47 | |
48 void DispatchMouseButtonEvent(int device_id, | |
49 const gfx::PointF& location, | |
50 unsigned int button, | |
51 bool down, | |
52 bool allow_remap) override { | |
53 ui_thread_runner_->PostTask( | |
54 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseButtonEvent, | |
55 event_factory_evdev_, device_id, location, button, | |
56 down, allow_remap)); | |
57 } | |
58 | |
59 void DispatchMouseWheelEvent(int device_id, | |
60 const gfx::PointF& location, | |
61 const gfx::Vector2d& delta) override { | |
62 ui_thread_runner_->PostTask( | |
63 FROM_HERE, | |
64 base::Bind(&EventFactoryEvdev::DispatchMouseWheelEvent, | |
65 event_factory_evdev_, device_id, location, delta)); | |
66 } | |
67 | |
68 void DispatchScrollEvent(const ScrollEventParams& params) override { | |
69 ui_thread_runner_->PostTask( | |
70 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchScrollEvent, | |
71 event_factory_evdev_, params)); | |
72 } | |
73 | |
74 void DispatchTouchEvent(const TouchEventParams& params) override { | |
75 ui_thread_runner_->PostTask( | |
76 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchTouchEvent, | |
77 event_factory_evdev_, params)); | |
78 } | |
79 | |
80 void DispatchKeyboardDevicesUpdated( | |
81 const std::vector<KeyboardDevice>& devices) override { | |
82 ui_thread_runner_->PostTask( | |
83 FROM_HERE, | |
84 base::Bind(&EventFactoryEvdev::DispatchKeyboardDevicesUpdated, | |
85 event_factory_evdev_, devices)); | |
86 } | |
87 void DispatchTouchscreenDevicesUpdated( | |
88 const std::vector<TouchscreenDevice>& devices) override { | |
89 ui_thread_runner_->PostTask( | |
90 FROM_HERE, | |
91 base::Bind(&EventFactoryEvdev::DispatchTouchscreenDevicesUpdated, | |
92 event_factory_evdev_, devices)); | |
93 } | |
94 void DispatchMouseDevicesUpdated( | |
95 const std::vector<InputDevice>& devices) override { | |
96 ui_thread_runner_->PostTask( | |
97 FROM_HERE, base::Bind(&EventFactoryEvdev::DispatchMouseDevicesUpdated, | |
98 event_factory_evdev_, devices)); | |
99 } | |
100 void DispatchTouchpadDevicesUpdated( | |
101 const std::vector<InputDevice>& devices) override { | |
102 ui_thread_runner_->PostTask( | |
103 FROM_HERE, | |
104 base::Bind(&EventFactoryEvdev::DispatchTouchpadDevicesUpdated, | |
105 event_factory_evdev_, devices)); | |
106 } | |
107 | |
108 private: | |
109 scoped_refptr<base::SingleThreadTaskRunner> ui_thread_runner_; | |
110 base::WeakPtr<EventFactoryEvdev> event_factory_evdev_; | |
111 }; | |
112 | |
113 } // namespace | |
114 | |
23 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, | 115 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
24 DeviceManager* device_manager, | 116 DeviceManager* device_manager, |
25 KeyboardLayoutEngine* keyboard_layout) | 117 KeyboardLayoutEngine* keyboard_layout) |
26 : last_device_id_(0), | 118 : last_device_id_(0), |
27 device_manager_(device_manager), | 119 device_manager_(device_manager), |
28 dispatch_callback_( | 120 dispatch_callback_( |
29 base::Bind(&EventFactoryEvdev::PostUiEvent, base::Unretained(this))), | 121 base::Bind(&EventFactoryEvdev::PostUiEvent, base::Unretained(this))), |
30 keyboard_(&modifiers_, keyboard_layout, dispatch_callback_), | 122 keyboard_(&modifiers_, keyboard_layout, dispatch_callback_), |
31 cursor_(cursor), | 123 cursor_(cursor), |
32 input_controller_(&keyboard_, &button_map_), | 124 input_controller_(&keyboard_, &button_map_), |
33 initialized_(false), | 125 initialized_(false), |
34 weak_ptr_factory_(this) { | 126 weak_ptr_factory_(this) { |
35 DCHECK(device_manager_); | 127 DCHECK(device_manager_); |
36 } | 128 } |
37 | 129 |
38 EventFactoryEvdev::~EventFactoryEvdev() { | 130 EventFactoryEvdev::~EventFactoryEvdev() { |
39 } | 131 } |
40 | 132 |
41 void EventFactoryEvdev::Init() { | 133 void EventFactoryEvdev::Init() { |
42 DCHECK(!initialized_); | 134 DCHECK(!initialized_); |
43 | 135 |
44 // Set up device factory. | 136 // Set up device factory. |
45 input_device_factory_.reset(new InputDeviceFactoryEvdev( | 137 scoped_ptr<DeviceEventDispatcherEvdev> dispatcher( |
46 this, base::ThreadTaskRunnerHandle::Get(), cursor_)); | 138 new ForwardingDeviceEventDispatcher(base::ThreadTaskRunnerHandle::Get(), |
139 weak_ptr_factory_.GetWeakPtr())); | |
140 input_device_factory_.reset( | |
141 new InputDeviceFactoryEvdev(dispatcher.Pass(), cursor_)); | |
142 | |
47 // TODO(spang): This settings interface is really broken. crbug.com/450899 | 143 // TODO(spang): This settings interface is really broken. crbug.com/450899 |
48 input_controller_.SetInputDeviceFactory(input_device_factory_.get()); | 144 input_controller_.SetInputDeviceFactory(input_device_factory_.get()); |
49 | 145 |
50 // Scan & monitor devices. | 146 // Scan & monitor devices. |
51 device_manager_->AddObserver(this); | 147 device_manager_->AddObserver(this); |
52 device_manager_->ScanDevices(this); | 148 device_manager_->ScanDevices(this); |
53 | 149 |
54 initialized_ = true; | 150 initialized_ = true; |
55 } | 151 } |
56 | 152 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 modifiers_.GetModifierFlags(), | 317 modifiers_.GetModifierFlags(), |
222 /* changed_button_flags */ 0))); | 318 /* changed_button_flags */ 0))); |
223 } | 319 } |
224 } | 320 } |
225 | 321 |
226 int EventFactoryEvdev::NextDeviceId() { | 322 int EventFactoryEvdev::NextDeviceId() { |
227 return ++last_device_id_; | 323 return ++last_device_id_; |
228 } | 324 } |
229 | 325 |
230 } // namespace ui | 326 } // namespace ui |
OLD | NEW |