1 // Copyright (c) 2011 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.
5 #include "ui/gfx/animation/animation.h"
7 #include "ui/gfx/animation/animation_container.h"
8 #include "ui/gfx/animation/animation_delegate.h"
9 #include "ui/gfx/animation/tween.h"
10 #include "ui/gfx/rect.h"
13 #include "base/win/windows_version.h"
18 Animation::Animation(base::TimeDelta timer_interval
)
19 : timer_interval_(timer_interval
),
24 Animation::~Animation() {
25 // Don't send out notification from the destructor. Chances are the delegate
26 // owns us and is being deleted as well.
28 container_
->Stop(this);
31 void Animation::Start() {
35 if (!container_
.get())
36 container_
= new AnimationContainer();
40 container_
->Start(this);
45 void Animation::Stop() {
49 is_animating_
= false;
51 // Notify the container first as the delegate may delete us.
52 container_
->Stop(this);
57 if (ShouldSendCanceledFromStop())
58 delegate_
->AnimationCanceled(this);
60 delegate_
->AnimationEnded(this);
64 double Animation::CurrentValueBetween(double start
, double target
) const {
65 return Tween::DoubleValueBetween(GetCurrentValue(), start
, target
);
68 int Animation::CurrentValueBetween(int start
, int target
) const {
69 return Tween::IntValueBetween(GetCurrentValue(), start
, target
);
72 gfx::Rect
Animation::CurrentValueBetween(const gfx::Rect
& start_bounds
,
73 const gfx::Rect
& target_bounds
) const {
74 return Tween::RectValueBetween(
75 GetCurrentValue(), start_bounds
, target_bounds
);
78 void Animation::SetContainer(AnimationContainer
* container
) {
79 if (container
== container_
.get())
83 container_
->Stop(this);
86 container_
= container
;
88 container_
= new AnimationContainer();
91 container_
->Start(this);
95 bool Animation::ShouldRenderRichAnimation() {
97 if (base::win::GetVersion() >= base::win::VERSION_VISTA
) {
99 // Get "Turn off all unnecessary animations" value.
100 if (::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION
, 0, &result
, 0)) {
101 // There seems to be a typo in the MSDN document (as of May 2009):
102 // http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx
103 // The document states that the result is TRUE when animations are
104 // _disabled_, but in fact, it is TRUE when they are _enabled_.
108 return !::GetSystemMetrics(SM_REMOTESESSION
);
114 bool Animation::ShouldSendCanceledFromStop() {
118 void Animation::SetStartTime(base::TimeTicks start_time
) {
119 start_time_
= start_time
;
122 base::TimeDelta
Animation::GetTimerInterval() const {
123 return timer_interval_
;