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_GESTURE_DETECTION_GESTURE_PROVIDER_H_
6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "ui/events/gesture_detection/gesture_detection_export.h"
11 #include "ui/events/gesture_detection/gesture_detector.h"
12 #include "ui/events/gesture_detection/scale_gesture_detector.h"
13 #include "ui/events/gesture_detection/snap_scroll_controller.h"
17 struct GestureEventData;
19 class GESTURE_DETECTION_EXPORT GestureProviderClient {
21 virtual ~GestureProviderClient() {}
22 virtual void OnGestureEvent(const GestureEventData& gesture) = 0;
25 // Given a stream of |MotionEvent|'s, provides gesture detection and gesture
27 class GESTURE_DETECTION_EXPORT GestureProvider {
29 struct GESTURE_DETECTION_EXPORT Config {
32 GestureDetector::Config gesture_detector_config;
33 ScaleGestureDetector::Config scale_gesture_detector_config;
34 SnapScrollController::Config snap_scroll_controller_config;
35 bool disable_click_delay;
38 GestureProvider(const Config& config, GestureProviderClient* client);
41 // Handle the incoming MotionEvent, returning false if the event could not
43 bool OnTouchEvent(const MotionEvent& event);
45 // Resets all gesture detectors; called on DidStartLoading().
46 void ResetGestureDetectors();
48 // Update whether multi-touch gestures are supported.
49 void SetMultiTouchSupportEnabled(bool enabled);
51 // Update whether double-tap gestures are supported. This allows
52 // double-tap gesture suppression independent of whether or not the page's
53 // viewport and scale would normally prevent double-tap.
54 // Note: This should not be called while a double-tap gesture is in progress.
55 void SetDoubleTapSupportForPlatformEnabled(bool enabled);
57 // Update whether double-tap gesture detection should be suppressed due to
58 // the viewport or scale of the current page. Suppressing double-tap gesture
59 // detection allows for rapid and responsive single-tap gestures.
60 void SetDoubleTapSupportForPageEnabled(bool enabled);
62 // Whether a scroll gesture is in-progress.
63 bool IsScrollInProgress() const;
65 // Whether a pinch gesture is in-progress (i.e. a pinch update has been
66 // forwarded and detection is still active).
67 bool IsPinchInProgress() const;
69 // Whether a double tap-gesture is in-progress.
70 bool IsDoubleTapInProgress() const;
72 // Whether the tap gesture delay is explicitly disabled (independent of
73 // whether double-tap is supported), see |Config.disable_click_delay|.
74 bool IsClickDelayDisabled() const;
76 // May be NULL if there is no currently active touch sequence.
77 const ui::MotionEvent* current_down_event() const {
78 return current_down_event_.get();
82 void InitGestureDetectors(const Config& config);
84 bool CanHandle(const MotionEvent& event) const;
86 void Fling(base::TimeTicks time,
91 void Send(const GestureEventData& gesture);
92 void SendTapCancelIfNecessary(const MotionEvent& event);
93 bool SendLongTapIfNecessary(const MotionEvent& event);
94 void EndTouchScrollIfNecessary(base::TimeTicks time,
95 bool send_scroll_end_event);
97 GestureProviderClient* const client_;
99 class GestureListenerImpl;
100 friend class GestureListenerImpl;
101 scoped_ptr<GestureListenerImpl> gesture_listener_;
103 class ScaleGestureListenerImpl;
104 friend class ScaleGestureListenerImpl;
105 scoped_ptr<ScaleGestureListenerImpl> scale_gesture_listener_;
107 scoped_ptr<MotionEvent> current_down_event_;
109 // Whether a GESTURE_SHOW_PRESS was sent for the current touch sequence.
110 // Sending a GESTURE_TAP event will forward a GESTURE_SHOW_PRESS if one has
111 // not yet been sent.
112 bool needs_show_press_event_;
114 // Whether a sent GESTURE_TAP_DOWN event has yet to be accompanied by a
115 // corresponding GESTURE_TAP, GESTURE_TAP_CANCEL or GESTURE_DOUBLE_TAP.
116 bool needs_tap_ending_event_;
118 // Whether the respective {SCROLL,PINCH}_BEGIN gestures have been terminated
119 // with a {SCROLL,PINCH}_END.
120 bool touch_scroll_in_progress_;
121 bool pinch_in_progress_;
123 // Keeps track of the current GESTURE_LONG_PRESS event. If a context menu is
124 // opened after a GESTURE_LONG_PRESS, this is used to insert a
125 // GESTURE_TAP_CANCEL for removing any ::active styling.
126 base::TimeTicks current_longpress_time_;
131 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_