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"
14 #include "ui/gfx/display.h"
18 struct GestureEventData;
20 class GESTURE_DETECTION_EXPORT GestureProviderClient {
22 virtual ~GestureProviderClient() {}
23 virtual void OnGestureEvent(const GestureEventData& gesture) = 0;
26 // Given a stream of |MotionEvent|'s, provides gesture detection and gesture
28 class GESTURE_DETECTION_EXPORT GestureProvider {
30 struct GESTURE_DETECTION_EXPORT Config {
34 GestureDetector::Config gesture_detector_config;
35 ScaleGestureDetector::Config scale_gesture_detector_config;
37 // If |disable_click_delay| is true and double-tap support is disabled,
38 // there will be no delay before tap events. When double-tap support is
39 // enabled, there will always be a delay before a tap event is fired, in
40 // order to allow the double tap gesture to occur without firing any tap
42 bool disable_click_delay;
44 // If |gesture_begin_end_types_enabled| is true, fire an ET_GESTURE_BEGIN
45 // event for every added touch point, and an ET_GESTURE_END event for every
46 // removed touch point. Defaults to false.
47 bool gesture_begin_end_types_enabled;
50 GestureProvider(const Config& config, GestureProviderClient* client);
53 // Handle the incoming MotionEvent, returning false if the event could not
55 bool OnTouchEvent(const MotionEvent& event);
57 // Update whether multi-touch pinch zoom is supported by the platform.
58 void SetMultiTouchZoomSupportEnabled(bool enabled);
60 // Update whether double-tap gestures are supported by the platform.
61 void SetDoubleTapSupportForPlatformEnabled(bool enabled);
63 // Update whether double-tap gesture detection should be suppressed, e.g.,
64 // if the page scale is fixed or the page has a mobile viewport. This disables
65 // the tap delay, allowing rapid and responsive single-tap gestures.
66 void SetDoubleTapSupportForPageEnabled(bool enabled);
68 // Whether a scroll gesture is in-progress.
69 bool IsScrollInProgress() const;
71 // Whether a pinch gesture is in-progress (i.e. a pinch update has been
72 // forwarded and detection is still active).
73 bool IsPinchInProgress() const;
75 // Whether a double-tap gesture is in-progress (either double-tap or
76 // double-tap drag zoom).
77 bool IsDoubleTapInProgress() const;
79 // May be NULL if there is no currently active touch sequence.
80 const ui::MotionEvent* current_down_event() const {
81 return current_down_event_.get();
85 void InitGestureDetectors(const Config& config);
87 bool CanHandle(const MotionEvent& event) const;
89 void Fling(const MotionEvent& e, float velocity_x, float velocity_y);
90 void Send(const GestureEventData& gesture);
91 bool SendLongTapIfNecessary(const MotionEvent& event);
92 void EndTouchScrollIfNecessary(const MotionEvent& event,
93 bool send_scroll_end_event);
94 void OnTouchEventHandlingBegin(const MotionEvent& event);
95 void OnTouchEventHandlingEnd(const MotionEvent& event);
96 void UpdateDoubleTapDetectionSupport();
98 GestureProviderClient* const client_;
100 class GestureListenerImpl;
101 friend class GestureListenerImpl;
102 scoped_ptr<GestureListenerImpl> gesture_listener_;
104 class ScaleGestureListenerImpl;
105 friend class ScaleGestureListenerImpl;
106 scoped_ptr<ScaleGestureListenerImpl> scale_gesture_listener_;
108 scoped_ptr<MotionEvent> current_down_event_;
110 // Whether the respective {SCROLL,PINCH}_BEGIN gestures have been terminated
111 // with a {SCROLL,PINCH}_END.
112 bool touch_scroll_in_progress_;
113 bool pinch_in_progress_;
115 // Whether double-tap gesture detection is currently supported.
116 bool double_tap_support_for_page_;
117 bool double_tap_support_for_platform_;
119 // Keeps track of the current GESTURE_LONG_PRESS event. If a context menu is
120 // opened after a GESTURE_LONG_PRESS, this is used to insert a
121 // GESTURE_TAP_CANCEL for removing any ::active styling.
122 base::TimeTicks current_longpress_time_;
124 bool gesture_begin_end_types_enabled_;
129 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_