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

Side by Side Diff: ui/events/ozone/evdev/event_factory_evdev.cc

Issue 193813003: ozone: evdev: Add libgestures bindings for touchpad & mouse support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "ui/events/ozone/evdev/cursor_delegate_evdev.h" 13 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
14 #include "ui/events/ozone/evdev/device_manager_evdev.h" 14 #include "ui/events/ozone/evdev/device_manager_evdev.h"
15 #include "ui/events/ozone/evdev/event_device_info.h" 15 #include "ui/events/ozone/evdev/event_device_info.h"
16 #include "ui/events/ozone/evdev/key_event_converter_evdev.h" 16 #include "ui/events/ozone/evdev/key_event_converter_evdev.h"
17 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h" 17 #include "ui/events/ozone/evdev/touch_event_converter_evdev.h"
18 18
19 #if defined(USE_UDEV) 19 #if defined(USE_UDEV)
20 #include "ui/events/ozone/evdev/device_manager_udev.h" 20 #include "ui/events/ozone/evdev/device_manager_udev.h"
21 #endif 21 #endif
22 22
23 #if defined(USE_EVDEV_GESTURES)
rjkroege 2014/03/11 12:58:47 do we ever not want to use evdev_gestures?
spang 2014/03/11 16:38:11 It is only present on chromeos. My suspicion is t
24 #include "ui/events/ozone/evdev/gestures/event_reader_libevdev_cros.h"
25 #include "ui/events/ozone/evdev/gestures/gesture_interpreter_libevdev_cros.h"
26 #endif
27
23 namespace ui { 28 namespace ui {
24 29
25 namespace { 30 namespace {
26 31
27 bool IsTouchPad(const EventDeviceInfo& devinfo) { 32 bool UseGesturesLibraryForDevice(const EventDeviceInfo& devinfo) {
28 if (!devinfo.HasEventType(EV_ABS)) 33 if (devinfo.HasAbsXY() && !devinfo.IsMappedToScreen())
29 return false; 34 return true; // touchpad
30 35
31 return devinfo.HasKeyEvent(BTN_LEFT) || devinfo.HasKeyEvent(BTN_MIDDLE) || 36 if (devinfo.HasRelXY())
32 devinfo.HasKeyEvent(BTN_RIGHT) || devinfo.HasKeyEvent(BTN_TOOL_FINGER); 37 return true; // mouse
38
39 return false;
33 } 40 }
34 41
35 bool IsTouchScreen(const EventDeviceInfo& devinfo) { 42 scoped_ptr<EventConverterEvdev> CreateConverter(int fd,
36 return devinfo.HasEventType(EV_ABS) && !IsTouchPad(devinfo); 43 const base::FilePath& path,
44 const EventDeviceInfo& devinfo,
45 EventModifiersEvdev* modifiers,
46 CursorDelegateEvdev* cursor) {
47 #if defined(USE_EVDEV_GESTURES)
48 // Touchpad: use gestures library.
49 // EventReaderLibevdevCros -> GestureInterpreterLibevdevCros -> DispatchEvent
50 if (UseGesturesLibraryForDevice(devinfo)) {
51 EventDispatchCallback dispatch =
52 base::Bind(&EventFactoryOzone::DispatchEvent);
53 scoped_ptr<GestureInterpreterLibevdevCros> gesture_interp = make_scoped_ptr(
54 new GestureInterpreterLibevdevCros(modifiers, cursor, dispatch));
55 scoped_ptr<EventReaderLibevdevCros> libevdev_reader =
56 make_scoped_ptr(new EventReaderLibevdevCros(
57 fd,
58 path,
59 gesture_interp.PassAs<EventReaderLibevdevCros::Delegate>()));
60 return libevdev_reader.PassAs<EventConverterEvdev>();
61 }
62 #endif
63
64 // Touchscreen: use TouchEventConverterEvdev.
65 scoped_ptr<EventConverterEvdev> converter;
66 if (devinfo.HasAbsXY())
67 return make_scoped_ptr<EventConverterEvdev>(
68 new TouchEventConverterEvdev(fd, path, devinfo));
69
70 // Everything else: use KeyEventConverterEvdev.
71 return make_scoped_ptr<EventConverterEvdev>(
72 new KeyEventConverterEvdev(fd, path, modifiers));
37 } 73 }
38 74
39 // Open an input device. Opening may put the calling thread to sleep, and 75 // Open an input device. Opening may put the calling thread to sleep, and
40 // therefore should be run on a thread where latency is not critical. We 76 // therefore should be run on a thread where latency is not critical. We
41 // run it on the FILE thread. 77 // run it on the FILE thread.
42 // 78 //
43 // This takes a TaskRunner and runs the reply on that thread, so that we 79 // This takes a TaskRunner and runs the reply on that thread, so that we
44 // can hop threads if necessary (back to the UI thread). 80 // can hop threads if necessary (back to the UI thread).
45 void OpenInputDevice( 81 void OpenInputDevice(
46 const base::FilePath& path, 82 const base::FilePath& path,
47 EventModifiersEvdev* modifiers, 83 EventModifiersEvdev* modifiers,
48 CursorDelegateEvdev* cursor, 84 CursorDelegateEvdev* cursor,
49 scoped_refptr<base::TaskRunner> reply_runner, 85 scoped_refptr<base::TaskRunner> reply_runner,
50 base::Callback<void(scoped_ptr<EventConverterEvdev>)> reply_callback) { 86 base::Callback<void(scoped_ptr<EventConverterEvdev>)> reply_callback) {
51 TRACE_EVENT1("ozone", "OpenInputDevice", "path", path.value()); 87 TRACE_EVENT1("ozone", "OpenInputDevice", "path", path.value());
52 88
53 int fd = open(path.value().c_str(), O_RDONLY | O_NONBLOCK); 89 int fd = open(path.value().c_str(), O_RDONLY | O_NONBLOCK);
54 if (fd < 0) { 90 if (fd < 0) {
55 PLOG(ERROR) << "Cannot open '" << path.value(); 91 PLOG(ERROR) << "Cannot open '" << path.value();
56 return; 92 return;
57 } 93 }
58 94
59 EventDeviceInfo devinfo; 95 EventDeviceInfo devinfo;
60 if (!devinfo.Initialize(fd)) { 96 if (!devinfo.Initialize(fd)) {
61 LOG(ERROR) << "failed to get device information for " << path.value(); 97 LOG(ERROR) << "failed to get device information for " << path.value();
62 close(fd); 98 close(fd);
63 return; 99 return;
64 } 100 }
65 101
66 if (IsTouchPad(devinfo)) { 102 scoped_ptr<EventConverterEvdev> converter =
67 LOG(WARNING) << "touchpad device not supported: " << path.value(); 103 CreateConverter(fd, path, devinfo, modifiers, cursor);
68 close(fd);
69 return;
70 }
71 104
72 // TODO(spang) Add more device types. 105 // Reply with the constructed converter.
73 scoped_ptr<EventConverterEvdev> converter; 106 reply_runner->PostTask(FROM_HERE,
74 if (IsTouchScreen(devinfo)) 107 base::Bind(reply_callback, base::Passed(&converter)));
75 converter.reset(new TouchEventConverterEvdev(fd, path, devinfo));
76 else if (devinfo.HasEventType(EV_KEY))
77 converter.reset(new KeyEventConverterEvdev(fd, path, modifiers));
78
79 if (converter) {
80 // Reply with the constructed converter.
81 reply_runner->PostTask(
82 FROM_HERE, base::Bind(reply_callback, base::Passed(&converter)));
83 } else {
84 close(fd);
85 }
86 } 108 }
87 109
88 // Close an input device. Closing may put the calling thread to sleep, and 110 // Close an input device. Closing may put the calling thread to sleep, and
89 // therefore should be run on a thread where latency is not critical. We 111 // therefore should be run on a thread where latency is not critical. We
90 // run it on the FILE thread. 112 // run it on the FILE thread.
91 void CloseInputDevice(const base::FilePath& path, 113 void CloseInputDevice(const base::FilePath& path,
92 scoped_ptr<EventConverterEvdev> converter) { 114 scoped_ptr<EventConverterEvdev> converter) {
93 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value()); 115 TRACE_EVENT1("ozone", "CloseInputDevice", "path", path.value());
94 converter.reset(); 116 converter.reset();
95 } 117 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 cursor_->MoveCursorTo(widget, location); 217 cursor_->MoveCursorTo(widget, location);
196 scoped_ptr<Event> ev(new MouseEvent(ET_MOUSE_MOVED, 218 scoped_ptr<Event> ev(new MouseEvent(ET_MOUSE_MOVED,
197 cursor_->location(), 219 cursor_->location(),
198 cursor_->location(), 220 cursor_->location(),
199 modifiers_.GetModifierFlags(), 221 modifiers_.GetModifierFlags(),
200 /* changed_button_flags */ 0)); 222 /* changed_button_flags */ 0));
201 DispatchEvent(ev.Pass()); 223 DispatchEvent(ev.Pass());
202 } 224 }
203 225
204 } // namespace ui 226 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698