Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: chrome/browser/ui/autofill/loading_animation.cc

Issue 73723002: [rAc OSX] Animate the dots in the "Loading ..." message. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Clean up new files Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 {
(...skipping 12 matching lines...) Expand all
23 23
24 void LoadingAnimation::Step(base::TimeTicks time_now) { 24 void LoadingAnimation::Step(base::TimeTicks time_now) {
25 LinearAnimation::Step(time_now); 25 LinearAnimation::Step(time_now);
26 26
27 if (!is_animating()) { 27 if (!is_animating()) {
28 first_cycle_ = false; 28 first_cycle_ = false;
29 Start(); 29 Start();
30 } 30 }
31 } 31 }
32 32
33 double LoadingAnimation::GetCurrentValueForDot(size_t dot_i) { 33 double LoadingAnimation::GetCurrentValueForDot(size_t dot_i) const {
34 double base_value = gfx::LinearAnimation::GetCurrentValue(); 34 double base_value = gfx::LinearAnimation::GetCurrentValue();
35 35
36 const double kSecondDotDelayMs = 100.0; 36 const double kSecondDotDelayMs = 100.0;
37 const double kThirdDotDelayMs = 300.0; 37 const double kThirdDotDelayMs = 300.0;
38 if (dot_i == 1) 38 if (dot_i == 1)
39 base_value -= kSecondDotDelayMs / kDurationMs; 39 base_value -= kSecondDotDelayMs / kDurationMs;
40 else if (dot_i == 2) 40 else if (dot_i == 2)
41 base_value -= kThirdDotDelayMs / kDurationMs; 41 base_value -= kThirdDotDelayMs / kDurationMs;
42 42
43 if (base_value < 0.0) 43 if (base_value < 0.0)
44 base_value = first_cycle_ ? 0.0 : base_value + 1.0; 44 base_value = first_cycle_ ? 0.0 : base_value + 1.0;
45 45
46 double value = gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, base_value); 46 double value = gfx::Tween::CalculateValue(gfx::Tween::EASE_OUT, base_value);
47 47
48 static AnimationFrame animation_frames[] = { 48 static AnimationFrame kAnimationFrames[] = {
49 { 0.0, 0.0 }, 49 { 0.0, 0.0 },
50 { 0.55, 0.0 }, 50 { 0.55, 0.0 },
51 { 0.6, -1.0 }, 51 { 0.6, -1.0 },
52 { 0.8, 0.3 }, 52 { 0.8, 0.3 },
53 { 0.9, -0.2 }, 53 { 0.9, -0.2 },
54 { 0.95, 0.1 }, 54 { 0.95, 0.1 },
55 { 1.0, 0.0 }, 55 { 1.0, 0.0 },
56 }; 56 };
57 static double kScale = 10.0;
Evan Stade 2013/11/15 21:58:46 nit: I don't really see the benefit in doing this
groby-ooo-7-16 2013/11/15 23:03:38 +1 on the ctor doing htis.
Ilya Sherman 2013/11/16 00:31:13 Done.
57 58
58 for (size_t i = 0; i < arraysize(animation_frames); ++i) { 59 for (size_t i = 0; i < arraysize(kAnimationFrames); ++i) {
59 if (value > animation_frames[i].value) 60 if (value > kAnimationFrames[i].value)
60 continue; 61 continue;
61 else if (i == 0)
62 return animation_frames[i].position;
63 62
64 return animation_frames[i - 1].position + 63 double position;
65 (animation_frames[i].position - animation_frames[i - 1].position) * 64 if (i == 0) {
66 (value - animation_frames[i - 1].value) / 65 position = kAnimationFrames[i].position;
67 (animation_frames[i].value - animation_frames[i - 1].value); 66 } else {
67 double distance =
Evan Stade 2013/11/15 21:58:46 nit: IMO, the distance and progress variable names
Ilya Sherman 2013/11/16 00:31:13 Done.
68 kAnimationFrames[i].position - kAnimationFrames[i - 1].position;
69 double progress =
70 (value - kAnimationFrames[i - 1].value) /
71 (kAnimationFrames[i].value - kAnimationFrames[i - 1].value);
72 position = kAnimationFrames[i - 1].position + distance * progress;
groby-ooo-7-16 2013/11/15 23:03:38 I kind of like clearing up the computation, becaus
Ilya Sherman 2013/11/16 00:31:13 Done. Good call on using Tween::FloatValueBetween
73 }
74 return position * kScale;
68 } 75 }
69 76
70 NOTREACHED(); 77 NOTREACHED();
71 return 0.0; 78 return 0.0;
72 } 79 }
73 80
74 void LoadingAnimation::Reset() { 81 void LoadingAnimation::Reset() {
75 Stop(); 82 Stop();
76 first_cycle_ = true; 83 first_cycle_ = true;
77 } 84 }
78 85
79 } // namespace autofill 86 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698