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

Side by Side Diff: ui/gfx/android/scroller.h

Issue 172933004: [Android] Port Scroller.java to C++ and use for fling animations (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_GFX_ANDROID_SCROLLER_H_
6 #define UI_GFX_ANDROID_SCROLLER_H_
7
8 #include "base/time/time.h"
9 #include "ui/gfx/gfx_export.h"
10
11 namespace gfx {
12
13 class SplineOverScroller;
14
15 // Native port of android.widget.Scroller
16 // Change-Id: I4365946f890a76fcfa78ca9d69f2a8e0848095a9
17 class GFX_EXPORT Scroller {
18 public:
19 // |enable_flywheel| determines whether successive calls to |Fling()| during
20 // an active fling animation will accumulate velocity.
21 explicit Scroller(bool enable_flywheel);
22 ~Scroller();
23
24 // Start scrolling by providing a starting point and the distance to travel.
25 // The default value of 250 milliseconds will be used for the duration.
26 void StartScroll(float start_x,
27 float start_y,
28 float dx,
29 float dy,
30 base::TimeTicks start_time);
31
32 // Start scrolling by providing a starting point, the distance to travel,
33 // and the duration of the scroll.
34 void StartScroll(float start_x,
35 float start_y,
36 float dx,
37 float dy,
38 base::TimeTicks start_time,
39 base::TimeDelta duration);
40
41 // Start scrolling based on a fling gesture. The distance travelled will
42 // depend on the initial velocity of the fling.
43 void Fling(float start_x,
44 float start_y,
45 float veloctiy_x,
aelias_OOO_until_Jul13 2014/02/21 02:42:35 typo
jdduke (slow) 2014/02/21 23:33:02 Done.
46 float velocity_y,
47 float min_x,
48 float max_x,
49 float min_y,
50 float max_y,
51 base::TimeTicks start_time);
52
53 // Call this when you want to know the new location. If it returns true,
54 // the animation is not yet finished.
55 bool ComputeScrollOffset(base::TimeTicks time);
56
57 // Extend the scroll animation by |extend|. This allows a running animation
58 // to scroll further and longer when used with |SetFinalX()| or |SetFinalY()|.
59 void ExtendDuration(base::TimeDelta extend);
60 void SetFinalX(float new_x);
61 void SetFinalY(float new_y);
62
63 // Stops the animation. Contrary to |ForceFinished()|, aborting the animation
64 // causes the scroller to move to the final x and y position.
65 void AbortAnimation();
66
67 // Terminate the scroll without affecting the current x and y positions.
68 void ForceFinished(bool finished);
69
70 // Returns whether the scroller has finished scrolling.
71 bool IsFinished() const;
72
73 // Returns the time elapsed since the beginning of the scrolling.
74 base::TimeDelta GetTimePassed() const;
75
76 // Returns how long the scroll event will take.
77 base::TimeDelta GetDuration() const;
78
79 float GetStartX() const;
80 float GetStartY() const;
81 float GetCurrX() const;
82 float GetCurrY() const;
83 float GetCurrVelocity() const;
84 float GetCurrVelocityX() const;
85 float GetCurrVelocityY() const;
86 float GetFinalX() const;
87 float GetFinalY() const;
88
89 bool IsScrollingInDirection(float xvel, float yvel) const;
90
91 private:
92 enum Mode {
93 UNDEFINED,
94 SCROLL_MODE,
95 FLING_MODE,
96 };
97
98 void RecomputeDeltas();
99
100 double GetSplineDeceleration(float velocity) const;
101 base::TimeDelta GetSplineFlingDuration(float velocity) const;
102 double GetSplineFlingDistance(float velocity) const;
103
104 Mode mode_;
105
106 // TODO(jdduke): Convert coordinates to float using proper geometry types.
aelias_OOO_until_Jul13 2014/02/21 02:42:35 On one hand this would make this code more concise
jdduke (slow) 2014/02/21 23:33:02 I'll remove the TODO for now, it's probably not hi
107 float start_x_;
108 float start_y_;
109 float final_x_;
110 float final_y_;
111
112 float min_x_;
113 float max_x_;
114 float min_y_;
115 float max_y_;
116
117 float curr_x_;
118 float curr_y_;
119 base::TimeTicks start_time_;
120 base::TimeTicks curr_time_;
121 base::TimeDelta duration_;
122 double duration_seconds_reciprocal_;
123 float delta_x_;
124 float delta_x_norm_;
125 float delta_y_;
126 float delta_y_norm_;
127 bool finished_;
128 bool flywheel_enabled_;
129
130 float velocity_;
131 float curr_velocity_;
132 float distance_;
133
134 float fling_friction_;
135 float deceleration_;
136 float tuning_coeff_;
137 };
138
139 } // namespace gfx
140
141 #endif // UI_GFX_ANDROID_SCROLLER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698