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/app_list_button.h" | 10 #include "ash/common/shelf/app_list_button.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_layout_manager.h" | 14 #include "ash/common/shelf/shelf_layout_manager.h" |
15 #include "ash/common/shelf/shelf_view.h" | 15 #include "ash/common/shelf/shelf_view.h" |
16 #include "ash/common/shelf/wm_dimmer_view.h" | |
17 #include "ash/common/shelf/wm_shelf.h" | 16 #include "ash/common/shelf/wm_shelf.h" |
18 #include "ash/common/shelf/wm_shelf_util.h" | 17 #include "ash/common/shelf/wm_shelf_util.h" |
19 #include "ash/common/system/status_area_layout_manager.h" | 18 #include "ash/common/system/status_area_layout_manager.h" |
20 #include "ash/common/system/status_area_widget.h" | 19 #include "ash/common/system/status_area_widget.h" |
21 #include "ash/common/wm_lookup.h" | 20 #include "ash/common/wm_lookup.h" |
22 #include "ash/common/wm_root_window_controller.h" | 21 #include "ash/common/wm_root_window_controller.h" |
23 #include "ash/common/wm_shell.h" | 22 #include "ash/common/wm_shell.h" |
24 #include "ash/common/wm_window.h" | 23 #include "ash/common/wm_window.h" |
25 #include "ash/common/wm_window_property.h" | 24 #include "ash/common/wm_window_property.h" |
26 #include "base/memory/ptr_util.h" | 25 #include "base/memory/ptr_util.h" |
(...skipping 29 matching lines...) Expand all Loading... | |
56 ~DelegateView() override; | 55 ~DelegateView() override; |
57 | 56 |
58 void set_focus_cycler(FocusCycler* focus_cycler) { | 57 void set_focus_cycler(FocusCycler* focus_cycler) { |
59 focus_cycler_ = focus_cycler; | 58 focus_cycler_ = focus_cycler; |
60 } | 59 } |
61 FocusCycler* focus_cycler() { return focus_cycler_; } | 60 FocusCycler* focus_cycler() { return focus_cycler_; } |
62 | 61 |
63 ui::Layer* opaque_background() { return &opaque_background_; } | 62 ui::Layer* opaque_background() { return &opaque_background_; } |
64 ui::Layer* opaque_foreground() { return &opaque_foreground_; } | 63 ui::Layer* opaque_foreground() { return &opaque_foreground_; } |
65 | 64 |
66 // Set if the shelf area is dimmed (eg when a window is maximized). | |
67 void SetDimmed(bool dimmed); | |
68 bool GetDimmed() const; | |
69 | |
70 void SetParentLayer(ui::Layer* layer); | 65 void SetParentLayer(ui::Layer* layer); |
71 | 66 |
72 // views::View overrides: | 67 // views::View overrides: |
73 void OnPaintBackground(gfx::Canvas* canvas) override; | 68 void OnPaintBackground(gfx::Canvas* canvas) override; |
74 | 69 |
75 // views::WidgetDelegateView overrides: | 70 // views::WidgetDelegateView overrides: |
76 views::Widget* GetWidget() override { return View::GetWidget(); } | 71 views::Widget* GetWidget() override { return View::GetWidget(); } |
77 const views::Widget* GetWidget() const override { return View::GetWidget(); } | 72 const views::Widget* GetWidget() const override { return View::GetWidget(); } |
78 | 73 |
79 bool CanActivate() const override; | 74 bool CanActivate() const override; |
80 void ReorderChildLayers(ui::Layer* parent_layer) override; | 75 void ReorderChildLayers(ui::Layer* parent_layer) override; |
81 // This will be called when the parent local bounds change. | 76 // This will be called when the parent local bounds change. |
82 void OnBoundsChanged(const gfx::Rect& old_bounds) override; | 77 void OnBoundsChanged(const gfx::Rect& old_bounds) override; |
83 | 78 |
84 // ShelfBackgroundAnimatorObserver: | 79 // ShelfBackgroundAnimatorObserver: |
85 void UpdateShelfOpaqueBackground(int alpha) override; | 80 void UpdateShelfOpaqueBackground(int alpha) override; |
86 void UpdateShelfAssetBackground(int alpha) override; | 81 void UpdateShelfAssetBackground(int alpha) override; |
87 | 82 |
88 // Force the shelf to be presented in an undimmed state. | |
89 void ForceUndimming(bool force); | |
90 | |
91 // A function to test the current alpha used by the dimming bar. If there is | |
92 // no dimmer active, the function will return -1. | |
93 int GetDimmingAlphaForTest(); | |
94 | |
95 // A function to test the bounds of the dimming bar. Returns gfx::Rect() if | |
96 // the dimmer is inactive. | |
97 gfx::Rect GetDimmerBoundsForTest(); | |
98 | |
99 // Disable dimming animations for running tests. This needs to be called | |
100 // prior to the creation of of the dimmer. | |
101 void disable_dimming_animations_for_test() { | |
102 disable_dimming_animations_for_test_ = true; | |
103 } | |
104 | |
105 private: | 83 private: |
106 WmShelf* wm_shelf_; | 84 WmShelf* wm_shelf_; |
107 ShelfWidget* shelf_widget_; | 85 ShelfWidget* shelf_widget_; |
108 FocusCycler* focus_cycler_; | 86 FocusCycler* focus_cycler_; |
109 int asset_background_alpha_; | 87 int asset_background_alpha_; |
110 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). | 88 // TODO(bruthig): Remove opaque_background_ (see https://crbug.com/621551). |
111 // A black background layer which is shown when a maximized window is visible. | 89 // A black background layer which is shown when a maximized window is visible. |
112 ui::Layer opaque_background_; | 90 ui::Layer opaque_background_; |
113 // A black foreground layer which is shown while transitioning between users. | 91 // A black foreground layer which is shown while transitioning between users. |
114 // Note: Since the back- and foreground layers have different functions they | 92 // Note: Since the back- and foreground layers have different functions they |
115 // can be used simultaneously - so no repurposing possible. | 93 // can be used simultaneously - so no repurposing possible. |
116 ui::Layer opaque_foreground_; | 94 ui::Layer opaque_foreground_; |
117 | 95 |
118 // The interface for the view which does the dimming. Null if the shelf is not | |
119 // being dimmed, or if dimming is not supported (e.g. for mus). | |
120 WmDimmerView* dimmer_view_; | |
121 | |
122 // True if dimming animations should be turned off. | |
123 bool disable_dimming_animations_for_test_; | |
124 | |
125 DISALLOW_COPY_AND_ASSIGN(DelegateView); | 96 DISALLOW_COPY_AND_ASSIGN(DelegateView); |
126 }; | 97 }; |
127 | 98 |
128 ShelfWidget::DelegateView::DelegateView(WmShelf* wm_shelf, | 99 ShelfWidget::DelegateView::DelegateView(WmShelf* wm_shelf, |
129 ShelfWidget* shelf_widget) | 100 ShelfWidget* shelf_widget) |
130 : wm_shelf_(wm_shelf), | 101 : wm_shelf_(wm_shelf), |
131 shelf_widget_(shelf_widget), | 102 shelf_widget_(shelf_widget), |
132 focus_cycler_(nullptr), | 103 focus_cycler_(nullptr), |
133 asset_background_alpha_(0), | 104 asset_background_alpha_(0), |
134 opaque_background_(ui::LAYER_SOLID_COLOR), | 105 opaque_background_(ui::LAYER_SOLID_COLOR), |
135 opaque_foreground_(ui::LAYER_SOLID_COLOR), | 106 opaque_foreground_(ui::LAYER_SOLID_COLOR) { |
136 dimmer_view_(nullptr), | |
137 disable_dimming_animations_for_test_(false) { | |
138 DCHECK(wm_shelf_); | 107 DCHECK(wm_shelf_); |
139 DCHECK(shelf_widget_); | 108 DCHECK(shelf_widget_); |
140 SetLayoutManager(new views::FillLayout()); | 109 SetLayoutManager(new views::FillLayout()); |
141 set_allow_deactivate_on_esc(true); | 110 set_allow_deactivate_on_esc(true); |
142 opaque_background_.SetColor(SK_ColorBLACK); | 111 opaque_background_.SetColor(SK_ColorBLACK); |
143 opaque_background_.SetBounds(GetLocalBounds()); | 112 opaque_background_.SetBounds(GetLocalBounds()); |
144 opaque_background_.SetOpacity(0.0f); | 113 opaque_background_.SetOpacity(0.0f); |
145 opaque_foreground_.SetColor(SK_ColorBLACK); | 114 opaque_foreground_.SetColor(SK_ColorBLACK); |
146 opaque_foreground_.SetBounds(GetLocalBounds()); | 115 opaque_foreground_.SetBounds(GetLocalBounds()); |
147 opaque_foreground_.SetOpacity(0.0f); | 116 opaque_foreground_.SetOpacity(0.0f); |
148 } | 117 } |
149 | 118 |
150 ShelfWidget::DelegateView::~DelegateView() { | 119 ShelfWidget::DelegateView::~DelegateView() {} |
151 // Make sure that the dimmer goes away since it might have set an observer. | |
152 SetDimmed(false); | |
153 } | |
154 | |
155 void ShelfWidget::DelegateView::SetDimmed(bool dimmed) { | |
156 // When starting dimming, attempt to create a dimmer view. | |
157 if (dimmed) { | |
158 if (!dimmer_view_) { | |
159 dimmer_view_ = | |
160 wm_shelf_->CreateDimmerView(disable_dimming_animations_for_test_); | |
161 } | |
162 return; | |
163 } | |
164 | |
165 // Close the dimmer widget when stopping dimming. | |
166 if (dimmer_view_) { | |
167 dimmer_view_->GetDimmerWidget()->CloseNow(); | |
168 dimmer_view_ = nullptr; | |
169 } | |
170 } | |
171 | |
172 bool ShelfWidget::DelegateView::GetDimmed() const { | |
173 return dimmer_view_ && dimmer_view_->GetDimmerWidget()->IsVisible(); | |
174 } | |
175 | 120 |
176 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { | 121 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { |
177 layer->Add(&opaque_background_); | 122 layer->Add(&opaque_background_); |
178 layer->Add(&opaque_foreground_); | 123 layer->Add(&opaque_foreground_); |
179 ReorderLayers(); | 124 ReorderLayers(); |
180 } | 125 } |
181 | 126 |
182 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { | 127 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { |
183 if (MaterialDesignController::IsShelfMaterial()) | 128 if (MaterialDesignController::IsShelfMaterial()) |
184 return; | 129 return; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 | 194 |
250 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { | 195 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { |
251 views::View::ReorderChildLayers(parent_layer); | 196 views::View::ReorderChildLayers(parent_layer); |
252 parent_layer->StackAtBottom(&opaque_background_); | 197 parent_layer->StackAtBottom(&opaque_background_); |
253 parent_layer->StackAtTop(&opaque_foreground_); | 198 parent_layer->StackAtTop(&opaque_foreground_); |
254 } | 199 } |
255 | 200 |
256 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { | 201 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { |
257 opaque_background_.SetBounds(GetLocalBounds()); | 202 opaque_background_.SetBounds(GetLocalBounds()); |
258 opaque_foreground_.SetBounds(GetLocalBounds()); | 203 opaque_foreground_.SetBounds(GetLocalBounds()); |
259 if (dimmer_view_) | |
260 dimmer_view_->GetDimmerWidget()->SetBounds(GetBoundsInScreen()); | |
261 } | |
262 | |
263 void ShelfWidget::DelegateView::ForceUndimming(bool force) { | |
264 if (GetDimmed()) | |
265 dimmer_view_->ForceUndimming(force); | |
266 } | |
267 | |
268 int ShelfWidget::DelegateView::GetDimmingAlphaForTest() { | |
269 if (GetDimmed()) | |
270 return dimmer_view_->GetDimmingAlphaForTest(); | |
271 return -1; | |
272 } | |
273 | |
274 gfx::Rect ShelfWidget::DelegateView::GetDimmerBoundsForTest() { | |
275 if (GetDimmed()) | |
276 return dimmer_view_->GetDimmerWidget()->GetWindowBoundsInScreen(); | |
277 return gfx::Rect(); | |
278 } | 204 } |
279 | 205 |
280 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { | 206 void ShelfWidget::DelegateView::UpdateShelfOpaqueBackground(int alpha) { |
281 const float kMaxAlpha = 255.0f; | 207 const float kMaxAlpha = 255.0f; |
282 opaque_background_.SetOpacity(alpha / kMaxAlpha); | 208 opaque_background_.SetOpacity(alpha / kMaxAlpha); |
283 } | 209 } |
284 | 210 |
285 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { | 211 void ShelfWidget::DelegateView::UpdateShelfAssetBackground(int alpha) { |
286 asset_background_alpha_ = alpha; | 212 asset_background_alpha_ = alpha; |
287 SchedulePaint(); | 213 SchedulePaint(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 ShelfAlignment ShelfWidget::GetAlignment() const { | 307 ShelfAlignment ShelfWidget::GetAlignment() const { |
382 return wm_shelf_->GetAlignment(); | 308 return wm_shelf_->GetAlignment(); |
383 } | 309 } |
384 | 310 |
385 void ShelfWidget::OnShelfAlignmentChanged() { | 311 void ShelfWidget::OnShelfAlignmentChanged() { |
386 shelf_view_->OnShelfAlignmentChanged(); | 312 shelf_view_->OnShelfAlignmentChanged(); |
387 status_area_widget_->SetShelfAlignment(GetAlignment()); | 313 status_area_widget_->SetShelfAlignment(GetAlignment()); |
388 delegate_view_->SchedulePaint(); | 314 delegate_view_->SchedulePaint(); |
389 } | 315 } |
390 | 316 |
391 void ShelfWidget::SetDimsShelf(bool dimming) { | |
392 delegate_view_->SetDimmed(dimming); | |
393 // Repaint all children, allowing updates to reflect dimmed state eg: | |
394 // status area background, app list button and overflow button. | |
395 if (shelf_view_) | |
396 shelf_view_->SchedulePaintForAllButtons(); | |
James Cook
2016/12/08 01:26:43
I think this is the only caller of SchedulePaintFo
Evan Stade
2016/12/08 17:13:38
Done.
| |
397 status_area_widget_->SchedulePaint(); | |
398 } | |
399 | |
400 bool ShelfWidget::GetDimsShelf() const { | |
401 return delegate_view_->GetDimmed(); | |
402 } | |
403 | |
404 ShelfView* ShelfWidget::CreateShelfView() { | 317 ShelfView* ShelfWidget::CreateShelfView() { |
405 DCHECK(!shelf_view_); | 318 DCHECK(!shelf_view_); |
406 | 319 |
407 shelf_view_ = | 320 shelf_view_ = |
408 new ShelfView(WmShell::Get()->shelf_model(), | 321 new ShelfView(WmShell::Get()->shelf_model(), |
409 WmShell::Get()->shelf_delegate(), wm_shelf_, this); | 322 WmShell::Get()->shelf_delegate(), wm_shelf_, this); |
410 shelf_view_->Init(); | 323 shelf_view_->Init(); |
411 GetContentsView()->AddChildView(shelf_view_); | 324 GetContentsView()->AddChildView(shelf_view_); |
412 return shelf_view_; | 325 return shelf_view_; |
413 } | 326 } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
450 delegate_view_->set_focus_cycler(focus_cycler); | 363 delegate_view_->set_focus_cycler(focus_cycler); |
451 if (focus_cycler) | 364 if (focus_cycler) |
452 focus_cycler->AddWidget(this); | 365 focus_cycler->AddWidget(this); |
453 } | 366 } |
454 | 367 |
455 FocusCycler* ShelfWidget::GetFocusCycler() { | 368 FocusCycler* ShelfWidget::GetFocusCycler() { |
456 return delegate_view_->focus_cycler(); | 369 return delegate_view_->focus_cycler(); |
457 } | 370 } |
458 | 371 |
459 void ShelfWidget::Shutdown() { | 372 void ShelfWidget::Shutdown() { |
460 // Tear down the dimmer before |shelf_layout_manager_|, since the dimmer uses | |
461 // |shelf_layout_manager_| to get the shelf's WmWindow, via WmShelf. | |
462 delegate_view_->SetDimmed(false); | |
463 | |
464 // Shutting down the status area widget may cause some widgets (e.g. bubbles) | 373 // Shutting down the status area widget may cause some widgets (e.g. bubbles) |
465 // to close, so uninstall the ShelfLayoutManager event filters first. Don't | 374 // to close, so uninstall the ShelfLayoutManager event filters first. Don't |
466 // reset the pointer until later because other widgets (e.g. app list) may | 375 // reset the pointer until later because other widgets (e.g. app list) may |
467 // access it later in shutdown. | 376 // access it later in shutdown. |
468 if (shelf_layout_manager_) | 377 if (shelf_layout_manager_) |
469 shelf_layout_manager_->PrepareForShutdown(); | 378 shelf_layout_manager_->PrepareForShutdown(); |
470 | 379 |
471 if (status_area_widget_) { | 380 if (status_area_widget_) { |
472 background_animator_.RemoveObserver(status_area_widget_); | 381 background_animator_.RemoveObserver(status_area_widget_); |
473 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); | 382 WmShell::Get()->focus_cycler()->RemoveWidget(status_area_widget_); |
474 status_area_widget_->Shutdown(); | 383 status_area_widget_->Shutdown(); |
475 status_area_widget_ = nullptr; | 384 status_area_widget_ = nullptr; |
476 } | 385 } |
477 | 386 |
478 CloseNow(); | 387 CloseNow(); |
479 } | 388 } |
480 | 389 |
481 void ShelfWidget::ForceUndimming(bool force) { | |
482 delegate_view_->ForceUndimming(force); | |
483 } | |
484 | |
485 void ShelfWidget::UpdateIconPositionForPanel(WmWindow* panel) { | 390 void ShelfWidget::UpdateIconPositionForPanel(WmWindow* panel) { |
486 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(this); | 391 WmWindow* shelf_window = WmLookup::Get()->GetWindowForWidget(this); |
487 shelf_view_->UpdatePanelIconPosition( | 392 shelf_view_->UpdatePanelIconPosition( |
488 panel->GetIntProperty(WmWindowProperty::SHELF_ID), | 393 panel->GetIntProperty(WmWindowProperty::SHELF_ID), |
489 shelf_window->ConvertRectFromScreen(panel->GetBoundsInScreen()) | 394 shelf_window->ConvertRectFromScreen(panel->GetBoundsInScreen()) |
490 .CenterPoint()); | 395 .CenterPoint()); |
491 } | 396 } |
492 | 397 |
493 gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { | 398 gfx::Rect ShelfWidget::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { |
494 ShelfID id = window->GetIntProperty(WmWindowProperty::SHELF_ID); | 399 ShelfID id = window->GetIntProperty(WmWindowProperty::SHELF_ID); |
(...skipping 16 matching lines...) Expand all Loading... | |
511 | 416 |
512 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget, | 417 void ShelfWidget::OnWidgetActivationChanged(views::Widget* widget, |
513 bool active) { | 418 bool active) { |
514 activating_as_fallback_ = false; | 419 activating_as_fallback_ = false; |
515 if (active) | 420 if (active) |
516 delegate_view_->SetPaneFocusAndFocusDefault(); | 421 delegate_view_->SetPaneFocusAndFocusDefault(); |
517 else | 422 else |
518 delegate_view_->GetFocusManager()->ClearFocus(); | 423 delegate_view_->GetFocusManager()->ClearFocus(); |
519 } | 424 } |
520 | 425 |
521 int ShelfWidget::GetDimmingAlphaForTest() { | |
522 if (delegate_view_) | |
523 return delegate_view_->GetDimmingAlphaForTest(); | |
524 return -1; | |
525 } | |
526 | |
527 gfx::Rect ShelfWidget::GetDimmerBoundsForTest() { | |
528 if (delegate_view_) | |
529 return delegate_view_->GetDimmerBoundsForTest(); | |
530 return gfx::Rect(); | |
531 } | |
532 | |
533 void ShelfWidget::DisableDimmingAnimationsForTest() { | |
534 DCHECK(delegate_view_); | |
535 delegate_view_->disable_dimming_animations_for_test(); | |
536 } | |
537 | |
538 void ShelfWidget::UpdateShelfItemBackground(int alpha) { | 426 void ShelfWidget::UpdateShelfItemBackground(int alpha) { |
539 if (shelf_view_) | 427 if (shelf_view_) |
540 shelf_view_->UpdateShelfItemBackground(alpha); | 428 shelf_view_->UpdateShelfItemBackground(alpha); |
541 } | 429 } |
542 | 430 |
543 void ShelfWidget::WillDeleteShelfLayoutManager() { | 431 void ShelfWidget::WillDeleteShelfLayoutManager() { |
544 shelf_layout_manager_->RemoveObserver(this); | 432 shelf_layout_manager_->RemoveObserver(this); |
545 shelf_layout_manager_ = nullptr; | 433 shelf_layout_manager_ = nullptr; |
546 } | 434 } |
547 | 435 |
548 } // namespace ash | 436 } // namespace ash |
OLD | NEW |