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 #include "ui/gfx/animation/linear_animation.h" | 5 #include "ui/gfx/animation/linear_animation.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 | 11 |
12 #include "ui/gfx/animation/animation_container.h" | 12 #include "ui/gfx/animation/animation_container.h" |
13 #include "ui/gfx/animation/animation_delegate.h" | 13 #include "ui/gfx/animation/animation_delegate.h" |
14 | 14 |
15 using base::Time; | 15 using base::Time; |
16 using base::TimeDelta; | 16 using base::TimeDelta; |
17 | 17 |
18 namespace gfx { | 18 namespace gfx { |
19 | 19 |
| 20 // How many frames per second to target. |
| 21 static const int kDefaultFrameRateHz = 60; |
| 22 |
20 static TimeDelta CalculateInterval(int frame_rate) { | 23 static TimeDelta CalculateInterval(int frame_rate) { |
21 int timer_interval = 1000000 / frame_rate; | 24 int timer_interval = 1000000 / frame_rate; |
22 if (timer_interval < 10000) | 25 if (timer_interval < 10000) |
23 timer_interval = 10000; | 26 timer_interval = 10000; |
24 return TimeDelta::FromMicroseconds(timer_interval); | 27 return TimeDelta::FromMicroseconds(timer_interval); |
25 } | 28 } |
26 | 29 |
27 LinearAnimation::LinearAnimation(int frame_rate, | 30 LinearAnimation::LinearAnimation(int frame_rate, AnimationDelegate* delegate) |
| 31 : LinearAnimation(0, frame_rate, delegate) {} |
| 32 |
| 33 LinearAnimation::LinearAnimation(AnimationDelegate* delegate) |
| 34 : LinearAnimation(kDefaultFrameRateHz, delegate) {} |
| 35 |
| 36 LinearAnimation::LinearAnimation(int duration, |
| 37 int frame_rate, |
28 AnimationDelegate* delegate) | 38 AnimationDelegate* delegate) |
29 : Animation(CalculateInterval(frame_rate)), | 39 : Animation(CalculateInterval(frame_rate)), |
30 state_(0.0), | 40 state_(0.0), |
31 in_end_(false) { | 41 in_end_(false) { |
32 set_delegate(delegate); | 42 set_delegate(delegate); |
33 } | |
34 | |
35 LinearAnimation::LinearAnimation(int duration, | |
36 int frame_rate, | |
37 AnimationDelegate* delegate) | |
38 : Animation(CalculateInterval(frame_rate)), | |
39 duration_(TimeDelta::FromMilliseconds(duration)), | |
40 state_(0.0), | |
41 in_end_(false) { | |
42 set_delegate(delegate); | |
43 SetDuration(duration); | 43 SetDuration(duration); |
44 } | 44 } |
45 | 45 |
46 double LinearAnimation::GetCurrentValue() const { | 46 double LinearAnimation::GetCurrentValue() const { |
47 // Default is linear relationship, subclass to adapt. | 47 // Default is linear relationship, subclass to adapt. |
48 return state_; | 48 return state_; |
49 } | 49 } |
50 | 50 |
51 void LinearAnimation::SetCurrentValue(double new_value) { | 51 void LinearAnimation::SetCurrentValue(double new_value) { |
52 new_value = std::max(0.0, std::min(1.0, new_value)); | 52 new_value = std::max(0.0, std::min(1.0, new_value)); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 // Set state_ to ensure we send ended to delegate and not canceled. | 102 // Set state_ to ensure we send ended to delegate and not canceled. |
103 state_ = 1; | 103 state_ = 1; |
104 AnimateToState(1.0); | 104 AnimateToState(1.0); |
105 } | 105 } |
106 | 106 |
107 bool LinearAnimation::ShouldSendCanceledFromStop() { | 107 bool LinearAnimation::ShouldSendCanceledFromStop() { |
108 return state_ != 1; | 108 return state_ != 1; |
109 } | 109 } |
110 | 110 |
111 } // namespace gfx | 111 } // namespace gfx |
OLD | NEW |