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

Unified Diff: ash/system/toast/toast_overlay.cc

Issue 1841563003: ARC Toast: Prevent onClosed event from being called multiple times (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 8 months 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
« no previous file with comments | « ash/system/toast/toast_overlay.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
« no previous file with comments | « ash/system/toast/toast_overlay.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698