| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/common/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/wm/always_on_top_controller.h" | 10 #include "ash/common/wm/always_on_top_controller.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 WorkspaceLayoutManager::WorkspaceLayoutManager( | 27 WorkspaceLayoutManager::WorkspaceLayoutManager( |
| 28 WmWindow* window, | 28 WmWindow* window, |
| 29 std::unique_ptr<wm::WorkspaceLayoutManagerDelegate> delegate) | 29 std::unique_ptr<wm::WorkspaceLayoutManagerDelegate> delegate) |
| 30 : window_(window), | 30 : window_(window), |
| 31 root_window_(window->GetRootWindow()), | 31 root_window_(window->GetRootWindow()), |
| 32 root_window_controller_(root_window_->GetRootWindowController()), | 32 root_window_controller_(root_window_->GetRootWindowController()), |
| 33 shell_(window_->GetShell()), | 33 shell_(window_->GetShell()), |
| 34 delegate_(std::move(delegate)), | 34 delegate_(std::move(delegate)), |
| 35 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), | 35 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), |
| 36 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { | 36 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr), |
| 37 is_pinned_(WmShell::Get()->IsPinned()) { |
| 37 shell_->AddActivationObserver(this); | 38 shell_->AddActivationObserver(this); |
| 38 root_window_->AddObserver(this); | 39 root_window_->AddObserver(this); |
| 39 root_window_controller_->AddObserver(this); | 40 root_window_controller_->AddObserver(this); |
| 40 DCHECK(window->GetBoolProperty( | 41 DCHECK(window->GetBoolProperty( |
| 41 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); | 42 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); |
| 42 } | 43 } |
| 43 | 44 |
| 44 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 45 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
| 45 if (root_window_) | 46 if (root_window_) |
| 46 root_window_->RemoveObserver(this); | 47 root_window_->RemoveObserver(this); |
| 47 for (WmWindow* window : windows_) | 48 for (WmWindow* window : windows_) { |
| 49 wm::WindowState* window_state = window->GetWindowState(); |
| 50 window_state->RemoveObserver(this); |
| 48 window->RemoveObserver(this); | 51 window->RemoveObserver(this); |
| 52 } |
| 49 root_window_->GetRootWindowController()->RemoveObserver(this); | 53 root_window_->GetRootWindowController()->RemoveObserver(this); |
| 50 shell_->RemoveActivationObserver(this); | 54 shell_->RemoveActivationObserver(this); |
| 51 } | 55 } |
| 52 | 56 |
| 53 void WorkspaceLayoutManager::DeleteDelegate() { | 57 void WorkspaceLayoutManager::DeleteDelegate() { |
| 54 delegate_.reset(); | 58 delegate_.reset(); |
| 55 } | 59 } |
| 56 | 60 |
| 57 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( | 61 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( |
| 58 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 62 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 AdjustAllWindowsBoundsForWorkAreaChange(&event); | 170 AdjustAllWindowsBoundsForWorkAreaChange(&event); |
| 167 } | 171 } |
| 168 if (backdrop_delegate_) | 172 if (backdrop_delegate_) |
| 169 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); | 173 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); |
| 170 } | 174 } |
| 171 | 175 |
| 172 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen) { | 176 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen) { |
| 173 if (is_fullscreen_ == is_fullscreen) | 177 if (is_fullscreen_ == is_fullscreen) |
| 174 return; | 178 return; |
| 175 | 179 |
| 180 bool was_always_on_top_allowed = !is_fullscreen_ && !is_pinned_; |
| 176 is_fullscreen_ = is_fullscreen; | 181 is_fullscreen_ = is_fullscreen; |
| 177 WmWindow* fullscreen_window = | 182 bool is_always_on_top_allowed = !is_fullscreen_ && !is_pinned_; |
| 178 is_fullscreen ? wm::GetWindowForFullscreenMode(window_) : nullptr; | 183 if (is_always_on_top_allowed != was_always_on_top_allowed) { |
| 179 // Changing always on top state may change window's parent. Iterate on a copy | 184 // In this pass, if is_always_on_top_allowed is false, then fullscreen |
| 180 // of |windows_| to avoid invalidating an iterator. Since both workspace and | 185 // window should be found. It is because; the situation only happens |
| 181 // always_on_top containers' layouts are managed by this class all the | 186 // when was_always_on_top_allowed is true, so (is_fullscreen, is_pinned) |
| 182 // appropriate windows will be included in the iteration. | 187 // is changed from (false, false) to (true, false). |
| 183 WindowSet windows(windows_); | 188 UpdateAlwaysOnTop(is_always_on_top_allowed |
| 184 for (auto window : windows) { | 189 ? nullptr |
| 185 wm::WindowState* window_state = window->GetWindowState(); | 190 : wm::GetWindowForFullscreenMode(window_)); |
| 186 if (is_fullscreen) | |
| 187 window_state->DisableAlwaysOnTop(fullscreen_window); | |
| 188 else | |
| 189 window_state->RestoreAlwaysOnTop(); | |
| 190 } | 191 } |
| 191 } | 192 } |
| 192 | 193 |
| 193 ////////////////////////////////////////////////////////////////////////////// | 194 ////////////////////////////////////////////////////////////////////////////// |
| 194 // WorkspaceLayoutManager, aura::WindowObserver implementation: | 195 // WorkspaceLayoutManager, aura::WindowObserver implementation: |
| 195 | 196 |
| 196 void WorkspaceLayoutManager::OnWindowTreeChanged( | 197 void WorkspaceLayoutManager::OnWindowTreeChanged( |
| 197 WmWindow* window, | 198 WmWindow* window, |
| 198 const WmWindowObserver::TreeChangeParams& params) { | 199 const WmWindowObserver::TreeChangeParams& params) { |
| 199 if (!params.target->GetWindowState()->IsActive()) | 200 if (!params.target->GetWindowState()->IsActive()) |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { | 278 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 278 UpdateFullscreenState(); | 279 UpdateFullscreenState(); |
| 279 } | 280 } |
| 280 | 281 |
| 281 UpdateShelfVisibility(); | 282 UpdateShelfVisibility(); |
| 282 if (backdrop_delegate_) | 283 if (backdrop_delegate_) |
| 283 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); | 284 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); |
| 284 } | 285 } |
| 285 | 286 |
| 286 ////////////////////////////////////////////////////////////////////////////// | 287 ////////////////////////////////////////////////////////////////////////////// |
| 288 // WorkspaceLayoutManager, ShellObserver implementation: |
| 289 |
| 290 void WorkspaceLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) { |
| 291 bool is_pinned = pinned_window->GetWindowState()->IsPinned(); |
| 292 if (is_pinned_ == is_pinned) |
| 293 return; |
| 294 |
| 295 bool was_always_on_top_allowed = !is_fullscreen_ && !is_pinned_; |
| 296 is_pinned_ = is_pinned; |
| 297 bool is_always_on_top_allowed = !is_fullscreen_ && !is_pinned_; |
| 298 if (is_always_on_top_allowed != was_always_on_top_allowed) { |
| 299 UpdateAlwaysOnTop(is_always_on_top_allowed ? nullptr : pinned_window); |
| 300 } |
| 301 } |
| 302 |
| 303 ////////////////////////////////////////////////////////////////////////////// |
| 287 // WorkspaceLayoutManager, private: | 304 // WorkspaceLayoutManager, private: |
| 288 | 305 |
| 289 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( | 306 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( |
| 290 const wm::WMEvent* event) { | 307 const wm::WMEvent* event) { |
| 291 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || | 308 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || |
| 292 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | 309 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
| 293 | 310 |
| 294 work_area_in_parent_ = wm::GetDisplayWorkAreaBounds(window_); | 311 work_area_in_parent_ = wm::GetDisplayWorkAreaBounds(window_); |
| 295 | 312 |
| 296 // Don't do any adjustments of the insets while we are in screen locked mode. | 313 // Don't do any adjustments of the insets while we are in screen locked mode. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 322 // technically any container could get a fullscreen window. | 339 // technically any container could get a fullscreen window. |
| 323 if (!delegate_) | 340 if (!delegate_) |
| 324 return; | 341 return; |
| 325 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr; | 342 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr; |
| 326 if (is_fullscreen != is_fullscreen_) { | 343 if (is_fullscreen != is_fullscreen_) { |
| 327 delegate_->OnFullscreenStateChanged(is_fullscreen); | 344 delegate_->OnFullscreenStateChanged(is_fullscreen); |
| 328 is_fullscreen_ = is_fullscreen; | 345 is_fullscreen_ = is_fullscreen; |
| 329 } | 346 } |
| 330 } | 347 } |
| 331 | 348 |
| 349 void WorkspaceLayoutManager::UpdateAlwaysOnTop(WmWindow* window_on_top) { |
| 350 // Changing always on top state may change window's parent. Iterate on a copy |
| 351 // of |windows_| to avoid invalidating an iterator. Since both workspace and |
| 352 // always_on_top containers' layouts are managed by this class all the |
| 353 // appropriate windows will be included in the iteration. |
| 354 WindowSet windows(windows_); |
| 355 for (auto window : windows) { |
| 356 wm::WindowState* window_state = window->GetWindowState(); |
| 357 if (window_on_top) |
| 358 window_state->DisableAlwaysOnTop(window_on_top); |
| 359 else |
| 360 window_state->RestoreAlwaysOnTop(); |
| 361 } |
| 362 } |
| 363 |
| 332 } // namespace ash | 364 } // namespace ash |
| OLD | NEW |