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

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

Issue 2091263004: Moves a couple of the maximize mode classes to ash/common (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: deps Created 4 years, 6 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/wm/maximize_mode/workspace_backdrop_delegate.h" 5 #include "ash/wm/maximize_mode/workspace_backdrop_delegate.h"
6 6
7 #include "ash/common/shell_window_ids.h"
7 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" 8 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h"
8 #include "ash/wm/window_animations.h" 9 #include "ash/common/wm_lookup.h"
9 #include "ash/wm/window_util.h" 10 #include "ash/common/wm_root_window_controller.h"
11 #include "ash/common/wm_window.h"
12 #include "ash/common/wm_window_observer.h"
10 #include "base/auto_reset.h" 13 #include "base/auto_reset.h"
11 #include "ui/aura/window.h"
12 #include "ui/aura/window_observer.h"
13 #include "ui/compositor/layer.h" 14 #include "ui/compositor/layer.h"
14 #include "ui/compositor/scoped_layer_animation_settings.h" 15 #include "ui/compositor/scoped_layer_animation_settings.h"
15 #include "ui/views/background.h" 16 #include "ui/views/background.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 #include "ui/wm/core/window_animations.h" 18 #include "ui/wm/core/window_animations.h"
18 #include "ui/wm/core/window_util.h" 19 #include "ui/wm/core/window_util.h"
19 20
20 namespace ash { 21 namespace ash {
21 namespace { 22 namespace {
22 23
23 // The opacity of the backdrop. 24 // The opacity of the backdrop.
24 const float kBackdropOpacity = 0.5f; 25 const float kBackdropOpacity = 0.5f;
25 26
26 } // namespace 27 } // namespace
27 28
28 class WorkspaceBackdropDelegate::WindowObserverImpl 29 class WorkspaceBackdropDelegate::WindowObserverImpl : public WmWindowObserver {
29 : public aura::WindowObserver {
30 public: 30 public:
31 explicit WindowObserverImpl(WorkspaceBackdropDelegate* delegate) 31 explicit WindowObserverImpl(WorkspaceBackdropDelegate* delegate)
32 : delegate_(delegate) {} 32 : delegate_(delegate) {}
33 ~WindowObserverImpl() override {} 33 ~WindowObserverImpl() override {}
34 34
35 private: 35 private:
36 // WindowObserver overrides: 36 // WmWindowObserver overrides:
37 void OnWindowBoundsChanged(aura::Window* window, 37 void OnWindowBoundsChanged(WmWindow* window,
38 const gfx::Rect& old_bounds, 38 const gfx::Rect& old_bounds,
39 const gfx::Rect& new_bounds) override { 39 const gfx::Rect& new_bounds) override {
40 // The container size has changed and the layer needs to be adapt to it. 40 // The container size has changed and the layer needs to be adapt to it.
41 delegate_->AdjustToContainerBounds(); 41 delegate_->AdjustToContainerBounds();
42 } 42 }
43 43
44 WorkspaceBackdropDelegate* delegate_; 44 WorkspaceBackdropDelegate* delegate_;
45 45
46 DISALLOW_COPY_AND_ASSIGN(WindowObserverImpl); 46 DISALLOW_COPY_AND_ASSIGN(WindowObserverImpl);
47 }; 47 };
48 48
49 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(aura::Window* container) 49 WorkspaceBackdropDelegate::WorkspaceBackdropDelegate(WmWindow* container)
50 : container_observer_(new WindowObserverImpl(this)), 50 : container_observer_(new WindowObserverImpl(this)),
51 background_(nullptr),
52 container_(container), 51 container_(container),
53 in_restacking_(false) { 52 in_restacking_(false) {
54 background_ = new views::Widget; 53 background_ = new views::Widget;
55 views::Widget::InitParams params( 54 views::Widget::InitParams params(
56 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 55 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
57 params.parent = container_;
58 params.bounds = container_->GetBoundsInScreen(); 56 params.bounds = container_->GetBoundsInScreen();
59 params.layer_type = ui::LAYER_SOLID_COLOR; 57 params.layer_type = ui::LAYER_SOLID_COLOR;
58 params.name = "WorkspaceBackdropDelegate";
60 // To disallow the MRU list from picking this window up it should not be 59 // To disallow the MRU list from picking this window up it should not be
61 // activateable. 60 // activateable.
62 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; 61 params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
62 DCHECK_NE(kShellWindowId_Invalid, container_->GetShellWindowId());
63 container_->GetRootWindowController()->ConfigureWidgetInitParamsForContainer(
64 background_, container_->GetShellWindowId(), &params);
63 background_->Init(params); 65 background_->Init(params);
66 background_window_ = WmLookup::Get()->GetWindowForWidget(background_);
64 // Do not use the animation system. We don't want the bounds animation and 67 // Do not use the animation system. We don't want the bounds animation and
65 // opacity needs to get set to |kBackdropOpacity|. 68 // opacity needs to get set to |kBackdropOpacity|.
66 ::wm::SetWindowVisibilityAnimationTransition( 69 background_window_->SetVisibilityAnimationTransition(::wm::ANIMATE_NONE);
67 background_->GetNativeView(), 70 background_window_->GetLayer()->SetColor(SK_ColorBLACK);
68 ::wm::ANIMATE_NONE);
69 background_->GetNativeView()->SetName("WorkspaceBackdropDelegate");
70 background_->GetNativeView()->layer()->SetColor(SK_ColorBLACK);
71 // Make sure that the layer covers visibly everything - including the shelf. 71 // Make sure that the layer covers visibly everything - including the shelf.
72 background_->GetNativeView()->layer()->SetBounds(params.bounds); 72 background_window_->GetLayer()->SetBounds(params.bounds);
73 DCHECK(background_window_->GetBounds() == params.bounds);
73 Show(); 74 Show();
74 RestackBackdrop(); 75 RestackBackdrop();
75 container_->AddObserver(container_observer_.get()); 76 container_->AddObserver(container_observer_.get());
76 } 77 }
77 78
78 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() { 79 WorkspaceBackdropDelegate::~WorkspaceBackdropDelegate() {
80 // TODO: this won't work right with mus: http://crbug.com/548396.
James Cook 2016/06/27 00:19:21 nit: Maybe clarify that "this" means the animation
sky 2016/06/27 15:27:26 Done.
79 container_->RemoveObserver(container_observer_.get()); 81 container_->RemoveObserver(container_observer_.get());
80 ::wm::ScopedHidingAnimationSettings hiding_settings( 82 ::wm::ScopedHidingAnimationSettings hiding_settings(
81 background_->GetNativeView()); 83 background_->GetNativeView());
82 background_->Close(); 84 background_->Close();
83 background_->GetNativeView()->layer()->SetOpacity(0.0f); 85 background_window_->GetLayer()->SetOpacity(0.0f);
84 } 86 }
85 87
86 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) { 88 void WorkspaceBackdropDelegate::OnWindowAddedToLayout(WmWindow* child) {
87 RestackBackdrop(); 89 RestackBackdrop();
88 } 90 }
89 91
90 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(WmWindow* child) { 92 void WorkspaceBackdropDelegate::OnWindowRemovedFromLayout(WmWindow* child) {
91 RestackBackdrop(); 93 RestackBackdrop();
92 } 94 }
93 95
(...skipping 14 matching lines...) Expand all
108 110
109 void WorkspaceBackdropDelegate::OnDisplayWorkAreaInsetsChanged() { 111 void WorkspaceBackdropDelegate::OnDisplayWorkAreaInsetsChanged() {
110 AdjustToContainerBounds(); 112 AdjustToContainerBounds();
111 } 113 }
112 114
113 void WorkspaceBackdropDelegate::RestackBackdrop() { 115 void WorkspaceBackdropDelegate::RestackBackdrop() {
114 // Avoid recursive calls. 116 // Avoid recursive calls.
115 if (in_restacking_) 117 if (in_restacking_)
116 return; 118 return;
117 119
118 aura::Window* window = GetCurrentTopWindow(); 120 WmWindow* window = GetCurrentTopWindow();
119 if (!window) { 121 if (!window) {
120 // Hide backdrop since no suitable window was found. 122 // Hide backdrop since no suitable window was found.
121 background_->Hide(); 123 background_->Hide();
122 return; 124 return;
123 } 125 }
124 if (window == background_->GetNativeWindow() && 126 if (window == background_window_ && background_->IsVisible())
125 background_->IsVisible()) {
126 return; 127 return;
127 } 128 if (window->GetRootWindow() != background_window_->GetRootWindow())
128 if (window->GetRootWindow() !=
129 background_->GetNativeWindow()->GetRootWindow()) {
130 return; 129 return;
131 }
132 // We are changing the order of windows which will cause recursion. 130 // We are changing the order of windows which will cause recursion.
133 base::AutoReset<bool> lock(&in_restacking_, true); 131 base::AutoReset<bool> lock(&in_restacking_, true);
134 if (!background_->IsVisible()) 132 if (!background_->IsVisible())
135 Show(); 133 Show();
136 // Since the backdrop needs to be immediately behind the window and the 134 // Since the backdrop needs to be immediately behind the window and the
137 // stacking functions only guarantee a "it's above or below", we need 135 // stacking functions only guarantee a "it's above or below", we need
138 // to re-arrange the two windows twice. 136 // to re-arrange the two windows twice.
139 container_->StackChildAbove(background_->GetNativeView(), window); 137 container_->StackChildAbove(background_window_, window);
140 container_->StackChildAbove(window, background_->GetNativeView()); 138 container_->StackChildAbove(window, background_window_);
141 } 139 }
142 140
143 aura::Window* WorkspaceBackdropDelegate::GetCurrentTopWindow() { 141 WmWindow* WorkspaceBackdropDelegate::GetCurrentTopWindow() {
144 const aura::Window::Windows& windows = container_->children(); 142 const WmWindow::Windows windows = container_->GetChildren();
145 for (aura::Window::Windows::const_reverse_iterator window_iter = 143 for (auto window_iter = windows.rbegin(); window_iter != windows.rend();
146 windows.rbegin(); 144 ++window_iter) {
147 window_iter != windows.rend(); ++window_iter) { 145 WmWindow* window = *window_iter;
148 aura::Window* window = *window_iter; 146 if (window->GetTargetVisibility() &&
149 if (window->TargetVisibility() && 147 window->GetType() == ui::wm::WINDOW_TYPE_NORMAL &&
150 window->type() == ui::wm::WINDOW_TYPE_NORMAL && 148 window->CanActivate())
151 ash::wm::CanActivateWindow(window))
152 return window; 149 return window;
153 } 150 }
154 return NULL; 151 return nullptr;
155 } 152 }
156 153
157 void WorkspaceBackdropDelegate::AdjustToContainerBounds() { 154 void WorkspaceBackdropDelegate::AdjustToContainerBounds() {
158 // Cover the entire container window. 155 // Cover the entire container window.
159 gfx::Rect target_rect(gfx::Point(0, 0), container_->bounds().size()); 156 gfx::Rect target_rect(gfx::Point(0, 0), container_->GetBounds().size());
160 if (target_rect != background_->GetNativeWindow()->bounds()) { 157 if (target_rect != background_window_->GetBounds()) {
158 // TODO: this won't work right with mus: http://crbug.com/548396.
161 // This needs to be instant. 159 // This needs to be instant.
162 ui::ScopedLayerAnimationSettings settings( 160 ui::ScopedLayerAnimationSettings settings(
163 background_->GetNativeView()->layer()->GetAnimator()); 161 background_window_->GetLayer()->GetAnimator());
164 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(0)); 162 settings.SetTransitionDuration(base::TimeDelta::FromMilliseconds(0));
165 background_->GetNativeWindow()->SetBounds(target_rect); 163 background_window_->SetBounds(target_rect);
166 if (!background_->IsVisible()) 164 if (!background_->IsVisible())
167 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity); 165 background_window_->GetLayer()->SetOpacity(kBackdropOpacity);
168 } 166 }
169 } 167 }
170 168
171 void WorkspaceBackdropDelegate::Show() { 169 void WorkspaceBackdropDelegate::Show() {
172 background_->GetNativeView()->layer()->SetOpacity(0.0f); 170 background_window_->GetLayer()->SetOpacity(0.0f);
173 background_->Show(); 171 background_->Show();
174 ui::ScopedLayerAnimationSettings settings( 172 ui::ScopedLayerAnimationSettings settings(
175 background_->GetNativeView()->layer()->GetAnimator()); 173 background_window_->GetLayer()->GetAnimator());
176 background_->GetNativeView()->layer()->SetOpacity(kBackdropOpacity); 174 background_window_->GetLayer()->SetOpacity(kBackdropOpacity);
177 } 175 }
178 176
179 } // namespace ash 177 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698