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/events_ozone_evdev_export.h"
15 #include "ui/events/ozone/evdev/libgestures_glue/event_reader_libevdev_cros.h"
20 class EventDeviceInfo
;
21 class EventModifiersEvdev
;
22 class CursorDelegateEvdev
;
24 typedef base::Callback
<void(Event
*)> EventDispatchCallback
;
26 // Convert libevdev-cros events to ui::Events using libgestures.
28 // This builds a GestureInterpreter for an input device (touchpad or
31 // Raw input events must be preprocessed into a form suitable for
32 // libgestures. The kernel protocol only emits changes to the device state,
33 // so changes must be accumulated until a sync event. The full device state
34 // at sync is then processed by libgestures.
36 // Once we have the state at sync, we convert it to a HardwareState object
37 // and forward it to libgestures. If any gestures are produced, they are
38 // converted to ui::Events and dispatched.
39 class EVENTS_OZONE_EVDEV_EXPORT GestureInterpreterLibevdevCros
40 : public EventReaderLibevdevCros::Delegate
{
42 GestureInterpreterLibevdevCros(EventModifiersEvdev
* modifiers
,
43 CursorDelegateEvdev
* cursor
,
44 const EventDispatchCallback
& callback
);
45 virtual ~GestureInterpreterLibevdevCros();
47 // Overriden from ui::EventReaderLibevdevCros::Delegate
48 virtual void OnLibEvdevCrosOpen(Evdev
* evdev
,
49 EventStateRec
* evstate
) OVERRIDE
;
50 virtual void OnLibEvdevCrosEvent(Evdev
* evdev
,
51 EventStateRec
* evstate
,
52 const timeval
& time
) OVERRIDE
;
54 // Handler for gesture events generated from libgestures.
55 void OnGestureReady(const Gesture
* gesture
);
58 void OnGestureMove(const Gesture
* gesture
, const GestureMove
* move
);
59 void OnGestureScroll(const Gesture
* gesture
, const GestureScroll
* move
);
60 void OnGestureButtonsChange(const Gesture
* gesture
,
61 const GestureButtonsChange
* move
);
62 void OnGestureContactInitiated(const Gesture
* gesture
);
63 void OnGestureFling(const Gesture
* gesture
, const GestureFling
* fling
);
64 void OnGestureSwipe(const Gesture
* gesture
, const GestureSwipe
* swipe
);
65 void OnGestureSwipeLift(const Gesture
* gesture
,
66 const GestureSwipeLift
* swipelift
);
67 void OnGesturePinch(const Gesture
* gesture
, const GesturePinch
* pinch
);
68 void OnGestureMetrics(const Gesture
* gesture
, const GestureMetrics
* metrics
);
70 void Dispatch(Event
* event
);
71 void DispatchMouseButton(unsigned int modifier
, bool down
);
73 // Shared modifier state.
74 EventModifiersEvdev
* modifiers_
;
76 // Shared cursor state.
77 CursorDelegateEvdev
* cursor_
;
79 // Callback for dispatching events.
80 EventDispatchCallback dispatch_callback_
;
82 // Gestures interpretation state.
83 gestures::GestureInterpreter
* interpreter_
;
85 DISALLOW_COPY_AND_ASSIGN(GestureInterpreterLibevdevCros
);
90 #endif // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_INTERPRETER_LIBEVDEV_CROS_H_