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