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