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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
// Copyright (c) 2010 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 "app/animation.h"
#include "app/tween.h"
#include "gfx/rect.h"
#if defined(OS_WIN)
#include "base/win_util.h"
#endif
Animation::Animation(base::TimeDelta timer_interval)
: timer_interval_(timer_interval),
is_animating_(false),
delegate_(NULL) {
}
Animation::~Animation() {
// Don't send out notification from the destructor. Chances are the delegate
// owns us and is being deleted as well.
if (is_animating_)
container_->Stop(this);
}
void Animation::Start() {
if (is_animating_)
return;
if (!container_.get())
container_ = new AnimationContainer();
is_animating_ = true;
container_->Start(this);
AnimationStarted();
}
void Animation::Stop() {
if (!is_animating_)
return;
is_animating_ = false;
// Notify the container first as the delegate may delete us.
container_->Stop(this);
AnimationStopped();
if (delegate_) {
if (ShouldSendCanceledFromStop())
delegate_->AnimationCanceled(this);
else
delegate_->AnimationEnded(this);
}
}
double Animation::CurrentValueBetween(double start, double target) const {
return Tween::ValueBetween(GetCurrentValue(), start, target);
}
int Animation::CurrentValueBetween(int start, int target) const {
return Tween::ValueBetween(GetCurrentValue(), start, target);
}
gfx::Rect Animation::CurrentValueBetween(const gfx::Rect& start_bounds,
const gfx::Rect& target_bounds) const {
return Tween::ValueBetween(GetCurrentValue(), start_bounds, target_bounds);
}
void Animation::SetContainer(AnimationContainer* container) {
if (container == container_.get())
return;
if (is_animating_)
container_->Stop(this);
if (container)
container_ = container;
else
container_ = new AnimationContainer();
if (is_animating_)
container_->Start(this);
}
// static
bool Animation::ShouldRenderRichAnimation() {
#if defined(OS_WIN)
if (win_util::GetWinVersion() >= win_util::WINVERSION_VISTA) {
BOOL result;
// Get "Turn off all unnecessary animations" value.
if (::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)) {
// There seems to be a typo in the MSDN document (as of May 2009):
// http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx
// The document states that the result is TRUE when animations are
// _disabled_, but in fact, it is TRUE when they are _enabled_.
return !!result;
}
}
return !::GetSystemMetrics(SM_REMOTESESSION);
#endif
return true;
}
void Animation::SetStartTime(base::TimeTicks start_time) {
start_time_ = start_time;
}
|