Chromium Code Reviews| Index: ash/system/toast/toast_overlay.cc |
| diff --git a/ash/system/toast/toast_overlay.cc b/ash/system/toast/toast_overlay.cc |
| index 45612b57b513d21e00bacf4f01d8f39f17b6d039..9ce8635397e4715ee24ef762cfbd9f1ab6047eaf 100644 |
| --- a/ash/system/toast/toast_overlay.cc |
| +++ b/ash/system/toast/toast_overlay.cc |
| @@ -213,14 +213,16 @@ ToastOverlay::~ToastOverlay() { |
| } |
| void ToastOverlay::Show(bool visible) { |
| - if (is_visible_ == visible) |
| + if (overlay_widget_->GetLayer()->GetTargetVisibility() == visible) |
| return; |
| - is_visible_ = visible; |
| + ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| + if (animator && animator->is_animating()) |
| + animator->StopAnimating(); |
| overlay_widget_->GetLayer()->GetAnimator()->AddObserver(this); |
|
oshima
2016/04/13 10:03:18
You can use ImplicitAnimationObserver to implement
yoshiki
2016/04/14 14:08:58
Done.
|
| - if (is_visible_) |
| + if (visible) |
| overlay_widget_->Show(); |
| else |
| overlay_widget_->Hide(); |
| @@ -238,25 +240,40 @@ gfx::Rect ToastOverlay::CalculateOverlayBounds() { |
| return bounds; |
| } |
| +void ToastOverlay::OnLayerAnimationStarted( |
| + ui::LayerAnimationSequence* sequence) { |
| + inflight_animations_.insert(sequence); |
| +} |
| + |
| +bool ToastOverlay::RequiresNotificationWhenAnimatorDestroyed() const { |
| + return true; |
| +} |
| + |
| void ToastOverlay::OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { |
| - ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| - if (animator) |
| - animator->RemoveObserver(this); |
| - if (!is_visible_) { |
| - // Acync operation, since delegate may remove this instance and removing |
| - // this here causes crash. |
| - base::ThreadTaskRunnerHandle::Get()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&Delegate::OnClosed, |
| - base::Unretained(delegate_) /* |delegate| lives longer */)); |
| + inflight_animations_.erase(sequence); |
| + OnAnimationStopped(); |
| +} |
| + |
| +void ToastOverlay::OnAnimationStopped() { |
| + if (inflight_animations_.empty()) { |
| + ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| + if (animator) |
| + animator->RemoveObserver(this); |
| + if (!overlay_widget_->GetLayer()->GetTargetVisibility()) { |
| + // Acync operation, since delegate may remove this instance and removing |
| + // this here causes crash. |
| + base::ThreadTaskRunnerHandle::Get()->PostTask( |
| + FROM_HERE, base::Bind(&Delegate::OnClosed, |
| + base::Unretained( |
| + delegate_) /* |delegate| lives longer */)); |
| + } |
| } |
| } |
| void ToastOverlay::OnLayerAnimationAborted( |
| ui::LayerAnimationSequence* sequence) { |
| - ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| - if (animator) |
| - animator->RemoveObserver(this); |
| + inflight_animations_.erase(sequence); |
| + OnAnimationStopped(); |
| } |
| void ToastOverlay::OnLayerAnimationScheduled( |