| 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 // Just set the bounds immediately. We fix up maximized and fullscreen |
| 102 // Avoid a janky resize on startup by ensuring the initial bounds fill the | 104 // bounds in OnWindowAddedToLayout() above. |
| 103 // screen. | 105 SetChildBoundsDirect(child, requested_bounds); |
| 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); | |
| 109 } | 106 } |
| 110 | 107 |
| 111 ///////////////////////////////////////////////////////////////////////////// | 108 ///////////////////////////////////////////////////////////////////////////// |
| 112 // BaseLayoutManager, RootWindowObserver overrides: | 109 // BaseLayoutManager, RootWindowObserver overrides: |
| 113 | 110 |
| 114 void BaseLayoutManager::OnRootWindowResized(const aura::RootWindow* root, | 111 void BaseLayoutManager::OnRootWindowResized(const aura::RootWindow* root, |
| 115 const gfx::Size& old_size) { | 112 const gfx::Size& old_size) { |
| 116 AdjustWindowSizesForScreenChange(); | 113 AdjustWindowSizesForScreenChange(); |
| 117 } | 114 } |
| 118 | 115 |
| 119 ///////////////////////////////////////////////////////////////////////////// | 116 ///////////////////////////////////////////////////////////////////////////// |
| 120 // BaseLayoutManager, ash::ShellObserver overrides: | 117 // BaseLayoutManager, ash::ShellObserver overrides: |
| 121 | 118 |
| 122 void BaseLayoutManager::OnMonitorWorkAreaInsetsChanged() { | 119 void BaseLayoutManager::OnMonitorWorkAreaInsetsChanged() { |
| 123 AdjustWindowSizesForScreenChange(); | 120 AdjustWindowSizesForScreenChange(); |
| 124 } | 121 } |
| 125 | 122 |
| 126 ///////////////////////////////////////////////////////////////////////////// | 123 ///////////////////////////////////////////////////////////////////////////// |
| 127 // BaseLayoutManager, WindowObserver overrides: | 124 // BaseLayoutManager, WindowObserver overrides: |
| 128 | 125 |
| 129 void BaseLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 126 void BaseLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
| 130 const void* key, | 127 const void* key, |
| 131 intptr_t old) { | 128 intptr_t old) { |
| 132 if (key == aura::client::kShowStateKey) { | 129 if (key == aura::client::kShowStateKey) { |
| 133 UpdateBoundsFromShowState(window); | 130 UpdateBoundsFromShowState(window, true); |
| 134 ShowStateChanged(window, static_cast<ui::WindowShowState>(old)); | 131 ShowStateChanged(window, static_cast<ui::WindowShowState>(old)); |
| 135 } | 132 } |
| 136 } | 133 } |
| 137 | 134 |
| 138 void BaseLayoutManager::OnWindowDestroying(aura::Window* window) { | 135 void BaseLayoutManager::OnWindowDestroying(aura::Window* window) { |
| 139 if (root_window_ == window) { | 136 if (root_window_ == window) { |
| 140 root_window_->RemoveObserver(this); | 137 root_window_->RemoveObserver(this); |
| 141 root_window_ = NULL; | 138 root_window_ = NULL; |
| 142 } | 139 } |
| 143 } | 140 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 160 wm::DeactivateWindow(window); | 157 wm::DeactivateWindow(window); |
| 161 } else if ((window->TargetVisibility() || | 158 } else if ((window->TargetVisibility() || |
| 162 last_show_state == ui::SHOW_STATE_MINIMIZED) && | 159 last_show_state == ui::SHOW_STATE_MINIMIZED) && |
| 163 !window->layer()->visible()) { | 160 !window->layer()->visible()) { |
| 164 // The layer may be hidden if the window was previously minimized. Make | 161 // The layer may be hidden if the window was previously minimized. Make |
| 165 // sure it's visible. | 162 // sure it's visible. |
| 166 window->Show(); | 163 window->Show(); |
| 167 } | 164 } |
| 168 } | 165 } |
| 169 | 166 |
| 170 void BaseLayoutManager::UpdateBoundsFromShowState(aura::Window* window) { | 167 void BaseLayoutManager::UpdateBoundsFromShowState(aura::Window* window, |
| 168 bool animate) { |
| 171 switch (window->GetProperty(aura::client::kShowStateKey)) { | 169 switch (window->GetProperty(aura::client::kShowStateKey)) { |
| 172 case ui::SHOW_STATE_DEFAULT: | 170 case ui::SHOW_STATE_DEFAULT: |
| 173 case ui::SHOW_STATE_NORMAL: { | 171 case ui::SHOW_STATE_NORMAL: { |
| 174 const gfx::Rect* restore = GetRestoreBounds(window); | 172 const gfx::Rect* restore = GetRestoreBounds(window); |
| 175 if (restore) { | 173 if (restore) { |
| 176 SetChildBoundsDirect(window, | 174 MaybeAnimateToBounds(window, |
| 175 animate, |
| 177 BoundsWithScreenEdgeVisible(window, *restore)); | 176 BoundsWithScreenEdgeVisible(window, *restore)); |
| 178 } | 177 } |
| 179 window->ClearProperty(aura::client::kRestoreBoundsKey); | 178 window->ClearProperty(aura::client::kRestoreBoundsKey); |
| 180 break; | 179 break; |
| 181 } | 180 } |
| 182 | 181 |
| 183 case ui::SHOW_STATE_MAXIMIZED: | 182 case ui::SHOW_STATE_MAXIMIZED: |
| 184 SetRestoreBoundsIfNotSet(window); | 183 SetRestoreBoundsIfNotSet(window); |
| 185 SetChildBoundsDirect(window, ScreenAsh::GetMaximizedWindowBounds(window)); | 184 MaybeAnimateToBounds(window, |
| 185 animate, |
| 186 ScreenAsh::GetMaximizedWindowBounds(window)); |
| 186 break; | 187 break; |
| 187 | 188 |
| 188 case ui::SHOW_STATE_FULLSCREEN: | 189 case ui::SHOW_STATE_FULLSCREEN: |
| 189 SetRestoreBoundsIfNotSet(window); | 190 SetRestoreBoundsIfNotSet(window); |
| 190 SetChildBoundsDirect( | 191 MaybeAnimateToBounds( |
| 191 window, gfx::Screen::GetMonitorNearestWindow(window).bounds()); | 192 window, |
| 193 animate, |
| 194 gfx::Screen::GetMonitorNearestWindow(window).bounds()); |
| 192 break; | 195 break; |
| 193 | 196 |
| 194 default: | 197 default: |
| 195 break; | 198 break; |
| 196 } | 199 } |
| 197 } | 200 } |
| 198 | 201 |
| 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::kAuraWindowAnimationsDisabled)) { |
| 210 CrossFadeToBounds(window, new_bounds); |
| 211 return; |
| 212 } |
| 213 SetChildBoundsDirect(window, new_bounds); |
| 214 } |
| 215 |
| 199 void BaseLayoutManager::AdjustWindowSizesForScreenChange() { | 216 void BaseLayoutManager::AdjustWindowSizesForScreenChange() { |
| 200 // If a user plugs an external monitor into a laptop running Aura the | 217 // 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. | 218 // 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 | 219 // We also do this when developers running Aura on a desktop manually resize |
| 203 // the host window. | 220 // the host window. |
| 204 // We also need to do this when the work area insets changes. | 221 // We also need to do this when the work area insets changes. |
| 205 for (WindowSet::const_iterator it = windows_.begin(); | 222 for (WindowSet::const_iterator it = windows_.begin(); |
| 206 it != windows_.end(); | 223 it != windows_.end(); |
| 207 ++it) { | 224 ++it) { |
| 208 aura::Window* window = *it; | 225 aura::Window* window = *it; |
| 209 if (wm::IsWindowMaximized(window)) { | 226 if (wm::IsWindowMaximized(window)) { |
| 210 SetChildBoundsDirect(window, ScreenAsh::GetMaximizedWindowBounds(window)); | 227 SetChildBoundsDirect(window, ScreenAsh::GetMaximizedWindowBounds(window)); |
| 211 } else if (wm::IsWindowFullscreen(window)) { | 228 } else if (wm::IsWindowFullscreen(window)) { |
| 212 SetChildBoundsDirect( | 229 SetChildBoundsDirect( |
| 213 window, gfx::Screen::GetMonitorNearestWindow(window).bounds()); | 230 window, gfx::Screen::GetMonitorNearestWindow(window).bounds()); |
| 214 } else { | 231 } else { |
| 215 // The work area may be smaller than the full screen. | 232 // The work area may be smaller than the full screen. |
| 216 gfx::Rect monitor_rect = | 233 gfx::Rect monitor_rect = |
| 217 gfx::Screen::GetMonitorNearestWindow(window).work_area(); | 234 gfx::Screen::GetMonitorNearestWindow(window).work_area(); |
| 218 // Put as much of the window as possible within the monitor area. | 235 // Put as much of the window as possible within the monitor area. |
| 219 window->SetBounds(window->bounds().AdjustToFit(monitor_rect)); | 236 window->SetBounds(window->bounds().AdjustToFit(monitor_rect)); |
| 220 } | 237 } |
| 221 } | 238 } |
| 222 } | 239 } |
| 223 | 240 |
| 224 } // namespace internal | 241 } // namespace internal |
| 225 } // namespace ash | 242 } // namespace ash |
| OLD | NEW |