| 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/wm/always_on_top_controller.h" | 11 #include "ash/common/wm/always_on_top_controller.h" |
| 12 #include "ash/common/wm/fullscreen_window_finder.h" | 12 #include "ash/common/wm/fullscreen_window_finder.h" |
| 13 #include "ash/common/wm/window_positioner.h" | 13 #include "ash/common/wm/window_positioner.h" |
| 14 #include "ash/common/wm/window_state.h" | 14 #include "ash/common/wm/window_state.h" |
| 15 #include "ash/common/wm/wm_event.h" | 15 #include "ash/common/wm/wm_event.h" |
| 16 #include "ash/common/wm/wm_screen_util.h" | 16 #include "ash/common/wm/wm_screen_util.h" |
| 17 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" | 17 #include "ash/common/wm/workspace/workspace_layout_manager_backdrop_delegate.h" |
| 18 #include "ash/common/wm_shell.h" | 18 #include "ash/common/wm_shell.h" |
| 19 #include "ash/common/wm_window.h" | 19 #include "ash/common/wm_window.h" |
| 20 #include "ash/common/wm_window_property.h" | 20 #include "ash/common/wm_window_property.h" |
| 21 #include "ash/public/cpp/shell_window_ids.h" | 21 #include "ash/public/cpp/shell_window_ids.h" |
| 22 #include "ash/root_window_controller.h" | 22 #include "ash/root_window_controller.h" |
| 23 #include "ash/wm/window_state_aura.h" |
| 23 #include "base/command_line.h" | 24 #include "base/command_line.h" |
| 25 #include "ui/aura/client/aura_constants.h" |
| 24 #include "ui/base/ui_base_switches.h" | 26 #include "ui/base/ui_base_switches.h" |
| 25 #include "ui/compositor/layer.h" | 27 #include "ui/compositor/layer.h" |
| 26 #include "ui/display/display.h" | 28 #include "ui/display/display.h" |
| 27 #include "ui/display/screen.h" | 29 #include "ui/display/screen.h" |
| 28 #include "ui/keyboard/keyboard_controller.h" | 30 #include "ui/keyboard/keyboard_controller.h" |
| 29 #include "ui/keyboard/keyboard_controller_observer.h" | 31 #include "ui/keyboard/keyboard_controller_observer.h" |
| 30 | 32 |
| 31 namespace ash { | 33 namespace ash { |
| 32 | 34 |
| 33 WorkspaceLayoutManager::WorkspaceLayoutManager(WmWindow* window) | 35 WorkspaceLayoutManager::WorkspaceLayoutManager(WmWindow* window) |
| 34 : window_(window), | 36 : window_(window), |
| 35 root_window_(window->GetRootWindow()), | 37 root_window_(window->GetRootWindow()), |
| 36 root_window_controller_(root_window_->GetRootWindowController()), | 38 root_window_controller_(root_window_->GetRootWindowController()), |
| 37 shell_(window_->GetShell()), | 39 shell_(window_->GetShell()), |
| 38 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), | 40 work_area_in_parent_(wm::GetDisplayWorkAreaBounds(window_)), |
| 39 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { | 41 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr) { |
| 40 shell_->AddShellObserver(this); | 42 shell_->AddShellObserver(this); |
| 41 shell_->AddActivationObserver(this); | 43 shell_->AddActivationObserver(this); |
| 42 root_window_->AddObserver(this); | 44 root_window_->aura_window()->AddObserver(this); |
| 43 display::Screen::GetScreen()->AddObserver(this); | 45 display::Screen::GetScreen()->AddObserver(this); |
| 44 DCHECK(window->GetBoolProperty( | 46 DCHECK(window->GetBoolProperty( |
| 45 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); | 47 WmWindowProperty::SNAP_CHILDREN_TO_PIXEL_BOUNDARY)); |
| 46 } | 48 } |
| 47 | 49 |
| 48 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 50 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
| 49 if (root_window_) | 51 if (root_window_) |
| 50 root_window_->RemoveObserver(this); | 52 root_window_->aura_window()->RemoveObserver(this); |
| 51 for (WmWindow* window : windows_) { | 53 for (WmWindow* window : windows_) { |
| 52 wm::WindowState* window_state = window->GetWindowState(); | 54 wm::WindowState* window_state = window->GetWindowState(); |
| 53 window_state->RemoveObserver(this); | 55 window_state->RemoveObserver(this); |
| 54 window->RemoveObserver(this); | 56 window->aura_window()->RemoveObserver(this); |
| 55 } | 57 } |
| 56 display::Screen::GetScreen()->RemoveObserver(this); | 58 display::Screen::GetScreen()->RemoveObserver(this); |
| 57 shell_->RemoveActivationObserver(this); | 59 shell_->RemoveActivationObserver(this); |
| 58 shell_->RemoveShellObserver(this); | 60 shell_->RemoveShellObserver(this); |
| 59 } | 61 } |
| 60 | 62 |
| 61 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( | 63 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( |
| 62 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 64 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { |
| 63 backdrop_delegate_ = std::move(delegate); | 65 backdrop_delegate_ = std::move(delegate); |
| 64 } | 66 } |
| 65 | 67 |
| 66 ////////////////////////////////////////////////////////////////////////////// | 68 ////////////////////////////////////////////////////////////////////////////// |
| 67 // WorkspaceLayoutManager, aura::LayoutManager implementation: | 69 // WorkspaceLayoutManager, aura::LayoutManager implementation: |
| 68 | 70 |
| 69 void WorkspaceLayoutManager::OnWindowResized() {} | 71 void WorkspaceLayoutManager::OnWindowResized() {} |
| 70 | 72 |
| 71 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) { | 73 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) { |
| 72 wm::WindowState* window_state = child->GetWindowState(); | 74 wm::WindowState* window_state = child->GetWindowState(); |
| 73 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | 75 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
| 74 window_state->OnWMEvent(&event); | 76 window_state->OnWMEvent(&event); |
| 75 windows_.insert(child); | 77 windows_.insert(child); |
| 76 child->AddObserver(this); | 78 child->aura_window()->AddObserver(this); |
| 77 window_state->AddObserver(this); | 79 window_state->AddObserver(this); |
| 78 UpdateShelfVisibility(); | 80 UpdateShelfVisibility(); |
| 79 UpdateFullscreenState(); | 81 UpdateFullscreenState(); |
| 80 if (backdrop_delegate_) | 82 if (backdrop_delegate_) |
| 81 backdrop_delegate_->OnWindowAddedToLayout(child); | 83 backdrop_delegate_->OnWindowAddedToLayout(child); |
| 82 WindowPositioner::RearrangeVisibleWindowOnShow(child); | 84 WindowPositioner::RearrangeVisibleWindowOnShow(child); |
| 83 if (WmShell::Get()->IsPinned()) | 85 if (WmShell::Get()->IsPinned()) |
| 84 child->GetWindowState()->DisableAlwaysOnTop(nullptr); | 86 child->GetWindowState()->DisableAlwaysOnTop(nullptr); |
| 85 } | 87 } |
| 86 | 88 |
| 87 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) { | 89 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) { |
| 88 windows_.erase(child); | 90 windows_.erase(child); |
| 89 child->RemoveObserver(this); | 91 child->aura_window()->RemoveObserver(this); |
| 90 child->GetWindowState()->RemoveObserver(this); | 92 child->GetWindowState()->RemoveObserver(this); |
| 91 | 93 |
| 92 if (child->GetTargetVisibility()) | 94 if (child->GetTargetVisibility()) |
| 93 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); | 95 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); |
| 94 } | 96 } |
| 95 | 97 |
| 96 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(WmWindow* child) { | 98 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(WmWindow* child) { |
| 97 UpdateShelfVisibility(); | 99 UpdateShelfVisibility(); |
| 98 UpdateFullscreenState(); | 100 UpdateFullscreenState(); |
| 99 if (backdrop_delegate_) | 101 if (backdrop_delegate_) |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 // override user intent. | 175 // override user intent. |
| 174 window_state->SetAndClearRestoreBounds(); | 176 window_state->SetAndClearRestoreBounds(); |
| 175 } | 177 } |
| 176 } | 178 } |
| 177 | 179 |
| 178 void WorkspaceLayoutManager::OnKeyboardClosed() {} | 180 void WorkspaceLayoutManager::OnKeyboardClosed() {} |
| 179 | 181 |
| 180 ////////////////////////////////////////////////////////////////////////////// | 182 ////////////////////////////////////////////////////////////////////////////// |
| 181 // WorkspaceLayoutManager, aura::WindowObserver implementation: | 183 // WorkspaceLayoutManager, aura::WindowObserver implementation: |
| 182 | 184 |
| 183 void WorkspaceLayoutManager::OnWindowTreeChanged( | 185 void WorkspaceLayoutManager::OnWindowHierarchyChanged( |
| 184 WmWindow* window, | 186 const HierarchyChangeParams& params) { |
| 185 const WmWindowObserver::TreeChangeParams& params) { | 187 if (!wm::GetWindowState(params.target)->IsActive()) |
| 186 if (!params.target->GetWindowState()->IsActive()) | |
| 187 return; | 188 return; |
| 188 // If the window is already tracked by the workspace this update would be | 189 // If the window is already tracked by the workspace this update would be |
| 189 // redundant as the fullscreen and shelf state would have been handled in | 190 // redundant as the fullscreen and shelf state would have been handled in |
| 190 // OnWindowAddedToLayout. | 191 // OnWindowAddedToLayout. |
| 191 if (windows_.find(params.target) != windows_.end()) | 192 if (windows_.find(WmWindow::Get(params.target)) != windows_.end()) |
| 192 return; | 193 return; |
| 193 | 194 |
| 194 // If the active window has moved to this root window then update the | 195 // If the active window has moved to this root window then update the |
| 195 // fullscreen state. | 196 // fullscreen state. |
| 196 // TODO(flackr): Track the active window leaving this root window and update | 197 // TODO(flackr): Track the active window leaving this root window and update |
| 197 // the fullscreen state accordingly. | 198 // the fullscreen state accordingly. |
| 198 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { | 199 if (params.new_parent && |
| 200 WmWindow::Get(params.new_parent->GetRootWindow()) == root_window_) { |
| 199 UpdateFullscreenState(); | 201 UpdateFullscreenState(); |
| 200 UpdateShelfVisibility(); | 202 UpdateShelfVisibility(); |
| 201 } | 203 } |
| 202 } | 204 } |
| 203 | 205 |
| 204 void WorkspaceLayoutManager::OnWindowPropertyChanged( | 206 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 205 WmWindow* window, | 207 const void* key, |
| 206 WmWindowProperty property) { | 208 intptr_t old) { |
| 207 if (property == WmWindowProperty::ALWAYS_ON_TOP && | 209 if (key == aura::client::kAlwaysOnTopKey && |
| 208 window->GetBoolProperty(WmWindowProperty::ALWAYS_ON_TOP)) { | 210 window->GetProperty(aura::client::kAlwaysOnTopKey)) { |
| 209 WmWindow* container = | 211 WmWindow* container = |
| 210 root_window_controller_->always_on_top_controller()->GetContainer( | 212 root_window_controller_->always_on_top_controller()->GetContainer( |
| 211 window); | 213 WmWindow::Get(window)); |
| 212 if (window->GetParent() != container) | 214 if (WmWindow::Get(window->parent()) != container) |
| 213 container->AddChild(window); | 215 container->AddChild(WmWindow::Get(window)); |
| 214 } | 216 } |
| 215 } | 217 } |
| 216 | 218 |
| 217 void WorkspaceLayoutManager::OnWindowStackingChanged(WmWindow* window) { | 219 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { |
| 218 UpdateShelfVisibility(); | 220 UpdateShelfVisibility(); |
| 219 UpdateFullscreenState(); | 221 UpdateFullscreenState(); |
| 220 if (backdrop_delegate_) | 222 if (backdrop_delegate_) |
| 221 backdrop_delegate_->OnWindowStackingChanged(window); | 223 backdrop_delegate_->OnWindowStackingChanged(WmWindow::Get(window)); |
| 222 } | 224 } |
| 223 | 225 |
| 224 void WorkspaceLayoutManager::OnWindowDestroying(WmWindow* window) { | 226 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 225 if (root_window_ == window) { | 227 if (root_window_ == WmWindow::Get(window)) { |
| 226 root_window_->RemoveObserver(this); | 228 root_window_->aura_window()->RemoveObserver(this); |
| 227 root_window_ = nullptr; | 229 root_window_ = nullptr; |
| 228 } | 230 } |
| 229 } | 231 } |
| 230 | 232 |
| 231 void WorkspaceLayoutManager::OnWindowBoundsChanged( | 233 void WorkspaceLayoutManager::OnWindowBoundsChanged( |
| 232 WmWindow* window, | 234 aura::Window* window, |
| 233 const gfx::Rect& old_bounds, | 235 const gfx::Rect& old_bounds, |
| 234 const gfx::Rect& new_bounds) { | 236 const gfx::Rect& new_bounds) { |
| 235 if (root_window_ == window) { | 237 if (root_window_ == WmWindow::Get(window)) { |
| 236 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); | 238 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); |
| 237 AdjustAllWindowsBoundsForWorkAreaChange(&wm_event); | 239 AdjustAllWindowsBoundsForWorkAreaChange(&wm_event); |
| 238 } | 240 } |
| 239 } | 241 } |
| 240 | 242 |
| 241 ////////////////////////////////////////////////////////////////////////////// | 243 ////////////////////////////////////////////////////////////////////////////// |
| 242 // WorkspaceLayoutManager, | 244 // WorkspaceLayoutManager, |
| 243 // aura::client::ActivationChangeObserver implementation: | 245 // aura::client::ActivationChangeObserver implementation: |
| 244 | 246 |
| 245 void WorkspaceLayoutManager::OnWindowActivated(WmWindow* gained_active, | 247 void WorkspaceLayoutManager::OnWindowActivated(WmWindow* gained_active, |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 for (auto* window : windows) { | 379 for (auto* window : windows) { |
| 378 wm::WindowState* window_state = window->GetWindowState(); | 380 wm::WindowState* window_state = window->GetWindowState(); |
| 379 if (window_on_top) | 381 if (window_on_top) |
| 380 window_state->DisableAlwaysOnTop(window_on_top); | 382 window_state->DisableAlwaysOnTop(window_on_top); |
| 381 else | 383 else |
| 382 window_state->RestoreAlwaysOnTop(); | 384 window_state->RestoreAlwaysOnTop(); |
| 383 } | 385 } |
| 384 } | 386 } |
| 385 | 387 |
| 386 } // namespace ash | 388 } // namespace ash |
| OLD | NEW |