summaryrefslogtreecommitdiffstats
path: root/app/animation.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 23:20:52 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-04-01 23:20:52 +0000
commit059e7a559572484fb677480ef6b95322cde3b34f (patch)
treed21b6b7393c4d27d1fb2ee172c2a0ac7330138ae /app/animation.cc
parente3f4cc62db9c967b911b00399674e392c71d0a7d (diff)
downloadchromium_src-059e7a559572484fb677480ef6b95322cde3b34f.zip
chromium_src-059e7a559572484fb677480ef6b95322cde3b34f.tar.gz
chromium_src-059e7a559572484fb677480ef6b95322cde3b34f.tar.bz2
Adds AnimationContainer, which can be used to group a set of
animations to have the same timer. By default each animation has one animationcontainer, but I'm going to change the tab renderer to share the animationcontainer so that the pulse effects happen in unison. Also updated the BoundsAnimator so that I can use it by the TabStrip. BUG=none TEST=none Review URL: http://codereview.chromium.org/1575011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@43407 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/animation.cc')
-rw-r--r--app/animation.cc97
1 files changed, 57 insertions, 40 deletions
diff --git a/app/animation.cc b/app/animation.cc
index f2d95f4..5e9d10c 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);
+}