| 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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); | 127 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); |
| 128 converter.reset(); | 128 converter.reset(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 } // namespace | 131 } // namespace |
| 132 | 132 |
| 133 EventFactoryEvdev::EventFactoryEvdev( | 133 EventFactoryEvdev::EventFactoryEvdev( |
| 134 CursorDelegateEvdev* cursor, | 134 CursorDelegateEvdev* cursor, |
| 135 DeviceManager* device_manager) | 135 DeviceManager* device_manager) |
| 136 : device_manager_(device_manager), | 136 : device_manager_(device_manager), |
| 137 has_started_processing_events_(false), | |
| 138 ui_task_runner_(base::MessageLoopProxy::current()), | |
| 139 cursor_(cursor), | 137 cursor_(cursor), |
| 140 dispatch_callback_( | 138 dispatch_callback_( |
| 141 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), | 139 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), |
| 142 base::Unretained(this))), | 140 base::Unretained(this))), |
| 143 weak_ptr_factory_(this) {} | 141 weak_ptr_factory_(this) { |
| 142 CHECK(device_manager_); |
| 143 } |
| 144 | 144 |
| 145 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 145 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } |
| 146 | 146 |
| 147 void EventFactoryEvdev::DispatchUiEvent(Event* event) { | 147 void EventFactoryEvdev::DispatchUiEvent(Event* event) { |
| 148 DispatchEvent(event); | 148 DispatchEvent(event); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void EventFactoryEvdev::AttachInputDevice( | 151 void EventFactoryEvdev::AttachInputDevice( |
| 152 const base::FilePath& path, | 152 const base::FilePath& path, |
| 153 scoped_ptr<EventConverterEvdev> converter) { | 153 scoped_ptr<EventConverterEvdev> converter) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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() { | 199 void EventFactoryEvdev::OnDispatcherListChanged() { |
| 200 if (ui_task_runner_) | 200 if (!ui_task_runner_) { |
| 201 return; | 201 ui_task_runner_ = base::MessageLoopProxy::current(); |
| 202 ui_task_runner_ = base::MessageLoopProxy::current(); | 202 // Scan & monitor devices. |
| 203 StartProcessingEvents(); | 203 device_manager_->AddObserver(this); |
| 204 device_manager_->ScanDevices(this); |
| 205 } |
| 204 } | 206 } |
| 205 | 207 |
| 206 void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { | 208 void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
| 207 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); | 209 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); |
| 208 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 210 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 209 | 211 |
| 210 // Remove device from map. | 212 // Remove device from map. |
| 211 scoped_ptr<EventConverterEvdev> converter(converters_[path]); | 213 scoped_ptr<EventConverterEvdev> converter(converters_[path]); |
| 212 converters_.erase(path); | 214 converters_.erase(path); |
| 213 | 215 |
| 214 if (converter) { | 216 if (converter) { |
| 215 // Cancel libevent notifications from this converter. This part must be | 217 // Cancel libevent notifications from this converter. This part must be |
| 216 // on UI since the polling happens on UI. | 218 // on UI since the polling happens on UI. |
| 217 converter->Stop(); | 219 converter->Stop(); |
| 218 | 220 |
| 219 // Dispatch task to close from the worker pool, since close may block. | 221 // Dispatch task to close from the worker pool, since close may block. |
| 220 base::WorkerPool::PostTask( | 222 base::WorkerPool::PostTask( |
| 221 FROM_HERE, | 223 FROM_HERE, |
| 222 base::Bind(&CloseInputDevice, path, base::Passed(&converter)), | 224 base::Bind(&CloseInputDevice, path, base::Passed(&converter)), |
| 223 true); | 225 true); |
| 224 } | 226 } |
| 225 } | 227 } |
| 226 | 228 |
| 227 void EventFactoryEvdev::StartProcessingEvents() { | |
| 228 if (!ui_task_runner_) | |
| 229 return; | |
| 230 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | |
| 231 | |
| 232 if (device_manager_ && !has_started_processing_events_) { | |
| 233 has_started_processing_events_ = true; | |
| 234 // Scan & monitor devices. | |
| 235 device_manager_->AddObserver(this); | |
| 236 device_manager_->ScanDevices(this); | |
| 237 } | |
| 238 } | |
| 239 | |
| 240 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, | 229 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, |
| 241 const gfx::PointF& location) { | 230 const gfx::PointF& location) { |
| 242 if (cursor_) { | 231 if (cursor_) { |
| 243 cursor_->MoveCursorTo(widget, location); | 232 cursor_->MoveCursorTo(widget, location); |
| 244 MouseEvent mouse_event(ET_MOUSE_MOVED, | 233 MouseEvent mouse_event(ET_MOUSE_MOVED, |
| 245 cursor_->location(), | 234 cursor_->location(), |
| 246 cursor_->location(), | 235 cursor_->location(), |
| 247 modifiers_.GetModifierFlags(), | 236 modifiers_.GetModifierFlags(), |
| 248 /* changed_button_flags */ 0); | 237 /* changed_button_flags */ 0); |
| 249 DispatchEvent(&mouse_event); | 238 DispatchEvent(&mouse_event); |
| 250 } | 239 } |
| 251 } | 240 } |
| 252 | 241 |
| 253 } // namespace ui | 242 } // namespace ui |
| OLD | NEW |