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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 } | 215 } |
| 216 | 216 |
| 217 void ToastOverlay::Show(bool visible) { | 217 void ToastOverlay::Show(bool visible) { |
| 218 if (is_visible_ == visible) | 218 if (is_visible_ == visible) |
| 219 return; | 219 return; |
| 220 | 220 |
| 221 is_visible_ = visible; | 221 is_visible_ = visible; |
| 222 | 222 |
| 223 overlay_widget_->GetLayer()->GetAnimator()->AddObserver(this); | 223 overlay_widget_->GetLayer()->GetAnimator()->AddObserver(this); |
| 224 | 224 |
| 225 if (is_visible_) | 225 if (is_visible_) { |
| 226 overlay_widget_->Show(); | 226 overlay_widget_->Show(); |
| 227 else | 227 } else { |
| 228 overlay_widget_->Hide(); | 228 overlay_widget_->Hide(); |
| 229 close_event_fired_ = false; | |
|
oshima
2016/03/30 19:11:50
(if you still need this)
move this before Hide bec
yoshiki
2016/04/01 18:32:35
Done.
| |
| 230 } | |
| 229 } | 231 } |
| 230 | 232 |
| 231 gfx::Rect ToastOverlay::CalculateOverlayBounds() { | 233 gfx::Rect ToastOverlay::CalculateOverlayBounds() { |
| 232 ShelfLayoutManager* shelf_layout_manager = | 234 ShelfLayoutManager* shelf_layout_manager = |
| 233 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); | 235 Shelf::ForPrimaryDisplay()->shelf_layout_manager(); |
| 234 gfx::Rect work_area_bounds = shelf_layout_manager->user_work_area_bounds(); | 236 gfx::Rect work_area_bounds = shelf_layout_manager->user_work_area_bounds(); |
| 235 | 237 |
| 236 gfx::Rect bounds = shelf_layout_manager->user_work_area_bounds(); | 238 gfx::Rect bounds = shelf_layout_manager->user_work_area_bounds(); |
| 237 int target_y = bounds.bottom() - widget_size_.height() - kVerticalOffset; | 239 int target_y = bounds.bottom() - widget_size_.height() - kVerticalOffset; |
| 238 bounds.ClampToCenteredSize(widget_size_); | 240 bounds.ClampToCenteredSize(widget_size_); |
| 239 bounds.set_y(target_y); | 241 bounds.set_y(target_y); |
| 240 return bounds; | 242 return bounds; |
| 241 } | 243 } |
| 242 | 244 |
| 243 void ToastOverlay::OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { | 245 void ToastOverlay::OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { |
| 244 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 246 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| 245 if (animator) | 247 if (animator) |
| 246 animator->RemoveObserver(this); | 248 animator->RemoveObserver(this); |
| 247 if (!is_visible_) { | 249 if (!is_visible_ && !close_event_fired_) { |
|
oshima
2016/03/30 19:11:50
can't you just check overlay_widget_'s visibility?
yoshiki
2016/04/01 18:32:35
Here overlay_widget_'s visibility is synced with |
oshima
2016/04/01 19:15:10
My question was do you even need is_visible_. Can'
yoshiki
2016/04/06 17:34:07
Sorry I was wrong. When this method is called, wid
| |
| 248 // Acync operation, since delegate may remove this instance and removing | 250 // Acync operation, since delegate may remove this instance and removing |
| 249 // this here causes crash. | 251 // this here causes crash. |
| 250 base::ThreadTaskRunnerHandle::Get()->PostTask( | 252 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 251 FROM_HERE, | 253 FROM_HERE, |
| 252 base::Bind(&Delegate::OnClosed, | 254 base::Bind(&Delegate::OnClosed, |
| 253 base::Unretained(delegate_) /* |delegate| lives longer */)); | 255 base::Unretained(delegate_) /* |delegate| lives longer */)); |
| 256 | |
| 257 // Prevent tha handler calling multiple times. | |
| 258 close_event_fired_ = true; | |
| 254 } | 259 } |
| 255 } | 260 } |
| 256 | 261 |
| 257 void ToastOverlay::OnLayerAnimationAborted( | 262 void ToastOverlay::OnLayerAnimationAborted( |
| 258 ui::LayerAnimationSequence* sequence) { | 263 ui::LayerAnimationSequence* sequence) { |
| 259 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); | 264 ui::LayerAnimator* animator = overlay_widget_->GetLayer()->GetAnimator(); |
| 260 if (animator) | 265 if (animator) |
| 261 animator->RemoveObserver(this); | 266 animator->RemoveObserver(this); |
| 262 } | 267 } |
| 263 | 268 |
| 264 void ToastOverlay::OnLayerAnimationScheduled( | 269 void ToastOverlay::OnLayerAnimationScheduled( |
| 265 ui::LayerAnimationSequence* sequence) {} | 270 ui::LayerAnimationSequence* sequence) {} |
| 266 | 271 |
| 267 views::Widget* ToastOverlay::widget_for_testing() { | 272 views::Widget* ToastOverlay::widget_for_testing() { |
| 268 return overlay_widget_.get(); | 273 return overlay_widget_.get(); |
| 269 } | 274 } |
| 270 | 275 |
| 271 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { | 276 void ToastOverlay::ClickDismissButtonForTesting(const ui::Event& event) { |
| 272 overlay_view_->button()->NotifyClick(event); | 277 overlay_view_->button()->NotifyClick(event); |
| 273 } | 278 } |
| 274 | 279 |
| 275 } // namespace ash | 280 } // namespace ash |
| OLD | NEW |