| 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 EventFactoryEvdev::EventFactoryEvdev( | 134 EventFactoryEvdev::EventFactoryEvdev( |
| 135 CursorDelegateEvdev* cursor, | 135 CursorDelegateEvdev* cursor, |
| 136 DeviceManager* device_manager) | 136 DeviceManager* device_manager) |
| 137 : device_manager_(device_manager), | 137 : device_manager_(device_manager), |
| 138 cursor_(cursor), | 138 cursor_(cursor), |
| 139 dispatch_callback_( | 139 dispatch_callback_( |
| 140 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), | 140 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), |
| 141 base::Unretained(this))), | 141 base::Unretained(this))), |
| 142 weak_ptr_factory_(this) { | 142 weak_ptr_factory_(this) { |
| 143 CHECK(device_manager_); | 143 DCHECK(device_manager_); |
| 144 } | 144 } |
| 145 | 145 |
| 146 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 146 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } |
| 147 | 147 |
| 148 void EventFactoryEvdev::DispatchUiEvent(Event* event) { | 148 void EventFactoryEvdev::DispatchUiEvent(Event* event) { |
| 149 DispatchEvent(event); | 149 DispatchEvent(event); |
| 150 } | 150 } |
| 151 | 151 |
| 152 void EventFactoryEvdev::AttachInputDevice( | 152 void EventFactoryEvdev::AttachInputDevice( |
| 153 const base::FilePath& path, | 153 const base::FilePath& path, |
| 154 scoped_ptr<EventConverterEvdev> converter) { | 154 scoped_ptr<EventConverterEvdev> converter) { |
| 155 TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); | 155 TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); |
| 156 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 156 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 157 | 157 |
| 158 // If we have an existing device, detach it. We don't want two | 158 // If we have an existing device, detach it. We don't want two |
| 159 // devices with the same name open at the same time. | 159 // devices with the same name open at the same time. |
| 160 if (converters_[path]) | 160 if (converters_[path]) |
| 161 DetachInputDevice(path); | 161 DetachInputDevice(path); |
| 162 | 162 |
| 163 // Add initialized device to map. | 163 // Add initialized device to map. |
| 164 converters_[path] = converter.release(); | 164 converters_[path] = converter.release(); |
| 165 converters_[path]->Start(); | 165 converters_[path]->Start(); |
| 166 } | 166 } |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 if (!ui_task_runner_.get()) { | 201 if (!ui_task_runner_.get()) { |
| 202 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); | 202 ui_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 203 // Scan & monitor devices. | 203 // Scan & monitor devices. |
| 204 device_manager_->AddObserver(this); | 204 device_manager_->AddObserver(this); |
| 205 device_manager_->ScanDevices(this); | 205 device_manager_->ScanDevices(this); |
| 206 } | 206 } |
| 207 } | 207 } |
| 208 | 208 |
| 209 void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { | 209 void EventFactoryEvdev::DetachInputDevice(const base::FilePath& path) { |
| 210 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); | 210 TRACE_EVENT1("ozone", "DetachInputDevice", "path", path.value()); |
| 211 CHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 211 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 212 | 212 |
| 213 // Remove device from map. | 213 // Remove device from map. |
| 214 scoped_ptr<EventConverterEvdev> converter(converters_[path]); | 214 scoped_ptr<EventConverterEvdev> converter(converters_[path]); |
| 215 converters_.erase(path); | 215 converters_.erase(path); |
| 216 | 216 |
| 217 if (converter) { | 217 if (converter) { |
| 218 // Cancel libevent notifications from this converter. This part must be | 218 // Cancel libevent notifications from this converter. This part must be |
| 219 // on UI since the polling happens on UI. | 219 // on UI since the polling happens on UI. |
| 220 converter->Stop(); | 220 converter->Stop(); |
| 221 | 221 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 234 MouseEvent mouse_event(ET_MOUSE_MOVED, | 234 MouseEvent mouse_event(ET_MOUSE_MOVED, |
| 235 cursor_->location(), | 235 cursor_->location(), |
| 236 cursor_->location(), | 236 cursor_->location(), |
| 237 modifiers_.GetModifierFlags(), | 237 modifiers_.GetModifierFlags(), |
| 238 /* changed_button_flags */ 0); | 238 /* changed_button_flags */ 0); |
| 239 DispatchEvent(&mouse_event); | 239 DispatchEvent(&mouse_event); |
| 240 } | 240 } |
| 241 } | 241 } |
| 242 | 242 |
| 243 } // namespace ui | 243 } // namespace ui |
| OLD | NEW |