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

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

Issue 501503003: Avoid an extra GestureDetector instance for double-tap drag zooming (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Code review Created 6 years, 4 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
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 the current span can deviate from the initial span before
26 // scaling will start (in dips). The span is the diameter of the circle with
27 // a radius of average pointer deviation from the focial point.
tdresser 2014/08/22 20:45:40 focial -> focal
jdduke (slow) 2014/08/22 21:26:55 Bah, yeah I'll do it now.
28 float span_slop;
27 29
28 // Minimum accepted value for TouchMajor while scaling (in dips). 30 // Minimum accepted value for TouchMajor while scaling (in dips).
29 float min_scaling_touch_major; 31 float min_scaling_touch_major;
30 32
31 // Minimum span needed to initiate a scaling gesture (in dips). 33 // Minimum span needed to initiate a scaling gesture (in dips).
32 float min_scaling_span; 34 float min_scaling_span;
33 35
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 36 // Minimum pinch span change before pinch occurs (in dips). See
38 // crbug.com/373318. 37 // crbug.com/373318.
39 float min_pinch_update_span_delta; 38 float min_pinch_update_span_delta;
40 }; 39 };
41 40
42 class ScaleGestureListener { 41 class ScaleGestureListener {
43 public: 42 public:
44 virtual ~ScaleGestureListener() {} 43 virtual ~ScaleGestureListener() {}
45 virtual bool OnScale(const ScaleGestureDetector& detector, 44 virtual bool OnScale(const ScaleGestureDetector& detector,
46 const MotionEvent& e) = 0; 45 const MotionEvent& e) = 0;
(...skipping 28 matching lines...) Expand all
75 // 74 //
76 // Note: Applications should pass a complete and consistent event stream to 75 // Note: Applications should pass a complete and consistent event stream to
77 // this method. A complete and consistent event stream involves all 76 // this method. A complete and consistent event stream involves all
78 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or 77 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or
79 // ACTION_CANCEL. 78 // ACTION_CANCEL.
80 // 79 //
81 // Returns true if the event was processed and the detector wants to receive 80 // Returns true if the event was processed and the detector wants to receive
82 // the rest of the MotionEvents in this event stream. 81 // the rest of the MotionEvents in this event stream.
83 bool OnTouchEvent(const MotionEvent& event); 82 bool OnTouchEvent(const MotionEvent& event);
84 83
84 // This method may be called by the owner when a a double-tap event has been
85 // detected *for the same event stream* being fed to this instance of the
86 // ScaleGestureDetector. As call order is important here, the double-tap
87 // detector should always be offered events *before* the ScaleGestureDetector.
88 bool OnDoubleTap(const MotionEvent& event);
89
85 // Set whether the associated |ScaleGestureListener| should receive 90 // Set whether the associated |ScaleGestureListener| should receive
86 // OnScale callbacks when the user performs a doubletap followed by a swipe. 91 // 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; 92 bool IsInProgress() const;
90 bool InDoubleTapMode() const; 93 bool InDoubleTapMode() const;
91 float GetFocusX() const; 94 float GetFocusX() const;
92 float GetFocusY() const; 95 float GetFocusY() const;
93 float GetCurrentSpan() const; 96 float GetCurrentSpan() const;
94 float GetCurrentSpanX() const; 97 float GetCurrentSpanX() const;
95 float GetCurrentSpanY() const; 98 float GetCurrentSpanY() const;
96 float GetPreviousSpan() const; 99 float GetPreviousSpan() const;
97 float GetPreviousSpanX() const; 100 float GetPreviousSpanX() const;
98 float GetPreviousSpanY() const; 101 float GetPreviousSpanY() const;
99 float GetScaleFactor() const; 102 float GetScaleFactor() const;
100 base::TimeDelta GetTimeDelta() const; 103 base::TimeDelta GetTimeDelta() const;
101 base::TimeTicks GetEventTime() const; 104 base::TimeTicks GetEventTime() const;
102 105
103 private: 106 private:
104 enum DoubleTapMode { DOUBLE_TAP_MODE_NONE, DOUBLE_TAP_MODE_IN_PROGRESS }; 107 enum DoubleTapMode { DOUBLE_TAP_MODE_NONE, DOUBLE_TAP_MODE_IN_PROGRESS };
105 108
106 // DoubleTapListener implementation.
107 virtual bool OnDoubleTap(const MotionEvent& ev) OVERRIDE;
108
109 // The TouchMajor/TouchMinor elements of a MotionEvent can flutter/jitter on 109 // The TouchMajor/TouchMinor elements of a MotionEvent can flutter/jitter on
110 // some hardware/driver combos. Smooth out to get kinder, gentler behavior. 110 // some hardware/driver combos. Smooth out to get kinder, gentler behavior.
111 void AddTouchHistory(const MotionEvent& ev); 111 void AddTouchHistory(const MotionEvent& ev);
112 void ResetTouchHistory(); 112 void ResetTouchHistory();
113 113
114 void ResetScaleWithSpan(float span); 114 void ResetScaleWithSpan(float span);
115 115
116 ScaleGestureListener* const listener_; 116 ScaleGestureListener* const listener_;
117 117
118 Config config_;
119
120 float focus_x_; 118 float focus_x_;
121 float focus_y_; 119 float focus_y_;
122
123 bool quick_scale_enabled_;
124
125 float curr_span_; 120 float curr_span_;
126 float prev_span_; 121 float prev_span_;
127 float initial_span_; 122 float initial_span_;
128 float curr_span_x_; 123 float curr_span_x_;
129 float curr_span_y_; 124 float curr_span_y_;
130 float prev_span_x_; 125 float prev_span_x_;
131 float prev_span_y_; 126 float prev_span_y_;
132 base::TimeTicks curr_time_; 127 base::TimeTicks curr_time_;
133 base::TimeTicks prev_time_; 128 base::TimeTicks prev_time_;
134 bool in_progress_; 129 bool in_progress_;
135 float span_slop_; 130 float span_slop_;
136 float min_span_; 131 float min_span_;
137 132
138 // Bounds for recently seen values. 133 // Bounds for recently seen values.
139 float touch_upper_; 134 float touch_upper_;
140 float touch_lower_; 135 float touch_lower_;
141 float touch_history_last_accepted_; 136 float touch_history_last_accepted_;
142 int touch_history_direction_; 137 int touch_history_direction_;
143 base::TimeTicks touch_history_last_accepted_time_; 138 base::TimeTicks touch_history_last_accepted_time_;
144 float touch_min_major_; 139 float touch_min_major_;
145 float touch_max_major_; 140 float touch_max_major_;
146 float double_tap_focus_x_; 141 float double_tap_focus_x_;
147 float double_tap_focus_y_; 142 float double_tap_focus_y_;
148 DoubleTapMode double_tap_mode_; 143 DoubleTapMode double_tap_mode_;
149 144
150 bool event_before_or_above_starting_gesture_event_; 145 bool event_before_or_above_starting_gesture_event_;
151 146
152 scoped_ptr<GestureDetector> gesture_detector_;
153
154 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector); 147 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector);
155 }; 148 };
156 149
157 } // namespace ui 150 } // namespace ui
158 151
159 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_ 152 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/gesture_provider_unittest.cc ('k') | ui/events/gesture_detection/scale_gesture_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698