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

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: Address tdresser@ comments and run clang-format on everything 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;
Xianzhu 2014/02/19 22:01:56 DISALLOW_COPY_AND_ASSIGN?
jdduke (slow) 2014/02/20 18:01:09 Hmm, as an empty class it's nice to leave that off
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 { DOUBLE_TAP_MODE_NONE, DOUBLE_TAP_MODE_IN_PROGRESS };
87
88 // OnDoubleTapListener
89 virtual bool OnDoubleTap(const MotionEvent& ev) OVERRIDE;
90
91 // The TouchMajor/TouchMinor elements of a MotionEvent can flutter/jitter on
92 // some hardware/driver combos. Smooth out to get kinder, gentler behavior.
93 void AddTouchHistory(const MotionEvent& ev);
94 void ClearTouchHistory();
95 bool InDoubleTapMode() const;
96
97 OnScaleGestureListener* const listener_;
98
99 Config config_;
100
101 float focus_x_;
102 float focus_y_;
103
104 bool quick_scale_enabled_;
105
106 float curr_span_;
107 float prev_span_;
108 float initial_span_;
109 float curr_span_x_;
110 float curr_span_y_;
111 float prev_span_x_;
112 float prev_span_y_;
113 base::TimeTicks curr_time_;
114 base::TimeTicks prev_time_;
115 bool in_progress_;
116 int span_slop_;
117 int min_span_;
118
119 // Bounds for recently seen values
120 float touch_upper_;
121 float touch_lower_;
122 float touch_history_last_accepted_;
123 int touch_history_direction_;
124 base::TimeTicks touch_history_last_accepted_time_;
125 int touch_min_major_;
126 float double_tap_focus_x_;
127 float double_tap_focus_y_;
128 DoubleTapMode double_tap_mode_;
129
130 bool event_before_or_above_starting_gesture_event_;
131
132 scoped_ptr<GestureDetector> gesture_detector_;
133
134 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector);
135 };
136
137 } // namespace ui
138
139 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698