| 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/common/shelf/shelf_widget.h" | 5 #include "ash/common/shelf/shelf_widget.h" |
| 6 | 6 |
| 7 #include "ash/common/focus_cycler.h" | 7 #include "ash/common/focus_cycler.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/shelf/shelf_background_animator_observer.h" | 10 #include "ash/common/shelf/shelf_background_animator_observer.h" |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { | 280 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { |
| 281 const float kMaxAlpha = 255.0f; | 281 const float kMaxAlpha = 255.0f; |
| 282 opaque_background_.SetOpacity(alpha / kMaxAlpha); | 282 opaque_background_.SetOpacity(alpha / kMaxAlpha); |
| 283 } | 283 } |
| 284 | 284 |
| 285 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { | 285 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { |
| 286 asset_background_alpha_ = alpha; | 286 asset_background_alpha_ = alpha; |
| 287 SchedulePaint(); | 287 SchedulePaint(); |
| 288 } | 288 } |
| 289 | 289 |
| 290 ShelfWidget::ShelfWidget(WmWindow* shelf_container, | 290 ShelfWidget::ShelfWidget(WmWindow* shelf_container, WmShelf* wm_shelf) |
| 291 WmWindow* status_container, | |
| 292 WmShelf* wm_shelf) | |
| 293 : wm_shelf_(wm_shelf), | 291 : wm_shelf_(wm_shelf), |
| 292 status_area_widget_(nullptr), |
| 294 delegate_view_(new DelegateView(wm_shelf, this)), | 293 delegate_view_(new DelegateView(wm_shelf, this)), |
| 295 shelf_view_(nullptr), | 294 shelf_view_(nullptr), |
| 296 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_), | 295 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_), |
| 297 activating_as_fallback_(false) { | 296 activating_as_fallback_(false) { |
| 298 background_animator_.AddObserver(this); | 297 background_animator_.AddObserver(this); |
| 299 background_animator_.AddObserver(delegate_view_); | 298 background_animator_.AddObserver(delegate_view_); |
| 300 | 299 |
| 301 views::Widget::InitParams params( | 300 views::Widget::InitParams params( |
| 302 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 301 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 303 params.name = "ShelfWidget"; | 302 params.name = "ShelfWidget"; |
| 304 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 303 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| 305 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 304 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 306 params.delegate = delegate_view_; | 305 params.delegate = delegate_view_; |
| 307 shelf_container->GetRootWindowController() | 306 shelf_container->GetRootWindowController() |
| 308 ->ConfigureWidgetInitParamsForContainer( | 307 ->ConfigureWidgetInitParamsForContainer( |
| 309 this, shelf_container->GetShellWindowId(), ¶ms); | 308 this, shelf_container->GetShellWindowId(), ¶ms); |
| 310 Init(params); | 309 Init(params); |
| 311 | 310 |
| 312 // The shelf should not take focus when initially shown. | 311 // The shelf should not take focus when initially shown. |
| 313 set_focus_on_creation(false); | 312 set_focus_on_creation(false); |
| 314 SetContentsView(delegate_view_); | 313 SetContentsView(delegate_view_); |
| 315 delegate_view_->SetParentLayer(GetLayer()); | 314 delegate_view_->SetParentLayer(GetLayer()); |
| 316 | 315 |
| 317 shelf_layout_manager_ = new ShelfLayoutManager(this, wm_shelf_); | 316 shelf_layout_manager_ = new ShelfLayoutManager(this, wm_shelf_); |
| 318 shelf_layout_manager_->AddObserver(this); | 317 shelf_layout_manager_->AddObserver(this); |
| 319 shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_)); | 318 shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_)); |
| 320 background_animator_.PaintBackground( | 319 background_animator_.PaintBackground( |
| 321 shelf_layout_manager_->GetShelfBackgroundType(), | 320 shelf_layout_manager_->GetShelfBackgroundType(), |
| 322 BACKGROUND_CHANGE_IMMEDIATE); | 321 BACKGROUND_CHANGE_IMMEDIATE); |
| 323 wm_shelf_->SetShelfLayoutManager(shelf_layout_manager_); | |
| 324 | |
| 325 // TODO(jamescook): Move ownership to RootWindowController. | |
| 326 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_); | |
| 327 status_area_widget_->CreateTrayViews(); | |
| 328 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) | |
| 329 status_area_widget_->Show(); | |
| 330 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); | |
| 331 background_animator_.AddObserver(status_area_widget_); | |
| 332 status_container->SetLayoutManager( | |
| 333 base::MakeUnique<StatusAreaLayoutManager>(this)); | |
| 334 | 322 |
| 335 views::Widget::AddObserver(this); | 323 views::Widget::AddObserver(this); |
| 336 } | 324 } |
| 337 | 325 |
| 338 ShelfWidget::~ShelfWidget() { | 326 ShelfWidget::~ShelfWidget() { |
| 339 // Must call Shutdown() before destruction. | 327 // Must call Shutdown() before destruction. |
| 340 DCHECK(!status_area_widget_); | 328 DCHECK(!status_area_widget_); |
| 341 WmShell::Get()->focus_cycler()->RemoveWidget(this); | 329 WmShell::Get()->focus_cycler()->RemoveWidget(this); |
| 342 SetFocusCycler(nullptr); | 330 SetFocusCycler(nullptr); |
| 343 RemoveObserver(this); | 331 RemoveObserver(this); |
| 344 background_animator_.RemoveObserver(delegate_view_); | 332 background_animator_.RemoveObserver(delegate_view_); |
| 345 background_animator_.RemoveObserver(this); | 333 background_animator_.RemoveObserver(this); |
| 346 } | 334 } |
| 347 | 335 |
| 336 void ShelfWidget::CreateStatusAreaWidget(WmWindow* status_container) { |
| 337 DCHECK(status_container); |
| 338 DCHECK(!status_area_widget_); |
| 339 // TODO(jamescook): Move ownership to RootWindowController. |
| 340 status_area_widget_ = new StatusAreaWidget(status_container, wm_shelf_); |
| 341 status_area_widget_->CreateTrayViews(); |
| 342 if (WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()) |
| 343 status_area_widget_->Show(); |
| 344 WmShell::Get()->focus_cycler()->AddWidget(status_area_widget_); |
| 345 background_animator_.AddObserver(status_area_widget_); |
| 346 status_container->SetLayoutManager( |
| 347 base::MakeUnique<StatusAreaLayoutManager>(this)); |
| 348 } |
| 349 |
| 348 void ShelfWidget::SetPaintsBackground( | 350 void ShelfWidget::SetPaintsBackground( |
| 349 ShelfBackgroundType background_type, | 351 ShelfBackgroundType background_type, |
| 350 BackgroundAnimatorChangeType change_type) { | 352 BackgroundAnimatorChangeType change_type) { |
| 351 background_animator_.PaintBackground(background_type, change_type); | 353 background_animator_.PaintBackground(background_type, change_type); |
| 352 } | 354 } |
| 353 | 355 |
| 354 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { | 356 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { |
| 355 return background_animator_.target_background_type(); | 357 return background_animator_.target_background_type(); |
| 356 } | 358 } |
| 357 | 359 |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 if (shelf_view_) | 560 if (shelf_view_) |
| 559 shelf_view_->UpdateShelfItemBackground(alpha); | 561 shelf_view_->UpdateShelfItemBackground(alpha); |
| 560 } | 562 } |
| 561 | 563 |
| 562 void ShelfWidget::WillDeleteShelfLayoutManager() { | 564 void ShelfWidget::WillDeleteShelfLayoutManager() { |
| 563 shelf_layout_manager_->RemoveObserver(this); | 565 shelf_layout_manager_->RemoveObserver(this); |
| 564 shelf_layout_manager_ = nullptr; | 566 shelf_layout_manager_ = nullptr; |
| 565 } | 567 } |
| 566 | 568 |
| 567 } // namespace ash | 569 } // namespace ash |
| OLD | NEW |