Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(336)

Side by Side Diff: ash/shelf/shelf_widget.cc

Issue 2235233006: ash: Refactor Shelf ownership and ShelfView creation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ash/shelf/shelf_widget.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 7 #include "ash/aura/wm_shelf_aura.h"
8 #include "ash/common/focus_cycler.h" 8 #include "ash/common/focus_cycler.h"
9 #include "ash/common/material_design/material_design_controller.h" 9 #include "ash/common/material_design/material_design_controller.h"
10 #include "ash/common/session/session_state_delegate.h" 10 #include "ash/common/session/session_state_delegate.h"
11 #include "ash/common/shelf/shelf_background_animator_observer.h" 11 #include "ash/common/shelf/shelf_background_animator_observer.h"
12 #include "ash/common/shelf/shelf_constants.h" 12 #include "ash/common/shelf/shelf_constants.h"
13 #include "ash/common/shelf/shelf_delegate.h" 13 #include "ash/common/shelf/shelf_delegate.h"
14 #include "ash/common/shelf/shelf_view.h"
14 #include "ash/common/shelf/wm_dimmer_view.h" 15 #include "ash/common/shelf/wm_dimmer_view.h"
15 #include "ash/common/shelf/wm_shelf.h" 16 #include "ash/common/shelf/wm_shelf.h"
16 #include "ash/common/shelf/wm_shelf_util.h" 17 #include "ash/common/shelf/wm_shelf_util.h"
17 #include "ash/common/system/status_area_widget.h" 18 #include "ash/common/system/status_area_widget.h"
18 #include "ash/common/system/tray/system_tray_delegate.h" 19 #include "ash/common/system/tray/system_tray_delegate.h"
19 #include "ash/common/wm_root_window_controller.h" 20 #include "ash/common/wm_root_window_controller.h"
20 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
21 #include "ash/common/wm_window.h" 22 #include "ash/common/wm_window.h"
22 #include "ash/shelf/shelf.h"
23 #include "ash/shelf/shelf_layout_manager.h" 23 #include "ash/shelf/shelf_layout_manager.h"
24 #include "ash/wm/status_area_layout_manager.h" 24 #include "ash/wm/status_area_layout_manager.h"
25 #include "base/memory/ptr_util.h" 25 #include "base/memory/ptr_util.h"
26 #include "grit/ash_resources.h" 26 #include "grit/ash_resources.h"
27 #include "ui/base/resource/resource_bundle.h" 27 #include "ui/base/resource/resource_bundle.h"
28 #include "ui/compositor/layer.h" 28 #include "ui/compositor/layer.h"
29 #include "ui/compositor/scoped_layer_animation_settings.h" 29 #include "ui/compositor/scoped_layer_animation_settings.h"
30 #include "ui/gfx/canvas.h" 30 #include "ui/gfx/canvas.h"
31 #include "ui/gfx/image/image.h" 31 #include "ui/gfx/image/image.h"
32 #include "ui/gfx/image/image_skia_operations.h" 32 #include "ui/gfx/image/image_skia_operations.h"
(...skipping 11 matching lines...) Expand all
44 const int kNumBlackPixels = 3; 44 const int kNumBlackPixels = 3;
45 45
46 } // namespace 46 } // namespace
47 47
48 // The contents view of the Shelf. This view contains ShelfView and 48 // The contents view of the Shelf. This view contains ShelfView and
49 // sizes it to the width of the shelf minus the size of the status area. 49 // sizes it to the width of the shelf minus the size of the status area.
50 class ShelfWidget::DelegateView : public views::WidgetDelegate, 50 class ShelfWidget::DelegateView : public views::WidgetDelegate,
51 public views::AccessiblePaneView, 51 public views::AccessiblePaneView,
52 public ShelfBackgroundAnimatorObserver { 52 public ShelfBackgroundAnimatorObserver {
53 public: 53 public:
54 explicit DelegateView(ShelfWidget* shelf); 54 DelegateView(WmShelf* wm_shelf, ShelfWidget* shelf);
55 ~DelegateView() override; 55 ~DelegateView() override;
56 56
57 void set_focus_cycler(FocusCycler* focus_cycler) { 57 void set_focus_cycler(FocusCycler* focus_cycler) {
58 focus_cycler_ = focus_cycler; 58 focus_cycler_ = focus_cycler;
59 } 59 }
60 FocusCycler* focus_cycler() { return focus_cycler_; } 60 FocusCycler* focus_cycler() { return focus_cycler_; }
61 61
62 ui::Layer* opaque_background() { return &opaque_background_; } 62 ui::Layer* opaque_background() { return &opaque_background_; }
63 ui::Layer* opaque_foreground() { return &opaque_foreground_; } 63 ui::Layer* opaque_foreground() { return &opaque_foreground_; }
64 64
(...skipping 30 matching lines...) Expand all
95 // the dimmer is inactive. 95 // the dimmer is inactive.
96 gfx::Rect GetDimmerBoundsForTest(); 96 gfx::Rect GetDimmerBoundsForTest();
97 97
98 // Disable dimming animations for running tests. This needs to be called 98 // Disable dimming animations for running tests. This needs to be called
99 // prior to the creation of of the dimmer. 99 // prior to the creation of of the dimmer.
100 void disable_dimming_animations_for_test() { 100 void disable_dimming_animations_for_test() {
101 disable_dimming_animations_for_test_ = true; 101 disable_dimming_animations_for_test_ = true;
102 } 102 }
103 103
104 private: 104 private:
105 WmShelf* wm_shelf_;
105 ShelfWidget* shelf_widget_; 106 ShelfWidget* shelf_widget_;
106 FocusCycler* focus_cycler_; 107 FocusCycler* focus_cycler_;
107 int asset_background_alpha_; 108 int asset_background_alpha_;
108 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). 109 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551).
109 // A black background layer which is shown when a maximized window is visible. 110 // A black background layer which is shown when a maximized window is visible.
110 ui::Layer opaque_background_; 111 ui::Layer opaque_background_;
111 // A black foreground layer which is shown while transitioning between users. 112 // A black foreground layer which is shown while transitioning between users.
112 // Note: Since the back- and foreground layers have different functions they 113 // Note: Since the back- and foreground layers have different functions they
113 // can be used simultaneously - so no repurposing possible. 114 // can be used simultaneously - so no repurposing possible.
114 ui::Layer opaque_foreground_; 115 ui::Layer opaque_foreground_;
115 116
116 // The interface for the view which does the dimming. Null if the shelf is not 117 // The interface for the view which does the dimming. Null if the shelf is not
117 // being dimmed, or if dimming is not supported (e.g. for mus). 118 // being dimmed, or if dimming is not supported (e.g. for mus).
118 WmDimmerView* dimmer_view_; 119 WmDimmerView* dimmer_view_;
119 120
120 // True if dimming animations should be turned off. 121 // True if dimming animations should be turned off.
121 bool disable_dimming_animations_for_test_; 122 bool disable_dimming_animations_for_test_;
122 123
123 DISALLOW_COPY_AND_ASSIGN(DelegateView); 124 DISALLOW_COPY_AND_ASSIGN(DelegateView);
124 }; 125 };
125 126
126 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf_widget) 127 ShelfWidget::DelegateView::DelegateView(WmShelf* wm_shelf,
127 : shelf_widget_(shelf_widget), 128 ShelfWidget* shelf_widget)
129 : wm_shelf_(wm_shelf),
130 shelf_widget_(shelf_widget),
128 focus_cycler_(nullptr), 131 focus_cycler_(nullptr),
129 asset_background_alpha_(0), 132 asset_background_alpha_(0),
130 opaque_background_(ui::LAYER_SOLID_COLOR), 133 opaque_background_(ui::LAYER_SOLID_COLOR),
131 opaque_foreground_(ui::LAYER_SOLID_COLOR), 134 opaque_foreground_(ui::LAYER_SOLID_COLOR),
132 dimmer_view_(nullptr), 135 dimmer_view_(nullptr),
133 disable_dimming_animations_for_test_(false) { 136 disable_dimming_animations_for_test_(false) {
137 DCHECK(wm_shelf_);
138 DCHECK(shelf_widget_);
134 SetLayoutManager(new views::FillLayout()); 139 SetLayoutManager(new views::FillLayout());
135 set_allow_deactivate_on_esc(true); 140 set_allow_deactivate_on_esc(true);
136 opaque_background_.SetColor(SK_ColorBLACK); 141 opaque_background_.SetColor(SK_ColorBLACK);
137 opaque_background_.SetBounds(GetLocalBounds()); 142 opaque_background_.SetBounds(GetLocalBounds());
138 opaque_background_.SetOpacity(0.0f); 143 opaque_background_.SetOpacity(0.0f);
139 opaque_foreground_.SetColor(SK_ColorBLACK); 144 opaque_foreground_.SetColor(SK_ColorBLACK);
140 opaque_foreground_.SetBounds(GetLocalBounds()); 145 opaque_foreground_.SetBounds(GetLocalBounds());
141 opaque_foreground_.SetOpacity(0.0f); 146 opaque_foreground_.SetOpacity(0.0f);
142 } 147 }
143 148
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 ReorderLayers(); 180 ReorderLayers();
176 } 181 }
177 182
178 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { 183 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
179 if (MaterialDesignController::IsShelfMaterial()) 184 if (MaterialDesignController::IsShelfMaterial())
180 return; 185 return;
181 186
182 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 187 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
183 gfx::ImageSkia shelf_background = 188 gfx::ImageSkia shelf_background =
184 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); 189 *rb->GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
185 const bool horizontal = IsHorizontalAlignment(shelf_widget_->GetAlignment()); 190 const bool horizontal = wm_shelf_->IsHorizontalAlignment();
186 if (!horizontal) { 191 if (!horizontal) {
187 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( 192 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
188 shelf_background, shelf_widget_->GetAlignment() == SHELF_ALIGNMENT_LEFT 193 shelf_background, wm_shelf_->GetAlignment() == SHELF_ALIGNMENT_LEFT
189 ? SkBitmapOperations::ROTATION_90_CW 194 ? SkBitmapOperations::ROTATION_90_CW
190 : SkBitmapOperations::ROTATION_270_CW); 195 : SkBitmapOperations::ROTATION_270_CW);
191 } 196 }
192 const gfx::Rect dock_bounds( 197 const gfx::Rect dock_bounds(
193 shelf_widget_->shelf_layout_manager()->dock_bounds()); 198 shelf_widget_->shelf_layout_manager()->dock_bounds());
194 SkPaint paint; 199 SkPaint paint;
195 paint.setAlpha(asset_background_alpha_); 200 paint.setAlpha(asset_background_alpha_);
196 canvas->DrawImageInt( 201 canvas->DrawImageInt(
197 shelf_background, 0, 0, shelf_background.width(), 202 shelf_background, 0, 0, shelf_background.width(),
198 shelf_background.height(), 203 shelf_background.height(),
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 285
281 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { 286 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) {
282 asset_background_alpha_ = alpha; 287 asset_background_alpha_ = alpha;
283 SchedulePaint(); 288 SchedulePaint();
284 } 289 }
285 290
286 ShelfWidget::ShelfWidget(WmWindow* shelf_container, 291 ShelfWidget::ShelfWidget(WmWindow* shelf_container,
287 WmWindow* status_container, 292 WmWindow* status_container,
288 WmShelfAura* wm_shelf_aura) 293 WmShelfAura* wm_shelf_aura)
289 : wm_shelf_aura_(wm_shelf_aura), 294 : wm_shelf_aura_(wm_shelf_aura),
290 delegate_view_(new DelegateView(this)), 295 shelf_(nullptr),
296 delegate_view_(new DelegateView(wm_shelf_aura, this)),
297 shelf_view_(nullptr),
291 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_aura_), 298 background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_aura_),
292 activating_as_fallback_(false) { 299 activating_as_fallback_(false) {
293 background_animator_.AddObserver(this); 300 background_animator_.AddObserver(this);
294 background_animator_.AddObserver(delegate_view_); 301 background_animator_.AddObserver(delegate_view_);
295 302
296 views::Widget::InitParams params( 303 views::Widget::InitParams params(
297 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 304 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
305 params.name = "ShelfWidget";
298 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 306 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
299 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 307 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
300 params.delegate = delegate_view_; 308 params.delegate = delegate_view_;
301 shelf_container->GetRootWindowController() 309 shelf_container->GetRootWindowController()
302 ->ConfigureWidgetInitParamsForContainer( 310 ->ConfigureWidgetInitParamsForContainer(
303 this, shelf_container->GetShellWindowId(), &params); 311 this, shelf_container->GetShellWindowId(), &params);
304 Init(params); 312 Init(params);
305 313
306 // The shelf should not take focus when initially shown. 314 // The shelf should not take focus when initially shown.
307 set_focus_on_creation(false); 315 set_focus_on_creation(false);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 case LoginStatus::KIOSK_APP: 399 case LoginStatus::KIOSK_APP:
392 case LoginStatus::NOT_LOGGED_IN: 400 case LoginStatus::NOT_LOGGED_IN:
393 return false; 401 return false;
394 } 402 }
395 403
396 NOTREACHED(); 404 NOTREACHED();
397 return false; 405 return false;
398 } 406 }
399 407
400 ShelfAlignment ShelfWidget::GetAlignment() const { 408 ShelfAlignment ShelfWidget::GetAlignment() const {
401 // TODO(msw): This should not be called before |shelf_| is created. 409 WmShelf* wm_shelf = static_cast<WmShelf*>(wm_shelf_aura_);
402 return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED; 410 return wm_shelf->GetAlignment();
403 } 411 }
404 412
405 void ShelfWidget::OnShelfAlignmentChanged() { 413 void ShelfWidget::OnShelfAlignmentChanged() {
406 status_area_widget_->SetShelfAlignment(GetAlignment()); 414 status_area_widget_->SetShelfAlignment(GetAlignment());
407 delegate_view_->SchedulePaint(); 415 delegate_view_->SchedulePaint();
408 } 416 }
409 417
410 void ShelfWidget::SetDimsShelf(bool dimming) { 418 void ShelfWidget::SetDimsShelf(bool dimming) {
411 delegate_view_->SetDimmed(dimming); 419 delegate_view_->SetDimmed(dimming);
412 // Repaint all children, allowing updates to reflect dimmed state eg: 420 // Repaint all children, allowing updates to reflect dimmed state eg:
413 // status area background, app list button and overflow button. 421 // status area background, app list button and overflow button.
414 if (shelf_) 422 if (shelf_view_)
415 shelf_->SchedulePaint(); 423 shelf_view_->SchedulePaintForAllButtons();
416 status_area_widget_->SchedulePaint(); 424 status_area_widget_->SchedulePaint();
417 } 425 }
418 426
419 bool ShelfWidget::GetDimsShelf() const { 427 bool ShelfWidget::GetDimsShelf() const {
420 return delegate_view_->GetDimmed(); 428 return delegate_view_->GetDimmed();
421 } 429 }
422 430
423 void ShelfWidget::CreateShelf() { 431 ShelfView* ShelfWidget::CreateShelfView() {
424 DCHECK(!shelf_); 432 DCHECK(!shelf_);
433 DCHECK(!shelf_view_);
425 434
426 shelf_.reset(new Shelf(WmShell::Get()->shelf_model(), wm_shelf_aura_, this)); 435 shelf_view_ =
427 // Must be initialized before the delegate is notified because the delegate 436 new ShelfView(WmShell::Get()->shelf_model(),
428 // may try to access the WmShelf. 437 WmShell::Get()->shelf_delegate(), wm_shelf_aura_, this);
429 wm_shelf_aura_->SetShelf(shelf_.get()); 438 shelf_view_->Init();
430 WmShell::Get()->shelf_delegate()->OnShelfCreated(shelf_.get()); 439 GetContentsView()->AddChildView(shelf_view_);
440 return shelf_view_;
441 }
431 442
443 void ShelfWidget::PostCreateShelf() {
432 SetFocusCycler(WmShell::Get()->focus_cycler()); 444 SetFocusCycler(WmShell::Get()->focus_cycler());
433 445
434 // Ensure the newly created |shelf_| gets current values. 446 // Ensure the newly created |shelf_| gets current values.
435 background_animator_.Initialize(this); 447 background_animator_.Initialize(this);
436 }
437 448
438 void ShelfWidget::PostCreateShelf() { 449 shelf_view_->SetVisible(
439 shelf_->SetVisible(
440 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted()); 450 WmShell::Get()->GetSessionStateDelegate()->IsActiveUserSessionStarted());
441 shelf_layout_manager_->LayoutShelf(); 451 shelf_layout_manager_->LayoutShelf();
442 shelf_layout_manager_->UpdateAutoHideState(); 452 shelf_layout_manager_->UpdateAutoHideState();
443 Show(); 453 Show();
444 } 454 }
445 455
446 bool ShelfWidget::IsShelfVisible() const { 456 bool ShelfWidget::IsShelfVisible() const {
447 return shelf_.get() && shelf_->IsVisible(); 457 return shelf_view_ && shelf_view_->visible();
448 } 458 }
449 459
450 void ShelfWidget::SetShelfVisibility(bool visible) { 460 void ShelfWidget::SetShelfVisibility(bool visible) {
451 if (shelf_) 461 if (shelf_view_)
452 shelf_->SetVisible(visible); 462 shelf_view_->SetVisible(visible);
453 } 463 }
454 464
455 void ShelfWidget::SetFocusCycler(FocusCycler* focus_cycler) { 465 void ShelfWidget::SetFocusCycler(FocusCycler* focus_cycler) {
456 delegate_view_->set_focus_cycler(focus_cycler); 466 delegate_view_->set_focus_cycler(focus_cycler);
457 if (focus_cycler) 467 if (focus_cycler)
458 focus_cycler->AddWidget(this); 468 focus_cycler->AddWidget(this);
459 } 469 }
460 470
461 FocusCycler* ShelfWidget::GetFocusCycler() { 471 FocusCycler* ShelfWidget::GetFocusCycler() {
462 return delegate_view_->focus_cycler(); 472 return delegate_view_->focus_cycler();
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 return delegate_view_->GetDimmerBoundsForTest(); 516 return delegate_view_->GetDimmerBoundsForTest();
507 return gfx::Rect(); 517 return gfx::Rect();
508 } 518 }
509 519
510 void ShelfWidget::DisableDimmingAnimationsForTest() { 520 void ShelfWidget::DisableDimmingAnimationsForTest() {
511 DCHECK(delegate_view_); 521 DCHECK(delegate_view_);
512 delegate_view_->disable_dimming_animations_for_test(); 522 delegate_view_->disable_dimming_animations_for_test();
513 } 523 }
514 524
515 void ShelfWidget::UpdateShelfItemBackground(int alpha) { 525 void ShelfWidget::UpdateShelfItemBackground(int alpha) {
516 if (shelf_) 526 if (shelf_view_)
517 shelf_->UpdateShelfItemBackground(alpha); 527 shelf_view_->UpdateShelfItemBackground(alpha);
518 } 528 }
519 529
520 void ShelfWidget::WillDeleteShelfLayoutManager() { 530 void ShelfWidget::WillDeleteShelfLayoutManager() {
521 shelf_layout_manager_->RemoveObserver(this); 531 shelf_layout_manager_->RemoveObserver(this);
522 shelf_layout_manager_ = nullptr; 532 shelf_layout_manager_ = nullptr;
523 } 533 }
524 534
525 } // namespace ash 535 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698