Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Unified Diff: ui/events/ozone/evdev/event_factory.cc

Issue 58473003: evdev: Fix crashing with touch devices (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: various comments from rjkroege Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/events/ozone/evdev/event_factory.cc
diff --git a/ui/events/ozone/evdev/event_factory.cc b/ui/events/ozone/evdev/event_factory.cc
index 37e1f0274145529853c695296b6d63216988682b..3dc3c5799718d9231c02c02805c12eecbb088474 100644
--- a/ui/events/ozone/evdev/event_factory.cc
+++ b/ui/events/ozone/evdev/event_factory.cc
@@ -11,12 +11,29 @@
#include <unistd.h>
#include "base/strings/stringprintf.h"
+#include "ui/events/ozone/evdev/event_device_info.h"
#include "ui/events/ozone/evdev/key_event_converter.h"
#include "ui/events/ozone/evdev/touch_event_converter.h"
#include "ui/events/ozone/event_factory_ozone.h"
namespace ui {
+namespace {
+
+bool IsTouchPad(const EventDeviceInfo& devinfo) {
+ if (!devinfo.HasEventType(EV_ABS))
+ return false;
+
+ return devinfo.HasKeyEvent(BTN_LEFT) || devinfo.HasKeyEvent(BTN_MIDDLE) ||
+ devinfo.HasKeyEvent(BTN_RIGHT) || devinfo.HasKeyEvent(BTN_TOOL_FINGER);
+}
+
+bool IsTouchScreen(const EventDeviceInfo& devinfo) {
+ return devinfo.HasEventType(EV_ABS) && !IsTouchPad(devinfo);
+}
+
+} // namespace
+
EventFactoryEvdev::EventFactoryEvdev() {}
EventFactoryEvdev::~EventFactoryEvdev() {}
@@ -34,19 +51,25 @@ void EventFactoryEvdev::StartProcessingEvents() {
DLOG(ERROR) << "Cannot open '" << path << "': " << strerror(errno);
break;
}
- size_t evtype = 0;
- COMPILE_ASSERT(sizeof(evtype) * 8 >= EV_MAX, evtype_wide_enough);
- if (ioctl(fd, EVIOCGBIT(0, sizeof(evtype)), &evtype) == -1) {
- DLOG(ERROR) << "failed ioctl EVIOCGBIT 0" << path;
+
+ EventDeviceInfo devinfo;
+ if (!devinfo.Initialize(fd)) {
+ DLOG(ERROR) << "failed to get device information for " << path;
+ close(fd);
+ continue;
+ }
+
+ if (IsTouchPad(devinfo)) {
+ LOG(WARNING) << "touchpad device not supported: " << path;
close(fd);
continue;
}
scoped_ptr<EventConverterOzone> converter;
// TODO(rjkroege) Add more device types. Support hot-plugging.
- if (evtype & (1 << EV_ABS))
+ if (IsTouchScreen(devinfo))
converter.reset(new TouchEventConverterEvdev(fd, id));
- else if (evtype & (1 << EV_KEY))
+ else if (devinfo.HasEventType(EV_KEY))
converter.reset(new KeyEventConverterEvdev(&modifiers_));
if (converter) {

Powered by Google App Engine
This is Rietveld 408576698