Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/toast/toast_overlay.h" | 5 #include "ash/system/toast/toast_overlay.h" |
| 6 | 6 |
| 7 #include "ash/screen_util.h" | 7 #include "ash/screen_util.h" |
| 8 #include "ash/shelf/shelf.h" | 8 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 if (layer) { | 206 if (layer) { |
| 207 ui::LayerAnimator* animator = layer->GetAnimator(); | 207 ui::LayerAnimator* animator = layer->GetAnimator(); |
| 208 if (animator) | 208 if (animator) |
| 209 animator->RemoveObserver(this); | 209 animator->RemoveObserver(this); |
| 210 } | 210 } |
| 211 | 211 |
| 212 overlay_widget_->Close(); | 212 overlay_widget_->Close(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void ToastOverlay::Show(bool visible) { | 215 void ToastOverlay::Show(bool visible) { |
| 216 if (is_visible_ == visible) | 216 if (overlay_widget_->GetLayer()->GetTargetVisibility() == visible) |
| 217 return; | 217 return; |
| 218 | 218 |
| 219 is_visible_ = visible; | 219 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| 220 if (animator && animator->is_animating()) | |
| 221 animator->StopAnimating(); | |
| 220 | 222 |
| 221 overlay_widget_->GetLayer()->GetAnimator()->AddObserver(this); | 223 overlay_widget_->GetLayer()->GetAnimator()->AddObserver(this); |
| 222 | 224 |
|
oshima
2016/04/13 10:03:18
You can use ImplicitAnimationObserver to implement
yoshiki
2016/04/14 14:08:58
Done.
| |
| 223 if (is_visible_) | 225 if (visible) |
| 224 overlay_widget_->Show(); | 226 overlay_widget_->Show(); |
| 225 else | 227 else |
| 226 overlay_widget_->Hide(); | 228 overlay_widget_->Hide(); |
| 227 } | 229 } |
| 228 | 230 |
| 229 gfx::Rect ToastOverlay::CalculateOverlayBounds() { | 231 gfx::Rect ToastOverlay::CalculateOverlayBounds() { |
| 230 ShelfLayoutManager* shelf_layout_manager = | 232 ShelfLayoutManager* shelf_layout_manager = |
| 231 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 233 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); |
| 232 gfx::Rect work_area_bounds = shelf_layout_manager->user_work_area_bounds(); | 234 gfx::Rect work_area_bounds = shelf_layout_manager->user_work_area_bounds(); |
| 233 | 235 |
| 234 gfx::Rect bounds = shelf_layout_manager->user_work_area_bounds(); | 236 gfx::Rect bounds = shelf_layout_manager->user_work_area_bounds(); |
| 235 int target_y = bounds.bottom() - widget_size_.height() - kVerticalOffset; | 237 int target_y = bounds.bottom() - widget_size_.height() - kVerticalOffset; |
| 236 bounds.ClampToCenteredSize(widget_size_); | 238 bounds.ClampToCenteredSize(widget_size_); |
| 237 bounds.set_y(target_y); | 239 bounds.set_y(target_y); |
| 238 return bounds; | 240 return bounds; |
| 239 } | 241 } |
| 240 | 242 |
| 243 void ToastOverlay::OnLayerAnimationStarted( | |
| 244 ui::LayerAnimationSequence* sequence) { | |
| 245 inflight_animations_.insert(sequence); | |
| 246 } | |
| 247 | |
| 248 bool ToastOverlay::RequiresNotificationWhenAnimatorDestroyed() const { | |
| 249 return true; | |
| 250 } | |
| 251 | |
| 241 void ToastOverlay::OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { | 252 void ToastOverlay::OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { |
| 242 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 253 inflight_animations_.erase(sequence); |
| 243 if (animator) | 254 OnAnimationStopped(); |
| 244 animator->RemoveObserver(this); | 255 } |
| 245 if (!is_visible_) { | 256 |
| 246 // Acync operation, since delegate may remove this instance and removing | 257 void ToastOverlay::OnAnimationStopped() { |
| 247 // this here causes crash. | 258 if (inflight_animations_.empty()) { |
| 248 base::ThreadTaskRunnerHandle::Get()->PostTask( | 259 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| 249 FROM_HERE, | 260 if (animator) |
| 250 base::Bind(&Delegate::OnClosed, | 261 animator->RemoveObserver(this); |
| 251 base::Unretained(delegate_) /* |delegate| lives longer */)); | 262 if (!overlay_widget_->GetLayer()->GetTargetVisibility()) { |
| 263 // Acync operation, since delegate may remove this instance and removing | |
| 264 // this here causes crash. | |
| 265 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 266 FROM_HERE, base::Bind(&Delegate::OnClosed, | |
| 267 base::Unretained( | |
| 268 delegate_) /* |delegate| lives longer */)); | |
| 269 } | |
| 252 } | 270 } |
| 253 } | 271 } |
| 254 | 272 |
| 255 void ToastOverlay::OnLayerAnimationAborted( | 273 void ToastOverlay::OnLayerAnimationAborted( |
| 256 ui::LayerAnimationSequence* sequence) { | 274 ui::LayerAnimationSequence* sequence) { |
| 257 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 275 inflight_animations_.erase(sequence); |
| 258 if (animator) | 276 OnAnimationStopped(); |
| 259 animator->RemoveObserver(this); | |
| 260 } | 277 } |
| 261 | 278 |
| 262 void ToastOverlay::OnLayerAnimationScheduled( | 279 void ToastOverlay::OnLayerAnimationScheduled( |
| 263 ui::LayerAnimationSequence* sequence) {} | 280 ui::LayerAnimationSequence* sequence) {} |
| 264 | 281 |
| 265 views::Widget* ToastOverlay::widget_for_testing() { | 282 views::Widget* ToastOverlay::widget_for_testing() { |
| 266 return overlay_widget_.get(); | 283 return overlay_widget_.get(); |
| 267 } | 284 } |
| 268 | 285 |
| 269 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { | 286 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { |
| 270 overlay_view_->button()->NotifyClick(event); | 287 overlay_view_->button()->NotifyClick(event); |
| 271 } | 288 } |
| 272 | 289 |
| 273 } // namespace ash | 290 } // namespace ash |
| OLD | NEW |