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