Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ui / events / ozone / evdev / libgestures_glue / gesture_interpreter_libevdev_cros.h
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.
4
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_
7
8 #include <gestures/gestures.h>
9 #include <libevdev/libevdev.h>
10
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"
16
17 namespace ui {
18
19 class Event;
20 class EventDeviceInfo;
21 class EventModifiersEvdev;
22 class CursorDelegateEvdev;
23
24 typedef base::Callback<void(Event*)> EventDispatchCallback;
25
26 // Convert libevdev-cros events to ui::Events using libgestures.
27 //
28 // This builds a GestureInterpreter for an input device (touchpad or
29 // mouse).
30 //
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.
35 //
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 {
41  public:
42   GestureInterpreterLibevdevCros(EventModifiersEvdev* modifiers,
43                                  CursorDelegateEvdev* cursor,
44                                  const EventDispatchCallback& callback);
45   virtual ~GestureInterpreterLibevdevCros();
46
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;
53
54   // Handler for gesture events generated from libgestures.
55   void OnGestureReady(const Gesture* gesture);
56
57  private:
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);
69
70   void Dispatch(Event* event);
71   void DispatchMouseButton(unsigned int modifier, bool down);
72
73   // Shared modifier state.
74   EventModifiersEvdev* modifiers_;
75
76   // Shared cursor state.
77   CursorDelegateEvdev* cursor_;
78
79   // Callback for dispatching events.
80   EventDispatchCallback dispatch_callback_;
81
82   // Gestures interpretation state.
83   gestures::GestureInterpreter* interpreter_;
84
85   DISALLOW_COPY_AND_ASSIGN(GestureInterpreterLibevdevCros);
86 };
87
88 }  // namspace ui
89
90 #endif  // UI_EVENTS_OZONE_EVDEV_LIBGESTURES_GLUE_GESTURE_INTERPRETER_LIBEVDEV_CROS_H_