| 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/base_layout_manager.h" | 5 #include "ash/wm/base_layout_manager.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | |
| 8 #include "ash/screen_ash.h" | 7 #include "ash/screen_ash.h" |
| 9 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 10 #include "ash/wm/shelf_layout_manager.h" | 9 #include "ash/wm/shelf_layout_manager.h" |
| 11 #include "ash/wm/window_animations.h" | 10 #include "ash/wm/window_animations.h" |
| 12 #include "ash/wm/window_properties.h" | 11 #include "ash/wm/window_properties.h" |
| 13 #include "ash/wm/window_util.h" | 12 #include "ash/wm/window_util.h" |
| 14 #include "base/command_line.h" | |
| 15 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
| 16 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
| 17 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 18 #include "ui/base/ui_base_types.h" | 16 #include "ui/base/ui_base_types.h" |
| 19 #include "ui/compositor/layer.h" | 17 #include "ui/compositor/layer.h" |
| 20 #include "ui/gfx/screen.h" | 18 #include "ui/gfx/screen.h" |
| 21 | 19 |
| 22 namespace { | 20 namespace { |
| 23 | 21 |
| 24 // Given a |window| and tentative |restore_bounds|, returns new bounds that | 22 // Given a |window| and tentative |restore_bounds|, returns new bounds that |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 68 |
| 71 void BaseLayoutManager::OnWindowResized() { | 69 void BaseLayoutManager::OnWindowResized() { |
| 72 } | 70 } |
| 73 | 71 |
| 74 void BaseLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 72 void BaseLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
| 75 windows_.insert(child); | 73 windows_.insert(child); |
| 76 child->AddObserver(this); | 74 child->AddObserver(this); |
| 77 // Only update the bounds if the window has a show state that depends on the | 75 // Only update the bounds if the window has a show state that depends on the |
| 78 // workspace area. | 76 // workspace area. |
| 79 if (wm::IsWindowMaximized(child) || wm::IsWindowFullscreen(child)) | 77 if (wm::IsWindowMaximized(child) || wm::IsWindowFullscreen(child)) |
| 80 UpdateBoundsFromShowState(child, false); | 78 UpdateBoundsFromShowState(child); |
| 81 } | 79 } |
| 82 | 80 |
| 83 void BaseLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | 81 void BaseLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
| 84 windows_.erase(child); | 82 windows_.erase(child); |
| 85 child->RemoveObserver(this); | 83 child->RemoveObserver(this); |
| 86 } | 84 } |
| 87 | 85 |
| 88 void BaseLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 86 void BaseLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
| 89 } | 87 } |
| 90 | 88 |
| 91 void BaseLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 89 void BaseLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
| 92 bool visible) { | 90 bool visible) { |
| 93 if (visible && wm::IsWindowMinimized(child)) { | 91 if (visible && wm::IsWindowMinimized(child)) { |
| 94 // Attempting to show a minimized window. Unminimize it. | 92 // Attempting to show a minimized window. Unminimize it. |
| 95 child->SetProperty(aura::client::kShowStateKey, | 93 child->SetProperty(aura::client::kShowStateKey, |
| 96 child->GetProperty(internal::kRestoreShowStateKey)); | 94 child->GetProperty(internal::kRestoreShowStateKey)); |
| 97 child->ClearProperty(internal::kRestoreShowStateKey); | 95 child->ClearProperty(internal::kRestoreShowStateKey); |
| 98 } | 96 } |
| 99 } | 97 } |
| 100 | 98 |
| 101 void BaseLayoutManager::SetChildBounds(aura::Window* child, | 99 void BaseLayoutManager::SetChildBounds(aura::Window* child, |
| 102 const gfx::Rect& requested_bounds) { | 100 const gfx::Rect& requested_bounds) { |
| 103 // Just set the bounds immediately. We fix up maximized and fullscreen | 101 gfx::Rect child_bounds(requested_bounds); |
| 104 // bounds in OnWindowAddedToLayout() above. | 102 // Avoid a janky resize on startup by ensuring the initial bounds fill the |
| 105 SetChildBoundsDirect(child, requested_bounds); | 103 // screen. |
| 104 if (wm::IsWindowMaximized(child)) |
| 105 child_bounds = ScreenAsh::GetMaximizedWindowBounds(child); |
| 106 else if (wm::IsWindowFullscreen(child)) |
| 107 child_bounds = gfx::Screen::GetMonitorNearestWindow(child).bounds(); |
| 108 SetChildBoundsDirect(child, child_bounds); |
| 106 } | 109 } |
| 107 | 110 |
| 108 ///////////////////////////////////////////////////////////////////////////// | 111 ///////////////////////////////////////////////////////////////////////////// |
| 109 // BaseLayoutManager, RootWindowObserver overrides: | 112 // BaseLayoutManager, RootWindowObserver overrides: |
| 110 | 113 |
| 111 void BaseLayoutManager::OnRootWindowResized(const aura::RootWindow* root, | 114 void BaseLayoutManager::OnRootWindowResized(const aura::RootWindow* root, |
| 112 const gfx::Size& old_size) { | 115 const gfx::Size& old_size) { |
| 113 AdjustWindowSizesForScreenChange(); | 116 AdjustWindowSizesForScreenChange(); |
| 114 } | 117 } |
| 115 | 118 |
| 116 ///////////////////////////////////////////////////////////////////////////// | 119 ///////////////////////////////////////////////////////////////////////////// |
| 117 // BaseLayoutManager, ash::ShellObserver overrides: | 120 // BaseLayoutManager, ash::ShellObserver overrides: |
| 118 | 121 |
| 119 void BaseLayoutManager::OnMonitorWorkAreaInsetsChanged() { | 122 void BaseLayoutManager::OnMonitorWorkAreaInsetsChanged() { |
| 120 AdjustWindowSizesForScreenChange(); | 123 AdjustWindowSizesForScreenChange(); |
| 121 } | 124 } |
| 122 | 125 |
| 123 ///////////////////////////////////////////////////////////////////////////// | 126 ///////////////////////////////////////////////////////////////////////////// |
| 124 // BaseLayoutManager, WindowObserver overrides: | 127 // BaseLayoutManager, WindowObserver overrides: |
| 125 | 128 |
| 126 void BaseLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 129 void BaseLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 127 const void* key, | 130 const void* key, |
| 128 intptr_t old) { | 131 intptr_t old) { |
| 129 if (key == aura::client::kShowStateKey) { | 132 if (key == aura::client::kShowStateKey) { |
| 130 UpdateBoundsFromShowState(window, true); | 133 UpdateBoundsFromShowState(window); |
| 131 ShowStateChanged(window, static_cast<ui::WindowShowState>(old)); | 134 ShowStateChanged(window, static_cast<ui::WindowShowState>(old)); |
| 132 } | 135 } |
| 133 } | 136 } |
| 134 | 137 |
| 135 void BaseLayoutManager::OnWindowDestroying(aura::Window* window) { | 138 void BaseLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 136 if (root_window_ == window) { | 139 if (root_window_ == window) { |
| 137 root_window_->RemoveObserver(this); | 140 root_window_->RemoveObserver(this); |
| 138 root_window_ = NULL; | 141 root_window_ = NULL; |
| 139 } | 142 } |
| 140 } | 143 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 157 wm::DeactivateWindow(window); | 160 wm::DeactivateWindow(window); |
| 158 } else if ((window->TargetVisibility() || | 161 } else if ((window->TargetVisibility() || |
| 159 last_show_state == ui::SHOW_STATE_MINIMIZED) && | 162 last_show_state == ui::SHOW_STATE_MINIMIZED) && |
| 160 !window->layer()->visible()) { | 163 !window->layer()->visible()) { |
| 161 // The layer may be hidden if the window was previously minimized. Make | 164 // The layer may be hidden if the window was previously minimized. Make |
| 162 // sure it's visible. | 165 // sure it's visible. |
| 163 window->Show(); | 166 window->Show(); |
| 164 } | 167 } |
| 165 } | 168 } |
| 166 | 169 |
| 167 void BaseLayoutManager::UpdateBoundsFromShowState(aura::Window* window, | 170 void BaseLayoutManager::UpdateBoundsFromShowState(aura::Window* window) { |
| 168 bool animate) { | |
| 169 switch (window->GetProperty(aura::client::kShowStateKey)) { | 171 switch (window->GetProperty(aura::client::kShowStateKey)) { |
| 170 case ui::SHOW_STATE_DEFAULT: | 172 case ui::SHOW_STATE_DEFAULT: |
| 171 case ui::SHOW_STATE_NORMAL: { | 173 case ui::SHOW_STATE_NORMAL: { |
| 172 const gfx::Rect* restore = GetRestoreBounds(window); | 174 const gfx::Rect* restore = GetRestoreBounds(window); |
| 173 if (restore) { | 175 if (restore) { |
| 174 MaybeAnimateToBounds(window, | 176 SetChildBoundsDirect(window, |
| 175 animate, | |
| 176 BoundsWithScreenEdgeVisible(window, *restore)); | 177 BoundsWithScreenEdgeVisible(window, *restore)); |
| 177 } | 178 } |
| 178 window->ClearProperty(aura::client::kRestoreBoundsKey); | 179 window->ClearProperty(aura::client::kRestoreBoundsKey); |
| 179 break; | 180 break; |
| 180 } | 181 } |
| 181 | 182 |
| 182 case ui::SHOW_STATE_MAXIMIZED: | 183 case ui::SHOW_STATE_MAXIMIZED: |
| 183 SetRestoreBoundsIfNotSet(window); | 184 SetRestoreBoundsIfNotSet(window); |
| 184 MaybeAnimateToBounds(window, | 185 SetChildBoundsDirect(window, ScreenAsh::GetMaximizedWindowBounds(window)); |
| 185 animate, | |
| 186 ScreenAsh::GetMaximizedWindowBounds(window)); | |
| 187 break; | 186 break; |
| 188 | 187 |
| 189 case ui::SHOW_STATE_FULLSCREEN: | 188 case ui::SHOW_STATE_FULLSCREEN: |
| 190 SetRestoreBoundsIfNotSet(window); | 189 SetRestoreBoundsIfNotSet(window); |
| 191 MaybeAnimateToBounds( | 190 SetChildBoundsDirect( |
| 192 window, | 191 window, gfx::Screen::GetMonitorNearestWindow(window).bounds()); |
| 193 animate, | |
| 194 gfx::Screen::GetMonitorNearestWindow(window).bounds()); | |
| 195 break; | 192 break; |
| 196 | 193 |
| 197 default: | 194 default: |
| 198 break; | 195 break; |
| 199 } | 196 } |
| 200 } | 197 } |
| 201 | 198 |
| 202 void BaseLayoutManager::MaybeAnimateToBounds(aura::Window* window, | |
| 203 bool animate, | |
| 204 const gfx::Rect& new_bounds) { | |
| 205 // Only animate visible windows. | |
| 206 if (animate && | |
| 207 window->TargetVisibility() && | |
| 208 !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 209 ash::switches::kAshWindowAnimationsDisabled)) { | |
| 210 CrossFadeToBounds(window, new_bounds); | |
| 211 return; | |
| 212 } | |
| 213 SetChildBoundsDirect(window, new_bounds); | |
| 214 } | |
| 215 | |
| 216 void BaseLayoutManager::AdjustWindowSizesForScreenChange() { | 199 void BaseLayoutManager::AdjustWindowSizesForScreenChange() { |
| 217 // If a user plugs an external monitor into a laptop running Aura the | 200 // If a user plugs an external monitor into a laptop running Aura the |
| 218 // monitor size will change. Maximized windows need to resize to match. | 201 // monitor size will change. Maximized windows need to resize to match. |
| 219 // We also do this when developers running Aura on a desktop manually resize | 202 // We also do this when developers running Aura on a desktop manually resize |
| 220 // the host window. | 203 // the host window. |
| 221 // We also need to do this when the work area insets changes. | 204 // We also need to do this when the work area insets changes. |
| 222 for (WindowSet::const_iterator it = windows_.begin(); | 205 for (WindowSet::const_iterator it = windows_.begin(); |
| 223 it != windows_.end(); | 206 it != windows_.end(); |
| 224 ++it) { | 207 ++it) { |
| 225 aura::Window* window = *it; | 208 aura::Window* window = *it; |
| 226 if (wm::IsWindowMaximized(window)) { | 209 if (wm::IsWindowMaximized(window)) { |
| 227 SetChildBoundsDirect(window, ScreenAsh::GetMaximizedWindowBounds(window)); | 210 SetChildBoundsDirect(window, ScreenAsh::GetMaximizedWindowBounds(window)); |
| 228 } else if (wm::IsWindowFullscreen(window)) { | 211 } else if (wm::IsWindowFullscreen(window)) { |
| 229 SetChildBoundsDirect( | 212 SetChildBoundsDirect( |
| 230 window, gfx::Screen::GetMonitorNearestWindow(window).bounds()); | 213 window, gfx::Screen::GetMonitorNearestWindow(window).bounds()); |
| 231 } else { | 214 } else { |
| 232 // The work area may be smaller than the full screen. | 215 // The work area may be smaller than the full screen. |
| 233 gfx::Rect monitor_rect = | 216 gfx::Rect monitor_rect = |
| 234 gfx::Screen::GetMonitorNearestWindow(window).work_area(); | 217 gfx::Screen::GetMonitorNearestWindow(window).work_area(); |
| 235 // Put as much of the window as possible within the monitor area. | 218 // Put as much of the window as possible within the monitor area. |
| 236 window->SetBounds(window->bounds().AdjustToFit(monitor_rect)); | 219 window->SetBounds(window->bounds().AdjustToFit(monitor_rect)); |
| 237 } | 220 } |
| 238 } | 221 } |
| 239 } | 222 } |
| 240 | 223 |
| 241 } // namespace internal | 224 } // namespace internal |
| 242 } // namespace ash | 225 } // namespace ash |
| OLD | NEW |