| 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_ = |
| 55 base::MakeUnique<BackdropController>(WmWindow::Get(window_)); |
| 53 } | 56 } |
| 54 | 57 |
| 55 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 58 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
| 56 if (root_window_) | 59 if (root_window_) |
| 57 root_window_->RemoveObserver(this); | 60 root_window_->RemoveObserver(this); |
| 58 for (aura::Window* window : windows_) { | 61 for (aura::Window* window : windows_) { |
| 59 wm::WindowState* window_state = wm::GetWindowState(window); | 62 wm::WindowState* window_state = wm::GetWindowState(window); |
| 60 window_state->RemoveObserver(this); | 63 window_state->RemoveObserver(this); |
| 61 window->RemoveObserver(this); | 64 window->RemoveObserver(this); |
| 62 } | 65 } |
| 63 display::Screen::GetScreen()->RemoveObserver(this); | 66 display::Screen::GetScreen()->RemoveObserver(this); |
| 64 Shell::Get()->activation_client()->RemoveObserver(this); | 67 Shell::Get()->activation_client()->RemoveObserver(this); |
| 65 Shell::Get()->RemoveShellObserver(this); | 68 Shell::Get()->RemoveShellObserver(this); |
| 66 } | 69 } |
| 67 | 70 |
| 68 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( | 71 void WorkspaceLayoutManager::SetBackdropDelegate( |
| 69 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 72 std::unique_ptr<BackdropDelegate> delegate) { |
| 70 backdrop_delegate_ = std::move(delegate); | 73 backdrop_controller_->SetBackdropDelegate(std::move(delegate)); |
| 71 } | 74 } |
| 72 | 75 |
| 73 ////////////////////////////////////////////////////////////////////////////// | 76 ////////////////////////////////////////////////////////////////////////////// |
| 74 // WorkspaceLayoutManager, aura::LayoutManager implementation: | 77 // WorkspaceLayoutManager, aura::LayoutManager implementation: |
| 75 | 78 |
| 76 void WorkspaceLayoutManager::OnWindowResized() {} | 79 void WorkspaceLayoutManager::OnWindowResized() {} |
| 77 | 80 |
| 78 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 81 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 79 wm::WindowState* window_state = wm::GetWindowState(child); | 82 wm::WindowState* window_state = wm::GetWindowState(child); |
| 80 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | 83 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
| 81 window_state->OnWMEvent(&event); | 84 window_state->OnWMEvent(&event); |
| 82 windows_.insert(child); | 85 windows_.insert(child); |
| 83 child->AddObserver(this); | 86 child->AddObserver(this); |
| 84 window_state->AddObserver(this); | 87 window_state->AddObserver(this); |
| 85 UpdateShelfVisibility(); | 88 UpdateShelfVisibility(); |
| 86 UpdateFullscreenState(); | 89 UpdateFullscreenState(); |
| 87 if (backdrop_delegate_) | 90 |
| 88 backdrop_delegate_->OnWindowAddedToLayout(WmWindow::Get(child)); | 91 backdrop_controller_->OnWindowAddedToLayout(child); |
| 89 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); | 92 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); |
| 90 if (Shell::Get()->screen_pinning_controller()->IsPinned()) | 93 if (Shell::Get()->screen_pinning_controller()->IsPinned()) |
| 91 wm::GetWindowState(child)->DisableAlwaysOnTop(nullptr); | 94 wm::GetWindowState(child)->DisableAlwaysOnTop(nullptr); |
| 92 } | 95 } |
| 93 | 96 |
| 94 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | 97 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
| 95 windows_.erase(child); | 98 windows_.erase(child); |
| 96 child->RemoveObserver(this); | 99 child->RemoveObserver(this); |
| 97 wm::GetWindowState(child)->RemoveObserver(this); | 100 wm::GetWindowState(child)->RemoveObserver(this); |
| 98 | 101 |
| 99 if (child->layer()->GetTargetVisibility()) | 102 if (child->layer()->GetTargetVisibility()) |
| 100 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( | 103 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( |
| 101 WmWindow::Get(child)); | 104 WmWindow::Get(child)); |
| 102 } | 105 } |
| 103 | 106 |
| 104 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 107 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
| 105 UpdateShelfVisibility(); | 108 UpdateShelfVisibility(); |
| 106 UpdateFullscreenState(); | 109 UpdateFullscreenState(); |
| 107 if (backdrop_delegate_) | 110 backdrop_controller_->OnWindowRemovedFromLayout(child); |
| 108 backdrop_delegate_->OnWindowRemovedFromLayout(WmWindow::Get(child)); | |
| 109 } | 111 } |
| 110 | 112 |
| 111 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 113 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
| 112 bool visible) { | 114 bool visible) { |
| 113 wm::WindowState* window_state = wm::GetWindowState(child); | 115 wm::WindowState* window_state = wm::GetWindowState(child); |
| 114 // Attempting to show a minimized window. Unminimize it. | 116 // Attempting to show a minimized window. Unminimize it. |
| 115 if (visible && window_state->IsMinimized()) | 117 if (visible && window_state->IsMinimized()) |
| 116 window_state->Unminimize(); | 118 window_state->Unminimize(); |
| 117 | 119 |
| 118 if (child->layer()->GetTargetVisibility()) | 120 if (child->layer()->GetTargetVisibility()) |
| 119 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); | 121 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); |
| 120 else | 122 else |
| 121 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( | 123 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( |
| 122 WmWindow::Get(child)); | 124 WmWindow::Get(child)); |
| 123 UpdateFullscreenState(); | 125 UpdateFullscreenState(); |
| 124 UpdateShelfVisibility(); | 126 UpdateShelfVisibility(); |
| 125 if (backdrop_delegate_) { | 127 backdrop_controller_->OnChildWindowVisibilityChanged(child, visible); |
| 126 backdrop_delegate_->OnChildWindowVisibilityChanged(WmWindow::Get(child), | |
| 127 visible); | |
| 128 } | |
| 129 } | 128 } |
| 130 | 129 |
| 131 void WorkspaceLayoutManager::SetChildBounds(aura::Window* child, | 130 void WorkspaceLayoutManager::SetChildBounds(aura::Window* child, |
| 132 const gfx::Rect& requested_bounds) { | 131 const gfx::Rect& requested_bounds) { |
| 133 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); | 132 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); |
| 134 wm::GetWindowState(child)->OnWMEvent(&event); | 133 wm::GetWindowState(child)->OnWMEvent(&event); |
| 135 UpdateShelfVisibility(); | 134 UpdateShelfVisibility(); |
| 136 } | 135 } |
| 137 | 136 |
| 138 ////////////////////////////////////////////////////////////////////////////// | 137 ////////////////////////////////////////////////////////////////////////////// |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 // the fullscreen state accordingly. | 208 // the fullscreen state accordingly. |
| 210 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { | 209 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { |
| 211 UpdateFullscreenState(); | 210 UpdateFullscreenState(); |
| 212 UpdateShelfVisibility(); | 211 UpdateShelfVisibility(); |
| 213 } | 212 } |
| 214 } | 213 } |
| 215 | 214 |
| 216 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 215 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 217 const void* key, | 216 const void* key, |
| 218 intptr_t old) { | 217 intptr_t old) { |
| 219 if (key == aura::client::kAlwaysOnTopKey && | 218 if (key == aura::client::kAlwaysOnTopKey) { |
| 220 window->GetProperty(aura::client::kAlwaysOnTopKey)) { | 219 if (window->GetProperty(aura::client::kAlwaysOnTopKey)) { |
| 221 aura::Window* container = | 220 aura::Window* container = |
| 222 root_window_controller_->always_on_top_controller() | 221 root_window_controller_->always_on_top_controller() |
| 223 ->GetContainer(WmWindow::Get(window)) | 222 ->GetContainer(WmWindow::Get(window)) |
| 224 ->aura_window(); | 223 ->aura_window(); |
| 225 if (window->parent() != container) | 224 if (window->parent() != container) |
| 226 container->AddChild(window); | 225 container->AddChild(window); |
| 226 } |
| 227 } else if (key == aura::client::kHasBackdrop) { |
| 228 backdrop_controller_->UpdateBackdrop(); |
| 227 } | 229 } |
| 228 } | 230 } |
| 229 | 231 |
| 230 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { | 232 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { |
| 231 UpdateShelfVisibility(); | 233 UpdateShelfVisibility(); |
| 232 UpdateFullscreenState(); | 234 UpdateFullscreenState(); |
| 233 if (backdrop_delegate_) | 235 backdrop_controller_->OnWindowStackingChanged(window); |
| 234 backdrop_delegate_->OnWindowStackingChanged(WmWindow::Get(window)); | |
| 235 } | 236 } |
| 236 | 237 |
| 237 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { | 238 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 238 if (root_window_ == window) { | 239 if (root_window_ == window) { |
| 239 root_window_->RemoveObserver(this); | 240 root_window_->RemoveObserver(this); |
| 240 root_window_ = nullptr; | 241 root_window_ = nullptr; |
| 241 } | 242 } |
| 242 } | 243 } |
| 243 | 244 |
| 244 void WorkspaceLayoutManager::OnWindowBoundsChanged( | 245 void WorkspaceLayoutManager::OnWindowBoundsChanged( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 275 void WorkspaceLayoutManager::OnPostWindowStateTypeChange( | 276 void WorkspaceLayoutManager::OnPostWindowStateTypeChange( |
| 276 wm::WindowState* window_state, | 277 wm::WindowState* window_state, |
| 277 wm::WindowStateType old_type) { | 278 wm::WindowStateType old_type) { |
| 278 // Notify observers that fullscreen state may be changing. | 279 // Notify observers that fullscreen state may be changing. |
| 279 if (window_state->IsFullscreen() || | 280 if (window_state->IsFullscreen() || |
| 280 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { | 281 old_type == wm::WINDOW_STATE_TYPE_FULLSCREEN) { |
| 281 UpdateFullscreenState(); | 282 UpdateFullscreenState(); |
| 282 } | 283 } |
| 283 | 284 |
| 284 UpdateShelfVisibility(); | 285 UpdateShelfVisibility(); |
| 285 if (backdrop_delegate_) | 286 backdrop_controller_->OnPostWindowStateTypeChange(window_state, old_type); |
| 286 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); | |
| 287 } | 287 } |
| 288 | 288 |
| 289 ////////////////////////////////////////////////////////////////////////////// | 289 ////////////////////////////////////////////////////////////////////////////// |
| 290 // WorkspaceLayoutManager, display::DisplayObserver implementation: | 290 // WorkspaceLayoutManager, display::DisplayObserver implementation: |
| 291 | 291 |
| 292 void WorkspaceLayoutManager::OnDisplayMetricsChanged( | 292 void WorkspaceLayoutManager::OnDisplayMetricsChanged( |
| 293 const display::Display& display, | 293 const display::Display& display, |
| 294 uint32_t changed_metrics) { | 294 uint32_t changed_metrics) { |
| 295 if (display::Screen::GetScreen()->GetDisplayNearestWindow(window_).id() != | 295 if (display::Screen::GetScreen()->GetDisplayNearestWindow(window_).id() != |
| 296 display.id()) { | 296 display.id()) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 403 for (aura::Window* window : windows) { | 403 for (aura::Window* window : windows) { |
| 404 wm::WindowState* window_state = wm::GetWindowState(window); | 404 wm::WindowState* window_state = wm::GetWindowState(window); |
| 405 if (window_on_top) | 405 if (window_on_top) |
| 406 window_state->DisableAlwaysOnTop(WmWindow::Get(window_on_top)); | 406 window_state->DisableAlwaysOnTop(WmWindow::Get(window_on_top)); |
| 407 else | 407 else |
| 408 window_state->RestoreAlwaysOnTop(); | 408 window_state->RestoreAlwaysOnTop(); |
| 409 } | 409 } |
| 410 } | 410 } |
| 411 | 411 |
| 412 } // namespace ash | 412 } // namespace ash |
| OLD | NEW |