BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / autofill / loading_animation.cc
blob38e257cda4d644fcd31232484685bc89aa2a5979
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"
10 namespace autofill {
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,
19 int font_height)
20 : LinearAnimation(kDurationMs, kHertz, delegate),
21 first_cycle_(true),
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()) {
30 first_cycle_ = false;
31 Start();
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;
40 if (dot_i == 1)
41 base_value -= kSecondDotDelayMs / kDurationMs;
42 else if (dot_i == 2)
43 base_value -= kThirdDotDelayMs / kDurationMs;
45 if (base_value < 0.0)
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[] = {
51 { 0.0, 0.0 },
52 { 0.55, 0.0 },
53 { 0.6, -1.0 },
54 { 0.8, 0.3 },
55 { 0.9, -0.2 },
56 { 0.95, 0.1 },
57 { 1.0, 0.0 },
60 for (size_t i = 0; i < arraysize(kAnimationFrames); ++i) {
61 if (value > kAnimationFrames[i].value)
62 continue;
64 double position;
65 if (i == 0) {
66 position = kAnimationFrames[i].position;
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);
75 return position * font_height_ / 2.0;
78 NOTREACHED();
79 return 0.0;
82 void LoadingAnimation::Reset() {
83 Stop();
84 first_cycle_ = true;
87 } // namespace autofill