1 // Copyright (c) 2011 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_GFX_ANIMATION_LINEAR_ANIMATION_H_
6 #define UI_GFX_ANIMATION_LINEAR_ANIMATION_H_
8 #include "base/time/time.h"
9 #include "ui/gfx/animation/animation.h"
13 class AnimationDelegate
;
15 // Linear time bounded animation. As the animation progresses AnimateToState is
17 class GFX_EXPORT LinearAnimation
: public Animation
{
19 // Initializes everything except the duration.
21 // Caller must make sure to call SetDuration() if they use this
22 // constructor; it is preferable to use the full one, but sometimes
23 // duration can change between calls to Start() and we need to
24 // expose this interface.
25 LinearAnimation(int frame_rate
, AnimationDelegate
* delegate
);
27 // Initializes all fields.
28 LinearAnimation(int duration
, int frame_rate
, AnimationDelegate
* delegate
);
30 // Gets the value for the current state, according to the animation curve in
31 // use. This class provides only for a linear relationship, however subclasses
32 // can override this to provide others.
33 double GetCurrentValue() const override
;
35 // Change the current state of the animation to |new_value|.
36 void SetCurrentValue(double new_value
);
38 // Skip to the end of the current animation.
41 // Changes the length of the animation. This resets the current
42 // state of the animation to the beginning.
43 void SetDuration(int duration
);
46 // Called when the animation progresses. Subclasses override this to
47 // efficiently update their state.
48 virtual void AnimateToState(double state
) {}
50 // Invoked by the AnimationContainer when the animation is running to advance
51 // the animation. Use |time_now| rather than Time::Now to avoid multiple
52 // animations running at the same time diverging.
53 void Step(base::TimeTicks time_now
) override
;
55 // Overriden to initialize state.
56 void AnimationStarted() override
;
58 // Overriden to advance to the end (if End was invoked).
59 void AnimationStopped() override
;
61 // Overriden to return true if state is not 1.
62 bool ShouldSendCanceledFromStop() override
;
65 base::TimeDelta duration_
;
67 // Current state, on a scale from 0.0 to 1.0.
70 // If true, we're in end. This is used to determine if the animation should
71 // be advanced to the end from AnimationStopped.
74 DISALLOW_COPY_AND_ASSIGN(LinearAnimation
);
79 #endif // APP_LINEAR_ANIMATION_H_