| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 #include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h" | 25 #include "ash/wm/workspace/workspace_layout_manager_backdrop_delegate.h" |
| 26 #include "ash/wm_window.h" | 26 #include "ash/wm_window.h" |
| 27 #include "base/command_line.h" | 27 #include "base/command_line.h" |
| 28 #include "ui/aura/client/aura_constants.h" | 28 #include "ui/aura/client/aura_constants.h" |
| 29 #include "ui/base/ui_base_switches.h" | 29 #include "ui/base/ui_base_switches.h" |
| 30 #include "ui/compositor/layer.h" | 30 #include "ui/compositor/layer.h" |
| 31 #include "ui/display/display.h" | 31 #include "ui/display/display.h" |
| 32 #include "ui/display/screen.h" | 32 #include "ui/display/screen.h" |
| 33 #include "ui/keyboard/keyboard_controller.h" | 33 #include "ui/keyboard/keyboard_controller.h" |
| 34 #include "ui/keyboard/keyboard_controller_observer.h" | 34 #include "ui/keyboard/keyboard_controller_observer.h" |
| 35 #include "ui/wm/core/coordinate_conversion.h" |
| 35 #include "ui/wm/public/activation_client.h" | 36 #include "ui/wm/public/activation_client.h" |
| 36 | 37 |
| 37 namespace ash { | 38 namespace ash { |
| 38 | 39 |
| 39 WorkspaceLayoutManager::WorkspaceLayoutManager(WmWindow* window) | 40 WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window) |
| 40 : window_(window), | 41 : window_(window), |
| 41 root_window_(window->GetRootWindow()), | 42 root_window_(window->GetRootWindow()), |
| 42 root_window_controller_(root_window_->GetRootWindowController()), | 43 root_window_controller_(RootWindowController::ForWindow(root_window_)), |
| 43 work_area_in_parent_( | 44 work_area_in_parent_( |
| 44 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_->aura_window())), | 45 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_)), |
| 45 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr), | 46 is_fullscreen_(wm::GetWindowForFullscreenMode(window) != nullptr), |
| 46 keyboard_observer_(this) { | 47 keyboard_observer_(this) { |
| 47 Shell::Get()->AddShellObserver(this); | 48 Shell::Get()->AddShellObserver(this); |
| 48 Shell::Get()->activation_client()->AddObserver(this); | 49 Shell::Get()->activation_client()->AddObserver(this); |
| 49 root_window_->aura_window()->AddObserver(this); | 50 root_window_->AddObserver(this); |
| 50 display::Screen::GetScreen()->AddObserver(this); | 51 display::Screen::GetScreen()->AddObserver(this); |
| 51 DCHECK(window->aura_window()->GetProperty(kSnapChildrenToPixelBoundary)); | 52 DCHECK(window->GetProperty(kSnapChildrenToPixelBoundary)); |
| 52 } | 53 } |
| 53 | 54 |
| 54 WorkspaceLayoutManager::~WorkspaceLayoutManager() { | 55 WorkspaceLayoutManager::~WorkspaceLayoutManager() { |
| 55 if (root_window_) | 56 if (root_window_) |
| 56 root_window_->aura_window()->RemoveObserver(this); | 57 root_window_->RemoveObserver(this); |
| 57 for (WmWindow* window : windows_) { | 58 for (aura::Window* window : windows_) { |
| 58 wm::WindowState* window_state = window->GetWindowState(); | 59 wm::WindowState* window_state = wm::GetWindowState(window); |
| 59 window_state->RemoveObserver(this); | 60 window_state->RemoveObserver(this); |
| 60 window->aura_window()->RemoveObserver(this); | 61 window->RemoveObserver(this); |
| 61 } | 62 } |
| 62 display::Screen::GetScreen()->RemoveObserver(this); | 63 display::Screen::GetScreen()->RemoveObserver(this); |
| 63 Shell::Get()->activation_client()->RemoveObserver(this); | 64 Shell::Get()->activation_client()->RemoveObserver(this); |
| 64 Shell::Get()->RemoveShellObserver(this); | 65 Shell::Get()->RemoveShellObserver(this); |
| 65 } | 66 } |
| 66 | 67 |
| 67 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( | 68 void WorkspaceLayoutManager::SetMaximizeBackdropDelegate( |
| 68 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { | 69 std::unique_ptr<WorkspaceLayoutManagerBackdropDelegate> delegate) { |
| 69 backdrop_delegate_ = std::move(delegate); | 70 backdrop_delegate_ = std::move(delegate); |
| 70 } | 71 } |
| 71 | 72 |
| 72 ////////////////////////////////////////////////////////////////////////////// | 73 ////////////////////////////////////////////////////////////////////////////// |
| 73 // WorkspaceLayoutManager, aura::LayoutManager implementation: | 74 // WorkspaceLayoutManager, aura::LayoutManager implementation: |
| 74 | 75 |
| 75 void WorkspaceLayoutManager::OnWindowResized() {} | 76 void WorkspaceLayoutManager::OnWindowResized() {} |
| 76 | 77 |
| 77 void WorkspaceLayoutManager::OnWindowAddedToLayout(WmWindow* child) { | 78 void WorkspaceLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 78 wm::WindowState* window_state = child->GetWindowState(); | 79 wm::WindowState* window_state = wm::GetWindowState(child); |
| 79 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); | 80 wm::WMEvent event(wm::WM_EVENT_ADDED_TO_WORKSPACE); |
| 80 window_state->OnWMEvent(&event); | 81 window_state->OnWMEvent(&event); |
| 81 windows_.insert(child); | 82 windows_.insert(child); |
| 82 child->aura_window()->AddObserver(this); | 83 child->AddObserver(this); |
| 83 window_state->AddObserver(this); | 84 window_state->AddObserver(this); |
| 84 UpdateShelfVisibility(); | 85 UpdateShelfVisibility(); |
| 85 UpdateFullscreenState(); | 86 UpdateFullscreenState(); |
| 86 if (backdrop_delegate_) | 87 if (backdrop_delegate_) |
| 87 backdrop_delegate_->OnWindowAddedToLayout(child); | 88 backdrop_delegate_->OnWindowAddedToLayout(WmWindow::Get(child)); |
| 88 WindowPositioner::RearrangeVisibleWindowOnShow(child); | 89 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); |
| 89 if (Shell::Get()->screen_pinning_controller()->IsPinned()) | 90 if (Shell::Get()->screen_pinning_controller()->IsPinned()) |
| 90 child->GetWindowState()->DisableAlwaysOnTop(nullptr); | 91 wm::GetWindowState(child)->DisableAlwaysOnTop(nullptr); |
| 91 } | 92 } |
| 92 | 93 |
| 93 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(WmWindow* child) { | 94 void WorkspaceLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
| 94 windows_.erase(child); | 95 windows_.erase(child); |
| 95 child->aura_window()->RemoveObserver(this); | 96 child->RemoveObserver(this); |
| 96 child->GetWindowState()->RemoveObserver(this); | 97 wm::GetWindowState(child)->RemoveObserver(this); |
| 97 | 98 |
| 98 if (child->GetTargetVisibility()) | 99 if (child->layer()->GetTargetVisibility()) |
| 99 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); | 100 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( |
| 101 WmWindow::Get(child)); |
| 100 } | 102 } |
| 101 | 103 |
| 102 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(WmWindow* child) { | 104 void WorkspaceLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
| 103 UpdateShelfVisibility(); | 105 UpdateShelfVisibility(); |
| 104 UpdateFullscreenState(); | 106 UpdateFullscreenState(); |
| 105 if (backdrop_delegate_) | 107 if (backdrop_delegate_) |
| 106 backdrop_delegate_->OnWindowRemovedFromLayout(child); | 108 backdrop_delegate_->OnWindowRemovedFromLayout(WmWindow::Get(child)); |
| 107 } | 109 } |
| 108 | 110 |
| 109 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(WmWindow* child, | 111 void WorkspaceLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
| 110 bool visible) { | 112 bool visible) { |
| 111 wm::WindowState* window_state = child->GetWindowState(); | 113 wm::WindowState* window_state = wm::GetWindowState(child); |
| 112 // Attempting to show a minimized window. Unminimize it. | 114 // Attempting to show a minimized window. Unminimize it. |
| 113 if (visible && window_state->IsMinimized()) | 115 if (visible && window_state->IsMinimized()) |
| 114 window_state->Unminimize(); | 116 window_state->Unminimize(); |
| 115 | 117 |
| 116 if (child->GetTargetVisibility()) | 118 if (child->layer()->GetTargetVisibility()) |
| 117 WindowPositioner::RearrangeVisibleWindowOnShow(child); | 119 WindowPositioner::RearrangeVisibleWindowOnShow(WmWindow::Get(child)); |
| 118 else | 120 else |
| 119 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove(child); | 121 WindowPositioner::RearrangeVisibleWindowOnHideOrRemove( |
| 122 WmWindow::Get(child)); |
| 120 UpdateFullscreenState(); | 123 UpdateFullscreenState(); |
| 121 UpdateShelfVisibility(); | 124 UpdateShelfVisibility(); |
| 122 if (backdrop_delegate_) | 125 if (backdrop_delegate_) { |
| 123 backdrop_delegate_->OnChildWindowVisibilityChanged(child, visible); | 126 backdrop_delegate_->OnChildWindowVisibilityChanged(WmWindow::Get(child), |
| 127 visible); |
| 128 } |
| 124 } | 129 } |
| 125 | 130 |
| 126 void WorkspaceLayoutManager::SetChildBounds(WmWindow* child, | 131 void WorkspaceLayoutManager::SetChildBounds(aura::Window* child, |
| 127 const gfx::Rect& requested_bounds) { | 132 const gfx::Rect& requested_bounds) { |
| 128 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); | 133 wm::SetBoundsEvent event(wm::WM_EVENT_SET_BOUNDS, requested_bounds); |
| 129 child->GetWindowState()->OnWMEvent(&event); | 134 wm::GetWindowState(child)->OnWMEvent(&event); |
| 130 UpdateShelfVisibility(); | 135 UpdateShelfVisibility(); |
| 131 } | 136 } |
| 132 | 137 |
| 133 ////////////////////////////////////////////////////////////////////////////// | 138 ////////////////////////////////////////////////////////////////////////////// |
| 134 // WorkspaceLayoutManager, keyboard::KeyboardControllerObserver implementation: | 139 // WorkspaceLayoutManager, keyboard::KeyboardControllerObserver implementation: |
| 135 | 140 |
| 136 void WorkspaceLayoutManager::OnKeyboardBoundsChanging( | 141 void WorkspaceLayoutManager::OnKeyboardBoundsChanging( |
| 137 const gfx::Rect& new_bounds) { | 142 const gfx::Rect& new_bounds) { |
| 138 // If new window behavior flag enabled and in non-sticky mode, do not change | 143 // If new window behavior flag enabled and in non-sticky mode, do not change |
| 139 // the work area. | 144 // the work area. |
| 140 bool change_work_area = | 145 bool change_work_area = |
| 141 (!base::CommandLine::ForCurrentProcess()->HasSwitch( | 146 (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 142 ::switches::kUseNewVirtualKeyboardBehavior) || | 147 ::switches::kUseNewVirtualKeyboardBehavior) || |
| 143 keyboard::KeyboardController::GetInstance()->keyboard_locked()); | 148 keyboard::KeyboardController::GetInstance()->keyboard_locked()); |
| 144 if (!change_work_area) | 149 if (!change_work_area) |
| 145 return; | 150 return; |
| 146 | 151 |
| 147 WmWindow* window = WmWindow::Get(wm::GetActiveWindow()); | 152 aura::Window* window = wm::GetActiveWindow(); |
| 148 if (!window) | 153 if (!window) |
| 149 return; | 154 return; |
| 150 | 155 |
| 151 window = window->GetToplevelWindow(); | 156 window = window->GetToplevelWindow(); |
| 152 if (!window_->Contains(window)) | 157 if (!window_->Contains(window)) |
| 153 return; | 158 return; |
| 154 | 159 |
| 155 wm::WindowState* window_state = window->GetWindowState(); | 160 wm::WindowState* window_state = wm::GetWindowState(window); |
| 156 if (window_state->ignore_keyboard_bounds_change()) | 161 if (window_state->ignore_keyboard_bounds_change()) |
| 157 return; | 162 return; |
| 158 | 163 |
| 159 if (!new_bounds.IsEmpty()) { | 164 if (!new_bounds.IsEmpty()) { |
| 160 // Store existing bounds to be restored before resizing for keyboard if it | 165 // Store existing bounds to be restored before resizing for keyboard if it |
| 161 // is not already stored. | 166 // is not already stored. |
| 162 if (!window_state->HasRestoreBounds()) | 167 if (!window_state->HasRestoreBounds()) |
| 163 window_state->SaveCurrentBoundsForRestore(); | 168 window_state->SaveCurrentBoundsForRestore(); |
| 164 | 169 |
| 165 gfx::Rect window_bounds = | 170 gfx::Rect window_bounds(window->GetTargetBounds()); |
| 166 window_->ConvertRectToScreen(window->GetTargetBounds()); | 171 ::wm::ConvertRectToScreen(window_, &window_bounds); |
| 167 int vertical_displacement = | 172 int vertical_displacement = |
| 168 std::max(0, window_bounds.bottom() - new_bounds.y()); | 173 std::max(0, window_bounds.bottom() - new_bounds.y()); |
| 169 int shift = std::min(vertical_displacement, | 174 int shift = std::min(vertical_displacement, |
| 170 window_bounds.y() - work_area_in_parent_.y()); | 175 window_bounds.y() - work_area_in_parent_.y()); |
| 171 if (shift > 0) { | 176 if (shift > 0) { |
| 172 gfx::Point origin(window_bounds.x(), window_bounds.y() - shift); | 177 gfx::Point origin(window_bounds.x(), window_bounds.y() - shift); |
| 173 SetChildBounds(window, gfx::Rect(origin, window_bounds.size())); | 178 SetChildBounds(window, gfx::Rect(origin, window_bounds.size())); |
| 174 } | 179 } |
| 175 } else if (window_state->HasRestoreBounds()) { | 180 } else if (window_state->HasRestoreBounds()) { |
| 176 // Keyboard hidden, restore original bounds if they exist. If the user has | 181 // Keyboard hidden, restore original bounds if they exist. If the user has |
| (...skipping 11 matching lines...) Expand all Loading... |
| 188 ////////////////////////////////////////////////////////////////////////////// | 193 ////////////////////////////////////////////////////////////////////////////// |
| 189 // WorkspaceLayoutManager, aura::WindowObserver implementation: | 194 // WorkspaceLayoutManager, aura::WindowObserver implementation: |
| 190 | 195 |
| 191 void WorkspaceLayoutManager::OnWindowHierarchyChanged( | 196 void WorkspaceLayoutManager::OnWindowHierarchyChanged( |
| 192 const HierarchyChangeParams& params) { | 197 const HierarchyChangeParams& params) { |
| 193 if (!wm::GetWindowState(params.target)->IsActive()) | 198 if (!wm::GetWindowState(params.target)->IsActive()) |
| 194 return; | 199 return; |
| 195 // If the window is already tracked by the workspace this update would be | 200 // If the window is already tracked by the workspace this update would be |
| 196 // redundant as the fullscreen and shelf state would have been handled in | 201 // redundant as the fullscreen and shelf state would have been handled in |
| 197 // OnWindowAddedToLayout. | 202 // OnWindowAddedToLayout. |
| 198 if (windows_.find(WmWindow::Get(params.target)) != windows_.end()) | 203 if (windows_.find(params.target) != windows_.end()) |
| 199 return; | 204 return; |
| 200 | 205 |
| 201 // If the active window has moved to this root window then update the | 206 // If the active window has moved to this root window then update the |
| 202 // fullscreen state. | 207 // fullscreen state. |
| 203 // TODO(flackr): Track the active window leaving this root window and update | 208 // TODO(flackr): Track the active window leaving this root window and update |
| 204 // the fullscreen state accordingly. | 209 // the fullscreen state accordingly. |
| 205 if (params.new_parent && | 210 if (params.new_parent && params.new_parent->GetRootWindow() == root_window_) { |
| 206 WmWindow::Get(params.new_parent->GetRootWindow()) == root_window_) { | |
| 207 UpdateFullscreenState(); | 211 UpdateFullscreenState(); |
| 208 UpdateShelfVisibility(); | 212 UpdateShelfVisibility(); |
| 209 } | 213 } |
| 210 } | 214 } |
| 211 | 215 |
| 212 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 216 void WorkspaceLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 213 const void* key, | 217 const void* key, |
| 214 intptr_t old) { | 218 intptr_t old) { |
| 215 if (key == aura::client::kAlwaysOnTopKey && | 219 if (key == aura::client::kAlwaysOnTopKey && |
| 216 window->GetProperty(aura::client::kAlwaysOnTopKey)) { | 220 window->GetProperty(aura::client::kAlwaysOnTopKey)) { |
| 217 WmWindow* container = | 221 aura::Window* container = |
| 218 root_window_controller_->always_on_top_controller()->GetContainer( | 222 root_window_controller_->always_on_top_controller() |
| 219 WmWindow::Get(window)); | 223 ->GetContainer(WmWindow::Get(window)) |
| 220 if (WmWindow::Get(window->parent()) != container) | 224 ->aura_window(); |
| 221 container->AddChild(WmWindow::Get(window)); | 225 if (window->parent() != container) |
| 226 container->AddChild(window); |
| 222 } | 227 } |
| 223 } | 228 } |
| 224 | 229 |
| 225 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { | 230 void WorkspaceLayoutManager::OnWindowStackingChanged(aura::Window* window) { |
| 226 UpdateShelfVisibility(); | 231 UpdateShelfVisibility(); |
| 227 UpdateFullscreenState(); | 232 UpdateFullscreenState(); |
| 228 if (backdrop_delegate_) | 233 if (backdrop_delegate_) |
| 229 backdrop_delegate_->OnWindowStackingChanged(WmWindow::Get(window)); | 234 backdrop_delegate_->OnWindowStackingChanged(WmWindow::Get(window)); |
| 230 } | 235 } |
| 231 | 236 |
| 232 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { | 237 void WorkspaceLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 233 if (root_window_ == WmWindow::Get(window)) { | 238 if (root_window_ == window) { |
| 234 root_window_->aura_window()->RemoveObserver(this); | 239 root_window_->RemoveObserver(this); |
| 235 root_window_ = nullptr; | 240 root_window_ = nullptr; |
| 236 } | 241 } |
| 237 } | 242 } |
| 238 | 243 |
| 239 void WorkspaceLayoutManager::OnWindowBoundsChanged( | 244 void WorkspaceLayoutManager::OnWindowBoundsChanged( |
| 240 aura::Window* window, | 245 aura::Window* window, |
| 241 const gfx::Rect& old_bounds, | 246 const gfx::Rect& old_bounds, |
| 242 const gfx::Rect& new_bounds) { | 247 const gfx::Rect& new_bounds) { |
| 243 if (root_window_ == WmWindow::Get(window)) { | 248 if (root_window_ == window) { |
| 244 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); | 249 const wm::WMEvent wm_event(wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED); |
| 245 AdjustAllWindowsBoundsForWorkAreaChange(&wm_event); | 250 AdjustAllWindowsBoundsForWorkAreaChange(&wm_event); |
| 246 } | 251 } |
| 247 } | 252 } |
| 248 | 253 |
| 249 ////////////////////////////////////////////////////////////////////////////// | 254 ////////////////////////////////////////////////////////////////////////////// |
| 250 // WorkspaceLayoutManager, | 255 // WorkspaceLayoutManager, |
| 251 // aura::client::ActivationChangeObserver implementation: | 256 // aura::client::ActivationChangeObserver implementation: |
| 252 | 257 |
| 253 void WorkspaceLayoutManager::OnWindowActivated(ActivationReason reason, | 258 void WorkspaceLayoutManager::OnWindowActivated(ActivationReason reason, |
| 254 aura::Window* gained_active, | 259 aura::Window* gained_active, |
| 255 aura::Window* lost_active) { | 260 aura::Window* lost_active) { |
| 256 WmWindow* wm_gained_active = WmWindow::Get(gained_active); | |
| 257 wm::WindowState* window_state = | 261 wm::WindowState* window_state = |
| 258 wm_gained_active ? wm_gained_active->GetWindowState() : nullptr; | 262 gained_active ? wm::GetWindowState(gained_active) : nullptr; |
| 259 if (window_state && window_state->IsMinimized() && | 263 if (window_state && window_state->IsMinimized() && |
| 260 !wm_gained_active->IsVisible()) { | 264 !gained_active->IsVisible()) { |
| 261 window_state->Unminimize(); | 265 window_state->Unminimize(); |
| 262 DCHECK(!window_state->IsMinimized()); | 266 DCHECK(!window_state->IsMinimized()); |
| 263 } | 267 } |
| 264 UpdateFullscreenState(); | 268 UpdateFullscreenState(); |
| 265 UpdateShelfVisibility(); | 269 UpdateShelfVisibility(); |
| 266 } | 270 } |
| 267 | 271 |
| 268 ////////////////////////////////////////////////////////////////////////////// | 272 ////////////////////////////////////////////////////////////////////////////// |
| 269 // WorkspaceLayoutManager, wm::WindowStateObserver implementation: | 273 // WorkspaceLayoutManager, wm::WindowStateObserver implementation: |
| 270 | 274 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 281 if (backdrop_delegate_) | 285 if (backdrop_delegate_) |
| 282 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); | 286 backdrop_delegate_->OnPostWindowStateTypeChange(window_state, old_type); |
| 283 } | 287 } |
| 284 | 288 |
| 285 ////////////////////////////////////////////////////////////////////////////// | 289 ////////////////////////////////////////////////////////////////////////////// |
| 286 // WorkspaceLayoutManager, display::DisplayObserver implementation: | 290 // WorkspaceLayoutManager, display::DisplayObserver implementation: |
| 287 | 291 |
| 288 void WorkspaceLayoutManager::OnDisplayMetricsChanged( | 292 void WorkspaceLayoutManager::OnDisplayMetricsChanged( |
| 289 const display::Display& display, | 293 const display::Display& display, |
| 290 uint32_t changed_metrics) { | 294 uint32_t changed_metrics) { |
| 291 if (window_->GetDisplayNearestWindow().id() != display.id()) | 295 if (display::Screen::GetScreen()->GetDisplayNearestWindow(window_).id() != |
| 296 display.id()) { |
| 292 return; | 297 return; |
| 298 } |
| 293 | 299 |
| 294 const gfx::Rect work_area( | 300 const gfx::Rect work_area( |
| 295 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_->aura_window())); | 301 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_)); |
| 296 if (work_area != work_area_in_parent_) { | 302 if (work_area != work_area_in_parent_) { |
| 297 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | 303 const wm::WMEvent event(wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
| 298 AdjustAllWindowsBoundsForWorkAreaChange(&event); | 304 AdjustAllWindowsBoundsForWorkAreaChange(&event); |
| 299 } | 305 } |
| 300 } | 306 } |
| 301 | 307 |
| 302 ////////////////////////////////////////////////////////////////////////////// | 308 ////////////////////////////////////////////////////////////////////////////// |
| 303 // WorkspaceLayoutManager, ShellObserver implementation: | 309 // WorkspaceLayoutManager, ShellObserver implementation: |
| 304 | 310 |
| 305 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen, | 311 void WorkspaceLayoutManager::OnFullscreenStateChanged(bool is_fullscreen, |
| 306 WmWindow* root_window) { | 312 WmWindow* root_window) { |
| 307 if (root_window != root_window_ || is_fullscreen_ == is_fullscreen) | 313 if (root_window->aura_window() != root_window_ || |
| 314 is_fullscreen_ == is_fullscreen) { |
| 308 return; | 315 return; |
| 316 } |
| 309 | 317 |
| 310 is_fullscreen_ = is_fullscreen; | 318 is_fullscreen_ = is_fullscreen; |
| 311 if (Shell::Get()->screen_pinning_controller()->IsPinned()) { | 319 if (Shell::Get()->screen_pinning_controller()->IsPinned()) { |
| 312 // If this is in pinned mode, then this event does not trigger the | 320 // If this is in pinned mode, then this event does not trigger the |
| 313 // always-on-top state change, because it is kept disabled regardless of | 321 // always-on-top state change, because it is kept disabled regardless of |
| 314 // the fullscreen state change. | 322 // the fullscreen state change. |
| 315 return; | 323 return; |
| 316 } | 324 } |
| 317 | 325 |
| 318 UpdateAlwaysOnTop(is_fullscreen_ ? wm::GetWindowForFullscreenMode(window_) | 326 UpdateAlwaysOnTop(is_fullscreen_ ? wm::GetWindowForFullscreenMode(window_) |
| 319 : nullptr); | 327 : nullptr); |
| 320 } | 328 } |
| 321 | 329 |
| 322 void WorkspaceLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) { | 330 void WorkspaceLayoutManager::OnPinnedStateChanged(WmWindow* pinned_window) { |
| 323 const bool is_pinned = Shell::Get()->screen_pinning_controller()->IsPinned(); | 331 const bool is_pinned = Shell::Get()->screen_pinning_controller()->IsPinned(); |
| 324 if (!is_pinned && is_fullscreen_) { | 332 if (!is_pinned && is_fullscreen_) { |
| 325 // On exiting from pinned mode, if the workspace is still in fullscreen | 333 // On exiting from pinned mode, if the workspace is still in fullscreen |
| 326 // mode, then this event does not trigger the restoring yet. On exiting | 334 // mode, then this event does not trigger the restoring yet. On exiting |
| 327 // from fullscreen, the temporarily disabled always-on-top property will be | 335 // from fullscreen, the temporarily disabled always-on-top property will be |
| 328 // restored. | 336 // restored. |
| 329 return; | 337 return; |
| 330 } | 338 } |
| 331 | 339 |
| 332 UpdateAlwaysOnTop(is_pinned ? pinned_window : nullptr); | 340 UpdateAlwaysOnTop(is_pinned ? pinned_window->aura_window() : nullptr); |
| 333 } | 341 } |
| 334 | 342 |
| 335 void WorkspaceLayoutManager::OnVirtualKeyboardStateChanged( | 343 void WorkspaceLayoutManager::OnVirtualKeyboardStateChanged( |
| 336 bool activated, | 344 bool activated, |
| 337 WmWindow* root_window) { | 345 WmWindow* root_window) { |
| 338 UpdateKeyboardObserverFromStateChanged(activated, root_window, root_window_, | 346 UpdateKeyboardObserverFromStateChanged( |
| 339 &keyboard_observer_); | 347 activated, root_window, WmWindow::Get(root_window_), &keyboard_observer_); |
| 340 } | 348 } |
| 341 | 349 |
| 342 ////////////////////////////////////////////////////////////////////////////// | 350 ////////////////////////////////////////////////////////////////////////////// |
| 343 // WorkspaceLayoutManager, private: | 351 // WorkspaceLayoutManager, private: |
| 344 | 352 |
| 345 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( | 353 void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( |
| 346 const wm::WMEvent* event) { | 354 const wm::WMEvent* event) { |
| 347 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || | 355 DCHECK(event->type() == wm::WM_EVENT_DISPLAY_BOUNDS_CHANGED || |
| 348 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); | 356 event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED); |
| 349 | 357 |
| 350 work_area_in_parent_ = | 358 work_area_in_parent_ = ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_); |
| 351 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window_->aura_window()); | |
| 352 | 359 |
| 353 // Don't do any adjustments of the insets while we are in screen locked mode. | 360 // Don't do any adjustments of the insets while we are in screen locked mode. |
| 354 // This would happen if the launcher was auto hidden before the login screen | 361 // This would happen if the launcher was auto hidden before the login screen |
| 355 // was shown and then gets shown when the login screen gets presented. | 362 // was shown and then gets shown when the login screen gets presented. |
| 356 if (event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED && | 363 if (event->type() == wm::WM_EVENT_WORKAREA_BOUNDS_CHANGED && |
| 357 Shell::Get()->session_controller()->IsScreenLocked()) | 364 Shell::Get()->session_controller()->IsScreenLocked()) |
| 358 return; | 365 return; |
| 359 | 366 |
| 360 // If a user plugs an external display into a laptop running Aura the | 367 // If a user plugs an external display into a laptop running Aura the |
| 361 // display size will change. Maximized windows need to resize to match. | 368 // display size will change. Maximized windows need to resize to match. |
| 362 // We also do this when developers running Aura on a desktop manually resize | 369 // We also do this when developers running Aura on a desktop manually resize |
| 363 // the host window. | 370 // the host window. |
| 364 // We also need to do this when the work area insets changes. | 371 // We also need to do this when the work area insets changes. |
| 365 for (WmWindow* window : windows_) | 372 for (aura::Window* window : windows_) |
| 366 window->GetWindowState()->OnWMEvent(event); | 373 wm::GetWindowState(window)->OnWMEvent(event); |
| 367 } | 374 } |
| 368 | 375 |
| 369 void WorkspaceLayoutManager::UpdateShelfVisibility() { | 376 void WorkspaceLayoutManager::UpdateShelfVisibility() { |
| 370 if (root_window_controller_->HasShelf()) | 377 if (root_window_controller_->HasShelf()) |
| 371 root_window_controller_->GetShelf()->UpdateVisibilityState(); | 378 root_window_controller_->GetShelf()->UpdateVisibilityState(); |
| 372 } | 379 } |
| 373 | 380 |
| 374 void WorkspaceLayoutManager::UpdateFullscreenState() { | 381 void WorkspaceLayoutManager::UpdateFullscreenState() { |
| 375 // TODO(flackr): The fullscreen state is currently tracked per workspace | 382 // TODO(flackr): The fullscreen state is currently tracked per workspace |
| 376 // but the shell notification implies a per root window state. Currently | 383 // but the shell notification implies a per root window state. Currently |
| 377 // only windows in the default workspace container will go fullscreen but | 384 // only windows in the default workspace container will go fullscreen but |
| 378 // this should really be tracked by the RootWindowController since | 385 // this should really be tracked by the RootWindowController since |
| 379 // technically any container could get a fullscreen window. | 386 // technically any container could get a fullscreen window. |
| 380 if (window_->aura_window()->id() != kShellWindowId_DefaultContainer) | 387 if (window_->id() != kShellWindowId_DefaultContainer) |
| 381 return; | 388 return; |
| 382 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr; | 389 bool is_fullscreen = wm::GetWindowForFullscreenMode(window_) != nullptr; |
| 383 if (is_fullscreen != is_fullscreen_) { | 390 if (is_fullscreen != is_fullscreen_) { |
| 384 Shell::Get()->NotifyFullscreenStateChanged(is_fullscreen, root_window_); | 391 Shell::Get()->NotifyFullscreenStateChanged(is_fullscreen, |
| 392 WmWindow::Get(root_window_)); |
| 385 is_fullscreen_ = is_fullscreen; | 393 is_fullscreen_ = is_fullscreen; |
| 386 } | 394 } |
| 387 } | 395 } |
| 388 | 396 |
| 389 void WorkspaceLayoutManager::UpdateAlwaysOnTop(WmWindow* window_on_top) { | 397 void WorkspaceLayoutManager::UpdateAlwaysOnTop(aura::Window* window_on_top) { |
| 390 // Changing always on top state may change window's parent. Iterate on a copy | 398 // Changing always on top state may change window's parent. Iterate on a copy |
| 391 // of |windows_| to avoid invalidating an iterator. Since both workspace and | 399 // of |windows_| to avoid invalidating an iterator. Since both workspace and |
| 392 // always_on_top containers' layouts are managed by this class all the | 400 // always_on_top containers' layouts are managed by this class all the |
| 393 // appropriate windows will be included in the iteration. | 401 // appropriate windows will be included in the iteration. |
| 394 WindowSet windows(windows_); | 402 WindowSet windows(windows_); |
| 395 for (auto* window : windows) { | 403 for (aura::Window* window : windows) { |
| 396 wm::WindowState* window_state = window->GetWindowState(); | 404 wm::WindowState* window_state = wm::GetWindowState(window); |
| 397 if (window_on_top) | 405 if (window_on_top) |
| 398 window_state->DisableAlwaysOnTop(window_on_top); | 406 window_state->DisableAlwaysOnTop(WmWindow::Get(window_on_top)); |
| 399 else | 407 else |
| 400 window_state->RestoreAlwaysOnTop(); | 408 window_state->RestoreAlwaysOnTop(); |
| 401 } | 409 } |
| 402 } | 410 } |
| 403 | 411 |
| 404 } // namespace ash | 412 } // namespace ash |
| OLD | NEW |