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/time/time.h" | 8 #include "base/time/time.h" |
9 #include "ui/events/gesture_detection/gesture_detection_export.h" | 9 #include "ui/events/gesture_detection/gesture_detection_export.h" |
10 | 10 |
11 namespace ui { | 11 namespace ui { |
12 | 12 |
13 class MotionEvent; | 13 class MotionEvent; |
| 14 class ScaleGestureListener; |
14 | 15 |
15 // Port of ScaleGestureDetector.java from Android | 16 // Port of ScaleGestureDetector.java from Android |
16 // * platform/frameworks/base/core/java/android/view/ScaleGestureDetector.java | 17 // * platform/frameworks/base/core/java/android/view/ScaleGestureDetector.java |
17 // * Change-Id: I3e7926a4f6f9ab4951f380bd004499c78b3bda69 | 18 // * Change-Id: I3e7926a4f6f9ab4951f380bd004499c78b3bda69 |
18 // * Please update the Change-Id as upstream Android changes are pulled. | 19 // * Please update the Change-Id as upstream Android changes are pulled. |
19 class ScaleGestureDetector { | 20 class GESTURE_DETECTION_EXPORT ScaleGestureDetector { |
20 public: | 21 public: |
21 struct GESTURE_DETECTION_EXPORT Config { | 22 struct GESTURE_DETECTION_EXPORT Config { |
22 Config(); | 23 Config(); |
23 ~Config(); | 24 ~Config(); |
24 | 25 |
25 // Distance the current span can deviate from the initial span before | 26 // 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 // scaling will start (in dips). The span is the diameter of the circle with |
27 // a radius of average pointer deviation from the focal point. | 28 // a radius of average pointer deviation from the focal point. |
28 float span_slop; | 29 float span_slop; |
29 | 30 |
30 // Minimum accepted value for TouchMajor while scaling (in dips). | 31 // Minimum accepted value for TouchMajor while scaling (in dips). |
31 float min_scaling_touch_major; | 32 float min_scaling_touch_major; |
32 | 33 |
33 // Minimum span needed to initiate a scaling gesture (in dips). | 34 // Minimum span needed to initiate a scaling gesture (in dips). |
34 float min_scaling_span; | 35 float min_scaling_span; |
35 | 36 |
36 // Minimum pinch span change before pinch occurs (in dips). See | 37 // Minimum pinch span change before pinch occurs (in dips). See |
37 // crbug.com/373318. | 38 // crbug.com/373318. |
38 float min_pinch_update_span_delta; | 39 float min_pinch_update_span_delta; |
39 }; | 40 }; |
40 | 41 |
41 class ScaleGestureListener { | |
42 public: | |
43 virtual ~ScaleGestureListener() {} | |
44 virtual bool OnScale(const ScaleGestureDetector& detector, | |
45 const MotionEvent& e) = 0; | |
46 virtual bool OnScaleBegin(const ScaleGestureDetector& detector, | |
47 const MotionEvent& e) = 0; | |
48 virtual void OnScaleEnd(const ScaleGestureDetector& detector, | |
49 const MotionEvent& e) = 0; | |
50 }; | |
51 | |
52 // A convenience class to extend when you only want to listen for a subset of | |
53 // scaling-related events. This implements all methods in | |
54 // |ScaleGestureListener| but does nothing. | |
55 // |OnScale()| returns false so that a subclass can retrieve the accumulated | |
56 // scale factor in an overridden |OnScaleEnd()|. | |
57 // |OnScaleBegin() returns true. | |
58 class SimpleScaleGestureListener : public ScaleGestureListener { | |
59 public: | |
60 // ScaleGestureListener implementation. | |
61 virtual bool OnScale(const ScaleGestureDetector&, | |
62 const MotionEvent&) OVERRIDE; | |
63 virtual bool OnScaleBegin(const ScaleGestureDetector&, | |
64 const MotionEvent&) OVERRIDE; | |
65 virtual void OnScaleEnd(const ScaleGestureDetector&, | |
66 const MotionEvent&) OVERRIDE; | |
67 }; | |
68 | |
69 ScaleGestureDetector(const Config& config, ScaleGestureListener* listener); | 42 ScaleGestureDetector(const Config& config, ScaleGestureListener* listener); |
70 virtual ~ScaleGestureDetector(); | 43 virtual ~ScaleGestureDetector(); |
71 | 44 |
72 // Accepts MotionEvents and dispatches events to a |ScaleGestureListener| | 45 // Accepts MotionEvents and dispatches events to a |ScaleGestureListener| |
73 // when appropriate. | 46 // when appropriate. |
74 // | 47 // |
75 // Note: Applications should pass a complete and consistent event stream to | 48 // Note: Applications should pass a complete and consistent event stream to |
76 // this method. A complete and consistent event stream involves all | 49 // this method. A complete and consistent event stream involves all |
77 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or | 50 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or |
78 // ACTION_CANCEL. | 51 // ACTION_CANCEL. |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 DoubleTapMode double_tap_mode_; | 116 DoubleTapMode double_tap_mode_; |
144 | 117 |
145 bool event_before_or_above_starting_gesture_event_; | 118 bool event_before_or_above_starting_gesture_event_; |
146 | 119 |
147 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector); | 120 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector); |
148 }; | 121 }; |
149 | 122 |
150 } // namespace ui | 123 } // namespace ui |
151 | 124 |
152 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_ | 125 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_ |
OLD | NEW |