OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/ui/autofill/loading_animation.h" | 5 #include "chrome/browser/ui/autofill/loading_animation.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/gfx/animation/tween.h" | 8 #include "ui/gfx/animation/tween.h" |
9 | 9 |
10 namespace autofill { | 10 namespace autofill { |
11 | 11 |
12 // Duration of one cycle of the animation. | 12 // Duration of one cycle of the animation. |
13 static const int kDurationMs = 1800; | 13 static const int kDurationMs = 1800; |
14 | 14 |
15 // The frame rate of the animation. | 15 // The frame rate of the animation. |
16 static const int kHertz = 60; | 16 static const int kHertz = 60; |
17 | 17 |
18 LoadingAnimation::LoadingAnimation(gfx::AnimationDelegate* delegate) | 18 LoadingAnimation::LoadingAnimation(gfx::AnimationDelegate* delegate, |
| 19 int font_height) |
19 : LinearAnimation(kDurationMs, kHertz, delegate), | 20 : LinearAnimation(kDurationMs, kHertz, delegate), |
20 first_cycle_(true) {} | 21 first_cycle_(true), |
| 22 font_height_(font_height) {} |
21 | 23 |
22 LoadingAnimation::~LoadingAnimation() {} | 24 LoadingAnimation::~LoadingAnimation() {} |
23 | 25 |
24 void LoadingAnimation::Step(base::TimeTicks time_now) { | 26 void LoadingAnimation::Step(base::TimeTicks time_now) { |
25 LinearAnimation::Step(time_now); | 27 LinearAnimation::Step(time_now); |
26 | 28 |
27 if (!is_animating()) { | 29 if (!is_animating()) { |
28 first_cycle_ = false; | 30 first_cycle_ = false; |
29 Start(); | 31 Start(); |
30 } | 32 } |
31 } | 33 } |
32 | 34 |
33 double LoadingAnimation::GetCurrentValueForDot(size_t dot_i) { | 35 double LoadingAnimation::GetCurrentValueForDot(size_t dot_i) const { |
34 double base_value = gfx::LinearAnimation::GetCurrentValue(); | 36 double base_value = gfx::LinearAnimation::GetCurrentValue(); |
35 | 37 |
36 const double kSecondDotDelayMs = 100.0; | 38 const double kSecondDotDelayMs = 100.0; |
37 const double kThirdDotDelayMs = 300.0; | 39 const double kThirdDotDelayMs = 300.0; |
38 if (dot_i == 1) | 40 if (dot_i == 1) |
39 base_value -= kSecondDotDelayMs / kDurationMs; | 41 base_value -= kSecondDotDelayMs / kDurationMs; |
40 else if (dot_i == 2) | 42 else if (dot_i == 2) |
41 base_value -= kThirdDotDelayMs / kDurationMs; | 43 base_value -= kThirdDotDelayMs / kDurationMs; |
42 | 44 |
43 if (base_value < 0.0) | 45 if (base_value < 0.0) |
44 base_value = first_cycle_ ? 0.0 : base_value + 1.0; | 46 base_value = first_cycle_ ? 0.0 : base_value + 1.0; |
45 | 47 |
46 double value = gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, base_value); | 48 double value = gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, base_value); |
47 | 49 |
48 static AnimationFrame animation_frames[] = { | 50 static AnimationFrame kAnimationFrames[] = { |
49 { 0.0, 0.0 }, | 51 { 0.0, 0.0 }, |
50 { 0.55, 0.0 }, | 52 { 0.55, 0.0 }, |
51 { 0.6, -1.0 }, | 53 { 0.6, -1.0 }, |
52 { 0.8, 0.3 }, | 54 { 0.8, 0.3 }, |
53 { 0.9, -0.2 }, | 55 { 0.9, -0.2 }, |
54 { 0.95, 0.1 }, | 56 { 0.95, 0.1 }, |
55 { 1.0, 0.0 }, | 57 { 1.0, 0.0 }, |
56 }; | 58 }; |
57 | 59 |
58 for (size_t i = 0; i < arraysize(animation_frames); ++i) { | 60 for (size_t i = 0; i < arraysize(kAnimationFrames); ++i) { |
59 if (value > animation_frames[i].value) | 61 if (value > kAnimationFrames[i].value) |
60 continue; | 62 continue; |
61 else if (i == 0) | |
62 return animation_frames[i].position; | |
63 | 63 |
64 return animation_frames[i - 1].position + | 64 double position; |
65 (animation_frames[i].position - animation_frames[i - 1].position) * | 65 if (i == 0) { |
66 (value - animation_frames[i - 1].value) / | 66 position = kAnimationFrames[i].position; |
67 (animation_frames[i].value - animation_frames[i - 1].value); | 67 } else { |
| 68 double inter_frame_value = |
| 69 (value - kAnimationFrames[i - 1].value) / |
| 70 (kAnimationFrames[i].value - kAnimationFrames[i - 1].value); |
| 71 position = gfx::Tween::FloatValueBetween(inter_frame_value, |
| 72 kAnimationFrames[i - 1].position, |
| 73 kAnimationFrames[i].position); |
| 74 } |
| 75 return position * font_height_ / 2.0; |
68 } | 76 } |
69 | 77 |
70 NOTREACHED(); | 78 NOTREACHED(); |
71 return 0.0; | 79 return 0.0; |
72 } | 80 } |
73 | 81 |
74 void LoadingAnimation::Reset() { | 82 void LoadingAnimation::Reset() { |
75 Stop(); | 83 Stop(); |
76 first_cycle_ = true; | 84 first_cycle_ = true; |
77 } | 85 } |
78 | 86 |
79 } // namespace autofill | 87 } // namespace autofill |
OLD | NEW |