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