diff options
Diffstat (limited to 'views/animation/bounds_animator.cc')
-rw-r--r-- | views/animation/bounds_animator.cc | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/views/animation/bounds_animator.cc b/views/animation/bounds_animator.cc index aee3675..e723504 100644 --- a/views/animation/bounds_animator.cc +++ b/views/animation/bounds_animator.cc @@ -28,7 +28,7 @@ BoundsAnimator::~BoundsAnimator() { // Delete all the animations, but don't remove any child views. We assume the // view owns us and is going to be deleted anyway. for (ViewToDataMap::iterator i = data_.begin(); i != data_.end(); ++i) - CleanupData(false, &(i->second), i->first); + CleanupData(&(i->second)); } void BoundsAnimator::AnimateViewTo(View* view, @@ -36,21 +36,21 @@ void BoundsAnimator::AnimateViewTo(View* view, bool delete_when_done) { DCHECK_EQ(view->GetParent(), parent_); - Data existing_data; - - if (data_.count(view) > 0) { - // Don't immediatly delete the animation, that might trigger a callback from - // the animationcontainer. - existing_data = data_[view]; - - RemoveFromMaps(view); + scoped_ptr<Animation> current_animation; + + if (data_.find(view) != data_.end()) { + // Currently animating this view, blow away the current animation and + // we'll create another animation below. + // We delay deleting the view until the end so that we don't prematurely + // send out notification that we're done. + current_animation.reset(ResetAnimationForView(view)); + } else if (target == view->bounds()) { + // View is already at the target location, delete it if necessary. + if (delete_when_done) + delete view; + return; } - // NOTE: we don't check if the view is already at the target location. Doing - // so leads to odd cases where no animations may be present after invoking - // AnimateViewTo. AnimationProgressed does nothing when the bounds of the - // view don't change. - Data& data = data_[view]; data.start_bounds = view->bounds(); data.target_bounds = target; @@ -60,8 +60,6 @@ void BoundsAnimator::AnimateViewTo(View* view, animation_to_view_[data.animation] = view; data.animation->Show(); - - CleanupData(true, &existing_data, NULL); } void BoundsAnimator::SetAnimationForView(View* view, @@ -128,25 +126,22 @@ SlideAnimation* BoundsAnimator::CreateAnimation() { return animation; } -void BoundsAnimator::RemoveFromMaps(View* view) { +void BoundsAnimator::RemoveFromMapsAndDelete(View* view) { DCHECK(data_.count(view) > 0); - animation_to_view_.erase(data_[view].animation); + Data& data = data_[view]; + animation_to_view_.erase(data.animation); + if (data.delete_when_done) + delete view; data_.erase(view); } -void BoundsAnimator::CleanupData(bool send_cancel, Data* data, View* view) { - if (send_cancel && data->delegate) - data->delegate->AnimationCanceled(data->animation); - +void BoundsAnimator::CleanupData(Data* data) { if (data->delete_delegate_when_done) { delete static_cast<OwnedAnimationDelegate*>(data->delegate); data->delegate = NULL; } - if (data->delete_when_done) - delete view; - delete data->animation; data->animation = NULL; } @@ -195,12 +190,12 @@ void BoundsAnimator::AnimationEnded(const Animation* animation) { // Make a copy of the data as Remove empties out the maps. Data data = data_[view]; - RemoveFromMaps(view); + RemoveFromMapsAndDelete(view); if (delegate) delegate->AnimationEnded(animation); - CleanupData(false, &data, view); + CleanupData(&data); } void BoundsAnimator::AnimationCanceled(const Animation* animation) { @@ -210,20 +205,17 @@ void BoundsAnimator::AnimationCanceled(const Animation* animation) { // Make a copy of the data as Remove empties out the maps. Data data = data_[view]; - RemoveFromMaps(view); + RemoveFromMapsAndDelete(view); if (delegate) delegate->AnimationCanceled(animation); - CleanupData(false, &data, view); + CleanupData(&data); } void BoundsAnimator::AnimationContainerProgressed( AnimationContainer* container) { if (!repaint_bounds_.IsEmpty()) { - // Adjust for rtl. - repaint_bounds_.set_x(parent_->MirroredXWithWidthInsideView( - repaint_bounds_.x(), repaint_bounds_.width())); parent_->SchedulePaint(repaint_bounds_, false); repaint_bounds_.SetRect(0, 0, 0, 0); } |