summaryrefslogtreecommitdiffstats
path: root/app/animation_container.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 03:43:55 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-05 03:43:55 +0000
commit4ce7e15da651c6221720e33dc8c500830d4b6b8a (patch)
tree376ef1d7e7951dae3376e65f4edee9e7367adc89 /app/animation_container.cc
parent5ee3ca64cdf2d00f82a1bc36f36e8ab5e520b4de (diff)
downloadchromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.zip
chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.tar.gz
chromium_src-4ce7e15da651c6221720e33dc8c500830d4b6b8a.tar.bz2
Refactors animation to allow for cleaner subclassing. I'm doing this
for creating a different animation subclass (which you'll see shortly). BUG=none TEST=none Review URL: http://codereview.chromium.org/1961001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46433 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'app/animation_container.cc')
-rw-r--r--app/animation_container.cc69
1 files changed, 34 insertions, 35 deletions
diff --git a/app/animation_container.cc b/app/animation_container.cc
index 221b453..2b41913 100644
--- a/app/animation_container.cc
+++ b/app/animation_container.cc
@@ -16,31 +16,31 @@ AnimationContainer::AnimationContainer()
AnimationContainer::~AnimationContainer() {
// The animations own us and stop themselves before being deleted. If
- // animations_ is not empty, something is wrong.
- DCHECK(animations_.empty());
+ // elements_ is not empty, something is wrong.
+ DCHECK(elements_.empty());
}
-void AnimationContainer::Start(Animation* animation) {
- DCHECK(animations_.count(animation) == 0); // Start should only be invoked
- // if the animation isn't running.
+void AnimationContainer::Start(Element* element) {
+ DCHECK(elements_.count(element) == 0); // Start should only be invoked if the
+ // element isn't running.
- if (animations_.empty()) {
+ if (elements_.empty()) {
last_tick_time_ = TimeTicks::Now();
- SetMinTimerInterval(animation->timer_interval());
- } else if (animation->timer_interval() < min_timer_interval_) {
- SetMinTimerInterval(animation->timer_interval());
+ SetMinTimerInterval(element->GetTimerInterval());
+ } else if (element->GetTimerInterval() < min_timer_interval_) {
+ SetMinTimerInterval(element->GetTimerInterval());
}
- animation->set_start_time(last_tick_time_);
- animations_.insert(animation);
+ element->SetStartTime(last_tick_time_);
+ elements_.insert(element);
}
-void AnimationContainer::Stop(Animation* animation) {
- DCHECK(animations_.count(animation) > 0); // The animation must be running.
+void AnimationContainer::Stop(Element* element) {
+ DCHECK(elements_.count(element) > 0); // The element must be running.
- animations_.erase(animation);
+ elements_.erase(element);
- if (animations_.empty()) {
+ if (elements_.empty()) {
timer_.Stop();
if (observer_)
observer_->AnimationContainerEmpty(this);
@@ -52,25 +52,24 @@ void AnimationContainer::Stop(Animation* animation) {
}
void AnimationContainer::Run() {
- // We notify the observer after updating all the animations. If all the
- // animations are deleted as a result of updating then our ref count would go
- // to zero and we would be deleted before we notify our observer. We add a
- // reference to ourself here to make sure we're still valid after running all
- // the animations.
+ // We notify the observer after updating all the elements. If all the elements
+ // are deleted as a result of updating then our ref count would go to zero and
+ // we would be deleted before we notify our observer. We add a reference to
+ // ourself here to make sure we're still valid after running all the elements.
scoped_refptr<AnimationContainer> this_ref(this);
TimeTicks current_time = TimeTicks::Now();
last_tick_time_ = current_time;
- // Make a copy of the animations to iterate over so that if any animations
- // are removed as part of invoking Step there aren't any problems.
- Animations animations = animations_;
+ // Make a copy of the elements to iterate over so that if any elements are
+ // removed as part of invoking Step there aren't any problems.
+ Elements elements = elements_;
- for (Animations::const_iterator i = animations.begin();
- i != animations.end(); ++i) {
- // Make sure the animation is still valid.
- if (animations_.find(*i) != animations_.end())
+ for (Elements::const_iterator i = elements.begin();
+ i != elements.end(); ++i) {
+ // Make sure the element is still valid.
+ if (elements_.find(*i) != elements_.end())
(*i)->Step(current_time);
}
@@ -79,22 +78,22 @@ void AnimationContainer::Run() {
}
void AnimationContainer::SetMinTimerInterval(base::TimeDelta delta) {
- // This doesn't take into account how far along current animation is, but that
- // shouldn't be a problem for uses of Animation/AnimationContainer.
+ // This doesn't take into account how far along the current element is, but
+ // that shouldn't be a problem for uses of Animation/AnimationContainer.
timer_.Stop();
min_timer_interval_ = delta;
timer_.Start(min_timer_interval_, this, &AnimationContainer::Run);
}
TimeDelta AnimationContainer::GetMinInterval() {
- DCHECK(!animations_.empty());
+ DCHECK(!elements_.empty());
TimeDelta min;
- Animations::const_iterator i = animations_.begin();
- min = (*i)->timer_interval();
- for (++i; i != animations_.end(); ++i) {
- if ((*i)->timer_interval() < min)
- min = (*i)->timer_interval();
+ Elements::const_iterator i = elements_.begin();
+ min = (*i)->GetTimerInterval();
+ for (++i; i != elements_.end(); ++i) {
+ if ((*i)->GetTimerInterval() < min)
+ min = (*i)->GetTimerInterval();
}
return min;
}