network_icon_animation.cc 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include "ash/system/network/network_icon_animation.h"
  5. #include "ash/system/network/network_icon_animation_observer.h"
  6. namespace ash {
  7. namespace network_icon {
  8. NetworkIconAnimation::NetworkIconAnimation() : animation_(this) {
  9. // Set up the animation throbber.
  10. animation_.SetThrobDuration(base::Milliseconds(750));
  11. animation_.SetTweenType(gfx::Tween::LINEAR);
  12. }
  13. NetworkIconAnimation::~NetworkIconAnimation() = default;
  14. void NetworkIconAnimation::AnimationProgressed(
  15. const gfx::Animation* animation) {
  16. if (animation != &animation_)
  17. return;
  18. for (AnimationObserver& observer : observers_)
  19. observer.NetworkIconChanged();
  20. }
  21. double NetworkIconAnimation::GetAnimation() {
  22. if (!animation_.is_animating()) {
  23. animation_.Reset();
  24. animation_.StartThrobbing(-1 /*throb indefinitely*/);
  25. return 0;
  26. }
  27. return animation_.GetCurrentValue();
  28. }
  29. void NetworkIconAnimation::AddObserver(AnimationObserver* observer) {
  30. if (!observers_.HasObserver(observer))
  31. observers_.AddObserver(observer);
  32. }
  33. void NetworkIconAnimation::RemoveObserver(AnimationObserver* observer) {
  34. observers_.RemoveObserver(observer);
  35. if (observers_.empty())
  36. animation_.Reset(); // Stops the animation and resets the current value.
  37. }
  38. // static
  39. NetworkIconAnimation* NetworkIconAnimation::GetInstance() {
  40. static NetworkIconAnimation* s_icon_animation = new NetworkIconAnimation();
  41. return s_icon_animation;
  42. }
  43. } // namespace network_icon
  44. } // namespace ash