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_SCALE_GESTURE_DETECTOR_H_ | 5 #ifndef UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_ |
6 #define UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_ | 6 #define UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "base/time/time.h" | 8 #include "base/time/time.h" |
10 #include "ui/events/gesture_detection/gesture_detection_export.h" | 9 #include "ui/events/gesture_detection/gesture_detection_export.h" |
11 #include "ui/events/gesture_detection/gesture_detector.h" | |
12 | 10 |
13 namespace ui { | 11 namespace ui { |
14 | 12 |
15 class MotionEvent; | 13 class MotionEvent; |
16 | 14 |
17 // Port of ScaleGestureDetector.java from Android | 15 // Port of ScaleGestureDetector.java from Android |
18 // * platform/frameworks/base/core/java/android/view/ScaleGestureDetector.java | 16 // * platform/frameworks/base/core/java/android/view/ScaleGestureDetector.java |
19 // * Change-Id: I3e7926a4f6f9ab4951f380bd004499c78b3bda69 | 17 // * Change-Id: I3e7926a4f6f9ab4951f380bd004499c78b3bda69 |
20 // * Please update the Change-Id as upstream Android changes are pulled. | 18 // * Please update the Change-Id as upstream Android changes are pulled. |
21 class ScaleGestureDetector : public GestureDetector::SimpleGestureListener { | 19 class ScaleGestureDetector { |
22 public: | 20 public: |
23 struct GESTURE_DETECTION_EXPORT Config { | 21 struct GESTURE_DETECTION_EXPORT Config { |
24 Config(); | 22 Config(); |
25 ~Config(); | 23 ~Config(); |
26 GestureDetector::Config gesture_detector_config; | 24 |
25 // Distance a span can deviate before scaling will start (in dips). | |
tdresser
2014/08/22 18:19:04
Reword this comment. (At least define span)
jdduke (slow)
2014/08/22 20:33:10
Done.
jdduke (slow)
2014/08/22 20:33:10
Done.
| |
26 float span_slop; | |
27 | 27 |
28 // Minimum accepted value for TouchMajor while scaling (in dips). | 28 // Minimum accepted value for TouchMajor while scaling (in dips). |
29 float min_scaling_touch_major; | 29 float min_scaling_touch_major; |
30 | 30 |
31 // Minimum span needed to initiate a scaling gesture (in dips). | 31 // Minimum span needed to initiate a scaling gesture (in dips). |
32 float min_scaling_span; | 32 float min_scaling_span; |
33 | 33 |
34 // Whether double-tap drag scaling is enabled. | |
35 bool quick_scale_enabled; | |
36 | |
37 // Minimum pinch span change before pinch occurs (in dips). See | 34 // Minimum pinch span change before pinch occurs (in dips). See |
38 // crbug.com/373318. | 35 // crbug.com/373318. |
39 float min_pinch_update_span_delta; | 36 float min_pinch_update_span_delta; |
40 }; | 37 }; |
41 | 38 |
42 class ScaleGestureListener { | 39 class ScaleGestureListener { |
43 public: | 40 public: |
44 virtual ~ScaleGestureListener() {} | 41 virtual ~ScaleGestureListener() {} |
45 virtual bool OnScale(const ScaleGestureDetector& detector, | 42 virtual bool OnScale(const ScaleGestureDetector& detector, |
46 const MotionEvent& e) = 0; | 43 const MotionEvent& e) = 0; |
(...skipping 28 matching lines...) Expand all Loading... | |
75 // | 72 // |
76 // Note: Applications should pass a complete and consistent event stream to | 73 // Note: Applications should pass a complete and consistent event stream to |
77 // this method. A complete and consistent event stream involves all | 74 // this method. A complete and consistent event stream involves all |
78 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or | 75 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or |
79 // ACTION_CANCEL. | 76 // ACTION_CANCEL. |
80 // | 77 // |
81 // Returns true if the event was processed and the detector wants to receive | 78 // Returns true if the event was processed and the detector wants to receive |
82 // the rest of the MotionEvents in this event stream. | 79 // the rest of the MotionEvents in this event stream. |
83 bool OnTouchEvent(const MotionEvent& event); | 80 bool OnTouchEvent(const MotionEvent& event); |
84 | 81 |
82 // This method may be called by the owner when a a double-tap event has been | |
83 // detected *for the same event stream* being fed to this instance of the | |
84 // ScaleGestureDetector. As call order is important here, the double-tap | |
85 // detector should always be offered events *before* the ScaleGestureDetector. | |
86 bool OnDoubleTap(const MotionEvent& event); | |
87 | |
85 // Set whether the associated |ScaleGestureListener| should receive | 88 // Set whether the associated |ScaleGestureListener| should receive |
86 // OnScale callbacks when the user performs a doubletap followed by a swipe. | 89 // OnScale callbacks when the user performs a doubletap followed by a swipe. |
87 void SetQuickScaleEnabled(bool scales); | |
88 bool IsQuickScaleEnabled() const; | |
89 bool IsInProgress() const; | 90 bool IsInProgress() const; |
90 bool InDoubleTapMode() const; | 91 bool InDoubleTapMode() const; |
91 float GetFocusX() const; | 92 float GetFocusX() const; |
92 float GetFocusY() const; | 93 float GetFocusY() const; |
93 float GetCurrentSpan() const; | 94 float GetCurrentSpan() const; |
94 float GetCurrentSpanX() const; | 95 float GetCurrentSpanX() const; |
95 float GetCurrentSpanY() const; | 96 float GetCurrentSpanY() const; |
96 float GetPreviousSpan() const; | 97 float GetPreviousSpan() const; |
97 float GetPreviousSpanX() const; | 98 float GetPreviousSpanX() const; |
98 float GetPreviousSpanY() const; | 99 float GetPreviousSpanY() const; |
99 float GetScaleFactor() const; | 100 float GetScaleFactor() const; |
100 base::TimeDelta GetTimeDelta() const; | 101 base::TimeDelta GetTimeDelta() const; |
101 base::TimeTicks GetEventTime() const; | 102 base::TimeTicks GetEventTime() const; |
102 | 103 |
103 private: | 104 private: |
104 enum DoubleTapMode { DOUBLE_TAP_MODE_NONE, DOUBLE_TAP_MODE_IN_PROGRESS }; | 105 enum DoubleTapMode { DOUBLE_TAP_MODE_NONE, DOUBLE_TAP_MODE_IN_PROGRESS }; |
105 | 106 |
106 // DoubleTapListener implementation. | |
107 virtual bool OnDoubleTap(const MotionEvent& ev) OVERRIDE; | |
108 | |
109 // The TouchMajor/TouchMinor elements of a MotionEvent can flutter/jitter on | 107 // The TouchMajor/TouchMinor elements of a MotionEvent can flutter/jitter on |
110 // some hardware/driver combos. Smooth out to get kinder, gentler behavior. | 108 // some hardware/driver combos. Smooth out to get kinder, gentler behavior. |
111 void AddTouchHistory(const MotionEvent& ev); | 109 void AddTouchHistory(const MotionEvent& ev); |
112 void ResetTouchHistory(); | 110 void ResetTouchHistory(); |
113 | 111 |
114 void ResetScaleWithSpan(float span); | 112 void ResetScaleWithSpan(float span); |
115 | 113 |
116 ScaleGestureListener* const listener_; | 114 ScaleGestureListener* const listener_; |
117 | 115 |
118 Config config_; | |
119 | |
120 float focus_x_; | 116 float focus_x_; |
121 float focus_y_; | 117 float focus_y_; |
122 | |
123 bool quick_scale_enabled_; | |
124 | |
125 float curr_span_; | 118 float curr_span_; |
126 float prev_span_; | 119 float prev_span_; |
127 float initial_span_; | 120 float initial_span_; |
128 float curr_span_x_; | 121 float curr_span_x_; |
129 float curr_span_y_; | 122 float curr_span_y_; |
130 float prev_span_x_; | 123 float prev_span_x_; |
131 float prev_span_y_; | 124 float prev_span_y_; |
132 base::TimeTicks curr_time_; | 125 base::TimeTicks curr_time_; |
133 base::TimeTicks prev_time_; | 126 base::TimeTicks prev_time_; |
134 bool in_progress_; | 127 bool in_progress_; |
135 float span_slop_; | 128 float span_slop_; |
136 float min_span_; | 129 float min_span_; |
137 | 130 |
138 // Bounds for recently seen values. | 131 // Bounds for recently seen values. |
139 float touch_upper_; | 132 float touch_upper_; |
140 float touch_lower_; | 133 float touch_lower_; |
141 float touch_history_last_accepted_; | 134 float touch_history_last_accepted_; |
142 int touch_history_direction_; | 135 int touch_history_direction_; |
143 base::TimeTicks touch_history_last_accepted_time_; | 136 base::TimeTicks touch_history_last_accepted_time_; |
144 float touch_min_major_; | 137 float touch_min_major_; |
145 float touch_max_major_; | 138 float touch_max_major_; |
146 float double_tap_focus_x_; | 139 float double_tap_focus_x_; |
147 float double_tap_focus_y_; | 140 float double_tap_focus_y_; |
148 DoubleTapMode double_tap_mode_; | 141 DoubleTapMode double_tap_mode_; |
149 | 142 |
150 bool event_before_or_above_starting_gesture_event_; | 143 bool event_before_or_above_starting_gesture_event_; |
151 | 144 |
152 scoped_ptr<GestureDetector> gesture_detector_; | |
153 | |
154 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector); | 145 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector); |
155 }; | 146 }; |
156 | 147 |
157 } // namespace ui | 148 } // namespace ui |
158 | 149 |
159 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_ | 150 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_ |
OLD | NEW |