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

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

Issue 128613003: [Tracking Patch] Unified gesture detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Cleanup 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_SCALE_GESTURE_DETECTOR_H_
6 #define UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/time/time.h"
10 #include "ui/events/gesture_detection/gesture_detection_export.h"
11 #include "ui/events/gesture_detection/gesture_detector.h"
12
13 namespace ui {
14
15 class MotionEvent;
16
17 // Port of ScaleGestureDetector.java from Android
18 // * platform/frameworks/base/core/java/android/view/ScaleGestureDetector.java
19 // * Change-Id: I3e7926a4f6f9ab4951f380bd004499c78b3bda69
20 // * Please update the Change-Id as upstream Android changes are pulled.
21 class ScaleGestureDetector : public GestureDetector::SimpleOnGestureListener {
22 public:
23 struct GESTURE_DETECTION_EXPORT Config {
24 Config();
25 ~Config();
26 GestureDetector::Config gesture_detector_config;
27 bool quick_scale_enabled;
28 int min_scaling_touch_major;
29 int min_scaling_span;
30 };
31
32 class OnScaleGestureListener {
33 public:
34 virtual ~OnScaleGestureListener() {}
35 virtual bool OnScale(const ScaleGestureDetector& detector) = 0;
36 virtual bool OnScaleBegin(const ScaleGestureDetector& detector) = 0;
37 virtual void OnScaleEnd(const ScaleGestureDetector& detector) = 0;
38 };
39
40 // A convenience class to extend when you only want to listen for a subset of
41 // scaling-related events. This implements all methods in
42 // |OnScaleGestureListener| but does nothing.
43 // |OnScale()| returns false so that a subclass can retrieve the accumulated
44 // scale factor in an overridden |OnScaleEnd()|.
45 // |OnScaleBegin() returns true.
46 class SimpleOnScaleGestureListener : public OnScaleGestureListener {
47 public:
48 virtual bool OnScale(const ScaleGestureDetector&) OVERRIDE;
49 virtual bool OnScaleBegin(const ScaleGestureDetector&) OVERRIDE;
50 virtual void OnScaleEnd(const ScaleGestureDetector&) OVERRIDE;
51 };
52
53 ScaleGestureDetector(const Config& config, OnScaleGestureListener* listener);
54 virtual ~ScaleGestureDetector();
55
56 // Accepts MotionEvents and dispatches events to a |OnScaleGestureListener|
57 // when appropriate.
58 //
59 // Note: Applications should pass a complete and consistent event stream to
60 // this method. A complete and consistent event stream involves all
61 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or
62 // ACTION_CANCEL.
63 //
64 // Returns true if the event was processed and the detector wants to receive
65 // the rest of the MotionEvents in this event stream.
66 bool OnTouchEvent(const MotionEvent& event);
67
68 // Set whether the associated |OnScaleGestureListener| should receive
69 // OnScale callbacks when the user performs a doubletap followed by a swipe.
70 void SetQuickScaleEnabled(bool scales);
71 bool IsQuickScaleEnabled() const;
72 bool IsInProgress() const;
73 float GetFocusX() const;
74 float GetFocusY() const;
75 float GetCurrentSpan() const;
76 float GetCurrentSpanX() const;
77 float GetCurrentSpanY() const;
78 float GetPreviousSpan() const;
79 float GetPreviousSpanX() const;
80 float GetPreviousSpanY() const;
81 float GetScaleFactor() const;
82 base::TimeDelta GetTimeDelta() const;
83 base::TimeTicks GetEventTime() const;
84
85 private:
86 enum DoubleTapMode {
87 DOUBLE_TAP_MODE_NONE,
88 DOUBLE_TAP_MODE_IN_PROGRESS
89 };
90
91 // OnDoubleTapListener
92 virtual bool OnDoubleTap(const MotionEvent& ev) OVERRIDE;
93
94 // The touchMajor/touchMinor elements of a MotionEvent can flutter/jitter on
95 // some hardware/driver combos. Smooth out to get kinder, gentler behavior.
96 void AddTouchHistory(const MotionEvent& ev);
97 void ClearTouchHistory();
98 bool InDoubleTapMode() const;
99
100 OnScaleGestureListener* const listener_;
101
102 Config config_;
103
104 float focus_x_;
105 float focus_y_;
106
107 bool quick_scale_enabled_;
108
109 float curr_span_;
110 float prev_span_;
111 float initial_span_;
112 float curr_span_x_;
113 float curr_span_y_;
114 float prev_span_x_;
115 float prev_span_y_;
116 base::TimeTicks curr_time_;
117 base::TimeTicks prev_time_;
118 bool in_progress_;
119 int span_slop_;
120 int min_span_;
121
122 // Bounds for recently seen values
123 float touch_upper_;
124 float touch_lower_;
125 float touch_history_last_accepted_;
126 int touch_history_direction_;
127 base::TimeTicks touch_history_last_accepted_time_;
128 int touch_min_major_;
129 float double_tap_focus_x_;
130 float double_tap_focus_y_;
131 DoubleTapMode double_tap_mode_;
132
133 bool event_before_or_above_starting_gesture_event_;
134
135 scoped_ptr<GestureDetector> gesture_detector_;
136
137 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector);
138 };
139
140 } // namespace ui
141
142 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698