Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/shelf/shelf_widget.h" | 5 #include "ash/shelf/shelf_widget.h" |
| 6 | 6 |
| 7 #include "ash/aura/wm_shelf_aura.h" | |
|
James Cook
2016/08/16 23:21:35
Awesome.
msw
2016/08/17 01:09:02
Acknowledged.
| |
| 8 #include "ash/common/focus_cycler.h" | 7 #include "ash/common/focus_cycler.h" |
| 9 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 10 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 11 #include "ash/common/shelf/shelf_background_animator_observer.h" | 10 #include "ash/common/shelf/shelf_background_animator_observer.h" |
| 12 #include "ash/common/shelf/shelf_constants.h" | 11 #include "ash/common/shelf/shelf_constants.h" |
| 13 #include "ash/common/shelf/shelf_delegate.h" | 12 #include "ash/common/shelf/shelf_delegate.h" |
| 14 #include "ash/common/shelf/shelf_view.h" | 13 #include "ash/common/shelf/shelf_view.h" |
| 15 #include "ash/common/shelf/wm_dimmer_view.h" | 14 #include "ash/common/shelf/wm_dimmer_view.h" |
| 16 #include "ash/common/shelf/wm_shelf.h" | 15 #include "ash/common/shelf/wm_shelf.h" |
| 17 #include "ash/common/shelf/wm_shelf_util.h" | 16 #include "ash/common/shelf/wm_shelf_util.h" |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 147 |
| 149 ShelfWidget::DelegateView::~DelegateView() { | 148 ShelfWidget::DelegateView::~DelegateView() { |
| 150 // Make sure that the dimmer goes away since it might have set an observer. | 149 // Make sure that the dimmer goes away since it might have set an observer. |
| 151 SetDimmed(false); | 150 SetDimmed(false); |
| 152 } | 151 } |
| 153 | 152 |
| 154 void ShelfWidget::DelegateView::SetDimmed(bool dimmed) { | 153 void ShelfWidget::DelegateView::SetDimmed(bool dimmed) { |
| 155 // When starting dimming, attempt to create a dimmer view. | 154 // When starting dimming, attempt to create a dimmer view. |
| 156 if (dimmed) { | 155 if (dimmed) { |
| 157 if (!dimmer_view_) { | 156 if (!dimmer_view_) { |
| 158 // The WmShelf interface is private in WmShelfAura. | |
| 159 WmShelf* shelf = static_cast<WmShelf*>(shelf_widget_->wm_shelf_aura_); | |
| 160 dimmer_view_ = | 157 dimmer_view_ = |
| 161 shelf->CreateDimmerView(disable_dimming_animations_for_test_); | 158 wm_shelf_->CreateDimmerView(disable_dimming_animations_for_test_); |
| 162 } | 159 } |
| 163 return; | 160 return; |
| 164 } | 161 } |
| 165 | 162 |
| 166 // Close the dimmer widget when stopping dimming. | 163 // Close the dimmer widget when stopping dimming. |
| 167 if (dimmer_view_) { | 164 if (dimmer_view_) { |
| 168 dimmer_view_->GetDimmerWidget()->CloseNow(); | 165 dimmer_view_->GetDimmerWidget()->CloseNow(); |
| 169 dimmer_view_ = nullptr; | 166 dimmer_view_ = nullptr; |
| 170 } | 167 } |
| 171 } | 168 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 opaque_background_.SetOpacity(alpha / kMaxAlpha); | 280 opaque_background_.SetOpacity(alpha / kMaxAlpha); |
| 284 } | 281 } |
| 285 | 282 |
| 286 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { | 283 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { |
| 287 asset_background_alpha_ = alpha; | 284 asset_background_alpha_ = alpha; |
| 288 SchedulePaint(); | 285 SchedulePaint(); |
| 289 } | 286 } |
| 290 | 287 |
| 291 ShelfWidget::ShelfWidget(WmWindow* shelf_container, | 288 ShelfWidget::ShelfWidget(WmWindow* shelf_container, |
| 292 WmWindow* status_container, | 289 WmWindow* status_container, |
| 293 WmShelfAura* wm_shelf_aura) | 290 WmShelf* wm_shelf) |
| 294 : wm_shelf_aura_(wm_shelf_aura), | 291 : wm_shelf_(wm_shelf), |
| 295 shelf_(nullptr), | 292 shelf_(nullptr), |
| 296 delegate_view_(new DelegateView(wm_shelf_aura, this)), | 293 delegate_view_(new DelegateView(wm_shelf, this)), |
| 297 shelf_view_(nullptr), | 294 shelf_view_(nullptr), |
| 298 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_aura_), | 295 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_), |
| 299 activating_as_fallback_(false) { | 296 activating_as_fallback_(false) { |
| 300 background_animator_.AddObserver(this); | 297 background_animator_.AddObserver(this); |
| 301 background_animator_.AddObserver(delegate_view_); | 298 background_animator_.AddObserver(delegate_view_); |
| 302 | 299 |
| 303 views::Widget::InitParams params( | 300 views::Widget::InitParams params( |
| 304 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 301 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 305 params.name = "ShelfWidget"; | 302 params.name = "ShelfWidget"; |
| 306 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 303 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 307 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 304 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 308 params.delegate = delegate_view_; | 305 params.delegate = delegate_view_; |
| 309 shelf_container->GetRootWindowController() | 306 shelf_container->GetRootWindowController() |
| 310 ->ConfigureWidgetInitParamsForContainer( | 307 ->ConfigureWidgetInitParamsForContainer( |
| 311 this, shelf_container->GetShellWindowId(), ¶ms); | 308 this, shelf_container->GetShellWindowId(), ¶ms); |
| 312 Init(params); | 309 Init(params); |
| 313 | 310 |
| 314 // The shelf should not take focus when initially shown. | 311 // The shelf should not take focus when initially shown. |
| 315 set_focus_on_creation(false); | 312 set_focus_on_creation(false); |
| 316 SetContentsView(delegate_view_); | 313 SetContentsView(delegate_view_); |
| 317 delegate_view_->SetParentLayer(GetLayer()); | 314 delegate_view_->SetParentLayer(GetLayer()); |
| 318 | 315 |
| 319 shelf_layout_manager_ = new ShelfLayoutManager(this); | 316 shelf_layout_manager_ = new ShelfLayoutManager(this); |
| 320 shelf_layout_manager_->AddObserver(this); | 317 shelf_layout_manager_->AddObserver(this); |
| 321 shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_)); | 318 shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_)); |
| 322 background_animator_.PaintBackground( | 319 background_animator_.PaintBackground( |
| 323 shelf_layout_manager_->GetShelfBackgroundType(), | 320 shelf_layout_manager_->GetShelfBackgroundType(), |
| 324 BACKGROUND_CHANGE_IMMEDIATE); | 321 BACKGROUND_CHANGE_IMMEDIATE); |
| 325 wm_shelf_aura_->SetShelfLayoutManager(shelf_layout_manager_); | 322 wm_shelf_->SetShelfLayoutManager(shelf_layout_manager_); |
| 326 | 323 |
| 327 // TODO(jamescook): Move ownership to RootWindowController. | 324 // TODO(jamescook): Move ownership to RootWindowController. |
| 328 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_aura_); | 325 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_); |
| 329 status_area_widget_->CreateTrayViews(); | 326 status_area_widget_->CreateTrayViews(); |
| 330 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) | 327 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) |
| 331 status_area_widget_->Show(); | 328 status_area_widget_->Show(); |
| 332 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); | 329 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); |
| 333 background_animator_.AddObserver(status_area_widget_); | 330 background_animator_.AddObserver(status_area_widget_); |
| 334 status_container->SetLayoutManager( | 331 status_container->SetLayoutManager( |
| 335 base::MakeUnique<StatusAreaLayoutManager>(this)); | 332 base::MakeUnique<StatusAreaLayoutManager>(this)); |
| 336 | 333 |
| 337 views::Widget::AddObserver(this); | 334 views::Widget::AddObserver(this); |
| 338 } | 335 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 399 case LoginStatus::KIOSK_APP: | 396 case LoginStatus::KIOSK_APP: |
| 400 case LoginStatus::NOT_LOGGED_IN: | 397 case LoginStatus::NOT_LOGGED_IN: |
| 401 return false; | 398 return false; |
| 402 } | 399 } |
| 403 | 400 |
| 404 NOTREACHED(); | 401 NOTREACHED(); |
| 405 return false; | 402 return false; |
| 406 } | 403 } |
| 407 | 404 |
| 408 ShelfAlignment ShelfWidget::GetAlignment() const { | 405 ShelfAlignment ShelfWidget::GetAlignment() const { |
| 409 WmShelf* wm_shelf = static_cast<WmShelf*>(wm_shelf_aura_); | 406 return wm_shelf_->GetAlignment(); |
| 410 return wm_shelf->GetAlignment(); | |
| 411 } | 407 } |
| 412 | 408 |
| 413 void ShelfWidget::OnShelfAlignmentChanged() { | 409 void ShelfWidget::OnShelfAlignmentChanged() { |
| 414 status_area_widget_->SetShelfAlignment(GetAlignment()); | 410 status_area_widget_->SetShelfAlignment(GetAlignment()); |
| 415 delegate_view_->SchedulePaint(); | 411 delegate_view_->SchedulePaint(); |
| 416 } | 412 } |
| 417 | 413 |
| 418 void ShelfWidget::SetDimsShelf(bool dimming) { | 414 void ShelfWidget::SetDimsShelf(bool dimming) { |
| 419 delegate_view_->SetDimmed(dimming); | 415 delegate_view_->SetDimmed(dimming); |
| 420 // Repaint all children, allowing updates to reflect dimmed state eg: | 416 // Repaint all children, allowing updates to reflect dimmed state eg: |
| 421 // status area background, app list button and overflow button. | 417 // status area background, app list button and overflow button. |
| 422 if (shelf_view_) | 418 if (shelf_view_) |
| 423 shelf_view_->SchedulePaintForAllButtons(); | 419 shelf_view_->SchedulePaintForAllButtons(); |
| 424 status_area_widget_->SchedulePaint(); | 420 status_area_widget_->SchedulePaint(); |
| 425 } | 421 } |
| 426 | 422 |
| 427 bool ShelfWidget::GetDimsShelf() const { | 423 bool ShelfWidget::GetDimsShelf() const { |
| 428 return delegate_view_->GetDimmed(); | 424 return delegate_view_->GetDimmed(); |
| 429 } | 425 } |
| 430 | 426 |
| 431 ShelfView* ShelfWidget::CreateShelfView() { | 427 ShelfView* ShelfWidget::CreateShelfView() { |
| 432 DCHECK(!shelf_); | 428 DCHECK(!shelf_); |
| 433 DCHECK(!shelf_view_); | 429 DCHECK(!shelf_view_); |
| 434 | 430 |
| 435 shelf_view_ = | 431 shelf_view_ = |
| 436 new ShelfView(WmShell::Get()->shelf_model(), | 432 new ShelfView(WmShell::Get()->shelf_model(), |
| 437 WmShell::Get()->shelf_delegate(), wm_shelf_aura_, this); | 433 WmShell::Get()->shelf_delegate(), wm_shelf_, this); |
| 438 shelf_view_->Init(); | 434 shelf_view_->Init(); |
| 439 GetContentsView()->AddChildView(shelf_view_); | 435 GetContentsView()->AddChildView(shelf_view_); |
| 440 return shelf_view_; | 436 return shelf_view_; |
| 441 } | 437 } |
| 442 | 438 |
| 443 void ShelfWidget::PostCreateShelf() { | 439 void ShelfWidget::PostCreateShelf() { |
| 444 SetFocusCycler(WmShell::Get()->focus_cycler()); | 440 SetFocusCycler(WmShell::Get()->focus_cycler()); |
| 445 | 441 |
| 446 // Ensure the newly created |shelf_| gets current values. | 442 // Ensure the newly created |shelf_| gets current values. |
| 447 background_animator_.Initialize(this); | 443 background_animator_.Initialize(this); |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 467 if (focus_cycler) | 463 if (focus_cycler) |
| 468 focus_cycler->AddWidget(this); | 464 focus_cycler->AddWidget(this); |
| 469 } | 465 } |
| 470 | 466 |
| 471 FocusCycler* ShelfWidget::GetFocusCycler() { | 467 FocusCycler* ShelfWidget::GetFocusCycler() { |
| 472 return delegate_view_->focus_cycler(); | 468 return delegate_view_->focus_cycler(); |
| 473 } | 469 } |
| 474 | 470 |
| 475 void ShelfWidget::Shutdown() { | 471 void ShelfWidget::Shutdown() { |
| 476 // Tear down the dimmer before |shelf_layout_manager_|, since the dimmer uses | 472 // Tear down the dimmer before |shelf_layout_manager_|, since the dimmer uses |
| 477 // |shelf_layout_manager_| to get the shelf's WmWindow, via WmShelfAura. | 473 // |shelf_layout_manager_| to get the shelf's WmWindow, via WmShelf. |
| 478 delegate_view_->SetDimmed(false); | 474 delegate_view_->SetDimmed(false); |
| 479 | 475 |
| 480 // Shutting down the status area widget may cause some widgets (e.g. bubbles) | 476 // Shutting down the status area widget may cause some widgets (e.g. bubbles) |
| 481 // to close, so uninstall the ShelfLayoutManager event filters first. Don't | 477 // to close, so uninstall the ShelfLayoutManager event filters first. Don't |
| 482 // reset the pointer until later because other widgets (e.g. app list) may | 478 // reset the pointer until later because other widgets (e.g. app list) may |
| 483 // access it later in shutdown. | 479 // access it later in shutdown. |
| 484 if (shelf_layout_manager_) | 480 if (shelf_layout_manager_) |
| 485 shelf_layout_manager_->PrepareForShutdown(); | 481 shelf_layout_manager_->PrepareForShutdown(); |
| 486 | 482 |
| 487 if (status_area_widget_) { | 483 if (status_area_widget_) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 if (shelf_view_) | 522 if (shelf_view_) |
| 527 shelf_view_->UpdateShelfItemBackground(alpha); | 523 shelf_view_->UpdateShelfItemBackground(alpha); |
| 528 } | 524 } |
| 529 | 525 |
| 530 void ShelfWidget::WillDeleteShelfLayoutManager() { | 526 void ShelfWidget::WillDeleteShelfLayoutManager() { |
| 531 shelf_layout_manager_->RemoveObserver(this); | 527 shelf_layout_manager_->RemoveObserver(this); |
| 532 shelf_layout_manager_ = nullptr; | 528 shelf_layout_manager_ = nullptr; |
| 533 } | 529 } |
| 534 | 530 |
| 535 } // namespace ash | 531 } // namespace ash |
| OLD | NEW |