OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/screen_pinning_controller.h" | 5 #include "ash/wm/screen_pinning_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
| 10 #include "ash/common/window_user_data.h" |
10 #include "ash/common/wm/container_finder.h" | 11 #include "ash/common/wm/container_finder.h" |
11 #include "ash/common/wm/window_dimmer.h" | 12 #include "ash/common/wm/window_dimmer.h" |
12 #include "ash/common/wm/window_state.h" | 13 #include "ash/common/wm/window_state.h" |
13 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
14 #include "ash/common/wm_window_user_data.h" | |
15 #include "ash/display/window_tree_host_manager.h" | 15 #include "ash/display/window_tree_host_manager.h" |
16 #include "ash/public/cpp/shell_window_ids.h" | 16 #include "ash/public/cpp/shell_window_ids.h" |
17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
18 #include "base/auto_reset.h" | 18 #include "base/auto_reset.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/memory/ptr_util.h" | 20 #include "base/memory/ptr_util.h" |
| 21 #include "ui/aura/window.h" |
21 #include "ui/aura/window_observer.h" | 22 #include "ui/aura/window_observer.h" |
| 23 #include "ui/wm/core/window_util.h" |
22 | 24 |
23 namespace ash { | 25 namespace ash { |
24 namespace { | 26 namespace { |
25 | 27 |
26 // Returns a list of WmWindows corresponding to SystemModalContainers, | 28 // Returns a list of WmWindows corresponding to SystemModalContainers, |
27 // except ones whose root is shared with |pinned_window|. | 29 // except ones whose root is shared with |pinned_window|. |
28 std::vector<WmWindow*> GetSystemModalWindowsExceptPinned( | 30 std::vector<WmWindow*> GetSystemModalWindowsExceptPinned( |
29 WmWindow* pinned_window) { | 31 WmWindow* pinned_window) { |
30 WmWindow* pinned_root = pinned_window->GetRootWindow(); | 32 WmWindow* pinned_root = pinned_window->GetRootWindow(); |
31 | 33 |
32 std::vector<WmWindow*> result; | 34 std::vector<WmWindow*> result; |
33 for (WmWindow* system_modal : wm::GetContainersFromAllRootWindows( | 35 for (aura::Window* system_modal : wm::GetContainersFromAllRootWindows( |
34 kShellWindowId_SystemModalContainer)) { | 36 kShellWindowId_SystemModalContainer)) { |
35 if (system_modal->GetRootWindow() == pinned_root) | 37 if (WmWindow::Get(system_modal)->GetRootWindow() == pinned_root) |
36 continue; | 38 continue; |
37 result.push_back(system_modal); | 39 result.push_back(WmWindow::Get(system_modal)); |
38 } | 40 } |
39 return result; | 41 return result; |
40 } | 42 } |
41 | 43 |
42 void AddObserverToChildren(WmWindow* container, | 44 void AddObserverToChildren(WmWindow* container, |
43 aura::WindowObserver* observer) { | 45 aura::WindowObserver* observer) { |
44 for (WmWindow* child : container->GetChildren()) { | 46 for (WmWindow* child : container->GetChildren()) { |
45 WmWindow::GetAuraWindow(child)->AddObserver(observer); | 47 WmWindow::GetAuraWindow(child)->AddObserver(observer); |
46 } | 48 } |
47 } | 49 } |
48 | 50 |
49 void RemoveObserverFromChildren(WmWindow* container, | 51 void RemoveObserverFromChildren(WmWindow* container, |
50 aura::WindowObserver* observer) { | 52 aura::WindowObserver* observer) { |
51 for (WmWindow* child : container->GetChildren()) { | 53 for (WmWindow* child : container->GetChildren()) { |
52 WmWindow::GetAuraWindow(child)->RemoveObserver(observer); | 54 WmWindow::GetAuraWindow(child)->RemoveObserver(observer); |
53 } | 55 } |
54 } | 56 } |
55 | 57 |
| 58 // Returns true if the aura::Window from a WindowDimmer is visible. |
| 59 bool IsWindowDimmerWindowVisible(WindowDimmer* window_dimmer) { |
| 60 return window_dimmer->window()->layer()->GetTargetVisibility(); |
| 61 } |
| 62 |
56 } // namespace | 63 } // namespace |
57 | 64 |
58 // Adapter to fire OnPinnedContainerWindowStackingChanged(). | 65 // Adapter to fire OnPinnedContainerWindowStackingChanged(). |
59 class ScreenPinningController::PinnedContainerChildWindowObserver | 66 class ScreenPinningController::PinnedContainerChildWindowObserver |
60 : public aura::WindowObserver { | 67 : public aura::WindowObserver { |
61 public: | 68 public: |
62 explicit PinnedContainerChildWindowObserver( | 69 explicit PinnedContainerChildWindowObserver( |
63 ScreenPinningController* controller) | 70 ScreenPinningController* controller) |
64 : controller_(controller) {} | 71 : controller_(controller) {} |
65 | 72 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 window->RemoveObserver(this); | 142 window->RemoveObserver(this); |
136 } | 143 } |
137 | 144 |
138 private: | 145 private: |
139 ScreenPinningController* controller_; | 146 ScreenPinningController* controller_; |
140 DISALLOW_COPY_AND_ASSIGN(SystemModalContainerWindowObserver); | 147 DISALLOW_COPY_AND_ASSIGN(SystemModalContainerWindowObserver); |
141 }; | 148 }; |
142 | 149 |
143 ScreenPinningController::ScreenPinningController( | 150 ScreenPinningController::ScreenPinningController( |
144 WindowTreeHostManager* window_tree_host_manager) | 151 WindowTreeHostManager* window_tree_host_manager) |
145 : window_dimmers_(base::MakeUnique<WmWindowUserData<WindowDimmer>>()), | 152 : window_dimmers_(base::MakeUnique<WindowUserData<WindowDimmer>>()), |
146 window_tree_host_manager_(window_tree_host_manager), | 153 window_tree_host_manager_(window_tree_host_manager), |
147 pinned_container_window_observer_( | 154 pinned_container_window_observer_( |
148 base::MakeUnique<PinnedContainerWindowObserver>(this)), | 155 base::MakeUnique<PinnedContainerWindowObserver>(this)), |
149 pinned_container_child_window_observer_( | 156 pinned_container_child_window_observer_( |
150 base::MakeUnique<PinnedContainerChildWindowObserver>(this)), | 157 base::MakeUnique<PinnedContainerChildWindowObserver>(this)), |
151 system_modal_container_window_observer_( | 158 system_modal_container_window_observer_( |
152 base::MakeUnique<SystemModalContainerWindowObserver>(this)), | 159 base::MakeUnique<SystemModalContainerWindowObserver>(this)), |
153 system_modal_container_child_window_observer_( | 160 system_modal_container_child_window_observer_( |
154 base::MakeUnique<SystemModalContainerChildWindowObserver>(this)) { | 161 base::MakeUnique<SystemModalContainerChildWindowObserver>(this)) { |
155 window_tree_host_manager_->AddObserver(this); | 162 window_tree_host_manager_->AddObserver(this); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 } | 252 } |
246 } | 253 } |
247 | 254 |
248 void ScreenPinningController::OnPinnedContainerWindowStackingChanged( | 255 void ScreenPinningController::OnPinnedContainerWindowStackingChanged( |
249 WmWindow* window) { | 256 WmWindow* window) { |
250 KeepPinnedWindowOnTop(); | 257 KeepPinnedWindowOnTop(); |
251 } | 258 } |
252 | 259 |
253 void ScreenPinningController::OnWindowAddedToSystemModalContainer( | 260 void ScreenPinningController::OnWindowAddedToSystemModalContainer( |
254 WmWindow* new_window) { | 261 WmWindow* new_window) { |
255 KeepDimWindowAtBottom(new_window->GetParent()); | 262 KeepDimWindowAtBottom(new_window->GetParent()->aura_window()); |
256 WmWindow::GetAuraWindow(new_window) | 263 WmWindow::GetAuraWindow(new_window) |
257 ->AddObserver(system_modal_container_child_window_observer_.get()); | 264 ->AddObserver(system_modal_container_child_window_observer_.get()); |
258 } | 265 } |
259 | 266 |
260 void ScreenPinningController::OnWillRemoveWindowFromSystemModalContainer( | 267 void ScreenPinningController::OnWillRemoveWindowFromSystemModalContainer( |
261 WmWindow* window) { | 268 WmWindow* window) { |
262 WmWindow::GetAuraWindow(window)->RemoveObserver( | 269 WmWindow::GetAuraWindow(window)->RemoveObserver( |
263 system_modal_container_child_window_observer_.get()); | 270 system_modal_container_child_window_observer_.get()); |
264 } | 271 } |
265 | 272 |
266 void ScreenPinningController::OnSystemModalContainerWindowStackingChanged( | 273 void ScreenPinningController::OnSystemModalContainerWindowStackingChanged( |
267 WmWindow* window) { | 274 WmWindow* window) { |
268 KeepDimWindowAtBottom(window->GetParent()); | 275 KeepDimWindowAtBottom(window->GetParent()->aura_window()); |
269 } | 276 } |
270 | 277 |
271 WmWindow* ScreenPinningController::CreateWindowDimmer(WmWindow* container) { | 278 WmWindow* ScreenPinningController::CreateWindowDimmer(WmWindow* container) { |
272 std::unique_ptr<WindowDimmer> window_dimmer = | 279 std::unique_ptr<WindowDimmer> window_dimmer = |
273 base::MakeUnique<WindowDimmer>(container); | 280 base::MakeUnique<WindowDimmer>(container->aura_window()); |
274 window_dimmer->SetDimOpacity(1); // Fully opaque. | 281 window_dimmer->SetDimOpacity(1); // Fully opaque. |
275 window_dimmer->window()->SetFullscreen(true); | 282 ::wm::SetWindowFullscreen(window_dimmer->window(), true); |
276 window_dimmer->window()->Show(); | 283 window_dimmer->window()->Show(); |
277 WmWindow* window = window_dimmer->window(); | 284 WmWindow* window = WmWindow::Get(window_dimmer->window()); |
278 window_dimmers_->Set(container, std::move(window_dimmer)); | 285 window_dimmers_->Set(container->aura_window(), std::move(window_dimmer)); |
279 return window; | 286 return window; |
280 } | 287 } |
281 | 288 |
282 void ScreenPinningController::OnDisplayConfigurationChanged() { | 289 void ScreenPinningController::OnDisplayConfigurationChanged() { |
283 // Note: this is called on display attached or detached. | 290 // Note: this is called on display attached or detached. |
284 if (!IsPinned()) | 291 if (!IsPinned()) |
285 return; | 292 return; |
286 | 293 |
287 // On display detaching, all necessary windows are transfered to the | 294 // On display detaching, all necessary windows are transfered to the |
288 // primary display's tree, and called this. | 295 // primary display's tree, and called this. |
289 // So, delete WindowDimmers which are not a part of target system modal | 296 // So, delete WindowDimmers which are not a part of target system modal |
290 // container. | 297 // container. |
291 // On display attaching, the new system modal container does not have the | 298 // On display attaching, the new system modal container does not have the |
292 // WindowDimmer. So create it. | 299 // WindowDimmer. So create it. |
293 | 300 |
294 // First, delete unnecessary WindowDimmers. | 301 // First, delete unnecessary WindowDimmers. |
295 for (WmWindow* container : window_dimmers_->GetWindows()) { | 302 for (aura::Window* container : window_dimmers_->GetWindows()) { |
296 if (container != pinned_window_->GetParent() && | 303 if (container != pinned_window_->GetParent()->aura_window() && |
297 !window_dimmers_->Get(container)->window()->GetTargetVisibility()) { | 304 !IsWindowDimmerWindowVisible(window_dimmers_->Get(container))) { |
298 window_dimmers_->Set(container, nullptr); | 305 window_dimmers_->Set(container, nullptr); |
299 } | 306 } |
300 } | 307 } |
301 | 308 |
302 // Then, create missing WindowDimmers. | 309 // Then, create missing WindowDimmers. |
303 std::vector<WmWindow*> system_modal_containers = | 310 std::vector<WmWindow*> system_modal_containers = |
304 GetSystemModalWindowsExceptPinned(pinned_window_); | 311 GetSystemModalWindowsExceptPinned(pinned_window_); |
305 for (WmWindow* system_modal : system_modal_containers) { | 312 for (WmWindow* system_modal : system_modal_containers) { |
306 if (window_dimmers_->Get(system_modal)) { | 313 if (window_dimmers_->Get(system_modal->aura_window())) { |
307 // |system_modal| already has a WindowDimmer. | 314 // |system_modal| already has a WindowDimmer. |
308 continue; | 315 continue; |
309 } | 316 } |
310 | 317 |
311 // This is the new system modal dialog. | 318 // This is the new system modal dialog. |
312 system_modal->StackChildAtBottom(CreateWindowDimmer(system_modal)); | 319 system_modal->StackChildAtBottom(CreateWindowDimmer(system_modal)); |
313 | 320 |
314 // Set observers to the tree. | 321 // Set observers to the tree. |
315 WmWindow::GetAuraWindow(system_modal) | 322 WmWindow::GetAuraWindow(system_modal) |
316 ->AddObserver(system_modal_container_window_observer_.get()); | 323 ->AddObserver(system_modal_container_window_observer_.get()); |
317 AddObserverToChildren(system_modal, | 324 AddObserverToChildren(system_modal, |
318 system_modal_container_child_window_observer_.get()); | 325 system_modal_container_child_window_observer_.get()); |
319 } | 326 } |
320 } | 327 } |
321 | 328 |
322 void ScreenPinningController::KeepPinnedWindowOnTop() { | 329 void ScreenPinningController::KeepPinnedWindowOnTop() { |
323 if (in_restacking_) | 330 if (in_restacking_) |
324 return; | 331 return; |
325 | 332 |
326 base::AutoReset<bool> auto_reset(&in_restacking_, true); | 333 base::AutoReset<bool> auto_reset(&in_restacking_, true); |
327 WmWindow* container = pinned_window_->GetParent(); | 334 WmWindow* container = pinned_window_->GetParent(); |
328 container->StackChildAtTop(pinned_window_); | 335 container->StackChildAtTop(pinned_window_); |
329 WindowDimmer* pinned_window_dimmer = window_dimmers_->Get(container); | 336 WindowDimmer* pinned_window_dimmer = |
330 if (pinned_window_dimmer && pinned_window_dimmer->window()) | 337 window_dimmers_->Get(container->aura_window()); |
331 container->StackChildBelow(pinned_window_dimmer->window(), pinned_window_); | 338 if (pinned_window_dimmer && pinned_window_dimmer->window()) { |
| 339 container->StackChildBelow(WmWindow::Get(pinned_window_dimmer->window()), |
| 340 pinned_window_); |
| 341 } |
332 } | 342 } |
333 | 343 |
334 void ScreenPinningController::KeepDimWindowAtBottom(WmWindow* container) { | 344 void ScreenPinningController::KeepDimWindowAtBottom(aura::Window* container) { |
335 if (in_restacking_) | 345 if (in_restacking_) |
336 return; | 346 return; |
337 | 347 |
338 WindowDimmer* window_dimmer = window_dimmers_->Get(container); | 348 WindowDimmer* window_dimmer = window_dimmers_->Get(container); |
339 if (window_dimmer) { | 349 if (window_dimmer) { |
340 base::AutoReset<bool> auto_reset(&in_restacking_, true); | 350 base::AutoReset<bool> auto_reset(&in_restacking_, true); |
341 container->StackChildAtBottom(window_dimmer->window()); | 351 container->StackChildAtBottom(window_dimmer->window()); |
342 } | 352 } |
343 } | 353 } |
344 | 354 |
345 } // namespace ash | 355 } // namespace ash |
OLD | NEW |