Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / scroll / ScrollAnimatorNone.h
1 /*
2  * Copyright (c) 2011, Google Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #ifndef ScrollAnimatorNone_h
32 #define ScrollAnimatorNone_h
33
34 #include "platform/Timer.h"
35 #include "platform/geometry/FloatPoint.h"
36 #include "platform/scroll/ScrollAnimator.h"
37
38 class ScrollAnimatorNoneTest;
39
40 namespace blink {
41
42 class PLATFORM_EXPORT ScrollAnimatorNone : public ScrollAnimator {
43 public:
44     explicit ScrollAnimatorNone(ScrollableArea*);
45     virtual ~ScrollAnimatorNone();
46
47     virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float delta) OVERRIDE;
48     virtual void scrollToOffsetWithoutAnimation(const FloatPoint&) OVERRIDE;
49
50     virtual void cancelAnimations() OVERRIDE;
51     virtual void serviceScrollAnimations() OVERRIDE;
52
53     virtual void willEndLiveResize() OVERRIDE;
54     virtual void didAddVerticalScrollbar(Scrollbar*) OVERRIDE;
55     virtual void didAddHorizontalScrollbar(Scrollbar*) OVERRIDE;
56
57     enum Curve {
58         Linear,
59         Quadratic,
60         Cubic,
61         Quartic,
62         Bounce
63     };
64
65     struct PLATFORM_EXPORT Parameters {
66         Parameters();
67         Parameters(bool isEnabled, double animationTime, double repeatMinimumSustainTime, Curve attackCurve, double attackTime, Curve releaseCurve, double releaseTime, Curve coastTimeCurve, double maximumCoastTime);
68
69         // Note that the times can be overspecified such that releaseTime or releaseTime and attackTime are greater
70         // than animationTime. animationTime takes priority over releaseTime, capping it. attackTime is capped at
71         // whatever time remains, or zero if none.
72         bool m_isEnabled;
73         double m_animationTime;
74         double m_repeatMinimumSustainTime;
75
76         Curve m_attackCurve;
77         double m_attackTime;
78
79         Curve m_releaseCurve;
80         double m_releaseTime;
81
82         Curve m_coastTimeCurve;
83         double m_maximumCoastTime;
84     };
85
86 protected:
87     virtual void animationWillStart() { }
88     virtual void animationDidFinish() { }
89
90     Parameters parametersForScrollGranularity(ScrollGranularity) const;
91
92     friend class ::ScrollAnimatorNoneTest;
93
94     struct PLATFORM_EXPORT PerAxisData {
95         PerAxisData(ScrollAnimatorNone* parent, float* currentPos, int visibleLength);
96         void reset();
97         bool updateDataFromParameters(float step, float delta, float scrollableSize, double currentTime, Parameters*);
98         bool animateScroll(double currentTime);
99         void updateVisibleLength(int visibleLength);
100
101         static double curveAt(Curve, double t);
102         static double attackCurve(Curve, double deltaT, double curveT, double startPos, double attackPos);
103         static double releaseCurve(Curve, double deltaT, double curveT, double releasePos, double desiredPos);
104         static double coastCurve(Curve, double factor);
105
106         static double curveIntegralAt(Curve, double t);
107         static double attackArea(Curve, double startT, double endT);
108         static double releaseArea(Curve, double startT, double endT);
109
110         double newScrollAnimationPosition(double deltaTime);
111
112         float* m_currentPosition;
113         double m_currentVelocity;
114
115         double m_desiredPosition;
116         double m_desiredVelocity;
117
118         double m_startPosition;
119         double m_startTime;
120         double m_startVelocity;
121
122         double m_animationTime;
123         double m_lastAnimationTime;
124
125         double m_attackPosition;
126         double m_attackTime;
127         Curve m_attackCurve;
128
129         double m_releasePosition;
130         double m_releaseTime;
131         Curve m_releaseCurve;
132
133         int m_visibleLength;
134     };
135
136     void startNextTimer();
137     void animationTimerFired();
138
139     void stopAnimationTimerIfNeeded();
140     bool animationTimerActive();
141     void updateVisibleLengths();
142
143     PerAxisData m_horizontalData;
144     PerAxisData m_verticalData;
145
146     double m_startTime;
147     bool m_animationActive;
148 };
149
150 } // namespace blink
151
152 #endif // ScrollAnimatorNone_h