Index: ui/events/ozone/event_factory_ozone.cc |
diff --git a/ui/events/ozone/event_factory_ozone.cc b/ui/events/ozone/event_factory_ozone.cc |
index acdf9958b55cb0363091d85a8480286575f19403..f3ba154c18e38d866ff1ef5498f554471e19f9da 100644 |
--- a/ui/events/ozone/event_factory_ozone.cc |
+++ b/ui/events/ozone/event_factory_ozone.cc |
@@ -4,21 +4,49 @@ |
#include "ui/events/ozone/event_factory_ozone.h" |
-#include <errno.h> |
-#include <fcntl.h> |
-#include <linux/input.h> |
-#include <poll.h> |
-#include <unistd.h> |
- |
+#include "base/command_line.h" |
#include "base/message_loop/message_pump_ozone.h" |
#include "base/stl_util.h" |
#include "base/strings/stringprintf.h" |
-#include "ui/events/ozone/evdev/key_event_converter_ozone.h" |
-#include "ui/events/ozone/evdev/touch_event_converter_ozone.h" |
+#include "ui/events/event_switches.h" |
#include "ui/events/ozone/event_factory_delegate_ozone.h" |
+#if defined(USE_OZONE_EVDEV) |
+#include "ui/events/ozone/evdev/event_factory_delegate.h" |
+#endif |
+ |
namespace ui { |
+namespace { |
+ |
+#if defined(USE_OZONE_EVDEV) |
+static const char kEventFactoryEvdev[] = "evdev"; |
+#endif |
+ |
+EventFactoryDelegateOzone* CreateDelegate(const std::string& event_delegate) { |
+#if defined(USE_OZONE_EVDEV) |
+ if (event_delegate == "evdev" || event_delegate == "default") |
+ return new EventFactoryDelegateEvdev; |
+#endif |
+ |
+ if (event_delegate == "none" || event_delegate == "default") { |
+ LOG(WARNING) << "No ozone events implementation - limited input support"; |
+ return NULL; |
+ } |
+ |
+ LOG(FATAL) << "Invalid ozone events implementation: " << event_delegate; |
+ return NULL; // not reached |
+} |
+ |
+std::string GetRequestedDelegate() { |
+ if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kOzoneEvents)) |
+ return "default"; |
+ return CommandLine::ForCurrentProcess()->GetSwitchValueASCII( |
+ switches::kOzoneEvents); |
+} |
+ |
+} // namespace |
+ |
// static |
EventFactoryDelegateOzone* EventFactoryOzone::delegate_ = NULL; |
@@ -31,48 +59,15 @@ EventFactoryOzone::~EventFactoryOzone() { |
} |
void EventFactoryOzone::CreateStartupEventConverters() { |
- if (delegate_) { |
- delegate_->CreateStartupEventConverters(this); |
- return; |
- } |
- |
- // If there is no |delegate_| set, read events from /dev/input/* |
- |
- // The number of devices in the directory is unknown without reading |
- // the contents of the directory. Further, with hot-plugging, the entries |
- // might decrease during the execution of this loop. So exciting from the |
- // loop on the first failure of open below is both cheaper and more |
- // reliable. |
- for (int id = 0; true; id++) { |
- std::string path = base::StringPrintf("/dev/input/event%d", id); |
- int fd = open(path.c_str(), O_RDONLY | O_NONBLOCK); |
- if (fd < 0) { |
- 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; |
- close(fd); |
- continue; |
- } |
- |
- scoped_ptr<EventConverterOzone> converter; |
- // TODO(rjkroege) Add more device types. Support hot-plugging. |
- if (evtype & (1 << EV_ABS)) |
- converter.reset(new TouchEventConverterOzone(fd, id)); |
- else if (evtype & (1 << EV_KEY)) |
- converter.reset(new KeyEventConverterOzone()); |
- |
- if (converter) { |
- AddEventConverter(fd, converter.Pass()); |
- } else { |
- close(fd); |
- } |
+ if (!delegate_) { |
+ std::string requested_delegate = GetRequestedDelegate(); |
+ SetEventFactoryDelegateOzone(CreateDelegate(requested_delegate)); |
} |
+ if (delegate_) |
+ delegate_->CreateStartupEventConverters(this); |
} |
+// static |
void EventFactoryOzone::SetEventFactoryDelegateOzone( |
EventFactoryDelegateOzone* delegate) { |
// It should be unnecessary to call this more than once. |