OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "ui/chromeos/network/network_icon_animation.h" | |
6 | |
7 #include "ui/chromeos/network/network_icon_animation_observer.h" | |
8 | |
9 namespace { | |
10 const int kThrobDurationMs = 750; // Animation cycle length. | |
11 } | |
12 | |
13 namespace ui { | |
14 namespace network_icon { | |
15 | |
16 NetworkIconAnimation::NetworkIconAnimation() | |
17 : animation_(this) { | |
18 // Set up the animation throbber. | |
19 animation_.SetThrobDuration(kThrobDurationMs); | |
20 animation_.SetTweenType(gfx::Tween::LINEAR); | |
21 } | |
22 | |
23 NetworkIconAnimation::~NetworkIconAnimation() { | |
24 } | |
25 | |
26 void NetworkIconAnimation::AnimationProgressed( | |
27 const gfx::Animation* animation) { | |
28 if (animation != &animation_) | |
29 return; | |
30 for (AnimationObserver& observer : observers_) | |
31 observer.NetworkIconChanged(); | |
32 } | |
33 | |
34 double NetworkIconAnimation::GetAnimation() { | |
35 if (!animation_.is_animating()) { | |
36 animation_.Reset(); | |
37 animation_.StartThrobbing(-1 /*throb indefinitely*/); | |
38 return 0; | |
39 } | |
40 return animation_.GetCurrentValue(); | |
41 } | |
42 | |
43 void NetworkIconAnimation::AddObserver(AnimationObserver* observer) { | |
44 if (!observers_.HasObserver(observer)) | |
45 observers_.AddObserver(observer); | |
46 } | |
47 | |
48 void NetworkIconAnimation::RemoveObserver(AnimationObserver* observer) { | |
49 observers_.RemoveObserver(observer); | |
50 if (!observers_.might_have_observers()) | |
51 animation_.Reset(); // Stops the animation and resets the current value. | |
52 } | |
53 | |
54 // static | |
55 NetworkIconAnimation* NetworkIconAnimation::GetInstance() { | |
56 static NetworkIconAnimation* s_icon_animation = | |
57 new NetworkIconAnimation(); | |
58 return s_icon_animation; | |
59 } | |
60 | |
61 } // namespace network_icon | |
62 } // namespace ui | |
OLD | NEW |