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

Side by Side Diff: ash/common/wm/maximize_mode/workspace_backdrop_delegate.cc

Issue 2792773002: Fullscreen backdrop window for maximize mode (Closed)
Patch Set: updated the test Created 3 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/wm/maximize_mode/workspace_backdrop_delegate.h" 5 #include "ash/common/wm/maximize_mode/workspace_backdrop_delegate.h"
6 6
7 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" 7 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h"
8 #include "ash/common/wm_window.h" 8 #include "ash/common/wm_window.h"
9 #include "ash/public/cpp/shell_window_ids.h" 9 #include "ash/public/cpp/shell_window_ids.h"
10 #include "ash/root_window_controller.h" 10 #include "ash/root_window_controller.h"
11 #include "base/auto_reset.h" 11 #include "base/auto_reset.h"
12 #include "ui/aura/window_observer.h"
13 #include "ui/compositor/layer.h" 12 #include "ui/compositor/layer.h"
14 #include "ui/compositor/scoped_layer_animation_settings.h" 13 #include "ui/compositor/scoped_layer_animation_settings.h"
15 #include "ui/views/background.h" 14 #include "ui/views/background.h"
16 #include "ui/views/widget/widget.h" 15 #include "ui/views/widget/widget.h"
17 #include "ui/wm/core/window_animations.h" 16 #include "ui/wm/core/window_animations.h"
18 #include "ui/wm/core/window_util.h" 17 #include "ui/wm/core/window_util.h"
19 18
20 namespace ash { 19 namespace ash {
21 namespace { 20 namespace {
22 21
23 // The opacity of the backdrop. 22 // The opacity of the backdrop.
24 const float kBackdropOpacity = 1.0f; 23 const float kBackdropOpacity = 1.0f;
25 24
26 } // namespace 25 } // namespace
27 26
28 class WorkspaceBackdropDelegate::WindowObserverImpl
29 : public aura::WindowObserver {
30 public:
31 explicit WindowObserverImpl(WorkspaceBackdropDelegate* delegate)
32 : delegate_(delegate) {}
33 ~WindowObserverImpl() override {}
34
35 private:
36 // aura::WindowObserver overrides:
37 void OnWindowBoundsChanged(aura::Window* window,
38 const gfx::Rect& old_bounds,
39 const gfx::Rect& new_bounds) override {
40 // The container size has changed and the layer needs to be adapt to it.
41 delegate_->AdjustToContainerBounds();
42 }
43
44 WorkspaceBackdropDelegate* delegate_;
45
46 DISALLOW_COPY_AND_ASSIGN(WindowObserverImpl);
47 };
48
49 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(WmWindow* container) 27 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(WmWindow* container)
50 : container_observer_(new WindowObserverImpl(this)), 28 : container_(container), in_restacking_(false) {
51 container_(container),
52 in_restacking_(false) {
53 background_ = new views::Widget; 29 background_ = new views::Widget;
54 views::Widget::InitParams params( 30 views::Widget::InitParams params(
55 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 31 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
56 params.bounds = container_->GetBoundsInScreen(); 32 params.bounds = container_->GetBoundsInScreen();
57 params.layer_type = ui::LAYER_SOLID_COLOR; 33 params.layer_type = ui::LAYER_SOLID_COLOR;
58 params.name = "WorkspaceBackdropDelegate"; 34 params.name = "WorkspaceBackdropDelegate";
59 // To disallow the MRU list from picking this window up it should not be 35 // To disallow the MRU list from picking this window up it should not be
60 // activateable. 36 // activateable.
61 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; 37 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
62 DCHECK_NE(kShellWindowId_Invalid, container_->GetShellWindowId()); 38 DCHECK_NE(kShellWindowId_Invalid, container_->GetShellWindowId());
63 container_->GetRootWindowController()->ConfigureWidgetInitParamsForContainer( 39 container_->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
64 background_, container_->GetShellWindowId(), &params); 40 background_, container_->GetShellWindowId(), &params);
65 background_->Init(params); 41 background_->Init(params);
66 background_window_ = WmWindow::Get(background_->GetNativeWindow()); 42 background_window_ = WmWindow::Get(background_->GetNativeWindow());
67 // Do not use the animation system. We don't want the bounds animation and 43 // Do not use the animation system. We don't want the bounds animation and
68 // opacity needs to get set to |kBackdropOpacity|. 44 // opacity needs to get set to |kBackdropOpacity|.
69 background_window_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE); 45 background_window_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE);
70 background_window_->GetLayer()->SetColor(SK_ColorBLACK); 46 background_window_->GetLayer()->SetColor(SK_ColorBLACK);
71 // Make sure that the layer covers visibly everything - including the shelf. 47 // Make sure that the layer covers visibly everything - including the shelf.
72 background_window_->GetLayer()->SetBounds(params.bounds); 48 background_window_->GetLayer()->SetBounds(params.bounds);
73 DCHECK(background_window_->GetBounds() == params.bounds); 49 DCHECK(background_window_->GetBounds() == params.bounds);
74 Show(); 50 Show();
75 RestackBackdrop(); 51 RestackBackdrop();
76 container_->aura_window()->AddObserver(container_observer_.get());
77 } 52 }
78 53
79 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() { 54 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() {
80 container_->aura_window()->RemoveObserver(container_observer_.get());
81 // TODO: animations won't work right with mus: http://crbug.com/548396. 55 // TODO: animations won't work right with mus: http://crbug.com/548396.
82 ::wm::ScopedHidingAnimationSettings hiding_settings( 56 ::wm::ScopedHidingAnimationSettings hiding_settings(
83 background_->GetNativeView()); 57 background_->GetNativeView());
84 background_->Close(); 58 background_->Close();
85 background_window_->GetLayer()->SetOpacity(0.0f); 59 background_window_->GetLayer()->SetOpacity(0.0f);
86 } 60 }
87 61
88 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) { 62 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) {
89 RestackBackdrop(); 63 RestackBackdrop();
90 } 64 }
(...skipping 10 matching lines...) Expand all
101 void WorkspaceBackdropDelegate::OnWindowStackingChanged(WmWindow* window) { 75 void WorkspaceBackdropDelegate::OnWindowStackingChanged(WmWindow* window) {
102 RestackBackdrop(); 76 RestackBackdrop();
103 } 77 }
104 78
105 void WorkspaceBackdropDelegate::OnPostWindowStateTypeChange( 79 void WorkspaceBackdropDelegate::OnPostWindowStateTypeChange(
106 wm::WindowState* window_state, 80 wm::WindowState* window_state,
107 wm::WindowStateType old_type) { 81 wm::WindowStateType old_type) {
108 RestackBackdrop(); 82 RestackBackdrop();
109 } 83 }
110 84
111 void WorkspaceBackdropDelegate::OnDisplayWorkAreaInsetsChanged() {
112 AdjustToContainerBounds();
113 }
114
115 void WorkspaceBackdropDelegate::RestackBackdrop() { 85 void WorkspaceBackdropDelegate::RestackBackdrop() {
116 // Avoid recursive calls. 86 // Avoid recursive calls.
117 if (in_restacking_) 87 if (in_restacking_)
118 return; 88 return;
119 89
120 WmWindow* window = GetCurrentTopWindow(); 90 WmWindow* window = GetCurrentTopWindow();
121 if (!window) { 91 if (!window) {
122 // Hide backdrop since no suitable window was found. 92 // Hide backdrop since no suitable window was found.
123 background_->Hide(); 93 background_->Hide();
124 return; 94 return;
(...skipping 19 matching lines...) Expand all
144 ++window_iter) { 114 ++window_iter) {
145 WmWindow* window = *window_iter; 115 WmWindow* window = *window_iter;
146 if (window->GetTargetVisibility() && 116 if (window->GetTargetVisibility() &&
147 window->GetType() == ui::wm::WINDOW_TYPE_NORMAL && 117 window->GetType() == ui::wm::WINDOW_TYPE_NORMAL &&
148 window->CanActivate()) 118 window->CanActivate())
149 return window; 119 return window;
150 } 120 }
151 return nullptr; 121 return nullptr;
152 } 122 }
153 123
154 void WorkspaceBackdropDelegate::AdjustToContainerBounds() {
155 // Cover the entire container window.
156 gfx::Rect target_rect(gfx::Point(0, 0), container_->GetBounds().size());
157 if (target_rect != background_window_->GetBounds()) {
158 // TODO: this won't work right with mus: http://crbug.com/548396.
159 // This needs to be instant.
160 ui::ScopedLayerAnimationSettings settings(
161 background_window_->GetLayer()->GetAnimator());
162 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(0));
163 background_window_->SetBounds(target_rect);
164 if (!background_->IsVisible())
165 background_window_->GetLayer()->SetOpacity(kBackdropOpacity);
166 }
167 }
168
169 void WorkspaceBackdropDelegate::Show() { 124 void WorkspaceBackdropDelegate::Show() {
170 background_window_->GetLayer()->SetOpacity(0.0f); 125 background_window_->GetLayer()->SetOpacity(0.0f);
171 background_->Show(); 126 background_->Show();
127 background_->SetFullscreen(true);
172 ui::ScopedLayerAnimationSettings settings( 128 ui::ScopedLayerAnimationSettings settings(
173 background_window_->GetLayer()->GetAnimator()); 129 background_window_->GetLayer()->GetAnimator());
174 background_window_->GetLayer()->SetOpacity(kBackdropOpacity); 130 background_window_->GetLayer()->SetOpacity(kBackdropOpacity);
175 } 131 }
176 132
177 } // namespace ash 133 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/wm/maximize_mode/workspace_backdrop_delegate.h ('k') | ash/common/wm/workspace/workspace_layout_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698