1 // Copyright (c) 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 "ui/chromeos/network/network_icon_animation.h"
7 #include "ui/chromeos/network/network_icon_animation_observer.h"
10 const int kThrobDurationMs
= 750; // Animation cycle length.
14 namespace network_icon
{
16 NetworkIconAnimation::NetworkIconAnimation()
18 // Set up the animation throbber.
19 animation_
.SetThrobDuration(kThrobDurationMs
);
20 animation_
.SetTweenType(gfx::Tween::LINEAR
);
23 NetworkIconAnimation::~NetworkIconAnimation() {
26 void NetworkIconAnimation::AnimationProgressed(
27 const gfx::Animation
* animation
) {
28 if (animation
!= &animation_
)
30 FOR_EACH_OBSERVER(AnimationObserver
, observers_
, NetworkIconChanged());
33 double NetworkIconAnimation::GetAnimation() {
34 if (!animation_
.is_animating()) {
36 animation_
.StartThrobbing(-1 /*throb indefinitely*/);
39 return animation_
.GetCurrentValue();
42 void NetworkIconAnimation::AddObserver(AnimationObserver
* observer
) {
43 if (!observers_
.HasObserver(observer
))
44 observers_
.AddObserver(observer
);
47 void NetworkIconAnimation::RemoveObserver(AnimationObserver
* observer
) {
48 observers_
.RemoveObserver(observer
);
49 if (!observers_
.might_have_observers())
50 animation_
.Reset(); // Stops the animation and resets the current value.
54 NetworkIconAnimation
* NetworkIconAnimation::GetInstance() {
55 static NetworkIconAnimation
* s_icon_animation
=
56 new NetworkIconAnimation();
57 return s_icon_animation
;
60 } // namespace network_icon