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