| 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" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/task_runner.h" | 12 #include "base/task_runner.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/worker_pool.h" | 14 #include "base/threading/worker_pool.h" |
| 15 #include "ui/events/devices/device_data_manager.h" | 15 #include "ui/events/devices/device_data_manager.h" |
| 16 #include "ui/events/devices/device_util_linux.h" |
| 17 #include "ui/events/devices/input_device.h" |
| 16 #include "ui/events/ozone/device/device_event.h" | 18 #include "ui/events/ozone/device/device_event.h" |
| 17 #include "ui/events/ozone/device/device_manager.h" | 19 #include "ui/events/ozone/device/device_manager.h" |
| 18 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" | 20 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h" |
| 19 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" | 21 #include "ui/events/ozone/evdev/event_converter_evdev_impl.h" |
| 20 #include "ui/events/ozone/evdev/input_injector_evdev.h" | 22 #include "ui/events/ozone/evdev/input_injector_evdev.h" |
| 21 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" | 23 #include "ui/events/ozone/evdev/tablet_event_converter_evdev.h" |
| 22 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" | 24 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" |
| 23 | 25 |
| 24 #if defined(USE_EVDEV_GESTURES) | 26 #if defined(USE_EVDEV_GESTURES) |
| 25 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" | 27 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 if (devinfo.HasRelXY()) | 69 if (devinfo.HasRelXY()) |
| 68 return true; // mouse | 70 return true; // mouse |
| 69 | 71 |
| 70 return false; | 72 return false; |
| 71 } | 73 } |
| 72 #endif | 74 #endif |
| 73 | 75 |
| 74 scoped_ptr<EventConverterEvdev> CreateConverter( | 76 scoped_ptr<EventConverterEvdev> CreateConverter( |
| 75 const OpenInputDeviceParams& params, | 77 const OpenInputDeviceParams& params, |
| 76 int fd, | 78 int fd, |
| 79 InputDeviceType type, |
| 77 const EventDeviceInfo& devinfo) { | 80 const EventDeviceInfo& devinfo) { |
| 78 #if defined(USE_EVDEV_GESTURES) | 81 #if defined(USE_EVDEV_GESTURES) |
| 79 // Touchpad or mouse: use gestures library. | 82 // Touchpad or mouse: use gestures library. |
| 80 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent | 83 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent |
| 81 if (UseGesturesLibraryForDevice(devinfo)) { | 84 if (UseGesturesLibraryForDevice(devinfo)) { |
| 82 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = | 85 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = |
| 83 make_scoped_ptr(new GestureInterpreterLibevdevCros( | 86 make_scoped_ptr(new GestureInterpreterLibevdevCros( |
| 84 params.id, params.modifiers, params.button_map, params.cursor, | 87 params.id, params.modifiers, params.button_map, params.cursor, |
| 85 params.keyboard, params.gesture_property_provider, | 88 params.keyboard, params.gesture_property_provider, |
| 86 params.dispatch_callback)); | 89 params.dispatch_callback)); |
| 87 return make_scoped_ptr(new EventReaderLibevdevCros( | 90 return make_scoped_ptr(new EventReaderLibevdevCros( |
| 88 fd, params.path, params.id, gesture_interp.Pass())); | 91 fd, params.path, params.id, type, gesture_interp.Pass())); |
| 89 } | 92 } |
| 90 #endif | 93 #endif |
| 91 | 94 |
| 92 // Touchscreen: use TouchEventConverterEvdev. | 95 // Touchscreen: use TouchEventConverterEvdev. |
| 93 if (devinfo.HasMTAbsXY()) { | 96 if (devinfo.HasMTAbsXY()) { |
| 94 scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( | 97 scoped_ptr<TouchEventConverterEvdev> converter(new TouchEventConverterEvdev( |
| 95 fd, params.path, params.id, params.dispatch_callback)); | 98 fd, params.path, params.id, type, params.dispatch_callback)); |
| 96 converter->Initialize(devinfo); | 99 converter->Initialize(devinfo); |
| 97 return converter.Pass(); | 100 return converter.Pass(); |
| 98 } | 101 } |
| 99 | 102 |
| 100 // Graphics tablet | 103 // Graphics tablet |
| 101 if (devinfo.HasAbsXY()) | 104 if (devinfo.HasAbsXY()) |
| 102 return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev( | 105 return make_scoped_ptr<EventConverterEvdev>(new TabletEventConverterEvdev( |
| 103 fd, params.path, params.id, params.modifiers, params.cursor, devinfo, | 106 fd, params.path, params.id, type, params.modifiers, params.cursor, |
| 104 params.dispatch_callback)); | 107 devinfo, params.dispatch_callback)); |
| 105 | 108 |
| 106 // Everything else: use EventConverterEvdevImpl. | 109 // Everything else: use EventConverterEvdevImpl. |
| 107 return make_scoped_ptr<EventConverterEvdevImpl>(new EventConverterEvdevImpl( | 110 return make_scoped_ptr<EventConverterEvdevImpl>(new EventConverterEvdevImpl( |
| 108 fd, params.path, params.id, params.modifiers, params.button_map, | 111 fd, params.path, params.id, type, params.modifiers, |
| 109 params.cursor, params.keyboard, params.dispatch_callback)); | 112 params.button_map, params.cursor, params.keyboard, |
| 113 params.dispatch_callback)); |
| 110 } | 114 } |
| 111 | 115 |
| 112 // Open an input device. Opening may put the calling thread to sleep, and | 116 // Open an input device. Opening may put the calling thread to sleep, and |
| 113 // therefore should be run on a thread where latency is not critical. We | 117 // therefore should be run on a thread where latency is not critical. We |
| 114 // run it on a thread from the worker pool. | 118 // run it on a thread from the worker pool. |
| 115 // | 119 // |
| 116 // This takes a TaskRunner and runs the reply on that thread, so that we | 120 // This takes a TaskRunner and runs the reply on that thread, so that we |
| 117 // can hop threads if necessary (back to the UI thread). | 121 // can hop threads if necessary (back to the UI thread). |
| 118 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, | 122 void OpenInputDevice(scoped_ptr<OpenInputDeviceParams> params, |
| 119 scoped_refptr<base::TaskRunner> reply_runner, | 123 scoped_refptr<base::TaskRunner> reply_runner, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 135 if (ioctl(fd, EVIOCSCLOCKID, &clk)) | 139 if (ioctl(fd, EVIOCSCLOCKID, &clk)) |
| 136 PLOG(ERROR) << "failed to set CLOCK_MONOTONIC"; | 140 PLOG(ERROR) << "failed to set CLOCK_MONOTONIC"; |
| 137 | 141 |
| 138 EventDeviceInfo devinfo; | 142 EventDeviceInfo devinfo; |
| 139 if (!devinfo.Initialize(fd)) { | 143 if (!devinfo.Initialize(fd)) { |
| 140 LOG(ERROR) << "failed to get device information for " << path.value(); | 144 LOG(ERROR) << "failed to get device information for " << path.value(); |
| 141 close(fd); | 145 close(fd); |
| 142 return; | 146 return; |
| 143 } | 147 } |
| 144 | 148 |
| 149 InputDeviceType type = GetInputDeviceTypeFromPath(path); |
| 150 |
| 145 scoped_ptr<EventConverterEvdev> converter = | 151 scoped_ptr<EventConverterEvdev> converter = |
| 146 CreateConverter(*params, fd, devinfo); | 152 CreateConverter(*params, fd, type, devinfo); |
| 147 | 153 |
| 148 // Reply with the constructed converter. | 154 // Reply with the constructed converter. |
| 149 reply_runner->PostTask(FROM_HERE, | 155 reply_runner->PostTask(FROM_HERE, |
| 150 base::Bind(reply_callback, base::Passed(&converter))); | 156 base::Bind(reply_callback, base::Passed(&converter))); |
| 151 } | 157 } |
| 152 | 158 |
| 153 // Close an input device. Closing may put the calling thread to sleep, and | 159 // Close an input device. Closing may put the calling thread to sleep, and |
| 154 // therefore should be run on a thread where latency is not critical. We | 160 // therefore should be run on a thread where latency is not critical. We |
| 155 // run it on the FILE thread. | 161 // run it on the FILE thread. |
| 156 void CloseInputDevice(const base::FilePath& path, | 162 void CloseInputDevice(const base::FilePath& path, |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 const EventConverterEvdev& converter) { | 317 const EventConverterEvdev& converter) { |
| 312 // For now the only information propagated is related to touchscreens. Ignore | 318 // For now the only information propagated is related to touchscreens. Ignore |
| 313 // events for everything but touchscreens. | 319 // events for everything but touchscreens. |
| 314 if (!converter.HasTouchscreen()) | 320 if (!converter.HasTouchscreen()) |
| 315 return; | 321 return; |
| 316 | 322 |
| 317 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); | 323 DeviceHotplugEventObserver* observer = DeviceDataManager::GetInstance(); |
| 318 std::vector<TouchscreenDevice> touchscreens; | 324 std::vector<TouchscreenDevice> touchscreens; |
| 319 for (auto it = converters_.begin(); it != converters_.end(); ++it) { | 325 for (auto it = converters_.begin(); it != converters_.end(); ++it) { |
| 320 if (it->second->HasTouchscreen()) { | 326 if (it->second->HasTouchscreen()) { |
| 321 InputDeviceType device_type = InputDeviceType::INPUT_DEVICE_EXTERNAL; | |
| 322 if (it->second->IsInternal()) | |
| 323 device_type = InputDeviceType::INPUT_DEVICE_INTERNAL; | |
| 324 | |
| 325 touchscreens.push_back( | 327 touchscreens.push_back( |
| 326 TouchscreenDevice(it->second->id(), | 328 TouchscreenDevice(it->second->id(), |
| 327 device_type, | 329 it->second->type(), |
| 328 std::string(), /* Device name */ | 330 std::string(), /* Device name */ |
| 329 it->second->GetTouchscreenSize())); | 331 it->second->GetTouchscreenSize())); |
| 330 } | 332 } |
| 331 } | 333 } |
| 332 | 334 |
| 333 observer->OnTouchscreenDevicesUpdated(touchscreens); | 335 observer->OnTouchscreenDevicesUpdated(touchscreens); |
| 334 } | 336 } |
| 335 | 337 |
| 336 int EventFactoryEvdev::NextDeviceId() { | 338 int EventFactoryEvdev::NextDeviceId() { |
| 337 return ++last_device_id_; | 339 return ++last_device_id_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 348 gesture_property_provider_->GetDeviceIdsByType(type, &ids); | 350 gesture_property_provider_->GetDeviceIdsByType(type, &ids); |
| 349 #endif | 351 #endif |
| 350 // In the future we can add other device matching logics here. | 352 // In the future we can add other device matching logics here. |
| 351 | 353 |
| 352 if (device_ids) | 354 if (device_ids) |
| 353 device_ids->assign(ids.begin(), ids.end()); | 355 device_ids->assign(ids.begin(), ids.end()); |
| 354 return !ids.empty(); | 356 return !ids.empty(); |
| 355 } | 357 } |
| 356 | 358 |
| 357 } // namespace ui | 359 } // namespace ui |
| OLD | NEW |