Revert of Roll src/third_party/WebKit e0eac24:489c548 (svn 193311:193320) (patchset...
[chromium-blink-merge.git] / ui / events / gesture_detection / gesture_provider.h
bloba9534d54a6ad7abd474fdd72a2c19b31aac85adf
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/gesture_event_data.h"
13 #include "ui/events/gesture_detection/gesture_touch_uma_histogram.h"
14 #include "ui/events/gesture_detection/scale_gesture_detector.h"
15 #include "ui/events/gesture_detection/snap_scroll_controller.h"
16 #include "ui/gfx/display.h"
18 namespace ui {
20 class GESTURE_DETECTION_EXPORT GestureProviderClient {
21 public:
22 virtual ~GestureProviderClient() {}
23 virtual void OnGestureEvent(const GestureEventData& gesture) = 0;
26 // Given a stream of |MotionEvent|'s, provides gesture detection and gesture
27 // event dispatch.
28 class GESTURE_DETECTION_EXPORT GestureProvider {
29 public:
30 struct GESTURE_DETECTION_EXPORT Config {
31 Config();
32 ~Config();
33 gfx::Display display;
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
41 // events.
42 bool disable_click_delay;
44 // Whether double-tap detection is supported by the platform. If disabled,
45 // there will be no delay before tap events. Defaults to true.
46 bool double_tap_support_for_platform_enabled;
48 // If |gesture_begin_end_types_enabled| is true, fire an ET_GESTURE_BEGIN
49 // event for every added touch point, and an ET_GESTURE_END event for every
50 // removed touch point. This requires one ACTION_CANCEL event to be sent per
51 // touch point, which only occurs on Aura. Defaults to false.
52 bool gesture_begin_end_types_enabled;
54 // The min and max size (both length and width, in dips) of the generated
55 // bounding box for all gesture types. This is useful for touch streams
56 // that may report zero or unreasonably small or large touch sizes.
57 // Note that these bounds are only applied for touch or unknown tool types;
58 // mouse and stylus-derived gestures will not be affected.
59 // Both values default to 0 (disabled).
60 float min_gesture_bounds_length;
61 float max_gesture_bounds_length;
64 GestureProvider(const Config& config, GestureProviderClient* client);
65 ~GestureProvider();
67 // Handle the incoming MotionEvent, returning false if the event could not
68 // be handled.
69 bool OnTouchEvent(const MotionEvent& event);
71 // Reset any active gesture detection, including detection of timeout-based
72 // events (e.g., double-tap or delayed tap) for which the pointer has already
73 // been released.
74 void ResetDetection();
76 // Update whether multi-touch pinch zoom is supported by the platform.
77 void SetMultiTouchZoomSupportEnabled(bool enabled);
79 // Update whether double-tap gestures are supported by the platform.
80 void SetDoubleTapSupportForPlatformEnabled(bool enabled);
82 // Update whether double-tap gesture detection should be suppressed, e.g.,
83 // if the page scale is fixed or the page has a mobile viewport. This disables
84 // the tap delay, allowing rapid and responsive single-tap gestures.
85 void SetDoubleTapSupportForPageEnabled(bool enabled);
87 // Whether a scroll gesture is in-progress.
88 bool IsScrollInProgress() const;
90 // Whether a pinch gesture is in-progress (i.e. a pinch update has been
91 // forwarded and detection is still active).
92 bool IsPinchInProgress() const;
94 // Whether a double-tap gesture is in-progress (either double-tap or
95 // double-tap drag zoom).
96 bool IsDoubleTapInProgress() const;
98 // May be NULL if there is no currently active touch sequence.
99 const ui::MotionEvent* current_down_event() const {
100 return current_down_event_.get();
103 private:
104 bool CanHandle(const MotionEvent& event) const;
105 void OnTouchEventHandlingBegin(const MotionEvent& event);
106 void OnTouchEventHandlingEnd(const MotionEvent& event);
107 void UpdateDoubleTapDetectionSupport();
109 class GestureListenerImpl;
110 scoped_ptr<GestureListenerImpl> gesture_listener_;
112 scoped_ptr<MotionEvent> current_down_event_;
114 // Logs information on touch and gesture events.
115 GestureTouchUMAHistogram uma_histogram_;
117 // Whether double-tap gesture detection is currently supported.
118 bool double_tap_support_for_page_;
119 bool double_tap_support_for_platform_;
121 const bool gesture_begin_end_types_enabled_;
124 } // namespace ui
126 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_