initial import
[vuplus_webkit] / Source / WebCore / platform / 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 #if ENABLE(SMOOTH_SCROLLING)
35
36 #include "LayoutTypes.h"
37 #include "ScrollAnimator.h"
38 #include "Timer.h"
39
40 class ScrollAnimatorNoneTest;
41
42 namespace WebCore {
43
44 struct ScrollAnimatorParameters;
45
46 class ScrollAnimatorNone : public ScrollAnimator {
47 public:
48     ScrollAnimatorNone(ScrollableArea*);
49     virtual ~ScrollAnimatorNone();
50
51     virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float multiplier);
52     virtual void scrollToOffsetWithoutAnimation(const FloatPoint&);
53
54     virtual void willEndLiveResize();
55     virtual void didAddVerticalScrollbar(Scrollbar*);
56     virtual void didAddHorizontalScrollbar(Scrollbar*);
57
58     enum Curve {
59         Linear,
60         Quadratic,
61         Cubic,
62         Quartic,
63         Bounce
64     };
65
66     struct Parameters {
67         Parameters();
68         Parameters(bool isEnabled, double animationTime, double repeatMinimumSustainTime, Curve attackCurve, double attackTime, Curve releaseCurve, double releaseTime, Curve coastTimeCurve, double maximumCoastTime);
69
70         // Note that the times can be overspecified such that releaseTime or releaseTime and attackTime are greater
71         // than animationTime. animationTime takes priority over releaseTime, capping it. attackTime is capped at
72         // whatever time remains, or zero if none.
73         bool m_isEnabled;
74         double m_animationTime;
75         double m_repeatMinimumSustainTime;
76
77         Curve m_attackCurve;
78         double m_attackTime;
79
80         Curve m_releaseCurve;
81         double m_releaseTime;
82
83         Curve m_coastTimeCurve;
84         double m_maximumCoastTime;
85     };
86
87 protected:
88     friend class ::ScrollAnimatorNoneTest;
89
90     struct PerAxisData {
91         PerAxisData(ScrollAnimatorNone* parent, float* currentPos, LayoutUnit visibleLength);
92         void reset();
93         bool updateDataFromParameters(float step, float multiplier, float scrollableSize, double currentTime, Parameters*);
94         bool animateScroll(double currentTime);
95         void updateVisibleLength(LayoutUnit visibleLength);
96
97         static double curveAt(Curve, double t);
98         static double attackCurve(Curve, double deltaT, double curveT, double startPos, double attackPos);
99         static double releaseCurve(Curve, double deltaT, double curveT, double releasePos, double desiredPos);
100         static double coastCurve(Curve, double factor);
101
102         static double curveIntegralAt(Curve, double t);
103         static double attackArea(Curve, double startT, double endT);
104         static double releaseArea(Curve, double startT, double endT);
105
106         float* m_currentPosition;
107         double m_currentVelocity;
108
109         double m_desiredPosition;
110         double m_desiredVelocity;
111
112         double m_startPosition;
113         double m_startTime;
114         double m_startVelocity;
115
116         double m_animationTime;
117         double m_lastAnimationTime;
118
119         double m_attackPosition;
120         double m_attackTime;
121         Curve m_attackCurve;
122
123         double m_releasePosition;
124         double m_releaseTime;
125         Curve m_releaseCurve;
126
127         LayoutUnit m_visibleLength;
128     };
129
130     void animationTimerFired(Timer<ScrollAnimatorNone>*);
131     void stopAnimationTimerIfNeeded();
132     void updateVisibleLengths();
133
134     PerAxisData m_horizontalData;
135     PerAxisData m_verticalData;
136
137     double m_startTime;
138     Timer<ScrollAnimatorNone> m_animationTimer;
139 };
140
141 } // namespace WebCore
142
143 #endif // ENABLE(SMOOTH_SCROLLING)
144
145 #endif // ScrollAnimatorNone_h