| 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/aura/wm_window_aura.h" | |
| 11 #include "ash/common/wm/container_finder.h" | 10 #include "ash/common/wm/container_finder.h" |
| 12 #include "ash/common/wm/window_dimmer.h" | 11 #include "ash/common/wm/window_dimmer.h" |
| 13 #include "ash/common/wm/window_state.h" | 12 #include "ash/common/wm/window_state.h" |
| 14 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
| 15 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
| 16 #include "ash/common/wm_window_observer.h" | 15 #include "ash/common/wm_window_observer.h" |
| 17 #include "ash/common/wm_window_user_data.h" | 16 #include "ash/common/wm_window_user_data.h" |
| 18 #include "ash/display/window_tree_host_manager.h" | 17 #include "ash/display/window_tree_host_manager.h" |
| 19 #include "ash/public/cpp/shell_window_ids.h" | 18 #include "ash/public/cpp/shell_window_ids.h" |
| 20 #include "base/auto_reset.h" | 19 #include "base/auto_reset.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 37 if (system_modal->GetRootWindow() == pinned_root) | 36 if (system_modal->GetRootWindow() == pinned_root) |
| 38 continue; | 37 continue; |
| 39 result.push_back(system_modal); | 38 result.push_back(system_modal); |
| 40 } | 39 } |
| 41 return result; | 40 return result; |
| 42 } | 41 } |
| 43 | 42 |
| 44 void AddObserverToChildren(WmWindow* container, | 43 void AddObserverToChildren(WmWindow* container, |
| 45 aura::WindowObserver* observer) { | 44 aura::WindowObserver* observer) { |
| 46 for (WmWindow* child : container->GetChildren()) { | 45 for (WmWindow* child : container->GetChildren()) { |
| 47 WmWindowAura::GetAuraWindow(child)->AddObserver(observer); | 46 WmWindow::GetAuraWindow(child)->AddObserver(observer); |
| 48 } | 47 } |
| 49 } | 48 } |
| 50 | 49 |
| 51 void RemoveObserverFromChildren(WmWindow* container, | 50 void RemoveObserverFromChildren(WmWindow* container, |
| 52 aura::WindowObserver* observer) { | 51 aura::WindowObserver* observer) { |
| 53 for (WmWindow* child : container->GetChildren()) { | 52 for (WmWindow* child : container->GetChildren()) { |
| 54 WmWindowAura::GetAuraWindow(child)->RemoveObserver(observer); | 53 WmWindow::GetAuraWindow(child)->RemoveObserver(observer); |
| 55 } | 54 } |
| 56 } | 55 } |
| 57 | 56 |
| 58 } // namespace | 57 } // namespace |
| 59 | 58 |
| 60 // Adapter to fire OnPinnedContainerWindowStackingChanged(). | 59 // Adapter to fire OnPinnedContainerWindowStackingChanged(). |
| 61 class ScreenPinningController::PinnedContainerChildWindowObserver | 60 class ScreenPinningController::PinnedContainerChildWindowObserver |
| 62 : public aura::WindowObserver { | 61 : public aura::WindowObserver { |
| 63 public: | 62 public: |
| 64 explicit PinnedContainerChildWindowObserver( | 63 explicit PinnedContainerChildWindowObserver( |
| 65 ScreenPinningController* controller) | 64 ScreenPinningController* controller) |
| 66 : controller_(controller) {} | 65 : controller_(controller) {} |
| 67 | 66 |
| 68 void OnWindowStackingChanged(aura::Window* window) override { | 67 void OnWindowStackingChanged(aura::Window* window) override { |
| 69 controller_->OnPinnedContainerWindowStackingChanged( | 68 controller_->OnPinnedContainerWindowStackingChanged(WmWindow::Get(window)); |
| 70 WmWindowAura::Get(window)); | |
| 71 } | 69 } |
| 72 | 70 |
| 73 private: | 71 private: |
| 74 ScreenPinningController* controller_; | 72 ScreenPinningController* controller_; |
| 75 DISALLOW_COPY_AND_ASSIGN(PinnedContainerChildWindowObserver); | 73 DISALLOW_COPY_AND_ASSIGN(PinnedContainerChildWindowObserver); |
| 76 }; | 74 }; |
| 77 | 75 |
| 78 // Adapter to translate OnWindowAdded/OnWillRemoveWindow for the container | 76 // Adapter to translate OnWindowAdded/OnWillRemoveWindow for the container |
| 79 // containing the pinned window, to the corresponding controller's methods. | 77 // containing the pinned window, to the corresponding controller's methods. |
| 80 class ScreenPinningController::PinnedContainerWindowObserver | 78 class ScreenPinningController::PinnedContainerWindowObserver |
| 81 : public aura::WindowObserver { | 79 : public aura::WindowObserver { |
| 82 public: | 80 public: |
| 83 explicit PinnedContainerWindowObserver(ScreenPinningController* controller) | 81 explicit PinnedContainerWindowObserver(ScreenPinningController* controller) |
| 84 : controller_(controller) {} | 82 : controller_(controller) {} |
| 85 | 83 |
| 86 void OnWindowAdded(aura::Window* new_window) override { | 84 void OnWindowAdded(aura::Window* new_window) override { |
| 87 controller_->OnWindowAddedToPinnedContainer(WmWindowAura::Get(new_window)); | 85 controller_->OnWindowAddedToPinnedContainer(WmWindow::Get(new_window)); |
| 88 } | 86 } |
| 89 void OnWillRemoveWindow(aura::Window* window) override { | 87 void OnWillRemoveWindow(aura::Window* window) override { |
| 90 controller_->OnWillRemoveWindowFromPinnedContainer( | 88 controller_->OnWillRemoveWindowFromPinnedContainer(WmWindow::Get(window)); |
| 91 WmWindowAura::Get(window)); | |
| 92 } | 89 } |
| 93 void OnWindowDestroying(aura::Window* window) override { | 90 void OnWindowDestroying(aura::Window* window) override { |
| 94 // Just in case. There is nothing we can do here. | 91 // Just in case. There is nothing we can do here. |
| 95 window->RemoveObserver(this); | 92 window->RemoveObserver(this); |
| 96 } | 93 } |
| 97 | 94 |
| 98 private: | 95 private: |
| 99 ScreenPinningController* controller_; | 96 ScreenPinningController* controller_; |
| 100 DISALLOW_COPY_AND_ASSIGN(PinnedContainerWindowObserver); | 97 DISALLOW_COPY_AND_ASSIGN(PinnedContainerWindowObserver); |
| 101 }; | 98 }; |
| 102 | 99 |
| 103 // Adapter to fire OnSystemModalContainerWindowStackingChanged(). | 100 // Adapter to fire OnSystemModalContainerWindowStackingChanged(). |
| 104 class ScreenPinningController::SystemModalContainerChildWindowObserver | 101 class ScreenPinningController::SystemModalContainerChildWindowObserver |
| 105 : public aura::WindowObserver { | 102 : public aura::WindowObserver { |
| 106 public: | 103 public: |
| 107 explicit SystemModalContainerChildWindowObserver( | 104 explicit SystemModalContainerChildWindowObserver( |
| 108 ScreenPinningController* controller) | 105 ScreenPinningController* controller) |
| 109 : controller_(controller) {} | 106 : controller_(controller) {} |
| 110 | 107 |
| 111 void OnWindowStackingChanged(aura::Window* window) override { | 108 void OnWindowStackingChanged(aura::Window* window) override { |
| 112 controller_->OnSystemModalContainerWindowStackingChanged( | 109 controller_->OnSystemModalContainerWindowStackingChanged( |
| 113 WmWindowAura::Get(window)); | 110 WmWindow::Get(window)); |
| 114 } | 111 } |
| 115 | 112 |
| 116 private: | 113 private: |
| 117 ScreenPinningController* controller_; | 114 ScreenPinningController* controller_; |
| 118 DISALLOW_COPY_AND_ASSIGN(SystemModalContainerChildWindowObserver); | 115 DISALLOW_COPY_AND_ASSIGN(SystemModalContainerChildWindowObserver); |
| 119 }; | 116 }; |
| 120 | 117 |
| 121 // Adapter to translate OnWindowAdded/OnWillRemoveWindow for the | 118 // Adapter to translate OnWindowAdded/OnWillRemoveWindow for the |
| 122 // SystemModalContainer to the corresponding controller's methods. | 119 // SystemModalContainer to the corresponding controller's methods. |
| 123 class ScreenPinningController::SystemModalContainerWindowObserver | 120 class ScreenPinningController::SystemModalContainerWindowObserver |
| 124 : public aura::WindowObserver { | 121 : public aura::WindowObserver { |
| 125 public: | 122 public: |
| 126 explicit SystemModalContainerWindowObserver( | 123 explicit SystemModalContainerWindowObserver( |
| 127 ScreenPinningController* controller) | 124 ScreenPinningController* controller) |
| 128 : controller_(controller) {} | 125 : controller_(controller) {} |
| 129 | 126 |
| 130 void OnWindowAdded(aura::Window* new_window) override { | 127 void OnWindowAdded(aura::Window* new_window) override { |
| 131 controller_->OnWindowAddedToSystemModalContainer( | 128 controller_->OnWindowAddedToSystemModalContainer(WmWindow::Get(new_window)); |
| 132 WmWindowAura::Get(new_window)); | |
| 133 } | 129 } |
| 134 void OnWillRemoveWindow(aura::Window* window) override { | 130 void OnWillRemoveWindow(aura::Window* window) override { |
| 135 controller_->OnWillRemoveWindowFromSystemModalContainer( | 131 controller_->OnWillRemoveWindowFromSystemModalContainer( |
| 136 WmWindowAura::Get(window)); | 132 WmWindow::Get(window)); |
| 137 } | 133 } |
| 138 void OnWindowDestroying(aura::Window* window) override { | 134 void OnWindowDestroying(aura::Window* window) override { |
| 139 // Just in case. There is nothing we can do here. | 135 // Just in case. There is nothing we can do here. |
| 140 window->RemoveObserver(this); | 136 window->RemoveObserver(this); |
| 141 } | 137 } |
| 142 | 138 |
| 143 private: | 139 private: |
| 144 ScreenPinningController* controller_; | 140 ScreenPinningController* controller_; |
| 145 DISALLOW_COPY_AND_ASSIGN(SystemModalContainerWindowObserver); | 141 DISALLOW_COPY_AND_ASSIGN(SystemModalContainerWindowObserver); |
| 146 }; | 142 }; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 pinned_window_ = pinned_window; | 182 pinned_window_ = pinned_window; |
| 187 container->StackChildAtTop(pinned_window); | 183 container->StackChildAtTop(pinned_window); |
| 188 container->StackChildBelow(CreateWindowDimmer(container), pinned_window); | 184 container->StackChildBelow(CreateWindowDimmer(container), pinned_window); |
| 189 | 185 |
| 190 // Set the dim windows to the system containers, other than the one which | 186 // Set the dim windows to the system containers, other than the one which |
| 191 // the root window of the pinned window holds. | 187 // the root window of the pinned window holds. |
| 192 for (WmWindow* system_modal : system_modal_containers) | 188 for (WmWindow* system_modal : system_modal_containers) |
| 193 system_modal->StackChildAtBottom(CreateWindowDimmer(system_modal)); | 189 system_modal->StackChildAtBottom(CreateWindowDimmer(system_modal)); |
| 194 | 190 |
| 195 // Set observers. | 191 // Set observers. |
| 196 WmWindowAura::GetAuraWindow(container)->AddObserver( | 192 WmWindow::GetAuraWindow(container)->AddObserver( |
| 197 pinned_container_window_observer_.get()); | 193 pinned_container_window_observer_.get()); |
| 198 AddObserverToChildren(container, | 194 AddObserverToChildren(container, |
| 199 pinned_container_child_window_observer_.get()); | 195 pinned_container_child_window_observer_.get()); |
| 200 for (WmWindow* system_modal : system_modal_containers) { | 196 for (WmWindow* system_modal : system_modal_containers) { |
| 201 WmWindowAura::GetAuraWindow(system_modal) | 197 WmWindow::GetAuraWindow(system_modal) |
| 202 ->AddObserver(system_modal_container_window_observer_.get()); | 198 ->AddObserver(system_modal_container_window_observer_.get()); |
| 203 AddObserverToChildren( | 199 AddObserverToChildren( |
| 204 system_modal, system_modal_container_child_window_observer_.get()); | 200 system_modal, system_modal_container_child_window_observer_.get()); |
| 205 } | 201 } |
| 206 } else { | 202 } else { |
| 207 if (pinned_window != pinned_window_) { | 203 if (pinned_window != pinned_window_) { |
| 208 LOG(DFATAL) << "Pinned mode is being disabled, but for the different " | 204 LOG(DFATAL) << "Pinned mode is being disabled, but for the different " |
| 209 << "target window."; | 205 << "target window."; |
| 210 return; | 206 return; |
| 211 } | 207 } |
| 212 | 208 |
| 213 WmWindow* container = pinned_window->GetParent(); | 209 WmWindow* container = pinned_window->GetParent(); |
| 214 std::vector<WmWindow*> system_modal_containers = | 210 std::vector<WmWindow*> system_modal_containers = |
| 215 GetSystemModalWindowsExceptPinned(pinned_window_); | 211 GetSystemModalWindowsExceptPinned(pinned_window_); |
| 216 | 212 |
| 217 // Unset observers. | 213 // Unset observers. |
| 218 for (WmWindow* system_modal : | 214 for (WmWindow* system_modal : |
| 219 GetSystemModalWindowsExceptPinned(pinned_window_)) { | 215 GetSystemModalWindowsExceptPinned(pinned_window_)) { |
| 220 RemoveObserverFromChildren( | 216 RemoveObserverFromChildren( |
| 221 system_modal, system_modal_container_child_window_observer_.get()); | 217 system_modal, system_modal_container_child_window_observer_.get()); |
| 222 WmWindowAura::GetAuraWindow(system_modal) | 218 WmWindow::GetAuraWindow(system_modal) |
| 223 ->RemoveObserver(system_modal_container_window_observer_.get()); | 219 ->RemoveObserver(system_modal_container_window_observer_.get()); |
| 224 } | 220 } |
| 225 RemoveObserverFromChildren(container, | 221 RemoveObserverFromChildren(container, |
| 226 pinned_container_child_window_observer_.get()); | 222 pinned_container_child_window_observer_.get()); |
| 227 WmWindowAura::GetAuraWindow(container)->RemoveObserver( | 223 WmWindow::GetAuraWindow(container)->RemoveObserver( |
| 228 pinned_container_window_observer_.get()); | 224 pinned_container_window_observer_.get()); |
| 229 | 225 |
| 230 pinned_window_ = nullptr; | 226 pinned_window_ = nullptr; |
| 231 } | 227 } |
| 232 | 228 |
| 233 WmShell::Get()->NotifyPinnedStateChanged(pinned_window); | 229 WmShell::Get()->NotifyPinnedStateChanged(pinned_window); |
| 234 } | 230 } |
| 235 | 231 |
| 236 void ScreenPinningController::OnWindowAddedToPinnedContainer( | 232 void ScreenPinningController::OnWindowAddedToPinnedContainer( |
| 237 WmWindow* new_window) { | 233 WmWindow* new_window) { |
| 238 KeepPinnedWindowOnTop(); | 234 KeepPinnedWindowOnTop(); |
| 239 WmWindowAura::GetAuraWindow(new_window) | 235 WmWindow::GetAuraWindow(new_window) |
| 240 ->AddObserver(pinned_container_child_window_observer_.get()); | 236 ->AddObserver(pinned_container_child_window_observer_.get()); |
| 241 } | 237 } |
| 242 | 238 |
| 243 void ScreenPinningController::OnWillRemoveWindowFromPinnedContainer( | 239 void ScreenPinningController::OnWillRemoveWindowFromPinnedContainer( |
| 244 WmWindow* window) { | 240 WmWindow* window) { |
| 245 WmWindowAura::GetAuraWindow(window)->RemoveObserver( | 241 WmWindow::GetAuraWindow(window)->RemoveObserver( |
| 246 pinned_container_child_window_observer_.get()); | 242 pinned_container_child_window_observer_.get()); |
| 247 if (window == pinned_window_) { | 243 if (window == pinned_window_) { |
| 248 pinned_window_->GetWindowState()->Restore(); | 244 pinned_window_->GetWindowState()->Restore(); |
| 249 return; | 245 return; |
| 250 } | 246 } |
| 251 } | 247 } |
| 252 | 248 |
| 253 void ScreenPinningController::OnPinnedContainerWindowStackingChanged( | 249 void ScreenPinningController::OnPinnedContainerWindowStackingChanged( |
| 254 WmWindow* window) { | 250 WmWindow* window) { |
| 255 KeepPinnedWindowOnTop(); | 251 KeepPinnedWindowOnTop(); |
| 256 } | 252 } |
| 257 | 253 |
| 258 void ScreenPinningController::OnWindowAddedToSystemModalContainer( | 254 void ScreenPinningController::OnWindowAddedToSystemModalContainer( |
| 259 WmWindow* new_window) { | 255 WmWindow* new_window) { |
| 260 KeepDimWindowAtBottom(new_window->GetParent()); | 256 KeepDimWindowAtBottom(new_window->GetParent()); |
| 261 WmWindowAura::GetAuraWindow(new_window) | 257 WmWindow::GetAuraWindow(new_window) |
| 262 ->AddObserver(system_modal_container_child_window_observer_.get()); | 258 ->AddObserver(system_modal_container_child_window_observer_.get()); |
| 263 } | 259 } |
| 264 | 260 |
| 265 void ScreenPinningController::OnWillRemoveWindowFromSystemModalContainer( | 261 void ScreenPinningController::OnWillRemoveWindowFromSystemModalContainer( |
| 266 WmWindow* window) { | 262 WmWindow* window) { |
| 267 WmWindowAura::GetAuraWindow(window)->RemoveObserver( | 263 WmWindow::GetAuraWindow(window)->RemoveObserver( |
| 268 system_modal_container_child_window_observer_.get()); | 264 system_modal_container_child_window_observer_.get()); |
| 269 } | 265 } |
| 270 | 266 |
| 271 void ScreenPinningController::OnSystemModalContainerWindowStackingChanged( | 267 void ScreenPinningController::OnSystemModalContainerWindowStackingChanged( |
| 272 WmWindow* window) { | 268 WmWindow* window) { |
| 273 KeepDimWindowAtBottom(window->GetParent()); | 269 KeepDimWindowAtBottom(window->GetParent()); |
| 274 } | 270 } |
| 275 | 271 |
| 276 WmWindow* ScreenPinningController::CreateWindowDimmer(WmWindow* container) { | 272 WmWindow* ScreenPinningController::CreateWindowDimmer(WmWindow* container) { |
| 277 std::unique_ptr<WindowDimmer> window_dimmer = | 273 std::unique_ptr<WindowDimmer> window_dimmer = |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 for (WmWindow* system_modal : system_modal_containers) { | 306 for (WmWindow* system_modal : system_modal_containers) { |
| 311 if (window_dimmers_->Get(system_modal)) { | 307 if (window_dimmers_->Get(system_modal)) { |
| 312 // |system_modal| already has a WindowDimmer. | 308 // |system_modal| already has a WindowDimmer. |
| 313 continue; | 309 continue; |
| 314 } | 310 } |
| 315 | 311 |
| 316 // This is the new system modal dialog. | 312 // This is the new system modal dialog. |
| 317 system_modal->StackChildAtBottom(CreateWindowDimmer(system_modal)); | 313 system_modal->StackChildAtBottom(CreateWindowDimmer(system_modal)); |
| 318 | 314 |
| 319 // Set observers to the tree. | 315 // Set observers to the tree. |
| 320 WmWindowAura::GetAuraWindow(system_modal) | 316 WmWindow::GetAuraWindow(system_modal) |
| 321 ->AddObserver(system_modal_container_window_observer_.get()); | 317 ->AddObserver(system_modal_container_window_observer_.get()); |
| 322 AddObserverToChildren(system_modal, | 318 AddObserverToChildren(system_modal, |
| 323 system_modal_container_child_window_observer_.get()); | 319 system_modal_container_child_window_observer_.get()); |
| 324 } | 320 } |
| 325 } | 321 } |
| 326 | 322 |
| 327 void ScreenPinningController::KeepPinnedWindowOnTop() { | 323 void ScreenPinningController::KeepPinnedWindowOnTop() { |
| 328 if (in_restacking_) | 324 if (in_restacking_) |
| 329 return; | 325 return; |
| 330 | 326 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 341 return; | 337 return; |
| 342 | 338 |
| 343 WindowDimmer* window_dimmer = window_dimmers_->Get(container); | 339 WindowDimmer* window_dimmer = window_dimmers_->Get(container); |
| 344 if (window_dimmer) { | 340 if (window_dimmer) { |
| 345 base::AutoReset<bool> auto_reset(&in_restacking_, true); | 341 base::AutoReset<bool> auto_reset(&in_restacking_, true); |
| 346 container->StackChildAtBottom(window_dimmer->window()); | 342 container->StackChildAtBottom(window_dimmer->window()); |
| 347 } | 343 } |
| 348 } | 344 } |
| 349 | 345 |
| 350 } // namespace ash | 346 } // namespace ash |
| OLD | NEW |