| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 converter.reset(); | 143 converter.reset(); |
| 144 } | 144 } |
| 145 | 145 |
| 146 } // namespace | 146 } // namespace |
| 147 | 147 |
| 148 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, | 148 EventFactoryEvdev::EventFactoryEvdev(CursorDelegateEvdev* cursor, |
| 149 DeviceManager* device_manager) | 149 DeviceManager* device_manager) |
| 150 : last_device_id_(0), | 150 : last_device_id_(0), |
| 151 device_manager_(device_manager), | 151 device_manager_(device_manager), |
| 152 dispatch_callback_( | 152 dispatch_callback_( |
| 153 base::Bind(base::IgnoreResult(&EventFactoryEvdev::DispatchUiEvent), | 153 base::Bind(&EventFactoryEvdev::PostUiEvent, base::Unretained(this))), |
| 154 base::Unretained(this))), | |
| 155 keyboard_(&modifiers_, dispatch_callback_), | 154 keyboard_(&modifiers_, dispatch_callback_), |
| 156 cursor_(cursor), | 155 cursor_(cursor), |
| 157 weak_ptr_factory_(this) { | 156 weak_ptr_factory_(this) { |
| 158 DCHECK(device_manager_); | 157 DCHECK(device_manager_); |
| 159 } | 158 } |
| 160 | 159 |
| 161 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 160 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } |
| 162 | 161 |
| 163 void EventFactoryEvdev::DispatchUiEvent(Event* event) { | 162 void EventFactoryEvdev::PostUiEvent(scoped_ptr<Event> event) { |
| 164 DispatchEvent(event); | 163 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 164 FROM_HERE, |
| 165 base::Bind(&EventFactoryEvdev::DispatchUiEventTask, |
| 166 weak_ptr_factory_.GetWeakPtr(), |
| 167 base::Passed(&event))); |
| 168 } |
| 169 |
| 170 void EventFactoryEvdev::DispatchUiEventTask(scoped_ptr<Event> event) { |
| 171 DispatchEvent(event.get()); |
| 165 } | 172 } |
| 166 | 173 |
| 167 void EventFactoryEvdev::AttachInputDevice( | 174 void EventFactoryEvdev::AttachInputDevice( |
| 168 scoped_ptr<EventConverterEvdev> converter) { | 175 scoped_ptr<EventConverterEvdev> converter) { |
| 169 const base::FilePath& path = converter->path(); | 176 const base::FilePath& path = converter->path(); |
| 170 | 177 |
| 171 TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); | 178 TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); |
| 172 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); | 179 DCHECK(ui_task_runner_->RunsTasksOnCurrentThread()); |
| 173 | 180 |
| 174 // If we have an existing device, detach it. We don't want two | 181 // If we have an existing device, detach it. We don't want two |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 FROM_HERE, | 257 FROM_HERE, |
| 251 base::Bind(&CloseInputDevice, path, base::Passed(&converter)), | 258 base::Bind(&CloseInputDevice, path, base::Passed(&converter)), |
| 252 true); | 259 true); |
| 253 } | 260 } |
| 254 } | 261 } |
| 255 | 262 |
| 256 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, | 263 void EventFactoryEvdev::WarpCursorTo(gfx::AcceleratedWidget widget, |
| 257 const gfx::PointF& location) { | 264 const gfx::PointF& location) { |
| 258 if (cursor_) { | 265 if (cursor_) { |
| 259 cursor_->MoveCursorTo(widget, location); | 266 cursor_->MoveCursorTo(widget, location); |
| 260 MouseEvent mouse_event(ET_MOUSE_MOVED, | 267 PostUiEvent(make_scoped_ptr(new MouseEvent(ET_MOUSE_MOVED, |
| 261 cursor_->location(), | 268 cursor_->location(), |
| 262 cursor_->location(), | 269 cursor_->location(), |
| 263 modifiers_.GetModifierFlags(), | 270 modifiers_.GetModifierFlags(), |
| 264 /* changed_button_flags */ 0); | 271 /* changed_button_flags */ 0))); |
| 265 DispatchEvent(&mouse_event); | |
| 266 } | 272 } |
| 267 } | 273 } |
| 268 | 274 |
| 269 void EventFactoryEvdev::NotifyHotplugEventObserver( | 275 void EventFactoryEvdev::NotifyHotplugEventObserver( |
| 270 const EventConverterEvdev& converter) { | 276 const EventConverterEvdev& converter) { |
| 271 // For now the only information propagated is related to touchscreens. Ignore | 277 // For now the only information propagated is related to touchscreens. Ignore |
| 272 // events for everything but touchscreens. | 278 // events for everything but touchscreens. |
| 273 if (!converter.HasTouchscreen()) | 279 if (!converter.HasTouchscreen()) |
| 274 return; | 280 return; |
| 275 | 281 |
| 276 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | 282 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| 277 std::vector<TouchscreenDevice> touchscreens; | 283 std::vector<TouchscreenDevice> touchscreens; |
| 278 for (auto it = converters_.begin(); it != converters_.end(); ++it) { | 284 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 279 if (it->second->HasTouchscreen()) { | 285 if (it->second->HasTouchscreen()) { |
| 280 touchscreens.push_back(TouchscreenDevice(it->second->id(), | 286 touchscreens.push_back(TouchscreenDevice(it->second->id(), |
| 281 it->second->GetTouchscreenSize(), | 287 it->second->GetTouchscreenSize(), |
| 282 false /* is_internal */)); | 288 false /* is_internal */)); |
| 283 } | 289 } |
| 284 } | 290 } |
| 285 | 291 |
| 286 observer->OnTouchscreenDevicesUpdated(touchscreens); | 292 observer->OnTouchscreenDevicesUpdated(touchscreens); |
| 287 } | 293 } |
| 288 | 294 |
| 289 int EventFactoryEvdev::NextDeviceId() { | 295 int EventFactoryEvdev::NextDeviceId() { |
| 290 return ++last_device_id_; | 296 return ++last_device_id_; |
| 291 } | 297 } |
| 292 | 298 |
| 293 } // namespace ui | 299 } // namespace ui |
| OLD | NEW |