Revert of Add Masonry to key_silk_cases. (patchset #3 id:40001 of https://codereview...
[chromium-blink-merge.git] / ui / gfx / animation / animation.cc
blob78231554233eedf44e5430ce733af020e1032196
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/geometry/rect.h"
12 #if defined(OS_WIN)
13 #include "base/win/windows_version.h"
14 #endif
16 namespace gfx {
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::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())
80 return;
82 if (is_animating_)
83 container_->Stop(this);
85 if (container)
86 container_ = container;
87 else
88 container_ = new AnimationContainer();
90 if (is_animating_)
91 container_->Start(this);
94 // static
95 bool Animation::ShouldRenderRichAnimation() {
96 #if defined(OS_WIN)
97 if (base::win::GetVersion() >= base::win::VERSION_VISTA) {
98 BOOL result;
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_.
105 return !!result;
108 return !::GetSystemMetrics(SM_REMOTESESSION);
109 #else
110 return true;
111 #endif
114 bool Animation::ShouldSendCanceledFromStop() {
115 return false;
118 void Animation::SetStartTime(base::TimeTicks start_time) {
119 start_time_ = start_time;
122 base::TimeDelta Animation::GetTimerInterval() const {
123 return timer_interval_;
126 } // namespace gfx