2 * Copyright (c) 2011, Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
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
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.
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.
31 #ifndef ScrollAnimatorNone_h
32 #define ScrollAnimatorNone_h
34 #include "platform/Timer.h"
35 #include "platform/geometry/FloatPoint.h"
36 #include "platform/scroll/ScrollAnimator.h"
38 class ScrollAnimatorNoneTest;
42 class PLATFORM_EXPORT ScrollAnimatorNone : public ScrollAnimator {
44 explicit ScrollAnimatorNone(ScrollableArea*);
45 virtual ~ScrollAnimatorNone();
47 virtual bool scroll(ScrollbarOrientation, ScrollGranularity, float step, float delta) OVERRIDE;
48 virtual void scrollToOffsetWithoutAnimation(const FloatPoint&) OVERRIDE;
50 virtual void cancelAnimations() OVERRIDE;
51 virtual void serviceScrollAnimations() OVERRIDE;
53 virtual void willEndLiveResize() OVERRIDE;
54 virtual void didAddVerticalScrollbar(Scrollbar*) OVERRIDE;
55 virtual void didAddHorizontalScrollbar(Scrollbar*) OVERRIDE;
65 struct PLATFORM_EXPORT Parameters {
67 Parameters(bool isEnabled, double animationTime, double repeatMinimumSustainTime, Curve attackCurve, double attackTime, Curve releaseCurve, double releaseTime, Curve coastTimeCurve, double maximumCoastTime);
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.
73 double m_animationTime;
74 double m_repeatMinimumSustainTime;
82 Curve m_coastTimeCurve;
83 double m_maximumCoastTime;
87 virtual void animationWillStart() { }
88 virtual void animationDidFinish() { }
90 Parameters parametersForScrollGranularity(ScrollGranularity) const;
92 friend class ::ScrollAnimatorNoneTest;
94 struct PLATFORM_EXPORT PerAxisData {
95 PerAxisData(ScrollAnimatorNone* parent, float* currentPos, int visibleLength);
97 bool updateDataFromParameters(float step, float delta, float scrollableSize, double currentTime, Parameters*);
98 bool animateScroll(double currentTime);
99 void updateVisibleLength(int visibleLength);
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);
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);
110 double newScrollAnimationPosition(double deltaTime);
112 float* m_currentPosition;
113 double m_currentVelocity;
115 double m_desiredPosition;
116 double m_desiredVelocity;
118 double m_startPosition;
120 double m_startVelocity;
122 double m_animationTime;
123 double m_lastAnimationTime;
125 double m_attackPosition;
129 double m_releasePosition;
130 double m_releaseTime;
131 Curve m_releaseCurve;
136 void startNextTimer();
137 void animationTimerFired();
139 void stopAnimationTimerIfNeeded();
140 bool animationTimerActive();
141 void updateVisibleLengths();
143 PerAxisData m_horizontalData;
144 PerAxisData m_verticalData;
147 bool m_animationActive;
152 #endif // ScrollAnimatorNone_h