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_GESTURE_DETECTION_UI_GESTURE_PROVIDER_H_
6 #define UI_EVENTS_GESTURE_DETECTION_UI_GESTURE_PROVIDER_H_
7 
8 #include <stdint.h>
9 
10 #include <memory>
11 #include <vector>
12 
13 #include "base/macros.h"
14 #include "ui/events/event.h"
15 #include "ui/events/events_export.h"
16 #include "ui/events/gesture_detection/filtered_gesture_provider.h"
17 #include "ui/events/gesture_detection/gesture_event_data_packet.h"
18 #include "ui/events/gesture_detection/touch_disposition_gesture_filter.h"
19 #include "ui/events/gestures/motion_event_aura.h"
20 
21 namespace ui {
22 
23 class GestureProviderAura;
24 
25 class EVENTS_EXPORT GestureProviderAuraClient {
26  public:
~GestureProviderAuraClient()27   virtual ~GestureProviderAuraClient() {}
28   virtual void OnGestureEvent(GestureConsumer* consumer,
29                               GestureEvent* event) = 0;
30 };
31 
32 // Provides gesture detection and dispatch given a sequence of touch events
33 // and touch event acks.
34 class EVENTS_EXPORT GestureProviderAura : public GestureProviderClient {
35  public:
36   GestureProviderAura(GestureConsumer* consumer,
37                       GestureProviderAuraClient* client);
38   ~GestureProviderAura() override;
39 
set_gesture_consumer(GestureConsumer * consumer)40   void set_gesture_consumer(GestureConsumer* consumer) {
41     gesture_consumer_ = consumer;
42   }
43 
44   bool OnTouchEvent(TouchEvent* event);
45   void OnTouchEventAck(uint32_t unique_touch_event_id,
46                        bool event_consumed,
47                        bool is_source_touch_event_set_non_blocking);
pointer_state()48   const MotionEventAura& pointer_state() { return pointer_state_; }
49   std::vector<std::unique_ptr<GestureEvent>> GetAndResetPendingGestures();
50   void OnTouchEnter(int pointer_id, float x, float y);
51 
52   void ResetGestureHandlingState();
53 
54   // GestureProviderClient implementation
55   void OnGestureEvent(const GestureEventData& gesture) override;
56   bool RequiresDoubleTapGestureEvents() const override;
57 
58  private:
59   GestureProviderAuraClient* client_;
60   MotionEventAura pointer_state_;
61   FilteredGestureProvider filtered_gesture_provider_;
62 
63   bool handling_event_;
64   std::vector<std::unique_ptr<GestureEvent>> pending_gestures_;
65 
66   // |gesture_consumer_| must outlive this object.
67   GestureConsumer* gesture_consumer_;
68 
69   DISALLOW_COPY_AND_ASSIGN(GestureProviderAura);
70 };
71 
72 }  // namespace ui
73 
74 #endif  // UI_EVENTS_GESTURE_DETECTION_UI_GESTURE_PROVIDER_H_
75