| 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/shelf/wm_shelf.h" | 10 #include "ash/common/shelf/wm_shelf.h" |
| 11 #include "ash/common/shell_window_ids.h" | 11 #include "ash/common/shell_window_ids.h" |
| 12 #include "ash/common/wm/always_on_top_controller.h" | 12 #include "ash/common/wm/always_on_top_controller.h" |
| 13 #include "ash/common/wm/fullscreen_window_finder.h" | 13 #include "ash/common/wm/fullscreen_window_finder.h" |
| 14 #include "ash/common/wm/window_positioner.h" | 14 #include "ash/common/wm/window_positioner.h" |
| 15 #include "ash/common/wm/window_state.h" | 15 #include "ash/common/wm/window_state.h" |
| 16 #include "ash/common/wm/wm_event.h" | 16 #include "ash/common/wm/wm_event.h" |
| 17 #include "ash/common/wm/wm_screen_util.h" | 17 #include "ash/common/wm/wm_screen_util.h" |
| 18 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" | 18 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" |
| 19 #include "ash/common/wm_root_window_controller.h" | 19 #include "ash/common/wm_root_window_controller.h" |
| 20 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 21 #include "ash/common/wm_window.h" | 21 #include "ash/common/wm_window.h" |
| 22 #include "ash/common/wm_window_property.h" | 22 #include "ash/common/wm_window_property.h" |
| 23 #include "base/command_line.h" | 23 #include "base/command_line.h" |
| 24 #include "ui/base/ui_base_switches.h" | 24 #include "ui/base/ui_base_switches.h" |
| 25 #include "ui/compositor/layer.h" | 25 #include "ui/compositor/layer.h" |
| 26 #include "ui/display/display.h" |
| 27 #include "ui/display/screen.h" |
| 26 #include "ui/keyboard/keyboard_controller.h" | 28 #include "ui/keyboard/keyboard_controller.h" |
| 27 #include "ui/keyboard/keyboard_controller_observer.h" | 29 #include "ui/keyboard/keyboard_controller_observer.h" |
| 28 | 30 |
| 29 namespace ash { | 31 namespace ash { |
| 30 | 32 |
| 31 WorkspaceLayoutManager::WorkspaceLayoutManager(WmWindow* window) | 33 WorkspaceLayoutManager::WorkspaceLayoutManager(WmWindow* window) |
| 32 : window_(window), | 34 : window_(window), |
| 33 root_window_(window->GetRootWindow()), | 35 root_window_(window->GetRootWindow()), |
| 34 root_window_controller_(root_window_->GetRootWindowController()), | 36 root_window_controller_(root_window_->GetRootWindowController()), |
| 35 shell_(window_->GetShell()), | 37 shell_(window_->GetShell()), |
| 36 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), | 38 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), |
| 37 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { | 39 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { |
| 38 shell_->AddShellObserver(this); | 40 shell_->AddShellObserver(this); |
| 39 shell_->AddActivationObserver(this); | 41 shell_->AddActivationObserver(this); |
| 40 root_window_->AddObserver(this); | 42 root_window_->AddObserver(this); |
| 41 root_window_controller_->AddObserver(this); | 43 display::Screen::GetScreen()->AddObserver(this); |
| 42 DCHECK(window->GetBoolProperty( | 44 DCHECK(window->GetBoolProperty( |
| 43 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); | 45 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); |
| 44 } | 46 } |
| 45 | 47 |
| 46 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 48 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
| 47 if (root_window_) | 49 if (root_window_) |
| 48 root_window_->RemoveObserver(this); | 50 root_window_->RemoveObserver(this); |
| 49 for (WmWindow* window : windows_) { | 51 for (WmWindow* window : windows_) { |
| 50 wm::WindowState* window_state = window->GetWindowState(); | 52 wm::WindowState* window_state = window->GetWindowState(); |
| 51 window_state->RemoveObserver(this); | 53 window_state->RemoveObserver(this); |
| 52 window->RemoveObserver(this); | 54 window->RemoveObserver(this); |
| 53 } | 55 } |
| 54 root_window_->GetRootWindowController()->RemoveObserver(this); | 56 display::Screen::GetScreen()->RemoveObserver(this); |
| 55 shell_->RemoveActivationObserver(this); | 57 shell_->RemoveActivationObserver(this); |
| 56 shell_->RemoveShellObserver(this); | 58 shell_->RemoveShellObserver(this); |
| 57 } | 59 } |
| 58 | 60 |
| 59 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( | 61 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( |
| 60 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 62 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { |
| 61 backdrop_delegate_.reset(delegate.release()); | 63 backdrop_delegate_.reset(delegate.release()); |
| 62 } | 64 } |
| 63 | 65 |
| 64 ////////////////////////////////////////////////////////////////////////////// | 66 ////////////////////////////////////////////////////////////////////////////// |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } else if (window_state->HasRestoreBounds()) { | 169 } else if (window_state->HasRestoreBounds()) { |
| 168 // Keyboard hidden, restore original bounds if they exist. If the user has | 170 // Keyboard hidden, restore original bounds if they exist. If the user has |
| 169 // resized or dragged the window in the meantime, WorkspaceWindowResizer | 171 // resized or dragged the window in the meantime, WorkspaceWindowResizer |
| 170 // will have cleared the restore bounds and this code will not accidentally | 172 // will have cleared the restore bounds and this code will not accidentally |
| 171 // override user intent. | 173 // override user intent. |
| 172 window_state->SetAndClearRestoreBounds(); | 174 window_state->SetAndClearRestoreBounds(); |
| 173 } | 175 } |
| 174 } | 176 } |
| 175 | 177 |
| 176 ////////////////////////////////////////////////////////////////////////////// | 178 ////////////////////////////////////////////////////////////////////////////// |
| 177 // WorkspaceLayoutManager, WmRootWindowControllerObserver implementation: | |
| 178 | |
| 179 void WorkspaceLayoutManager::OnWorkAreaChanged() { | |
| 180 const gfx::Rect work_area(wm::GetDisplayWorkAreaBounds(window_)); | |
| 181 if (work_area != work_area_in_parent_) { | |
| 182 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | |
| 183 AdjustAllWindowsBoundsForWorkAreaChange(&event); | |
| 184 } | |
| 185 if (backdrop_delegate_) | |
| 186 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); | |
| 187 } | |
| 188 | |
| 189 ////////////////////////////////////////////////////////////////////////////// | |
| 190 // WorkspaceLayoutManager, aura::WindowObserver implementation: | 179 // WorkspaceLayoutManager, aura::WindowObserver implementation: |
| 191 | 180 |
| 192 void WorkspaceLayoutManager::OnWindowTreeChanged( | 181 void WorkspaceLayoutManager::OnWindowTreeChanged( |
| 193 WmWindow* window, | 182 WmWindow* window, |
| 194 const WmWindowObserver::TreeChangeParams& params) { | 183 const WmWindowObserver::TreeChangeParams& params) { |
| 195 if (!params.target->GetWindowState()->IsActive()) | 184 if (!params.target->GetWindowState()->IsActive()) |
| 196 return; | 185 return; |
| 197 // If the window is already tracked by the workspace this update would be | 186 // If the window is already tracked by the workspace this update would be |
| 198 // redundant as the fullscreen and shelf state would have been handled in | 187 // redundant as the fullscreen and shelf state would have been handled in |
| 199 // OnWindowAddedToLayout. | 188 // OnWindowAddedToLayout. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { | 264 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 276 UpdateFullscreenState(); | 265 UpdateFullscreenState(); |
| 277 } | 266 } |
| 278 | 267 |
| 279 UpdateShelfVisibility(); | 268 UpdateShelfVisibility(); |
| 280 if (backdrop_delegate_) | 269 if (backdrop_delegate_) |
| 281 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); | 270 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); |
| 282 } | 271 } |
| 283 | 272 |
| 284 ////////////////////////////////////////////////////////////////////////////// | 273 ////////////////////////////////////////////////////////////////////////////// |
| 274 // WorkspaceLayoutManager, display::DisplayObserver implementation: |
| 275 |
| 276 void WorkspaceLayoutManager::OnDisplayMetricsChanged( |
| 277 const display::Display& display, |
| 278 uint32_t changed_metrics) { |
| 279 if (window_->GetDisplayNearestWindow().id() != display.id()) |
| 280 return; |
| 281 |
| 282 const gfx::Rect work_area(wm::GetDisplayWorkAreaBounds(window_)); |
| 283 if (work_area != work_area_in_parent_) { |
| 284 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
| 285 AdjustAllWindowsBoundsForWorkAreaChange(&event); |
| 286 } |
| 287 if (backdrop_delegate_) |
| 288 backdrop_delegate_->OnDisplayWorkAreaInsetsChanged(); |
| 289 } |
| 290 |
| 291 ////////////////////////////////////////////////////////////////////////////// |
| 285 // WorkspaceLayoutManager, ShellObserver implementation: | 292 // WorkspaceLayoutManager, ShellObserver implementation: |
| 286 | 293 |
| 287 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen, | 294 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen, |
| 288 WmWindow* root_window) { | 295 WmWindow* root_window) { |
| 289 if (root_window != root_window_ || is_fullscreen_ == is_fullscreen) | 296 if (root_window != root_window_ || is_fullscreen_ == is_fullscreen) |
| 290 return; | 297 return; |
| 291 | 298 |
| 292 is_fullscreen_ = is_fullscreen; | 299 is_fullscreen_ = is_fullscreen; |
| 293 if (WmShell::Get()->IsPinned()) { | 300 if (WmShell::Get()->IsPinned()) { |
| 294 // If this is in pinned mode, then this event does not trigger the | 301 // If this is in pinned mode, then this event does not trigger the |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 for (auto* window : windows) { | 375 for (auto* window : windows) { |
| 369 wm::WindowState* window_state = window->GetWindowState(); | 376 wm::WindowState* window_state = window->GetWindowState(); |
| 370 if (window_on_top) | 377 if (window_on_top) |
| 371 window_state->DisableAlwaysOnTop(window_on_top); | 378 window_state->DisableAlwaysOnTop(window_on_top); |
| 372 else | 379 else |
| 373 window_state->RestoreAlwaysOnTop(); | 380 window_state->RestoreAlwaysOnTop(); |
| 374 } | 381 } |
| 375 } | 382 } |
| 376 | 383 |
| 377 } // namespace ash | 384 } // namespace ash |
| OLD | NEW |