| 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/wm/workspace/workspace_layout_manager.h" | 5 #include "ash/wm/workspace/workspace_layout_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/keyboard/keyboard_observer_register.h" | 9 #include "ash/keyboard/keyboard_observer_register.h" |
| 10 #include "ash/public/cpp/shell_window_ids.h" | 10 #include "ash/public/cpp/shell_window_ids.h" |
| 11 #include "ash/root_window_controller.h" | 11 #include "ash/root_window_controller.h" |
| 12 #include "ash/screen_util.h" | 12 #include "ash/screen_util.h" |
| 13 #include "ash/session/session_controller.h" | 13 #include "ash/session/session_controller.h" |
| 14 #include "ash/shelf/wm_shelf.h" | 14 #include "ash/shelf/wm_shelf.h" |
| 15 #include "ash/shell.h" | 15 #include "ash/shell.h" |
| 16 #include "ash/wm/always_on_top_controller.h" | 16 #include "ash/wm/always_on_top_controller.h" |
| 17 #include "ash/wm/fullscreen_window_finder.h" | 17 #include "ash/wm/fullscreen_window_finder.h" |
| 18 #include "ash/wm/screen_pinning_controller.h" | 18 #include "ash/wm/screen_pinning_controller.h" |
| 19 #include "ash/wm/window_positioner.h" | 19 #include "ash/wm/window_positioner.h" |
| 20 #include "ash/wm/window_properties.h" | 20 #include "ash/wm/window_properties.h" |
| 21 #include "ash/wm/window_state.h" | 21 #include "ash/wm/window_state.h" |
| 22 #include "ash/wm/window_state_aura.h" | 22 #include "ash/wm/window_state_aura.h" |
| 23 #include "ash/wm/window_util.h" | 23 #include "ash/wm/window_util.h" |
| 24 #include "ash/wm/wm_event.h" | 24 #include "ash/wm/wm_event.h" |
| 25 #include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h" | 25 #include "ash/wm/workspace/backdrop_controller.h" |
| 26 #include "ash/wm/workspace/backdrop_delegate.h" |
| 26 #include "ash/wm_window.h" | 27 #include "ash/wm_window.h" |
| 27 #include "base/command_line.h" | 28 #include "base/command_line.h" |
| 28 #include "ui/aura/client/aura_constants.h" | 29 #include "ui/aura/client/aura_constants.h" |
| 29 #include "ui/base/ui_base_switches.h" | 30 #include "ui/base/ui_base_switches.h" |
| 30 #include "ui/compositor/layer.h" | 31 #include "ui/compositor/layer.h" |
| 31 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
| 32 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
| 33 #include "ui/keyboard/keyboard_controller.h" | 34 #include "ui/keyboard/keyboard_controller.h" |
| 34 #include "ui/keyboard/keyboard_controller_observer.h" | 35 #include "ui/keyboard/keyboard_controller_observer.h" |
| 35 #include "ui/wm/core/coordinate_conversion.h" | 36 #include "ui/wm/core/coordinate_conversion.h" |
| 36 #include "ui/wm/public/activation_client.h" | 37 #include "ui/wm/public/activation_client.h" |
| 37 | 38 |
| 38 namespace ash { | 39 namespace ash { |
| 39 | 40 |
| 40 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window) | 41 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window) |
| 41 : window_(window), | 42 : window_(window), |
| 42 root_window_(window->GetRootWindow()), | 43 root_window_(window->GetRootWindow()), |
| 43 root_window_controller_(RootWindowController::ForWindow(root_window_)), | 44 root_window_controller_(RootWindowController::ForWindow(root_window_)), |
| 44 work_area_in_parent_( | 45 work_area_in_parent_( |
| 45 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_)), | 46 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_)), |
| 46 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr), | 47 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr), |
| 47 keyboard_observer_(this) { | 48 keyboard_observer_(this) { |
| 48 Shell::Get()->AddShellObserver(this); | 49 Shell::Get()->AddShellObserver(this); |
| 49 Shell::Get()->activation_client()->AddObserver(this); | 50 Shell::Get()->activation_client()->AddObserver(this); |
| 50 root_window_->AddObserver(this); | 51 root_window_->AddObserver(this); |
| 51 display::Screen::GetScreen()->AddObserver(this); | 52 display::Screen::GetScreen()->AddObserver(this); |
| 52 DCHECK(window->GetProperty(kSnapChildrenToPixelBoundary)); | 53 DCHECK(window->GetProperty(kSnapChildrenToPixelBoundary)); |
| 54 backdrop_controller_ = base::MakeUnique<BackdropController>(window_); |
| 53 } | 55 } |
| 54 | 56 |
| 55 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 57 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
| 56 if (root_window_) | 58 if (root_window_) |
| 57 root_window_->RemoveObserver(this); | 59 root_window_->RemoveObserver(this); |
| 58 for (aura::Window* window : windows_) { | 60 for (aura::Window* window : windows_) { |
| 59 wm::WindowState* window_state = wm::GetWindowState(window); | 61 wm::WindowState* window_state = wm::GetWindowState(window); |
| 60 window_state->RemoveObserver(this); | 62 window_state->RemoveObserver(this); |
| 61 window->RemoveObserver(this); | 63 window->RemoveObserver(this); |
| 62 } | 64 } |
| 63 display::Screen::GetScreen()->RemoveObserver(this); | 65 display::Screen::GetScreen()->RemoveObserver(this); |
| 64 Shell::Get()->activation_client()->RemoveObserver(this); | 66 Shell::Get()->activation_client()->RemoveObserver(this); |
| 65 Shell::Get()->RemoveShellObserver(this); | 67 Shell::Get()->RemoveShellObserver(this); |
| 66 } | 68 } |
| 67 | 69 |
| 68 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( | 70 void WorkspaceLayoutManager::SetBackdropDelegate( |
| 69 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 71 std::unique_ptr<BackdropDelegate> delegate) { |
| 70 backdrop_delegate_ = std::move(delegate); | 72 backdrop_controller_->SetBackdropDelegate(std::move(delegate)); |
| 71 } | 73 } |
| 72 | 74 |
| 73 ////////////////////////////////////////////////////////////////////////////// | 75 ////////////////////////////////////////////////////////////////////////////// |
| 74 // WorkspaceLayoutManager, aura::LayoutManager implementation: | 76 // WorkspaceLayoutManager, aura::LayoutManager implementation: |
| 75 | 77 |
| 76 void WorkspaceLayoutManager::OnWindowResized() {} | 78 void WorkspaceLayoutManager::OnWindowResized() {} |
| 77 | 79 |
| 78 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 80 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 79 wm::WindowState* window_state = wm::GetWindowState(child); | 81 wm::WindowState* window_state = wm::GetWindowState(child); |
| 80 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | 82 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
| 81 window_state->OnWMEvent(&event); | 83 window_state->OnWMEvent(&event); |
| 82 windows_.insert(child); | 84 windows_.insert(child); |
| 83 child->AddObserver(this); | 85 child->AddObserver(this); |
| 84 window_state->AddObserver(this); | 86 window_state->AddObserver(this); |
| 85 UpdateShelfVisibility(); | 87 UpdateShelfVisibility(); |
| 86 UpdateFullscreenState(); | 88 UpdateFullscreenState(); |
| 87 if (backdrop_delegate_) | 89 |
| 88 backdrop_delegate_->OnWindowAddedToLayout(WmWindow::Get(child)); | 90 backdrop_controller_->OnWindowAddedToLayout(child); |
| 89 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); | 91 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); |
| 90 if (Shell::Get()->screen_pinning_controller()->IsPinned()) | 92 if (Shell::Get()->screen_pinning_controller()->IsPinned()) |
| 91 wm::GetWindowState(child)->DisableAlwaysOnTop(nullptr); | 93 wm::GetWindowState(child)->DisableAlwaysOnTop(nullptr); |
| 92 } | 94 } |
| 93 | 95 |
| 94 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | 96 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
| 95 windows_.erase(child); | 97 windows_.erase(child); |
| 96 child->RemoveObserver(this); | 98 child->RemoveObserver(this); |
| 97 wm::GetWindowState(child)->RemoveObserver(this); | 99 wm::GetWindowState(child)->RemoveObserver(this); |
| 98 | 100 |
| 99 if (child->layer()->GetTargetVisibility()) | 101 if (child->layer()->GetTargetVisibility()) |
| 100 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( | 102 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( |
| 101 WmWindow::Get(child)); | 103 WmWindow::Get(child)); |
| 102 } | 104 } |
| 103 | 105 |
| 104 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 106 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
| 105 UpdateShelfVisibility(); | 107 UpdateShelfVisibility(); |
| 106 UpdateFullscreenState(); | 108 UpdateFullscreenState(); |
| 107 if (backdrop_delegate_) | 109 backdrop_controller_->OnWindowRemovedFromLayout(child); |
| 108 backdrop_delegate_->OnWindowRemovedFromLayout(WmWindow::Get(child)); | |
| 109 } | 110 } |
| 110 | 111 |
| 111 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 112 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
| 112 bool visible) { | 113 bool visible) { |
| 113 wm::WindowState* window_state = wm::GetWindowState(child); | 114 wm::WindowState* window_state = wm::GetWindowState(child); |
| 114 // Attempting to show a minimized window. Unminimize it. | 115 // Attempting to show a minimized window. Unminimize it. |
| 115 if (visible && window_state->IsMinimized()) | 116 if (visible && window_state->IsMinimized()) |
| 116 window_state->Unminimize(); | 117 window_state->Unminimize(); |
| 117 | 118 |
| 118 if (child->layer()->GetTargetVisibility()) | 119 if (child->layer()->GetTargetVisibility()) |
| 119 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); | 120 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); |
| 120 else | 121 else |
| 121 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( | 122 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( |
| 122 WmWindow::Get(child)); | 123 WmWindow::Get(child)); |
| 123 UpdateFullscreenState(); | 124 UpdateFullscreenState(); |
| 124 UpdateShelfVisibility(); | 125 UpdateShelfVisibility(); |
| 125 if (backdrop_delegate_) { | 126 backdrop_controller_->OnChildWindowVisibilityChanged(child, visible); |
| 126 backdrop_delegate_->OnChildWindowVisibilityChanged(WmWindow::Get(child), | |
| 127 visible); | |
| 128 } | |
| 129 } | 127 } |
| 130 | 128 |
| 131 void WorkspaceLayoutManager::SetChildBounds(aura::Window* child, | 129 void WorkspaceLayoutManager::SetChildBounds(aura::Window* child, |
| 132 const gfx::Rect& requested_bounds) { | 130 const gfx::Rect& requested_bounds) { |
| 133 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); | 131 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); |
| 134 wm::GetWindowState(child)->OnWMEvent(&event); | 132 wm::GetWindowState(child)->OnWMEvent(&event); |
| 135 UpdateShelfVisibility(); | 133 UpdateShelfVisibility(); |
| 136 } | 134 } |
| 137 | 135 |
| 138 ////////////////////////////////////////////////////////////////////////////// | 136 ////////////////////////////////////////////////////////////////////////////// |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // the fullscreen state accordingly. | 207 // the fullscreen state accordingly. |
| 210 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { | 208 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { |
| 211 UpdateFullscreenState(); | 209 UpdateFullscreenState(); |
| 212 UpdateShelfVisibility(); | 210 UpdateShelfVisibility(); |
| 213 } | 211 } |
| 214 } | 212 } |
| 215 | 213 |
| 216 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 214 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 217 const void* key, | 215 const void* key, |
| 218 intptr_t old) { | 216 intptr_t old) { |
| 219 if (key == aura::client::kAlwaysOnTopKey && | 217 if (key == aura::client::kAlwaysOnTopKey) { |
| 220 window->GetProperty(aura::client::kAlwaysOnTopKey)) { | 218 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) { |
| 221 aura::Window* container = | 219 aura::Window* container = |
| 222 root_window_controller_->always_on_top_controller() | 220 root_window_controller_->always_on_top_controller() |
| 223 ->GetContainer(WmWindow::Get(window)) | 221 ->GetContainer(WmWindow::Get(window)) |
| 224 ->aura_window(); | 222 ->aura_window(); |
| 225 if (window->parent() != container) | 223 if (window->parent() != container) |
| 226 container->AddChild(window); | 224 container->AddChild(window); |
| 225 } |
| 226 } else if (key == aura::client::kHasBackdrop) { |
| 227 backdrop_controller_->UpdateBackdrop(); |
| 227 } | 228 } |
| 228 } | 229 } |
| 229 | 230 |
| 230 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { | 231 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { |
| 231 UpdateShelfVisibility(); | 232 UpdateShelfVisibility(); |
| 232 UpdateFullscreenState(); | 233 UpdateFullscreenState(); |
| 233 if (backdrop_delegate_) | 234 backdrop_controller_->OnWindowStackingChanged(window); |
| 234 backdrop_delegate_->OnWindowStackingChanged(WmWindow::Get(window)); | |
| 235 } | 235 } |
| 236 | 236 |
| 237 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { | 237 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 238 if (root_window_ == window) { | 238 if (root_window_ == window) { |
| 239 root_window_->RemoveObserver(this); | 239 root_window_->RemoveObserver(this); |
| 240 root_window_ = nullptr; | 240 root_window_ = nullptr; |
| 241 } | 241 } |
| 242 } | 242 } |
| 243 | 243 |
| 244 void WorkspaceLayoutManager::OnWindowBoundsChanged( | 244 void WorkspaceLayoutManager::OnWindowBoundsChanged( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 275 void WorkspaceLayoutManager::OnPostWindowStateTypeChange( | 275 void WorkspaceLayoutManager::OnPostWindowStateTypeChange( |
| 276 wm::WindowState* window_state, | 276 wm::WindowState* window_state, |
| 277 wm::WindowStateType old_type) { | 277 wm::WindowStateType old_type) { |
| 278 // Notify observers that fullscreen state may be changing. | 278 // Notify observers that fullscreen state may be changing. |
| 279 if (window_state->IsFullscreen() || | 279 if (window_state->IsFullscreen() || |
| 280 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { | 280 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 281 UpdateFullscreenState(); | 281 UpdateFullscreenState(); |
| 282 } | 282 } |
| 283 | 283 |
| 284 UpdateShelfVisibility(); | 284 UpdateShelfVisibility(); |
| 285 if (backdrop_delegate_) | 285 backdrop_controller_->OnPostWindowStateTypeChange(window_state, old_type); |
| 286 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); | |
| 287 } | 286 } |
| 288 | 287 |
| 289 ////////////////////////////////////////////////////////////////////////////// | 288 ////////////////////////////////////////////////////////////////////////////// |
| 290 // WorkspaceLayoutManager, display::DisplayObserver implementation: | 289 // WorkspaceLayoutManager, display::DisplayObserver implementation: |
| 291 | 290 |
| 292 void WorkspaceLayoutManager::OnDisplayMetricsChanged( | 291 void WorkspaceLayoutManager::OnDisplayMetricsChanged( |
| 293 const display::Display& display, | 292 const display::Display& display, |
| 294 uint32_t changed_metrics) { | 293 uint32_t changed_metrics) { |
| 295 if (display::Screen::GetScreen()->GetDisplayNearestWindow(window_).id() != | 294 if (display::Screen::GetScreen()->GetDisplayNearestWindow(window_).id() != |
| 296 display.id()) { | 295 display.id()) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 for (aura::Window* window : windows) { | 402 for (aura::Window* window : windows) { |
| 404 wm::WindowState* window_state = wm::GetWindowState(window); | 403 wm::WindowState* window_state = wm::GetWindowState(window); |
| 405 if (window_on_top) | 404 if (window_on_top) |
| 406 window_state->DisableAlwaysOnTop(WmWindow::Get(window_on_top)); | 405 window_state->DisableAlwaysOnTop(WmWindow::Get(window_on_top)); |
| 407 else | 406 else |
| 408 window_state->RestoreAlwaysOnTop(); | 407 window_state->RestoreAlwaysOnTop(); |
| 409 } | 408 } |
| 410 } | 409 } |
| 411 | 410 |
| 412 } // namespace ash | 411 } // namespace ash |
| OLD | NEW |