Fix build break
[chromium-blink-merge.git] / ui / base / animation / animation.cc
blob78ee4d9c213c189bdebc63b0cffb4c23d5dfa447
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/base/animation/animation.h"
7 #include "ui/base/animation/animation_container.h"
8 #include "ui/base/animation/animation_delegate.h"
9 #include "ui/base/animation/tween.h"
10 #include "ui/gfx/rect.h"
12 #if defined(OS_WIN)
13 #include "base/win/windows_version.h"
14 #endif
16 namespace ui {
18 Animation::Animation(base::TimeDelta timer_interval)
19 : timer_interval_(timer_interval),
20 is_animating_(false),
21 delegate_(NULL) {
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.
27 if (is_animating_)
28 container_->Stop(this);
31 void Animation::Start() {
32 if (is_animating_)
33 return;
35 if (!container_.get())
36 container_ = new AnimationContainer();
38 is_animating_ = true;
40 container_->Start(this);
42 AnimationStarted();
45 void Animation::Stop() {
46 if (!is_animating_)
47 return;
49 is_animating_ = false;
51 // Notify the container first as the delegate may delete us.
52 container_->Stop(this);
54 AnimationStopped();
56 if (delegate_) {
57 if (ShouldSendCanceledFromStop())
58 delegate_->AnimationCanceled(this);
59 else
60 delegate_->AnimationEnded(this);
64 double Animation::CurrentValueBetween(double start, double target) const {
65 return Tween::ValueBetween(GetCurrentValue(), start, target);
68 int Animation::CurrentValueBetween(int start, int target) const {
69 return Tween::ValueBetween(GetCurrentValue(), start, target);
72 gfx::Rect Animation::CurrentValueBetween(const gfx::Rect& start_bounds,
73 const gfx::Rect& target_bounds) const {
74 return Tween::ValueBetween(GetCurrentValue(), start_bounds, target_bounds);
77 void Animation::SetContainer(AnimationContainer* container) {
78 if (container == container_.get())
79 return;
81 if (is_animating_)
82 container_->Stop(this);
84 if (container)
85 container_ = container;
86 else
87 container_ = new AnimationContainer();
89 if (is_animating_)
90 container_->Start(this);
93 // static
94 bool Animation::ShouldRenderRichAnimation() {
95 #if defined(OS_WIN)
96 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
97 BOOL result;
98 // Get "Turn off all unnecessary animations" value.
99 if (::SystemParametersInfo(SPI_GETCLIENTAREAANIMATION, 0, &result, 0)) {
100 // There seems to be a typo in the MSDN document (as of May 2009):
101 // http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx
102 // The document states that the result is TRUE when animations are
103 // _disabled_, but in fact, it is TRUE when they are _enabled_.
104 return !!result;
107 return !::GetSystemMetrics(SM_REMOTESESSION);
108 #endif
109 return true;
112 bool Animation::ShouldSendCanceledFromStop() {
113 return false;
116 void Animation::SetStartTime(base::TimeTicks start_time) {
117 start_time_ = start_time;
120 base::TimeDelta Animation::GetTimerInterval() const {
121 return timer_interval_;
124 } // namespace ui