| OLD | NEW | 
|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.h" | 5 #include "ui/events/ozone/evdev/event_factory.h" | 
| 6 | 6 | 
| 7 #include <errno.h> | 7 #include <errno.h> | 
| 8 #include <fcntl.h> | 8 #include <fcntl.h> | 
| 9 #include <linux/input.h> | 9 #include <linux/input.h> | 
| 10 #include <poll.h> | 10 #include <poll.h> | 
| 11 #include <unistd.h> | 11 #include <unistd.h> | 
| 12 | 12 | 
| 13 #include "base/debug/trace_event.h" | 13 #include "base/debug/trace_event.h" | 
| 14 #include "base/files/file_enumerator.h" | 14 #include "base/files/file_enumerator.h" | 
|  | 15 #include "base/stl_util.h" | 
| 15 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" | 
| 16 #include "base/threading/thread_restrictions.h" | 17 #include "base/threading/thread_restrictions.h" | 
| 17 #include "ui/events/ozone/evdev/event_device_info.h" | 18 #include "ui/events/ozone/evdev/event_device_info.h" | 
| 18 #include "ui/events/ozone/evdev/key_event_converter.h" | 19 #include "ui/events/ozone/evdev/key_event_converter.h" | 
| 19 #include "ui/events/ozone/evdev/touch_event_converter.h" | 20 #include "ui/events/ozone/evdev/touch_event_converter.h" | 
| 20 #include "ui/events/ozone/event_factory_ozone.h" | 21 #include "ui/events/ozone/event_factory_ozone.h" | 
| 21 | 22 | 
| 22 namespace ui { | 23 namespace ui { | 
| 23 | 24 | 
| 24 namespace { | 25 namespace { | 
| 25 | 26 | 
| 26 bool IsTouchPad(const EventDeviceInfo& devinfo) { | 27 bool IsTouchPad(const EventDeviceInfo& devinfo) { | 
| 27   if (!devinfo.HasEventType(EV_ABS)) | 28   if (!devinfo.HasEventType(EV_ABS)) | 
| 28     return false; | 29     return false; | 
| 29 | 30 | 
| 30   return devinfo.HasKeyEvent(BTN_LEFT) || devinfo.HasKeyEvent(BTN_MIDDLE) || | 31   return devinfo.HasKeyEvent(BTN_LEFT) || devinfo.HasKeyEvent(BTN_MIDDLE) || | 
| 31          devinfo.HasKeyEvent(BTN_RIGHT) || devinfo.HasKeyEvent(BTN_TOOL_FINGER); | 32          devinfo.HasKeyEvent(BTN_RIGHT) || devinfo.HasKeyEvent(BTN_TOOL_FINGER); | 
| 32 } | 33 } | 
| 33 | 34 | 
| 34 bool IsTouchScreen(const EventDeviceInfo& devinfo) { | 35 bool IsTouchScreen(const EventDeviceInfo& devinfo) { | 
| 35   return devinfo.HasEventType(EV_ABS) && !IsTouchPad(devinfo); | 36   return devinfo.HasEventType(EV_ABS) && !IsTouchPad(devinfo); | 
| 36 } | 37 } | 
| 37 | 38 | 
| 38 }  // namespace | 39 }  // namespace | 
| 39 | 40 | 
| 40 EventFactoryEvdev::EventFactoryEvdev() {} | 41 EventFactoryEvdev::EventFactoryEvdev() {} | 
| 41 | 42 | 
| 42 EventFactoryEvdev::~EventFactoryEvdev() {} | 43 EventFactoryEvdev::~EventFactoryEvdev() { STLDeleteValues(&converters_); } | 
| 43 | 44 | 
| 44 void EventFactoryEvdev::AttachInputDevice(const base::FilePath& path) { | 45 void EventFactoryEvdev::AttachInputDevice(const base::FilePath& path) { | 
| 45   TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); | 46   TRACE_EVENT1("ozone", "AttachInputDevice", "path", path.value()); | 
| 46 | 47 | 
| 47   int fd = open(path.value().c_str(), O_RDONLY | O_NONBLOCK); | 48   int fd = open(path.value().c_str(), O_RDONLY | O_NONBLOCK); | 
| 48   if (fd < 0) { | 49   if (fd < 0) { | 
| 49     PLOG(ERROR) << "Cannot open '" << path.value(); | 50     PLOG(ERROR) << "Cannot open '" << path.value(); | 
| 50     return; | 51     return; | 
| 51   } | 52   } | 
| 52 | 53 | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
| 64   } | 65   } | 
| 65 | 66 | 
| 66   // TODO(spang) Add more device types. Support hot-plugging. | 67   // TODO(spang) Add more device types. Support hot-plugging. | 
| 67   scoped_ptr<EventConverterOzone> converter; | 68   scoped_ptr<EventConverterOzone> converter; | 
| 68   if (IsTouchScreen(devinfo)) | 69   if (IsTouchScreen(devinfo)) | 
| 69     converter.reset(new TouchEventConverterEvdev(fd, path)); | 70     converter.reset(new TouchEventConverterEvdev(fd, path)); | 
| 70   else if (devinfo.HasEventType(EV_KEY)) | 71   else if (devinfo.HasEventType(EV_KEY)) | 
| 71     converter.reset(new KeyEventConverterEvdev(fd, path, &modifiers_)); | 72     converter.reset(new KeyEventConverterEvdev(fd, path, &modifiers_)); | 
| 72 | 73 | 
| 73   if (converter) { | 74   if (converter) { | 
| 74     AddEventConverter(fd, converter.Pass()); | 75     converters_[path] = converter.release(); | 
| 75   } else { | 76   } else { | 
| 76     close(fd); | 77     close(fd); | 
| 77   } | 78   } | 
| 78 } | 79 } | 
| 79 | 80 | 
| 80 void EventFactoryEvdev::StartProcessingEvents() { | 81 void EventFactoryEvdev::StartProcessingEvents() { | 
| 81   base::ThreadRestrictions::AssertIOAllowed(); | 82   base::ThreadRestrictions::AssertIOAllowed(); | 
| 82 | 83 | 
| 83   base::FileEnumerator file_enum( | 84   base::FileEnumerator file_enum( | 
| 84       base::FilePath("/dev/input"), false, base::FileEnumerator::FILES); | 85       base::FilePath("/dev/input"), false, base::FileEnumerator::FILES); | 
| 85   for (base::FilePath path = file_enum.Next(); !path.empty(); | 86   for (base::FilePath path = file_enum.Next(); !path.empty(); | 
| 86        path = file_enum.Next()) | 87        path = file_enum.Next()) | 
| 87     AttachInputDevice(path); | 88     AttachInputDevice(path); | 
| 88 } | 89 } | 
| 89 | 90 | 
| 90 }  // namespace ui | 91 }  // namespace ui | 
| OLD | NEW | 
|---|