OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_BASE_ANIMATION_LINEAR_ANIMATION_H_ | 5 #ifndef UI_BASE_ANIMATION_LINEAR_ANIMATION_H_ |
6 #define UI_BASE_ANIMATION_LINEAR_ANIMATION_H_ | 6 #define UI_BASE_ANIMATION_LINEAR_ANIMATION_H_ |
7 | 7 |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "ui/base/animation/animation.h" | 9 #include "ui/base/animation/animation.h" |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 LinearAnimation(int frame_rate, AnimationDelegate* delegate); | 25 LinearAnimation(int frame_rate, AnimationDelegate* delegate); |
26 | 26 |
27 // Initializes all fields. | 27 // Initializes all fields. |
28 LinearAnimation(int duration, int frame_rate, AnimationDelegate* delegate); | 28 LinearAnimation(int duration, int frame_rate, AnimationDelegate* delegate); |
29 | 29 |
30 // Gets the value for the current state, according to the animation curve in | 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 | 31 // use. This class provides only for a linear relationship, however subclasses |
32 // can override this to provide others. | 32 // can override this to provide others. |
33 virtual double GetCurrentValue() const OVERRIDE; | 33 virtual double GetCurrentValue() const OVERRIDE; |
34 | 34 |
| 35 // Change the current state of the animation to |new_value|. |
| 36 void SetCurrentValue(double new_value); |
| 37 |
35 // Skip to the end of the current animation. | 38 // Skip to the end of the current animation. |
36 void End(); | 39 void End(); |
37 | 40 |
38 // Changes the length of the animation. This resets the current | 41 // Changes the length of the animation. This resets the current |
39 // state of the animation to the beginning. | 42 // state of the animation to the beginning. |
40 void SetDuration(int duration); | 43 void SetDuration(int duration); |
41 | 44 |
42 protected: | 45 protected: |
43 // Called when the animation progresses. Subclasses override this to | 46 // Called when the animation progresses. Subclasses override this to |
44 // efficiently update their state. | 47 // efficiently update their state. |
45 virtual void AnimateToState(double state) = 0; | 48 virtual void AnimateToState(double state) {} |
46 | 49 |
47 // Invoked by the AnimationContainer when the animation is running to advance | 50 // Invoked by the AnimationContainer when the animation is running to advance |
48 // the animation. Use |time_now| rather than Time::Now to avoid multiple | 51 // the animation. Use |time_now| rather than Time::Now to avoid multiple |
49 // animations running at the same time diverging. | 52 // animations running at the same time diverging. |
50 virtual void Step(base::TimeTicks time_now) OVERRIDE; | 53 virtual void Step(base::TimeTicks time_now) OVERRIDE; |
51 | 54 |
| 55 // Overriden to initialize state. |
| 56 virtual void AnimationStarted() OVERRIDE; |
| 57 |
52 // Overriden to advance to the end (if End was invoked). | 58 // Overriden to advance to the end (if End was invoked). |
53 virtual void AnimationStopped() OVERRIDE; | 59 virtual void AnimationStopped() OVERRIDE; |
54 | 60 |
55 // Overriden to return true if state is not 1. | 61 // Overriden to return true if state is not 1. |
56 virtual bool ShouldSendCanceledFromStop() OVERRIDE; | 62 virtual bool ShouldSendCanceledFromStop() OVERRIDE; |
57 | 63 |
58 private: | 64 private: |
59 base::TimeDelta duration_; | 65 base::TimeDelta duration_; |
60 | 66 |
61 // Current state, on a scale from 0.0 to 1.0. | 67 // Current state, on a scale from 0.0 to 1.0. |
62 double state_; | 68 double state_; |
63 | 69 |
64 // If true, we're in end. This is used to determine if the animation should | 70 // If true, we're in end. This is used to determine if the animation should |
65 // be advanced to the end from AnimationStopped. | 71 // be advanced to the end from AnimationStopped. |
66 bool in_end_; | 72 bool in_end_; |
67 | 73 |
68 DISALLOW_COPY_AND_ASSIGN(LinearAnimation); | 74 DISALLOW_COPY_AND_ASSIGN(LinearAnimation); |
69 }; | 75 }; |
70 | 76 |
71 } // namespace ui | 77 } // namespace ui |
72 | 78 |
73 #endif // APP_LINEAR_ANIMATION_H_ | 79 #endif // APP_LINEAR_ANIMATION_H_ |
OLD | NEW |