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 <fcntl.h> | 7 #include <fcntl.h> |
8 #include <linux/input.h> | 8 #include <linux/input.h> |
9 | 9 |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 } | 189 } |
190 break; | 190 break; |
191 case DeviceEvent::REMOVE: { | 191 case DeviceEvent::REMOVE: { |
192 TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value()); | 192 TRACE_EVENT1("ozone", "OnDeviceRemoved", "path", event.path().value()); |
193 DetachInputDevice(event.path()); | 193 DetachInputDevice(event.path()); |
194 } | 194 } |
195 break; | 195 break; |
196 } | 196 } |
197 } | 197 } |
198 | 198 |
| 199 void EventFactoryEvdev::OnDispatcherListChanged() { |
| 200 if (ui_task_runner_) |
| 201 return; |
| 202 ui_task_runner_ = base::MessageLoopProxy::current(); |
| 203 StartProcessingEvents(); |
| 204 } |
| 205 |
199 void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { | 206 void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
200 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); | 207 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); |
201 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 208 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
202 | 209 |
203 // Remove device from map. | 210 // Remove device from map. |
204 scoped_ptr<EventConverterEvdev> converter(converters_[path]); | 211 scoped_ptr<EventConverterEvdev> converter(converters_[path]); |
205 converters_.erase(path); | 212 converters_.erase(path); |
206 | 213 |
207 if (converter) { | 214 if (converter) { |
208 // Cancel libevent notifications from this converter. This part must be | 215 // Cancel libevent notifications from this converter. This part must be |
209 // on UI since the polling happens on UI. | 216 // on UI since the polling happens on UI. |
210 converter->Stop(); | 217 converter->Stop(); |
211 | 218 |
212 // Dispatch task to close from the worker pool, since close may block. | 219 // Dispatch task to close from the worker pool, since close may block. |
213 base::WorkerPool::PostTask( | 220 base::WorkerPool::PostTask( |
214 FROM_HERE, | 221 FROM_HERE, |
215 base::Bind(&CloseInputDevice, path, base::Passed(&converter)), | 222 base::Bind(&CloseInputDevice, path, base::Passed(&converter)), |
216 true); | 223 true); |
217 } | 224 } |
218 } | 225 } |
219 | 226 |
220 void EventFactoryEvdev::StartProcessingEvents() { | 227 void EventFactoryEvdev::StartProcessingEvents() { |
| 228 if (!ui_task_runner_) |
| 229 return; |
221 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 230 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
222 | 231 |
223 if (device_manager_ && !has_started_processing_events_) { | 232 if (device_manager_ && !has_started_processing_events_) { |
224 has_started_processing_events_ = true; | 233 has_started_processing_events_ = true; |
225 // Scan & monitor devices. | 234 // Scan & monitor devices. |
226 device_manager_->AddObserver(this); | 235 device_manager_->AddObserver(this); |
227 device_manager_->ScanDevices(this); | 236 device_manager_->ScanDevices(this); |
228 } | 237 } |
229 } | 238 } |
230 | 239 |
231 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, | 240 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, |
232 const gfx::PointF& location) { | 241 const gfx::PointF& location) { |
233 if (cursor_) { | 242 if (cursor_) { |
234 cursor_->MoveCursorTo(widget, location); | 243 cursor_->MoveCursorTo(widget, location); |
235 MouseEvent mouse_event(ET_MOUSE_MOVED, | 244 MouseEvent mouse_event(ET_MOUSE_MOVED, |
236 cursor_->location(), | 245 cursor_->location(), |
237 cursor_->location(), | 246 cursor_->location(), |
238 modifiers_.GetModifierFlags(), | 247 modifiers_.GetModifierFlags(), |
239 /* changed_button_flags */ 0); | 248 /* changed_button_flags */ 0); |
240 DispatchEvent(&mouse_event); | 249 DispatchEvent(&mouse_event); |
241 } | 250 } |
242 } | 251 } |
243 | 252 |
244 } // namespace ui | 253 } // namespace ui |
OLD | NEW |