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

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

Issue 171773012: Port of Android platform gesture detection code to C++ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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::SimpleGestureListener {
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 ScaleGestureListener {
33 public:
34 virtual ~ScaleGestureListener() {}
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 // |ScaleGestureListener| 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 SimpleScaleGestureListener : public ScaleGestureListener {
47 public:
48 // ScaleGestureListener implementation.
49 virtual bool OnScale(const ScaleGestureDetector&) OVERRIDE;
50 virtual bool OnScaleBegin(const ScaleGestureDetector&) OVERRIDE;
51 virtual void OnScaleEnd(const ScaleGestureDetector&) OVERRIDE;
52 };
53
54 ScaleGestureDetector(const Config& config, ScaleGestureListener* listener);
55 virtual ~ScaleGestureDetector();
56
57 // Accepts MotionEvents and dispatches events to a |ScaleGestureListener|
58 // when appropriate.
59 //
60 // Note: Applications should pass a complete and consistent event stream to
61 // this method. A complete and consistent event stream involves all
62 // MotionEvents from the initial ACTION_DOWN to the final ACTION_UP or
63 // ACTION_CANCEL.
64 //
65 // Returns true if the event was processed and the detector wants to receive
66 // the rest of the MotionEvents in this event stream.
67 bool OnTouchEvent(const MotionEvent& event);
68
69 // Set whether the associated |ScaleGestureListener| should receive
70 // OnScale callbacks when the user performs a doubletap followed by a swipe.
71 void SetQuickScaleEnabled(bool scales);
72 bool IsQuickScaleEnabled() const;
73 bool IsInProgress() const;
74 float GetFocusX() const;
75 float GetFocusY() const;
76 float GetCurrentSpan() const;
77 float GetCurrentSpanX() const;
78 float GetCurrentSpanY() const;
79 float GetPreviousSpan() const;
80 float GetPreviousSpanX() const;
81 float GetPreviousSpanY() const;
82 float GetScaleFactor() const;
83 base::TimeDelta GetTimeDelta() const;
84 base::TimeTicks GetEventTime() const;
85
86 private:
87 enum DoubleTapMode { DOUBLE_TAP_MODE_NONE, DOUBLE_TAP_MODE_IN_PROGRESS };
88
89 // DoubleTapListener implementation.
90 virtual bool OnDoubleTap(const MotionEvent& ev) OVERRIDE;
91
92 // The TouchMajor/TouchMinor elements of a MotionEvent can flutter/jitter on
93 // some hardware/driver combos. Smooth out to get kinder, gentler behavior.
94 void AddTouchHistory(const MotionEvent& ev);
95 void ClearTouchHistory();
96 bool InDoubleTapMode() const;
97
98 ScaleGestureListener* const listener_;
99
100 Config config_;
101
102 float focus_x_;
103 float focus_y_;
104
105 bool quick_scale_enabled_;
106
107 float curr_span_;
108 float prev_span_;
109 float initial_span_;
110 float curr_span_x_;
111 float curr_span_y_;
112 float prev_span_x_;
113 float prev_span_y_;
114 base::TimeTicks curr_time_;
115 base::TimeTicks prev_time_;
116 bool in_progress_;
117 int span_slop_;
118 int min_span_;
119
120 // Bounds for recently seen values.
121 float touch_upper_;
122 float touch_lower_;
123 float touch_history_last_accepted_;
124 int touch_history_direction_;
125 base::TimeTicks touch_history_last_accepted_time_;
126 int touch_min_major_;
127 float double_tap_focus_x_;
128 float double_tap_focus_y_;
129 DoubleTapMode double_tap_mode_;
130
131 bool event_before_or_above_starting_gesture_event_;
132
133 scoped_ptr<GestureDetector> gesture_detector_;
134
135 DISALLOW_COPY_AND_ASSIGN(ScaleGestureDetector);
136 };
137
138 } // namespace ui
139
140 #endif // UI_EVENTS_GESTURE_DETECTION_SCALE_GESTURE_DETECTOR_H_
OLDNEW
« no previous file with comments | « ui/events/gesture_detection/motion_event.h ('k') | ui/events/gesture_detection/scale_gesture_detector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698