Index: app/animation.cc |
diff --git a/app/animation.cc b/app/animation.cc |
index f2d95f48dcd4254d64d45feaf01e1b7c52c14511..5e9d10cf75bcc9b3818fe97b0b49f5a846527418 100644 |
--- a/app/animation.cc |
+++ b/app/animation.cc |
@@ -1,10 +1,10 @@ |
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
+// 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 "base/message_loop.h" |
+#include "app/animation_container.h" |
#include "gfx/rect.h" |
#if defined(OS_WIN) |
@@ -37,10 +37,8 @@ Animation::Animation(int duration, |
} |
Animation::~Animation() { |
-} |
- |
-void Animation::Reset() { |
- start_time_ = Time::Now(); |
+ if (animating_) |
+ container_->Stop(this); |
} |
double Animation::GetCurrentValue() const { |
@@ -69,10 +67,13 @@ gfx::Rect Animation::CurrentValueBetween(const gfx::Rect& start_bounds, |
void Animation::Start() { |
if (!animating_) { |
- start_time_ = Time::Now(); |
- timer_.Start(timer_interval_, this, &Animation::Run); |
+ if (!container_.get()) |
+ container_ = new AnimationContainer(); |
animating_ = true; |
+ |
+ container_->Start(this); |
+ |
if (delegate_) |
delegate_->AnimationStarted(this); |
} |
@@ -80,9 +81,11 @@ void Animation::Start() { |
void Animation::Stop() { |
if (animating_) { |
- timer_.Stop(); |
- |
animating_ = false; |
+ |
+ // Notify the container first as the delegate may delete us. |
+ container_->Stop(this); |
+ |
if (delegate_) { |
if (state_ >= 1.0) |
delegate_->AnimationEnded(this); |
@@ -94,9 +97,11 @@ void Animation::Stop() { |
void Animation::End() { |
if (animating_) { |
- timer_.Stop(); |
- |
animating_ = false; |
+ |
+ // Notify the container first as the delegate may delete us. |
+ container_->Stop(this); |
+ |
AnimateToState(1.0); |
if (delegate_) |
delegate_->AnimationEnded(this); |
@@ -111,34 +116,8 @@ void Animation::SetDuration(int duration) { |
duration_ = TimeDelta::FromMilliseconds(duration); |
if (duration_ < timer_interval_) |
duration_ = timer_interval_; |
- start_time_ = Time::Now(); |
-} |
- |
-void Animation::Step() { |
- TimeDelta elapsed_time = Time::Now() - start_time_; |
- state_ = static_cast<double>(elapsed_time.InMicroseconds()) / |
- static_cast<double>(duration_.InMicroseconds()); |
- |
- if (state_ >= 1.0) |
- state_ = 1.0; |
- |
- AnimateToState(state_); |
- if (delegate_) |
- delegate_->AnimationProgressed(this); |
- |
- if (state_ == 1.0) |
- Stop(); |
-} |
- |
-void Animation::Run() { |
- Step(); |
-} |
- |
-TimeDelta Animation::CalculateInterval(int frame_rate) { |
- int timer_interval = 1000000 / frame_rate; |
- if (timer_interval < 10000) |
- timer_interval = 10000; |
- return TimeDelta::FromMicroseconds(timer_interval); |
+ if (animating_) |
+ start_time_ = container_->last_tick_time(); |
} |
// static |
@@ -160,3 +139,41 @@ bool Animation::ShouldRenderRichAnimation() { |
return true; |
} |
+void Animation::SetContainer(AnimationContainer* container) { |
+ if (container == container_.get()) |
+ return; |
+ |
+ if (animating_) |
+ container_->Stop(this); |
+ |
+ if (container) |
+ container_ = container; |
+ else |
+ container_ = new AnimationContainer(); |
+ |
+ if (animating_) |
+ container_->Start(this); |
+} |
+ |
+void Animation::Step(base::TimeTicks time_now) { |
+ TimeDelta elapsed_time = time_now - start_time_; |
+ state_ = static_cast<double>(elapsed_time.InMicroseconds()) / |
+ static_cast<double>(duration_.InMicroseconds()); |
+ if (state_ >= 1.0) |
+ state_ = 1.0; |
+ |
+ AnimateToState(state_); |
+ |
+ if (delegate_) |
+ delegate_->AnimationProgressed(this); |
+ |
+ if (state_ == 1.0) |
+ Stop(); |
+} |
+ |
+TimeDelta Animation::CalculateInterval(int frame_rate) { |
+ int timer_interval = 1000000 / frame_rate; |
+ if (timer_interval < 10000) |
+ timer_interval = 10000; |
+ return TimeDelta::FromMicroseconds(timer_interval); |
+} |