Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / ui / events / android / scroller.h
blob37d41cd3e1bfa127dbe0c50234982bb1740e6485
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.
5 #ifndef UI_EVENTS_ANDROID_SCROLLER_H_
6 #define UI_EVENTS_ANDROID_SCROLLER_H_
8 #include "base/time/time.h"
9 #include "ui/events/events_base_export.h"
10 #include "ui/events/gesture_curve.h"
11 #include "ui/gfx/geometry/vector2d_f.h"
13 namespace ui {
15 // Native port of android.widget.Scroller.
16 // * Change-Id: I4365946f890a76fcfa78ca9d69f2a8e0848095a9
17 // * Please update the Change-Id as upstream Android changes are pulled.
18 class EVENTS_BASE_EXPORT Scroller : public GestureCurve {
19 public:
20 struct Config {
21 Config();
23 // Controls fling deceleration. Defaults to 0.015f.
24 float fling_friction;
26 // Controls fling accumulation. Defaults to disabled.
27 bool flywheel_enabled;
30 explicit Scroller(const Config& config);
31 ~Scroller() override;
33 // GestureCurve implementation.
34 bool ComputeScrollOffset(base::TimeTicks time,
35 gfx::Vector2dF* offset,
36 gfx::Vector2dF* velocity) override;
38 // Start scrolling by providing a starting point and the distance to travel.
39 // The default value of 250 milliseconds will be used for the duration.
40 void StartScroll(float start_x,
41 float start_y,
42 float dx,
43 float dy,
44 base::TimeTicks start_time);
46 // Start scrolling by providing a starting point, the distance to travel,
47 // and the duration of the scroll.
48 void StartScroll(float start_x,
49 float start_y,
50 float dx,
51 float dy,
52 base::TimeTicks start_time,
53 base::TimeDelta duration);
55 // Start scrolling based on a fling gesture. The distance travelled will
56 // depend on the initial velocity of the fling.
57 void Fling(float start_x,
58 float start_y,
59 float velocity_x,
60 float velocity_y,
61 float min_x,
62 float max_x,
63 float min_y,
64 float max_y,
65 base::TimeTicks start_time);
67 // Extend the scroll animation by |extend|. This allows a running animation
68 // to scroll further and longer when used with |SetFinalX()| or |SetFinalY()|.
69 void ExtendDuration(base::TimeDelta extend);
70 void SetFinalX(float new_x);
71 void SetFinalY(float new_y);
73 // Stops the animation. Contrary to |ForceFinished()|, aborting the animation
74 // causes the scroller to move to the final x and y position.
75 void AbortAnimation();
77 // Terminate the scroll without affecting the current x and y positions.
78 void ForceFinished(bool finished);
80 // Returns whether the scroller has finished scrolling.
81 bool IsFinished() const;
83 // Returns the time elapsed since the beginning of the scrolling.
84 base::TimeDelta GetTimePassed() const;
86 // Returns how long the scroll event will take.
87 base::TimeDelta GetDuration() const;
89 float GetStartX() const;
90 float GetStartY() const;
91 float GetCurrX() const;
92 float GetCurrY() const;
93 float GetCurrVelocity() const;
94 float GetCurrVelocityX() const;
95 float GetCurrVelocityY() const;
96 float GetFinalX() const;
97 float GetFinalY() const;
99 bool IsScrollingInDirection(float xvel, float yvel) const;
101 private:
102 enum Mode {
103 UNDEFINED,
104 SCROLL_MODE,
105 FLING_MODE,
108 bool ComputeScrollOffsetInternal(base::TimeTicks time);
109 void RecomputeDeltas();
111 double GetSplineDeceleration(float velocity) const;
112 base::TimeDelta GetSplineFlingDuration(float velocity) const;
113 double GetSplineFlingDistance(float velocity) const;
115 Mode mode_;
117 float start_x_;
118 float start_y_;
119 float final_x_;
120 float final_y_;
122 float min_x_;
123 float max_x_;
124 float min_y_;
125 float max_y_;
127 float curr_x_;
128 float curr_y_;
129 base::TimeTicks start_time_;
130 base::TimeTicks curr_time_;
131 base::TimeDelta duration_;
132 double duration_seconds_reciprocal_;
133 float delta_x_;
134 float delta_x_norm_;
135 float delta_y_;
136 float delta_y_norm_;
137 bool finished_;
138 bool flywheel_enabled_;
140 float velocity_;
141 float curr_velocity_;
142 float distance_;
144 float fling_friction_;
145 float deceleration_;
146 float tuning_coeff_;
149 } // namespace ui
151 #endif // UI_EVENTS_ANDROID_SCROLLER_H_