Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(555)

Unified Diff: ui/wm/core/window_animations.cc

Issue 795113002: compositor/layer_animator: handle delegate removal in LayerAnimation::StopAnimating (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/wm/core/window_animations.cc
diff --git a/ui/wm/core/window_animations.cc b/ui/wm/core/window_animations.cc
index 03bb1b99f421b335d3033c685e49661fc93cdc6b..3205ed41a5d1f87225359c8ecbb7b1960754bc1b 100644
--- a/ui/wm/core/window_animations.cc
+++ b/ui/wm/core/window_animations.cc
@@ -404,21 +404,34 @@ class RotateHidingWindowAnimationObserver
// Destroys itself after |last_sequence| ends or is aborted. Does not take
// ownership of |last_sequence|, which should not be NULL.
- void SetLastSequence(ui::LayerAnimationSequence* last_sequence) {
- last_sequence->AddObserver(this);
+ void AddSequence(ui::LayerAnimationSequence* sequence) {
+ sequences_.push_back(sequence);
+ sequence->AddObserver(this);
}
// ui::LayerAnimationObserver:
void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) override {
- OnAnimationCompleted();
+ RemoveAnimation(sequence);
}
void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) override {
- OnAnimationCompleted();
+ RemoveAnimation(sequence);
}
void OnLayerAnimationScheduled(
ui::LayerAnimationSequence* sequence) override {}
private:
+ // Destroys itself after last sequence ends or is aborted.
+ void RemoveAnimation(ui::LayerAnimationSequence *sequence) {
+ auto it = std::remove(sequences_.begin(), sequences_.end(), sequence);
+ if (it != sequences_.end()) {
+ sequences_.erase(it);
+ if (sequences_.empty())
+ OnAnimationCompleted();
+ }
+ }
+
+ std::vector<ui::LayerAnimationSequence *> sequences_;
+
DISALLOW_COPY_AND_ASSIGN(RotateHidingWindowAnimationObserver);
};
@@ -442,8 +455,11 @@ void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
show ? kWindowAnimation_ShowOpacity : kWindowAnimation_HideOpacity,
duration * kWindowAnimation_Rotate_OpacityDurationPercent / 100));
opacity->set_tween_type(gfx::Tween::EASE_IN_OUT);
- window->layer()->GetAnimator()->ScheduleAnimation(
- new ui::LayerAnimationSequence(opacity.release()));
+ ui::LayerAnimationSequence *opacity_sequence =
+ new ui::LayerAnimationSequence(opacity.release());
+ window->layer()->GetAnimator()->ScheduleAnimation(opacity_sequence);
+ if (observer)
+ observer->AddSequence(opacity_sequence);
float xcenter = window->bounds().width() * 0.5;
@@ -477,12 +493,12 @@ void AddLayerAnimationsForRotate(aura::Window* window, bool show) {
scoped_ptr<ui::LayerAnimationElement> transition(
ui::LayerAnimationElement::CreateInterpolatedTransformElement(
rotation.release(), duration));
- ui::LayerAnimationSequence* last_sequence =
+ ui::LayerAnimationSequence* transition_sequence =
new ui::LayerAnimationSequence(transition.release());
- window->layer()->GetAnimator()->ScheduleAnimation(last_sequence);
+ window->layer()->GetAnimator()->ScheduleAnimation(transition_sequence);
if (observer) {
- observer->SetLastSequence(last_sequence);
+ observer->AddSequence(transition_sequence);
observer->DetachAndRecreateLayers();
}
}
« ui/compositor/layer_animator_unittest.cc ('K') | « ui/compositor/layer_animator_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698