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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/autofill/loading_animation.h"
7 #include "base/logging.h"
8 #include "ui/gfx/animation/tween.h"
12 // Duration of one cycle of the animation.
13 static const int kDurationMs
= 1800;
15 // The frame rate of the animation.
16 static const int kHertz
= 60;
18 LoadingAnimation::LoadingAnimation(gfx::AnimationDelegate
* delegate
,
20 : LinearAnimation(kDurationMs
, kHertz
, delegate
),
22 font_height_(font_height
) {}
24 LoadingAnimation::~LoadingAnimation() {}
26 void LoadingAnimation::Step(base::TimeTicks time_now
) {
27 LinearAnimation::Step(time_now
);
29 if (!is_animating()) {
35 double LoadingAnimation::GetCurrentValueForDot(size_t dot_i
) const {
36 double base_value
= gfx::LinearAnimation::GetCurrentValue();
38 const double kSecondDotDelayMs
= 100.0;
39 const double kThirdDotDelayMs
= 300.0;
41 base_value
-= kSecondDotDelayMs
/ kDurationMs
;
43 base_value
-= kThirdDotDelayMs
/ kDurationMs
;
46 base_value
= first_cycle_
? 0.0 : base_value
+ 1.0;
48 double value
= gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT
, base_value
);
50 static AnimationFrame kAnimationFrames
[] = {
60 for (size_t i
= 0; i
< arraysize(kAnimationFrames
); ++i
) {
61 if (value
> kAnimationFrames
[i
].value
)
66 position
= kAnimationFrames
[i
].position
;
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
);
75 return position
* font_height_
/ 2.0;
82 void LoadingAnimation::Reset() {
87 } // namespace autofill