| 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 | 190 |
| 191 gfx::NativeWindow native_view = overlay_widget_->GetNativeView(); | 191 gfx::NativeWindow native_view = overlay_widget_->GetNativeView(); |
| 192 wm::SetWindowVisibilityAnimationType( | 192 wm::SetWindowVisibilityAnimationType( |
| 193 native_view, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); | 193 native_view, wm::WINDOW_VISIBILITY_ANIMATION_TYPE_VERTICAL); |
| 194 wm::SetWindowVisibilityAnimationDuration( | 194 wm::SetWindowVisibilityAnimationDuration( |
| 195 native_view, | 195 native_view, |
| 196 base::TimeDelta::FromMilliseconds(kSlideAnimationDurationMs)); | 196 base::TimeDelta::FromMilliseconds(kSlideAnimationDurationMs)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 ToastOverlay::~ToastOverlay() { | 199 ToastOverlay::~ToastOverlay() { |
| 200 gfx::NativeWindow native_view = overlay_widget_->GetNativeView(); | |
| 201 wm::SetWindowVisibilityAnimationTransition(native_view, wm::ANIMATE_NONE); | |
| 202 | |
| 203 // Remove ourself from the animator to avoid being re-entrantly called in | |
| 204 // |overlay_widget_|'s destructor. | |
| 205 ui::Layer* layer = overlay_widget_->GetLayer(); | |
| 206 if (layer) { | |
| 207 ui::LayerAnimator* animator = layer->GetAnimator(); | |
| 208 if (animator) | |
| 209 animator->RemoveObserver(this); | |
| 210 } | |
| 211 | |
| 212 overlay_widget_->Close(); | 200 overlay_widget_->Close(); |
| 213 } | 201 } |
| 214 | 202 |
| 215 void ToastOverlay::Show(bool visible) { | 203 void ToastOverlay::Show(bool visible) { |
| 216 if (is_visible_ == visible) | 204 if (overlay_widget_->GetLayer()->GetTargetVisibility() == visible) |
| 217 return; | 205 return; |
| 218 | 206 |
| 219 is_visible_ = visible; | 207 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| 208 DCHECK(animator); |
| 220 | 209 |
| 221 overlay_widget_->GetLayer()->GetAnimator()->AddObserver(this); | 210 base::TimeDelta original_duration = animator->GetTransitionDuration(); |
| 211 ui::ScopedLayerAnimationSettings animation_settings(animator); |
| 212 // ScopedLayerAnimationSettings ctor chanes the transition duration, so change |
| 213 // back it to the original value (should be zero). |
| 214 animation_settings.SetTransitionDuration(original_duration); |
| 222 | 215 |
| 223 if (is_visible_) | 216 animation_settings.AddObserver(this); |
| 217 |
| 218 if (visible) |
| 224 overlay_widget_->Show(); | 219 overlay_widget_->Show(); |
| 225 else | 220 else |
| 226 overlay_widget_->Hide(); | 221 overlay_widget_->Hide(); |
| 227 } | 222 } |
| 228 | 223 |
| 229 gfx::Rect ToastOverlay::CalculateOverlayBounds() { | 224 gfx::Rect ToastOverlay::CalculateOverlayBounds() { |
| 230 ShelfLayoutManager* shelf_layout_manager = | 225 ShelfLayoutManager* shelf_layout_manager = |
| 231 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 226 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); |
| 232 gfx::Rect work_area_bounds = shelf_layout_manager->user_work_area_bounds(); | 227 gfx::Rect work_area_bounds = shelf_layout_manager->user_work_area_bounds(); |
| 233 | 228 |
| 234 gfx::Rect bounds = shelf_layout_manager->user_work_area_bounds(); | 229 gfx::Rect bounds = shelf_layout_manager->user_work_area_bounds(); |
| 235 int target_y = bounds.bottom() - widget_size_.height() - kVerticalOffset; | 230 int target_y = bounds.bottom() - widget_size_.height() - kVerticalOffset; |
| 236 bounds.ClampToCenteredSize(widget_size_); | 231 bounds.ClampToCenteredSize(widget_size_); |
| 237 bounds.set_y(target_y); | 232 bounds.set_y(target_y); |
| 238 return bounds; | 233 return bounds; |
| 239 } | 234 } |
| 240 | 235 |
| 241 void ToastOverlay::OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { | 236 void ToastOverlay::OnImplicitAnimationsScheduled() {} |
| 242 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 237 |
| 243 if (animator) | 238 void ToastOverlay::OnImplicitAnimationsCompleted() { |
| 244 animator->RemoveObserver(this); | 239 if (!overlay_widget_->GetLayer()->GetTargetVisibility()) |
| 245 if (!is_visible_) { | 240 delegate_->OnClosed(); |
| 246 // Acync operation, since delegate may remove this instance and removing | |
| 247 // this here causes crash. | |
| 248 base::ThreadTaskRunnerHandle::Get()->PostTask( | |
| 249 FROM_HERE, | |
| 250 base::Bind(&Delegate::OnClosed, | |
| 251 base::Unretained(delegate_) /* |delegate| lives longer */)); | |
| 252 } | |
| 253 } | 241 } |
| 254 | 242 |
| 255 void ToastOverlay::OnLayerAnimationAborted( | |
| 256 ui::LayerAnimationSequence* sequence) { | |
| 257 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | |
| 258 if (animator) | |
| 259 animator->RemoveObserver(this); | |
| 260 } | |
| 261 | |
| 262 void ToastOverlay::OnLayerAnimationScheduled( | |
| 263 ui::LayerAnimationSequence* sequence) {} | |
| 264 | |
| 265 views::Widget* ToastOverlay::widget_for_testing() { | 243 views::Widget* ToastOverlay::widget_for_testing() { |
| 266 return overlay_widget_.get(); | 244 return overlay_widget_.get(); |
| 267 } | 245 } |
| 268 | 246 |
| 269 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { | 247 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { |
| 270 overlay_view_->button()->NotifyClick(event); | 248 overlay_view_->button()->NotifyClick(event); |
| 271 } | 249 } |
| 272 | 250 |
| 273 } // namespace ash | 251 } // namespace ash |
| OLD | NEW |