Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(524)

Side by Side Diff: ui/events/gesture_detection/gesture_provider.h

Issue 171773012: Port of Android platform gesture detection code to C++ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_GESTURE_PROVIDER_H_
6 #define UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_
7
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
15 namespace ui {
16
17 struct GestureEventParams;
18
19 class GESTURE_DETECTION_EXPORT GestureProviderClient {
20 public:
21 virtual ~GestureProviderClient() {}
22 virtual void OnGestureEvent(const GestureEventParams& gesture) = 0;
23 };
24
25 // Given a stream of |MotionEvent|'s, provides gesture detection and gesture
26 // event dispatch.
27 class GESTURE_DETECTION_EXPORT GestureProvider {
28 public:
29 struct GESTURE_DETECTION_EXPORT Config {
30 Config();
31 ~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;
36 };
37
38 GestureProvider(const Config& config, GestureProviderClient* client);
39 ~GestureProvider();
40
41 // Handle the incoming MotionEvent, returning false if the event could not
42 // be handled.
43 bool OnTouchEvent(const MotionEvent& event);
44
45 // Resets all gesture detectors; called on DidStartLoading().
46 void ResetGestureDetectors();
47
48 // Cancel the current touch event sequence by sending ACTION_CANCEL, and
49 // ignore all the subsequent events until the next ACTION_DOWN.
50 // One example usecase is to stop processing the touch events when showing
51 // a context popup menu.
52 void CancelActiveTouchSequence();
53
54 // Update whether multi-touch gestures are supported.
55 void UpdateMultiTouchSupport(bool support_multi_touch_zoom);
56
57 // Update whether double-tap gestures are supported. This allows
58 // double-tap gesture suppression independent of whether or not the page's
59 // viewport and scale would normally prevent double-tap.
60 // Note: This should not be called while a double-tap gesture is in progress.
61 void UpdateDoubleTapSupportForPlatform(bool support_double_tap);
62
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
65 // detection allows for rapid and responsive single-tap gestures.
66 void UpdateDoubleTapSupportForPage(bool support_double_tap);
67
68 // Whether a scroll gesture is in-progress.
69 bool IsScrollInProgress() const;
70
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;
74
75 // Whether a double tap-gesture is in-progress.
76 bool IsDoubleTapInProgress() const;
77
78 private:
79 void InitGestureDetectors(const Config& config);
80
81 bool CanHandle(const MotionEvent& event) const;
82
83 void Fling(base::TimeTicks time,
84 float x,
85 float y,
86 float velocity_x,
87 float velocity_y);
88 void Send(const GestureEventParams& gesture);
89 void SendTapCancelIfNecessary(const MotionEvent& event);
90 bool SendLongTapIfNecessary(const MotionEvent& event);
91 void EndTouchScrollIfNecessary(base::TimeTicks time,
92 bool send_scroll_end_event);
93
94 GestureProviderClient* const client_;
95
96 class GestureListenerImpl;
97 friend class GestureListenerImpl;
98 scoped_ptr<GestureListenerImpl> gesture_listener_;
99
100 class ScaleGestureListenerImpl;
101 friend class ScaleGestureListenerImpl;
102 scoped_ptr<ScaleGestureListenerImpl> scale_gesture_listener_;
103
104 scoped_ptr<MotionEvent> current_down_event_;
105
106 // 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
108 // one has not yet been sent.
109 bool needs_show_press_event_;
110
111 // Whether a sent GESTURE_TAP_DOWN event has yet to be accompanied by a
112 // corresponding GESTURE_SINGLE_TAP_CONFIRMED, GESTURE_TAP_CANCEL or
113 // GESTURE_DOUBLE_TAP.
114 bool needs_tap_ending_event_;
115
116 // Whether the respective {SCROLL,PINCH}_BEGIN gestures have been terminated
117 // with a {SCROLL,PINCH}_END.
118 bool touch_scroll_in_progress_;
119 bool pinch_in_progress_;
120
121 // 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
123 // GESTURE_TAP_CANCEL for removing any ::active styling.
124 base::TimeTicks current_longpress_time_;
125 };
126
127 } // namespace ui
128
129 #endif // UI_EVENTS_GESTURE_DETECTION_GESTURE_PROVIDER_H_
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_event_params.cc ('k') | ui/events/gesture_detection/gesture_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698