OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ | 5 #ifndef UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ |
6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ | 6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "ui/events/gesture_detection/gesture_detection_export.h" | 10 #include "ui/events/gesture_detection/gesture_detection_export.h" |
11 #include "ui/events/gesture_detection/gesture_detector.h" | 11 #include "ui/events/gesture_detection/gesture_detector.h" |
12 #include "ui/events/gesture_detection/scale_gesture_detector.h" | 12 #include "ui/events/gesture_detection/scale_gesture_detector.h" |
13 #include "ui/events/gesture_detection/snap_scroll_controller.h" | 13 #include "ui/events/gesture_detection/snap_scroll_controller.h" |
14 | 14 |
15 namespace ui { | 15 namespace ui { |
16 | 16 |
17 struct GestureEventParams; | 17 struct GestureEventData; |
18 | 18 |
19 class GESTURE_DETECTION_EXPORT GestureProviderClient { | 19 class GESTURE_DETECTION_EXPORT GestureProviderClient { |
20 public: | 20 public: |
21 virtual ~GestureProviderClient() {} | 21 virtual ~GestureProviderClient() {} |
22 virtual void OnGestureEvent(const GestureEventParams& gesture) = 0; | 22 virtual void OnGestureEvent(const GestureEventData& gesture) = 0; |
23 }; | 23 }; |
24 | 24 |
25 // Given a stream of |MotionEvent|'s, provides gesture detection and gesture | 25 // Given a stream of |MotionEvent|'s, provides gesture detection and gesture |
26 // event dispatch. | 26 // event dispatch. |
27 class GESTURE_DETECTION_EXPORT GestureProvider { | 27 class GESTURE_DETECTION_EXPORT GestureProvider { |
28 public: | 28 public: |
29 struct GESTURE_DETECTION_EXPORT Config { | 29 struct GESTURE_DETECTION_EXPORT Config { |
30 Config(); | 30 Config(); |
31 ~Config(); | 31 ~Config(); |
32 GestureDetector::Config gesture_detector_config; | 32 GestureDetector::Config gesture_detector_config; |
(...skipping 12 matching lines...) Expand all Loading... |
45 // Resets all gesture detectors; called on DidStartLoading(). | 45 // Resets all gesture detectors; called on DidStartLoading(). |
46 void ResetGestureDetectors(); | 46 void ResetGestureDetectors(); |
47 | 47 |
48 // Cancel the current touch event sequence by sending ACTION_CANCEL, and | 48 // Cancel the current touch event sequence by sending ACTION_CANCEL, and |
49 // ignore all the subsequent events until the next ACTION_DOWN. | 49 // ignore all the subsequent events until the next ACTION_DOWN. |
50 // One example usecase is to stop processing the touch events when showing | 50 // One example usecase is to stop processing the touch events when showing |
51 // a context popup menu. | 51 // a context popup menu. |
52 void CancelActiveTouchSequence(); | 52 void CancelActiveTouchSequence(); |
53 | 53 |
54 // Update whether multi-touch gestures are supported. | 54 // Update whether multi-touch gestures are supported. |
55 void UpdateMultiTouchSupport(bool support_multi_touch_zoom); | 55 void SetMultiTouchSupportEnabled(bool enabled); |
56 | 56 |
57 // Update whether double-tap gestures are supported. This allows | 57 // Update whether double-tap gestures are supported. This allows |
58 // double-tap gesture suppression independent of whether or not the page's | 58 // double-tap gesture suppression independent of whether or not the page's |
59 // viewport and scale would normally prevent double-tap. | 59 // viewport and scale would normally prevent double-tap. |
60 // Note: This should not be called while a double-tap gesture is in progress. | 60 // Note: This should not be called while a double-tap gesture is in progress. |
61 void UpdateDoubleTapSupportForPlatform(bool support_double_tap); | 61 void SetDoubleTapSupportForPlatformEnabled(bool enabled); |
62 | 62 |
63 // Update whether double-tap gesture detection should be suppressed due to | 63 // Update whether double-tap gesture detection should be suppressed due to |
64 // the viewport or scale of the current page. Suppressing double-tap gesture | 64 // the viewport or scale of the current page. Suppressing double-tap gesture |
65 // detection allows for rapid and responsive single-tap gestures. | 65 // detection allows for rapid and responsive single-tap gestures. |
66 void UpdateDoubleTapSupportForPage(bool support_double_tap); | 66 void SetDoubleTapSupportForPageEnabled(bool enabled); |
67 | 67 |
68 // Whether a scroll gesture is in-progress. | 68 // Whether a scroll gesture is in-progress. |
69 bool IsScrollInProgress() const; | 69 bool IsScrollInProgress() const; |
70 | 70 |
71 // Whether a pinch gesture is in-progress (i.e. a pinch update has been | 71 // Whether a pinch gesture is in-progress (i.e. a pinch update has been |
72 // forwarded and detection is still active). | 72 // forwarded and detection is still active). |
73 bool IsPinchInProgress() const; | 73 bool IsPinchInProgress() const; |
74 | 74 |
75 // Whether a double tap-gesture is in-progress. | 75 // Whether a double tap-gesture is in-progress. |
76 bool IsDoubleTapInProgress() const; | 76 bool IsDoubleTapInProgress() const; |
77 | 77 |
| 78 // Whether the tap gesture delay is explicitly disabled (independent of |
| 79 // whether double-tap is supported), see |Config.disable_click_delay|. |
| 80 bool IsClickDelayDisabled() const; |
| 81 |
78 private: | 82 private: |
79 void InitGestureDetectors(const Config& config); | 83 void InitGestureDetectors(const Config& config); |
80 | 84 |
81 bool CanHandle(const MotionEvent& event) const; | 85 bool CanHandle(const MotionEvent& event) const; |
82 | 86 |
83 void Fling(base::TimeTicks time, | 87 void Fling(base::TimeTicks time, |
84 float x, | 88 float x, |
85 float y, | 89 float y, |
86 float velocity_x, | 90 float velocity_x, |
87 float velocity_y); | 91 float velocity_y); |
88 void Send(const GestureEventParams& gesture); | 92 void Send(const GestureEventData& gesture); |
89 void SendTapCancelIfNecessary(const MotionEvent& event); | 93 void SendTapCancelIfNecessary(const MotionEvent& event); |
90 bool SendLongTapIfNecessary(const MotionEvent& event); | 94 bool SendLongTapIfNecessary(const MotionEvent& event); |
91 void EndTouchScrollIfNecessary(base::TimeTicks time, | 95 void EndTouchScrollIfNecessary(base::TimeTicks time, |
92 bool send_scroll_end_event); | 96 bool send_scroll_end_event); |
93 | 97 |
94 GestureProviderClient* const client_; | 98 GestureProviderClient* const client_; |
95 | 99 |
96 class GestureListenerImpl; | 100 class GestureListenerImpl; |
97 friend class GestureListenerImpl; | 101 friend class GestureListenerImpl; |
98 scoped_ptr<GestureListenerImpl> gesture_listener_; | 102 scoped_ptr<GestureListenerImpl> gesture_listener_; |
99 | 103 |
100 class ScaleGestureListenerImpl; | 104 class ScaleGestureListenerImpl; |
101 friend class ScaleGestureListenerImpl; | 105 friend class ScaleGestureListenerImpl; |
102 scoped_ptr<ScaleGestureListenerImpl> scale_gesture_listener_; | 106 scoped_ptr<ScaleGestureListenerImpl> scale_gesture_listener_; |
103 | 107 |
104 scoped_ptr<MotionEvent> current_down_event_; | 108 scoped_ptr<MotionEvent> current_down_event_; |
105 | 109 |
106 // Whether a GESTURE_SHOW_PRESS was sent for the current touch sequence. | 110 // Whether a GESTURE_SHOW_PRESS was sent for the current touch sequence. |
107 // Sending a GESTURE_SINGLE_TAP* event will forward a GESTURE_SHOW_PRESS if | 111 // Sending a GESTURE_TAP event will forward a GESTURE_SHOW_PRESS if one has |
108 // one has not yet been sent. | 112 // not yet been sent. |
109 bool needs_show_press_event_; | 113 bool needs_show_press_event_; |
110 | 114 |
111 // Whether a sent GESTURE_TAP_DOWN event has yet to be accompanied by a | 115 // Whether a sent GESTURE_TAP_DOWN event has yet to be accompanied by a |
112 // corresponding GESTURE_SINGLE_TAP_CONFIRMED, GESTURE_TAP_CANCEL or | 116 // corresponding GESTURE_TAP, GESTURE_TAP_CANCEL or GESTURE_DOUBLE_TAP. |
113 // GESTURE_DOUBLE_TAP. | |
114 bool needs_tap_ending_event_; | 117 bool needs_tap_ending_event_; |
115 | 118 |
116 // Whether the respective {SCROLL,PINCH}_BEGIN gestures have been terminated | 119 // Whether the respective {SCROLL,PINCH}_BEGIN gestures have been terminated |
117 // with a {SCROLL,PINCH}_END. | 120 // with a {SCROLL,PINCH}_END. |
118 bool touch_scroll_in_progress_; | 121 bool touch_scroll_in_progress_; |
119 bool pinch_in_progress_; | 122 bool pinch_in_progress_; |
120 | 123 |
121 // Keeps track of the current GESTURE_LONG_PRESS event. If a context menu is | 124 // Keeps track of the current GESTURE_LONG_PRESS event. If a context menu is |
122 // opened after a GESTURE_LONG_PRESS, this is used to insert a | 125 // opened after a GESTURE_LONG_PRESS, this is used to insert a |
123 // GESTURE_TAP_CANCEL for removing any ::active styling. | 126 // GESTURE_TAP_CANCEL for removing any ::active styling. |
124 base::TimeTicks current_longpress_time_; | 127 base::TimeTicks current_longpress_time_; |
125 }; | 128 }; |
126 | 129 |
127 } // namespace ui | 130 } // namespace ui |
128 | 131 |
129 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ | 132 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_ |
OLD | NEW |