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

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

Issue 634373003: Consolidate content fling implementations (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix win build Created 6 years, 2 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
« no previous file with comments | « ui/events/android/OWNERS ('k') | ui/events/android/scroller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_GFX_ANDROID_SCROLLER_H_ 5 #ifndef UI_EVENTS_ANDROID_SCROLLER_H_
6 #define UI_GFX_ANDROID_SCROLLER_H_ 6 #define UI_EVENTS_ANDROID_SCROLLER_H_
7 7
8 #include "base/time/time.h" 8 #include "base/time/time.h"
9 #include "ui/gfx/gfx_export.h" 9 #include "ui/events/events_base_export.h"
10 #include "ui/events/gesture_curve.h"
11 #include "ui/gfx/geometry/vector2d_f.h"
10 12
11 namespace gfx { 13 namespace ui {
12 14
13 // Native port of android.widget.Scroller. 15 // Native port of android.widget.Scroller.
14 // * Change-Id: I4365946f890a76fcfa78ca9d69f2a8e0848095a9 16 // * Change-Id: I4365946f890a76fcfa78ca9d69f2a8e0848095a9
15 // * Please update the Change-Id as upstream Android changes are pulled. 17 // * Please update the Change-Id as upstream Android changes are pulled.
16 class GFX_EXPORT Scroller { 18 class EVENTS_BASE_EXPORT Scroller : public GestureCurve {
17 public: 19 public:
18 struct Config { 20 struct Config {
19 Config(); 21 Config();
20 22
21 // Controls fling deceleration. Defaults to 0.015f. 23 // Controls fling deceleration. Defaults to 0.015f.
22 float fling_friction; 24 float fling_friction;
23 25
24 // Controls fling accumulation. Defaults to disabled. 26 // Controls fling accumulation. Defaults to disabled.
25 bool flywheel_enabled; 27 bool flywheel_enabled;
26 }; 28 };
27 29
28 explicit Scroller(const Config& config); 30 explicit Scroller(const Config& config);
29 ~Scroller(); 31 virtual ~Scroller();
32
33 // GestureCurve implementation.
34 virtual bool ComputeScrollOffset(base::TimeTicks time,
35 gfx::Vector2dF* offset,
36 gfx::Vector2dF* velocity) override;
30 37
31 // Start scrolling by providing a starting point and the distance to travel. 38 // Start scrolling by providing a starting point and the distance to travel.
32 // The default value of 250 milliseconds will be used for the duration. 39 // The default value of 250 milliseconds will be used for the duration.
33 void StartScroll(float start_x, 40 void StartScroll(float start_x,
34 float start_y, 41 float start_y,
35 float dx, 42 float dx,
36 float dy, 43 float dy,
37 base::TimeTicks start_time); 44 base::TimeTicks start_time);
38 45
39 // Start scrolling by providing a starting point, the distance to travel, 46 // Start scrolling by providing a starting point, the distance to travel,
(...skipping 10 matching lines...) Expand all
50 void Fling(float start_x, 57 void Fling(float start_x,
51 float start_y, 58 float start_y,
52 float velocity_x, 59 float velocity_x,
53 float velocity_y, 60 float velocity_y,
54 float min_x, 61 float min_x,
55 float max_x, 62 float max_x,
56 float min_y, 63 float min_y,
57 float max_y, 64 float max_y,
58 base::TimeTicks start_time); 65 base::TimeTicks start_time);
59 66
60 // Call this when you want to know the new location. If it returns true,
61 // the animation is not yet finished.
62 bool ComputeScrollOffset(base::TimeTicks time);
63
64 // Extend the scroll animation by |extend|. This allows a running animation 67 // Extend the scroll animation by |extend|. This allows a running animation
65 // to scroll further and longer when used with |SetFinalX()| or |SetFinalY()|. 68 // to scroll further and longer when used with |SetFinalX()| or |SetFinalY()|.
66 void ExtendDuration(base::TimeDelta extend); 69 void ExtendDuration(base::TimeDelta extend);
67 void SetFinalX(float new_x); 70 void SetFinalX(float new_x);
68 void SetFinalY(float new_y); 71 void SetFinalY(float new_y);
69 72
70 // Stops the animation. Contrary to |ForceFinished()|, aborting the animation 73 // Stops the animation. Contrary to |ForceFinished()|, aborting the animation
71 // causes the scroller to move to the final x and y position. 74 // causes the scroller to move to the final x and y position.
72 void AbortAnimation(); 75 void AbortAnimation();
73 76
(...skipping 21 matching lines...) Expand all
95 98
96 bool IsScrollingInDirection(float xvel, float yvel) const; 99 bool IsScrollingInDirection(float xvel, float yvel) const;
97 100
98 private: 101 private:
99 enum Mode { 102 enum Mode {
100 UNDEFINED, 103 UNDEFINED,
101 SCROLL_MODE, 104 SCROLL_MODE,
102 FLING_MODE, 105 FLING_MODE,
103 }; 106 };
104 107
105 void OnDurationChanged(); 108 bool ComputeScrollOffsetInternal(base::TimeTicks time);
106 void RecomputeDeltas(); 109 void RecomputeDeltas();
107 110
108 double GetSplineDeceleration(float velocity) const; 111 double GetSplineDeceleration(float velocity) const;
109 base::TimeDelta GetSplineFlingDuration(float velocity) const; 112 base::TimeDelta GetSplineFlingDuration(float velocity) const;
110 double GetSplineFlingDistance(float velocity) const; 113 double GetSplineFlingDistance(float velocity) const;
111 114
112 Mode mode_; 115 Mode mode_;
113 116
114 float start_x_; 117 float start_x_;
115 float start_y_; 118 float start_y_;
(...skipping 20 matching lines...) Expand all
136 139
137 float velocity_; 140 float velocity_;
138 float curr_velocity_; 141 float curr_velocity_;
139 float distance_; 142 float distance_;
140 143
141 float fling_friction_; 144 float fling_friction_;
142 float deceleration_; 145 float deceleration_;
143 float tuning_coeff_; 146 float tuning_coeff_;
144 }; 147 };
145 148
146 } // namespace gfx 149 } // namespace ui
147 150
148 #endif // UI_GFX_ANDROID_SCROLLER_H_ 151 #endif // UI_EVENTS_ANDROID_SCROLLER_H_
OLDNEW
« no previous file with comments | « ui/events/android/OWNERS ('k') | ui/events/android/scroller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698