blob: 5065745c849f1a8571ef614dc2e30f5cffc4e334 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/chromeos/network/network_icon_animation.h"
#include "ash/system/chromeos/network/network_icon_animation_observer.h"
namespace {
const int kThrobDurationMs = 750; // Animation cycle length.
}
namespace ash {
namespace network_icon {
NetworkIconAnimation::NetworkIconAnimation()
: animation_(this) {
// Set up the animation throbber.
animation_.SetThrobDuration(kThrobDurationMs);
animation_.SetTweenType(gfx::Tween::LINEAR);
}
NetworkIconAnimation::~NetworkIconAnimation() {
}
void NetworkIconAnimation::AnimationProgressed(
const gfx::Animation* animation) {
if (animation != &animation_)
return;
FOR_EACH_OBSERVER(AnimationObserver, observers_, NetworkIconChanged());
}
double NetworkIconAnimation::GetAnimation() {
if (!animation_.is_animating()) {
animation_.Reset();
animation_.StartThrobbing(-1 /*throb indefinitely*/);
return 0;
}
return animation_.GetCurrentValue();
}
void NetworkIconAnimation::AddObserver(AnimationObserver* observer) {
if (!observers_.HasObserver(observer))
observers_.AddObserver(observer);
}
void NetworkIconAnimation::RemoveObserver(AnimationObserver* observer) {
observers_.RemoveObserver(observer);
if (!observers_.might_have_observers())
animation_.Reset(); // Stops the animation and resets the current value.
}
// static
NetworkIconAnimation* NetworkIconAnimation::GetInstance() {
static NetworkIconAnimation* s_icon_animation =
new NetworkIconAnimation();
return s_icon_animation;
}
} // namespace network_icon
} // namespace ash
|