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_
9 #include <gestures/gestures.h>
10 #include <libevdev/libevdev.h>
12 #include "base/callback.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "ui/events/ozone/evdev/cursor_delegate_evdev.h"
15 #include "ui/events/ozone/evdev/event_device_util.h"
16 #include "ui/events/ozone/evdev/event_dispatch_callback.h"
17 #include "ui/events/ozone/evdev/events_ozone_evdev_export.h"
18 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h"
22 class DeviceEventDispatcherEvdev
;
23 class EventDeviceInfo
;
24 class CursorDelegateEvdev
;
25 struct GestureDeviceProperties
;
26 class GesturePropertyProvider
;
28 // Convert libevdev-cros events to ui::Events using libgestures.
30 // This builds a GestureInterpreter for an input device (touchpad or
33 // Raw input events must be preprocessed into a form suitable for
34 // libgestures. The kernel protocol only emits changes to the device state,
35 // so changes must be accumulated until a sync event. The full device state
36 // at sync is then processed by libgestures.
38 // Once we have the state at sync, we convert it to a HardwareState object
39 // and forward it to libgestures. If any gestures are produced, they are
40 // converted to ui::Events and dispatched.
41 class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros
42 : public EventReaderLibevdevCros::Delegate
{
44 GestureInterpreterLibevdevCros(int id
,
45 CursorDelegateEvdev
* cursor
,
46 GesturePropertyProvider
* property_provider
,
47 DeviceEventDispatcherEvdev
* dispatcher
);
48 ~GestureInterpreterLibevdevCros() override
;
50 // Overriden from ui::EventReaderLibevdevCros::Delegate
51 void OnLibEvdevCrosOpen(Evdev
* evdev
, EventStateRec
* evstate
) override
;
52 void OnLibEvdevCrosEvent(Evdev
* evdev
,
53 EventStateRec
* evstate
,
54 const timeval
& time
) override
;
55 void OnLibEvdevCrosStopped(Evdev
* evdev
, EventStateRec
* state
) override
;
57 // Handler for gesture events generated from libgestures.
58 void OnGestureReady(const Gesture
* gesture
);
61 int id() { return id_
; }
62 GesturePropertyProvider
* property_provider() { return property_provider_
; }
63 Evdev
* evdev() { return evdev_
; }
66 void OnGestureMove(const Gesture
* gesture
, const GestureMove
* move
);
67 void OnGestureScroll(const Gesture
* gesture
, const GestureScroll
* move
);
68 void OnGestureButtonsChange(const Gesture
* gesture
,
69 const GestureButtonsChange
* move
);
70 void OnGestureContactInitiated(const Gesture
* gesture
);
71 void OnGestureFling(const Gesture
* gesture
, const GestureFling
* fling
);
72 void OnGestureSwipe(const Gesture
* gesture
, const GestureSwipe
* swipe
);
73 void OnGestureSwipeLift(const Gesture
* gesture
,
74 const GestureSwipeLift
* swipelift
);
75 void OnGesturePinch(const Gesture
* gesture
, const GesturePinch
* pinch
);
76 void OnGestureMetrics(const Gesture
* gesture
, const GestureMetrics
* metrics
);
78 void DispatchChangedMouseButtons(unsigned int changed_buttons
,
81 void DispatchMouseButton(unsigned int button
,
84 void DispatchChangedKeys(unsigned long* changed_keys
, stime_t timestamp
);
85 void ReleaseKeys(stime_t timestamp
);
86 bool SetMouseButtonState(unsigned int button
, bool down
);
87 void ReleaseMouseButtons(stime_t timestamp
);
89 // The unique device id.
92 // True if the device may be regarded as a mouse. This includes normal mice
93 // and multi-touch mice.
94 bool is_mouse_
= false;
96 // Shared cursor state.
97 CursorDelegateEvdev
* cursor_
;
99 // Shared gesture property provider.
100 GesturePropertyProvider
* property_provider_
;
102 // Dispatcher for events.
103 DeviceEventDispatcherEvdev
* dispatcher_
;
105 // Gestures interpretation state.
106 gestures::GestureInterpreter
* interpreter_
= nullptr;
108 // Last key state from libevdev.
109 unsigned long prev_key_state_
[EVDEV_BITS_TO_LONGS(KEY_CNT
)];
111 // Last mouse button state.
112 static const int kMouseButtonCount
= BTN_JOYSTICK
- BTN_MOUSE
;
113 std::bitset
<kMouseButtonCount
> mouse_button_state_
;
116 Evdev
* evdev_
= nullptr;
118 // Gesture lib device properties.
119 scoped_ptr
<GestureDeviceProperties
> device_properties_
;
121 DISALLOW_COPY_AND_ASSIGN(GestureInterpreterLibevdevCros
);
126 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_INTERPRETER_LIBEVDEV_CROS_H_