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/screen_ash.h" | 7 #include "ash/screen_ash.h" |
8 #include "ash/session_state_delegate.h" | 8 #include "ash/session_state_delegate.h" |
9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/wm/window_animations.h" | 11 #include "ash/wm/window_animations.h" |
12 #include "ash/wm/window_properties.h" | 12 #include "ash/wm/window_properties.h" |
13 #include "ash/wm/window_settings.h" | 13 #include "ash/wm/window_state.h" |
14 #include "ash/wm/window_util.h" | 14 #include "ash/wm/window_util.h" |
15 #include "ash/wm/workspace/workspace_window_resizer.h" | 15 #include "ash/wm/workspace/workspace_window_resizer.h" |
16 #include "ui/aura/client/activation_client.h" | 16 #include "ui/aura/client/activation_client.h" |
17 #include "ui/aura/client/aura_constants.h" | 17 #include "ui/aura/client/aura_constants.h" |
18 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
19 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
20 #include "ui/base/ui_base_types.h" | 20 #include "ui/base/ui_base_types.h" |
21 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
22 #include "ui/gfx/screen.h" | 22 #include "ui/gfx/screen.h" |
23 #include "ui/views/corewm/corewm_switches.h" | 23 #include "ui/views/corewm/corewm_switches.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
62 | 62 |
63 ///////////////////////////////////////////////////////////////////////////// | 63 ///////////////////////////////////////////////////////////////////////////// |
64 // BaseLayoutManager, aura::LayoutManager overrides: | 64 // BaseLayoutManager, aura::LayoutManager overrides: |
65 | 65 |
66 void BaseLayoutManager::OnWindowResized() { | 66 void BaseLayoutManager::OnWindowResized() { |
67 } | 67 } |
68 | 68 |
69 void BaseLayoutManager::OnWindowAddedToLayout(aura::Window* child) { | 69 void BaseLayoutManager::OnWindowAddedToLayout(aura::Window* child) { |
70 windows_.insert(child); | 70 windows_.insert(child); |
71 child->AddObserver(this); | 71 child->AddObserver(this); |
72 wm::GetWindowSettings(child)->AddObserver(this); | 72 wm::WindowState* window_state = wm::GetWindowState(child); |
73 window_state->AddObserver(this); | |
74 | |
73 // 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 |
74 // workspace area. | 76 // workspace area. |
75 if (wm::IsWindowMaximized(child) || wm::IsWindowFullscreen(child)) | 77 if (window_state->IsMaximizedOrFullscreen()) |
76 UpdateBoundsFromShowState(child); | 78 UpdateBoundsFromShowState(window_state); |
77 } | 79 } |
78 | 80 |
79 void BaseLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { | 81 void BaseLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { |
80 windows_.erase(child); | 82 windows_.erase(child); |
81 child->RemoveObserver(this); | 83 child->RemoveObserver(this); |
82 wm::GetWindowSettings(child)->RemoveObserver(this); | 84 wm::GetWindowState(child)->RemoveObserver(this); |
83 } | 85 } |
84 | 86 |
85 void BaseLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 87 void BaseLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
86 } | 88 } |
87 | 89 |
88 void BaseLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, | 90 void BaseLayoutManager::OnChildWindowVisibilityChanged(aura::Window* child, |
89 bool visible) { | 91 bool visible) { |
90 if (visible && wm::IsWindowMinimized(child)) { | 92 wm::WindowState* window_state = wm::GetWindowState(child); |
91 // Attempting to show a minimized window. Unminimize it. | 93 // Attempting to show a minimized window. Unminimize it. |
92 child->SetProperty(aura::client::kShowStateKey, | 94 if (visible && window_state->IsMinimized()) |
93 child->GetProperty(aura::client::kRestoreShowStateKey)); | 95 window_state->Unminimize(); |
James Cook
2013/09/18 20:44:17
Nice, much easier to read
| |
94 child->ClearProperty(aura::client::kRestoreShowStateKey); | |
95 } | |
96 } | 96 } |
97 | 97 |
98 void BaseLayoutManager::SetChildBounds(aura::Window* child, | 98 void BaseLayoutManager::SetChildBounds(aura::Window* child, |
99 const gfx::Rect& requested_bounds) { | 99 const gfx::Rect& requested_bounds) { |
100 gfx::Rect child_bounds(requested_bounds); | 100 gfx::Rect child_bounds(requested_bounds); |
101 wm::WindowState* window_state = wm::GetWindowState(child); | |
101 // Some windows rely on this to set their initial bounds. | 102 // Some windows rely on this to set their initial bounds. |
102 if (wm::IsWindowMaximized(child)) | 103 if (window_state->IsMaximized()) |
103 child_bounds = ScreenAsh::GetMaximizedWindowBoundsInParent(child); | 104 child_bounds = ScreenAsh::GetMaximizedWindowBoundsInParent(child); |
104 else if (wm::IsWindowFullscreen(child)) | 105 else if (window_state->IsFullscreen()) |
105 child_bounds = ScreenAsh::GetDisplayBoundsInParent(child); | 106 child_bounds = ScreenAsh::GetDisplayBoundsInParent(child); |
106 SetChildBoundsDirect(child, child_bounds); | 107 SetChildBoundsDirect(child, child_bounds); |
107 } | 108 } |
108 | 109 |
109 ///////////////////////////////////////////////////////////////////////////// | 110 ///////////////////////////////////////////////////////////////////////////// |
110 // BaseLayoutManager, aura::WindowObserver overrides: | 111 // BaseLayoutManager, aura::WindowObserver overrides: |
111 | 112 |
112 void BaseLayoutManager::OnWindowPropertyChanged(aura::Window* window, | 113 void BaseLayoutManager::OnWindowPropertyChanged(aura::Window* window, |
113 const void* key, | 114 const void* key, |
114 intptr_t old) { | 115 intptr_t old) { |
115 if (key == aura::client::kShowStateKey) { | 116 if (key == aura::client::kShowStateKey) { |
116 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); | 117 ui::WindowShowState old_state = static_cast<ui::WindowShowState>(old); |
117 ui::WindowShowState new_state = | 118 ui::WindowShowState new_state = |
118 window->GetProperty(aura::client::kShowStateKey); | 119 window->GetProperty(aura::client::kShowStateKey); |
120 wm::WindowState* window_state = wm::GetWindowState(window); | |
121 | |
119 if (old_state != new_state && old_state != ui::SHOW_STATE_MINIMIZED && | 122 if (old_state != new_state && old_state != ui::SHOW_STATE_MINIMIZED && |
120 !GetRestoreBoundsInScreen(window) && | 123 !window_state->HasRestoreBounds() && |
121 ((new_state == ui::SHOW_STATE_MAXIMIZED && | 124 ((new_state == ui::SHOW_STATE_MAXIMIZED && |
122 old_state != ui::SHOW_STATE_FULLSCREEN) || | 125 old_state != ui::SHOW_STATE_FULLSCREEN) || |
123 (new_state == ui::SHOW_STATE_FULLSCREEN && | 126 (new_state == ui::SHOW_STATE_FULLSCREEN && |
124 old_state != ui::SHOW_STATE_MAXIMIZED))) { | 127 old_state != ui::SHOW_STATE_MAXIMIZED))) { |
125 SetRestoreBoundsInParent(window, window->bounds()); | 128 window_state->SetRestoreBoundsInParent(window->bounds()); |
126 } | 129 } |
127 | 130 |
128 UpdateBoundsFromShowState(window); | 131 UpdateBoundsFromShowState(window_state); |
129 ShowStateChanged(window, old_state); | 132 ShowStateChanged(window_state, old_state); |
130 } | 133 } |
131 } | 134 } |
132 | 135 |
133 void BaseLayoutManager::OnWindowDestroying(aura::Window* window) { | 136 void BaseLayoutManager::OnWindowDestroying(aura::Window* window) { |
134 if (root_window_ == window) { | 137 if (root_window_ == window) { |
135 root_window_->RemoveObserver(this); | 138 root_window_->RemoveObserver(this); |
136 root_window_ = NULL; | 139 root_window_ = NULL; |
137 } | 140 } |
138 } | 141 } |
139 | 142 |
140 void BaseLayoutManager::OnWindowBoundsChanged(aura::Window* window, | 143 void BaseLayoutManager::OnWindowBoundsChanged(aura::Window* window, |
141 const gfx::Rect& old_bounds, | 144 const gfx::Rect& old_bounds, |
142 const gfx::Rect& new_bounds) { | 145 const gfx::Rect& new_bounds) { |
143 if (root_window_ == window) | 146 if (root_window_ == window) |
144 AdjustAllWindowsBoundsForWorkAreaChange(ADJUST_WINDOW_DISPLAY_SIZE_CHANGED); | 147 AdjustAllWindowsBoundsForWorkAreaChange(ADJUST_WINDOW_DISPLAY_SIZE_CHANGED); |
145 } | 148 } |
146 | 149 |
147 ////////////////////////////////////////////////////////////////////////////// | 150 ////////////////////////////////////////////////////////////////////////////// |
148 // BaseLayoutManager, aura::client::ActivationChangeObserver implementation: | 151 // BaseLayoutManager, aura::client::ActivationChangeObserver implementation: |
149 | 152 |
150 void BaseLayoutManager::OnWindowActivated(aura::Window* gained_active, | 153 void BaseLayoutManager::OnWindowActivated(aura::Window* gained_active, |
151 aura::Window* lost_active) { | 154 aura::Window* lost_active) { |
152 if (gained_active && wm::IsWindowMinimized(gained_active) && | 155 wm::WindowState* window_state = wm::GetWindowState(gained_active); |
156 if (window_state && window_state->IsMinimized() && | |
James Cook
2013/09/18 20:44:17
Do you need to check window_state? I thought GetW
oshima
2013/09/19 01:52:01
gained_ative may be NULL, in which case, GetWindow
| |
153 !gained_active->IsVisible()) { | 157 !gained_active->IsVisible()) { |
154 gained_active->Show(); | 158 gained_active->Show(); |
155 DCHECK(!wm::IsWindowMinimized(gained_active)); | 159 DCHECK(!window_state->IsMinimized()); |
156 } | 160 } |
157 } | 161 } |
158 | 162 |
159 ///////////////////////////////////////////////////////////////////////////// | 163 ///////////////////////////////////////////////////////////////////////////// |
160 // BaseLayoutManager, ash::ShellObserver overrides: | 164 // BaseLayoutManager, ash::ShellObserver overrides: |
161 | 165 |
162 void BaseLayoutManager::OnDisplayWorkAreaInsetsChanged() { | 166 void BaseLayoutManager::OnDisplayWorkAreaInsetsChanged() { |
163 AdjustAllWindowsBoundsForWorkAreaChange( | 167 AdjustAllWindowsBoundsForWorkAreaChange( |
164 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED); | 168 ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED); |
165 } | 169 } |
166 | 170 |
167 ////////////////////////////////////////////////////////////////////////////// | 171 ////////////////////////////////////////////////////////////////////////////// |
168 // BaseLayoutManager, protected: | 172 // BaseLayoutManager, protected: |
169 | 173 |
170 void BaseLayoutManager::ShowStateChanged(aura::Window* window, | 174 void BaseLayoutManager::ShowStateChanged( |
171 ui::WindowShowState last_show_state) { | 175 wm::WindowState* window_state, |
James Cook
2013/09/18 20:44:17
Mostly a question: Since you can get the WindowSta
oshima
2013/09/19 01:52:01
I'm using
aura::Window* window = window_state->win
James Cook
2013/09/19 03:49:53
Good point that window_state->window() is much che
| |
172 if (wm::IsWindowMinimized(window)) { | 176 ui::WindowShowState last_show_state) { |
177 if (window_state->IsMinimized()) { | |
173 // Save the previous show state so that we can correctly restore it. | 178 // Save the previous show state so that we can correctly restore it. |
174 window->SetProperty(aura::client::kRestoreShowStateKey, last_show_state); | 179 window_state->window()->SetProperty(aura::client::kRestoreShowStateKey, |
180 last_show_state); | |
175 views::corewm::SetWindowVisibilityAnimationType( | 181 views::corewm::SetWindowVisibilityAnimationType( |
176 window, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 182 window_state->window(), WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
177 | 183 |
178 // Hide the window. | 184 // Hide the window. |
179 window->Hide(); | 185 window_state->window()->Hide(); |
180 // Activate another window. | 186 // Activate another window. |
181 if (wm::IsActiveWindow(window)) | 187 if (window_state->IsActive()) |
182 wm::DeactivateWindow(window); | 188 window_state->Deactivate(); |
183 } else if ((window->TargetVisibility() || | 189 } else if ((window_state->window()->TargetVisibility() || |
184 last_show_state == ui::SHOW_STATE_MINIMIZED) && | 190 last_show_state == ui::SHOW_STATE_MINIMIZED) && |
185 !window->layer()->visible()) { | 191 !window_state->window()->layer()->visible()) { |
186 // The layer may be hidden if the window was previously minimized. Make | 192 // The layer may be hidden if the window was previously minimized. Make |
187 // sure it's visible. | 193 // sure it's visible. |
188 window->Show(); | 194 window_state->window()->Show(); |
189 if (last_show_state == ui::SHOW_STATE_MINIMIZED && | 195 if (last_show_state == ui::SHOW_STATE_MINIMIZED && |
190 !wm::IsWindowMaximized(window) && | 196 !window_state->IsMaximizedOrFullscreen()) { |
191 !wm::IsWindowFullscreen(window)) { | 197 window_state->set_always_restores_to_restore_bounds(false); |
192 window->ClearProperty(internal::kWindowRestoresToRestoreBounds); | |
193 } | 198 } |
194 } | 199 } |
195 } | 200 } |
196 | 201 |
197 void BaseLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( | 202 void BaseLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange( |
198 AdjustWindowReason reason) { | 203 AdjustWindowReason reason) { |
199 // Don't do any adjustments of the insets while we are in screen locked mode. | 204 // Don't do any adjustments of the insets while we are in screen locked mode. |
200 // This would happen if the launcher was auto hidden before the login screen | 205 // This would happen if the launcher was auto hidden before the login screen |
201 // was shown and then gets shown when the login screen gets presented. | 206 // was shown and then gets shown when the login screen gets presented. |
202 if (reason == ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED && | 207 if (reason == ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED && |
203 Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) | 208 Shell::GetInstance()->session_state_delegate()->IsScreenLocked()) |
204 return; | 209 return; |
205 | 210 |
206 // If a user plugs an external display into a laptop running Aura the | 211 // If a user plugs an external display into a laptop running Aura the |
207 // display size will change. Maximized windows need to resize to match. | 212 // display size will change. Maximized windows need to resize to match. |
208 // We also do this when developers running Aura on a desktop manually resize | 213 // We also do this when developers running Aura on a desktop manually resize |
209 // the host window. | 214 // the host window. |
210 // We also need to do this when the work area insets changes. | 215 // We also need to do this when the work area insets changes. |
211 for (WindowSet::const_iterator it = windows_.begin(); | 216 for (WindowSet::const_iterator it = windows_.begin(); |
212 it != windows_.end(); | 217 it != windows_.end(); |
213 ++it) { | 218 ++it) { |
214 AdjustWindowBoundsForWorkAreaChange(*it, reason); | 219 AdjustWindowBoundsForWorkAreaChange(wm::GetWindowState(*it), reason); |
215 } | 220 } |
216 } | 221 } |
217 | 222 |
218 void BaseLayoutManager::AdjustWindowBoundsForWorkAreaChange( | 223 void BaseLayoutManager::AdjustWindowBoundsForWorkAreaChange( |
219 aura::Window* window, | 224 wm::WindowState* window_state, |
James Cook
2013/09/18 20:44:17
Same question as above
| |
220 AdjustWindowReason reason) { | 225 AdjustWindowReason reason) { |
221 if (wm::IsWindowMaximized(window)) { | 226 aura::Window* window = window_state->window(); |
227 if (window_state->IsMaximized()) { | |
222 SetChildBoundsDirect( | 228 SetChildBoundsDirect( |
223 window, ScreenAsh::GetMaximizedWindowBoundsInParent(window)); | 229 window, ScreenAsh::GetMaximizedWindowBoundsInParent(window)); |
224 } else if (wm::IsWindowFullscreen(window)) { | 230 } else if (window_state->IsFullscreen()) { |
225 SetChildBoundsDirect( | 231 SetChildBoundsDirect( |
226 window, ScreenAsh::GetDisplayBoundsInParent(window)); | 232 window, ScreenAsh::GetDisplayBoundsInParent(window)); |
227 } else { | 233 } else { |
228 // The work area may be smaller than the full screen. | 234 // The work area may be smaller than the full screen. |
229 gfx::Rect display_rect = | 235 gfx::Rect display_rect = |
230 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window); | 236 ScreenAsh::GetDisplayWorkAreaBoundsInParent(window); |
231 // Put as much of the window as possible within the display area. | 237 // Put as much of the window as possible within the display area. |
232 gfx::Rect bounds = window->bounds(); | 238 gfx::Rect bounds = window->bounds(); |
233 bounds.AdjustToFit(display_rect); | 239 bounds.AdjustToFit(display_rect); |
234 window->SetBounds(bounds); | 240 window->SetBounds(bounds); |
235 } | 241 } |
236 } | 242 } |
237 | 243 |
238 ////////////////////////////////////////////////////////////////////////////// | 244 ////////////////////////////////////////////////////////////////////////////// |
239 // BaseLayoutManager, private: | 245 // BaseLayoutManager, private: |
240 | 246 |
241 void BaseLayoutManager::UpdateBoundsFromShowState(aura::Window* window) { | 247 void BaseLayoutManager::UpdateBoundsFromShowState( |
242 switch (window->GetProperty(aura::client::kShowStateKey)) { | 248 wm::WindowState* window_state) { |
249 aura::Window* window = window_state->window(); | |
250 switch (window_state->GetShowState()) { | |
243 case ui::SHOW_STATE_DEFAULT: | 251 case ui::SHOW_STATE_DEFAULT: |
244 case ui::SHOW_STATE_NORMAL: { | 252 case ui::SHOW_STATE_NORMAL: { |
245 const gfx::Rect* restore = GetRestoreBoundsInScreen(window); | 253 if (window_state->HasRestoreBounds()) { |
246 if (restore) { | 254 gfx::Rect bounds_in_parent = window_state->GetRestoreBoundsInParent(); |
247 gfx::Rect bounds_in_parent = | |
248 ScreenAsh::ConvertRectFromScreen(window->parent(), *restore); | |
249 SetChildBoundsDirect(window, | 255 SetChildBoundsDirect(window, |
250 BoundsWithScreenEdgeVisible(window, | 256 BoundsWithScreenEdgeVisible(window, |
251 bounds_in_parent)); | 257 bounds_in_parent)); |
252 } | 258 } |
253 ClearRestoreBounds(window); | 259 window_state->ClearRestoreBounds(); |
254 break; | 260 break; |
255 } | 261 } |
256 | 262 |
257 case ui::SHOW_STATE_MAXIMIZED: | 263 case ui::SHOW_STATE_MAXIMIZED: |
258 SetChildBoundsDirect(window, | 264 SetChildBoundsDirect( |
259 ScreenAsh::GetMaximizedWindowBoundsInParent(window)); | 265 window, ScreenAsh::GetMaximizedWindowBoundsInParent(window)); |
260 break; | 266 break; |
261 | 267 |
262 case ui::SHOW_STATE_FULLSCREEN: | 268 case ui::SHOW_STATE_FULLSCREEN: |
263 // Don't animate the full-screen window transition. | 269 // Don't animate the full-screen window transition. |
264 // TODO(jamescook): Use animation here. Be sure the lock screen works. | 270 // TODO(jamescook): Use animation here. Be sure the lock screen works. |
265 SetChildBoundsDirect( | 271 SetChildBoundsDirect(window, |
266 window, ScreenAsh::GetDisplayBoundsInParent(window)); | 272 ScreenAsh::GetDisplayBoundsInParent(window)); |
267 break; | 273 break; |
268 | 274 |
269 default: | 275 default: |
270 break; | 276 break; |
271 } | 277 } |
272 } | 278 } |
273 | 279 |
274 } // namespace internal | 280 } // namespace internal |
275 } // namespace ash | 281 } // namespace ash |
OLD | NEW |