ozone: evdev: Sync caps lock LED state to evdev
[chromium-blink-merge.git] / ui / events / ozone / evdev / libgestures_glue / gesture_interpreter_libevdev_cros.h
blob6b0276a02281eeb1390a9e10c0f20fa723503ac5
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
3 // found in the LICENSE file.
5 #ifndef UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_INTERPRETER_LIBEVDEV_CROS_H_
6 #define UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_INTERPRETER_LIBEVDEV_CROS_H_
8 #include <gestures/gestures.h>
9 #include <libevdev/libevdev.h>
11 #include "base/callback.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
14 #include "ui/events/ozone/evdev/event_device_util.h"
15 #include "ui/events/ozone/evdev/event_dispatch_callback.h"
16 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
17 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h"
19 namespace ui {
21 class DeviceEventDispatcherEvdev;
22 class EventDeviceInfo;
23 class CursorDelegateEvdev;
24 struct GestureDeviceProperties;
25 class GesturePropertyProvider;
27 // Convert libevdev-cros events to ui::Events using libgestures.
29 // This builds a GestureInterpreter for an input device (touchpad or
30 // mouse).
32 // Raw input events must be preprocessed into a form suitable for
33 // libgestures. The kernel protocol only emits changes to the device state,
34 // so changes must be accumulated until a sync event. The full device state
35 // at sync is then processed by libgestures.
37 // Once we have the state at sync, we convert it to a HardwareState object
38 // and forward it to libgestures. If any gestures are produced, they are
39 // converted to ui::Events and dispatched.
40 class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros
41 : public EventReaderLibevdevCros::Delegate {
42 public:
43 GestureInterpreterLibevdevCros(int id,
44 CursorDelegateEvdev* cursor,
45 GesturePropertyProvider* property_provider,
46 DeviceEventDispatcherEvdev* dispatcher);
47 ~GestureInterpreterLibevdevCros() override;
49 // Overriden from ui::EventReaderLibevdevCros::Delegate
50 void OnLibEvdevCrosOpen(Evdev* evdev, EventStateRec* evstate) override;
51 void OnLibEvdevCrosEvent(Evdev* evdev,
52 EventStateRec* evstate,
53 const timeval& time) override;
54 void SetAllowedKeys(
55 scoped_ptr<std::set<DomCode>> allowed_keys) override;
56 void AllowAllKeys() override;
58 // Handler for gesture events generated from libgestures.
59 void OnGestureReady(const Gesture* gesture);
61 // Accessors.
62 int id() { return id_; }
63 GesturePropertyProvider* property_provider() { return property_provider_; }
64 Evdev* evdev() { return evdev_; }
66 private:
67 void OnGestureMove(const Gesture* gesture, const GestureMove* move);
68 void OnGestureScroll(const Gesture* gesture, const GestureScroll* move);
69 void OnGestureButtonsChange(const Gesture* gesture,
70 const GestureButtonsChange* move);
71 void OnGestureContactInitiated(const Gesture* gesture);
72 void OnGestureFling(const Gesture* gesture, const GestureFling* fling);
73 void OnGestureSwipe(const Gesture* gesture, const GestureSwipe* swipe);
74 void OnGestureSwipeLift(const Gesture* gesture,
75 const GestureSwipeLift* swipelift);
76 void OnGesturePinch(const Gesture* gesture, const GesturePinch* pinch);
77 void OnGestureMetrics(const Gesture* gesture, const GestureMetrics* metrics);
79 void DispatchMouseButton(unsigned int modifier,
80 bool down,
81 stime_t time);
82 void DispatchChangedKeys(Evdev* evdev, const timeval& time);
84 // The unique device id.
85 int id_;
87 // True if the device may be regarded as a mouse. This includes normal mice
88 // and multi-touch mice.
89 bool is_mouse_;
91 // The evdev codes of the keys which should be processed. nullptr if all keys
92 // should be processed.
93 scoped_ptr<std::set<int>> allowed_keys_;
95 // Shared cursor state.
96 CursorDelegateEvdev* cursor_;
98 // Shared gesture property provider.
99 GesturePropertyProvider* property_provider_;
101 // Dispatcher for events.
102 DeviceEventDispatcherEvdev* dispatcher_;
104 // Gestures interpretation state.
105 gestures::GestureInterpreter* interpreter_;
107 // Last key state from libevdev.
108 unsigned long prev_key_state_[EVDEV_BITS_TO_LONGS(KEY_CNT)];
110 // Device pointer.
111 Evdev* evdev_;
113 // Gesture lib device properties.
114 scoped_ptr<GestureDeviceProperties> device_properties_;
116 DISALLOW_COPY_AND_ASSIGN(GestureInterpreterLibevdevCros);
119 } // namspace ui
121 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_INTERPRETER_LIBEVDEV_CROS_H_