Chromium Code Reviews| 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 <linux/input.h> | 5 #include <linux/input.h> |
| 6 | 6 |
| 7 #include "ui/events/ozone/evdev/event_converter_evdev.h" | 7 #include "ui/events/ozone/evdev/event_converter_evdev.h" |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "ui/events/devices/input_device.h" | 12 #include "ui/events/devices/input_device.h" |
| 13 | 13 |
| 14 namespace ui { | 14 namespace ui { |
| 15 | 15 |
| 16 namespace { | |
| 17 // USB vendor and product strings are pragmatically limited to 126 | |
| 18 // characters each, so device names more than twice that should be | |
| 19 // unusual. | |
| 20 const size_t kMaximumDeviceNameLength = 256; | |
| 21 } // anonymous namespace | |
| 22 | |
| 16 EventConverterEvdev::EventConverterEvdev(int fd, | 23 EventConverterEvdev::EventConverterEvdev(int fd, |
| 17 const base::FilePath& path, | 24 const base::FilePath& path, |
| 18 int id, | 25 int id, |
| 19 InputDeviceType type) | 26 InputDeviceType type) |
| 20 : fd_(fd), path_(path), id_(id), type_(type), ignore_events_(false) { | 27 : fd_(fd), |
| 28 path_(path), | |
| 29 input_device_(id, type, std::string()), | |
| 30 ignore_events_(false) { | |
| 31 char device_name[kMaximumDeviceNameLength]; | |
| 32 if (ioctl(fd, EVIOCGNAME(kMaximumDeviceNameLength - 1), &device_name) < 0) { | |
|
spang
2015/04/08 22:54:30
Can you move these to EventDeviceInfo? That's wher
kpschoedel
2015/04/09 18:51:41
Done.
| |
| 33 PLOG(INFO) << "Can't read device name for " << id; | |
| 34 } else { | |
| 35 input_device_.name = device_name; | |
| 36 } | |
| 37 struct input_id evdev_id; | |
| 38 if (ioctl(fd, EVIOCGID, &evdev_id) < 0) { | |
| 39 PLOG(INFO) << "Can't read device identification for " << id; | |
| 40 } else { | |
| 41 input_device_.vendor_id = evdev_id.vendor; | |
| 42 input_device_.product_id = evdev_id.product; | |
| 43 } | |
| 21 } | 44 } |
| 22 | 45 |
| 23 EventConverterEvdev::~EventConverterEvdev() { | 46 EventConverterEvdev::~EventConverterEvdev() { |
| 24 Stop(); | 47 Stop(); |
| 25 } | 48 } |
| 26 | 49 |
| 27 void EventConverterEvdev::Start() { | 50 void EventConverterEvdev::Start() { |
| 28 base::MessageLoopForUI::current()->WatchFileDescriptor( | 51 base::MessageLoopForUI::current()->WatchFileDescriptor( |
| 29 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this); | 52 fd_, true, base::MessagePumpLibevent::WATCH_READ, &controller_, this); |
| 30 } | 53 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 107 Stop(); | 130 Stop(); |
| 108 } | 131 } |
| 109 } | 132 } |
| 110 | 133 |
| 111 base::TimeDelta EventConverterEvdev::TimeDeltaFromInputEvent( | 134 base::TimeDelta EventConverterEvdev::TimeDeltaFromInputEvent( |
| 112 const input_event& event) { | 135 const input_event& event) { |
| 113 return base::TimeDelta::FromMicroseconds(event.time.tv_sec * 1000000 + | 136 return base::TimeDelta::FromMicroseconds(event.time.tv_sec * 1000000 + |
| 114 event.time.tv_usec); | 137 event.time.tv_usec); |
| 115 } | 138 } |
| 116 } // namespace ui | 139 } // namespace ui |
| OLD | NEW |