OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/maximize_mode/maximize_mode_window_state.h" | 5 #include "ash/wm/maximize_mode/maximize_mode_window_state.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "ash/public/cpp/shell_window_ids.h" | 9 #include "ash/public/cpp/shell_window_ids.h" |
10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" | 12 #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" |
13 #include "ash/wm/screen_pinning_controller.h" | 13 #include "ash/wm/screen_pinning_controller.h" |
14 #include "ash/wm/window_animation_types.h" | 14 #include "ash/wm/window_animation_types.h" |
| 15 #include "ash/wm/window_properties.h" |
15 #include "ash/wm/window_state_util.h" | 16 #include "ash/wm/window_state_util.h" |
16 #include "ash/wm/wm_event.h" | 17 #include "ash/wm/wm_event.h" |
17 #include "ash/wm_window.h" | 18 #include "ash/wm_window.h" |
| 19 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_delegate.h" |
18 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
19 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
20 | 23 |
21 namespace ash { | 24 namespace ash { |
22 namespace { | 25 namespace { |
23 | 26 |
| 27 // Sets the restore bounds and show state overrides. These values take |
| 28 // precedence over the restore bounds and restore show state (if set). |
| 29 // If |bounds_override| is empty the values are cleared. |
| 30 void SetWindowRestoreOverrides(aura::Window* window, |
| 31 const gfx::Rect& bounds_override, |
| 32 ui::WindowShowState window_state_override) { |
| 33 if (bounds_override.IsEmpty()) { |
| 34 window->ClearProperty(kRestoreShowStateOverrideKey); |
| 35 window->ClearProperty(kRestoreBoundsOverrideKey); |
| 36 return; |
| 37 } |
| 38 window->SetProperty(kRestoreShowStateOverrideKey, window_state_override); |
| 39 window->SetProperty(kRestoreBoundsOverrideKey, |
| 40 new gfx::Rect(bounds_override)); |
| 41 } |
| 42 |
24 // Returns the biggest possible size for a window which is about to be | 43 // Returns the biggest possible size for a window which is about to be |
25 // maximized. | 44 // maximized. |
26 gfx::Size GetMaximumSizeOfWindow(wm::WindowState* window_state) { | 45 gfx::Size GetMaximumSizeOfWindow(wm::WindowState* window_state) { |
27 DCHECK(window_state->CanMaximize() || window_state->CanResize()); | 46 DCHECK(window_state->CanMaximize() || window_state->CanResize()); |
28 | 47 |
29 gfx::Size workspace_size = ScreenUtil::GetMaximizedWindowBoundsInParent( | 48 gfx::Size workspace_size = |
30 window_state->window()->aura_window()) | 49 ScreenUtil::GetMaximizedWindowBoundsInParent(window_state->window()) |
31 .size(); | 50 .size(); |
32 | 51 |
33 gfx::Size size = window_state->window()->GetMaximumSize(); | 52 gfx::Size size = window_state->window()->delegate() |
| 53 ? window_state->window()->delegate()->GetMaximumSize() |
| 54 : gfx::Size(); |
34 if (size.IsEmpty()) | 55 if (size.IsEmpty()) |
35 return workspace_size; | 56 return workspace_size; |
36 | 57 |
37 size.SetToMin(workspace_size); | 58 size.SetToMin(workspace_size); |
38 return size; | 59 return size; |
39 } | 60 } |
40 | 61 |
41 // Returns the centered bounds of the given bounds in the work area. | 62 // Returns the centered bounds of the given bounds in the work area. |
42 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent, | 63 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent, |
43 wm::WindowState* state_object) { | 64 wm::WindowState* state_object) { |
44 gfx::Rect work_area_in_parent = ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 65 gfx::Rect work_area_in_parent = |
45 state_object->window()->aura_window()); | 66 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window()); |
46 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); | 67 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); |
47 return work_area_in_parent; | 68 return work_area_in_parent; |
48 } | 69 } |
49 | 70 |
50 // Returns the maximized/full screen and/or centered bounds of a window. | 71 // Returns the maximized/full screen and/or centered bounds of a window. |
51 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { | 72 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { |
52 if (state_object->IsFullscreen() || state_object->IsPinned()) | 73 if (state_object->IsFullscreen() || state_object->IsPinned()) |
53 return ScreenUtil::GetDisplayBoundsInParent( | 74 return ScreenUtil::GetDisplayBoundsInParent(state_object->window()); |
54 state_object->window()->aura_window()); | |
55 | 75 |
56 gfx::Rect bounds_in_parent; | 76 gfx::Rect bounds_in_parent; |
57 // Make the window as big as possible. | 77 // Make the window as big as possible. |
58 if (state_object->CanMaximize() || state_object->CanResize()) { | 78 if (state_object->CanMaximize() || state_object->CanResize()) { |
59 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); | 79 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); |
60 } else { | 80 } else { |
61 // We prefer the user given window dimensions over the current windows | 81 // We prefer the user given window dimensions over the current windows |
62 // dimensions since they are likely to be the result from some other state | 82 // dimensions since they are likely to be the result from some other state |
63 // object logic. | 83 // object logic. |
64 if (state_object->HasRestoreBounds()) | 84 if (state_object->HasRestoreBounds()) |
65 bounds_in_parent = state_object->GetRestoreBoundsInParent(); | 85 bounds_in_parent = state_object->GetRestoreBoundsInParent(); |
66 else | 86 else |
67 bounds_in_parent = state_object->window()->GetBounds(); | 87 bounds_in_parent = state_object->window()->bounds(); |
68 } | 88 } |
69 return GetCenteredBounds(bounds_in_parent, state_object); | 89 return GetCenteredBounds(bounds_in_parent, state_object); |
70 } | 90 } |
71 | 91 |
72 gfx::Rect GetRestoreBounds(wm::WindowState* window_state) { | 92 gfx::Rect GetRestoreBounds(wm::WindowState* window_state) { |
73 if (window_state->IsMinimized() || window_state->IsMaximized() || | 93 if (window_state->IsMinimized() || window_state->IsMaximized() || |
74 window_state->IsFullscreen()) { | 94 window_state->IsFullscreen()) { |
75 gfx::Rect restore_bounds = window_state->GetRestoreBoundsInScreen(); | 95 gfx::Rect restore_bounds = window_state->GetRestoreBoundsInScreen(); |
76 if (!restore_bounds.IsEmpty()) | 96 if (!restore_bounds.IsEmpty()) |
77 return restore_bounds; | 97 return restore_bounds; |
78 } | 98 } |
79 return window_state->window()->GetBoundsInScreen(); | 99 return window_state->window()->GetBoundsInScreen(); |
80 } | 100 } |
81 | 101 |
82 } // namespace | 102 } // namespace |
83 | 103 |
84 // static | 104 // static |
85 void MaximizeModeWindowState::UpdateWindowPosition( | 105 void MaximizeModeWindowState::UpdateWindowPosition( |
86 wm::WindowState* window_state) { | 106 wm::WindowState* window_state) { |
87 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); | 107 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); |
88 if (bounds_in_parent == window_state->window()->GetBounds()) | 108 if (bounds_in_parent == window_state->window()->bounds()) |
89 return; | 109 return; |
90 window_state->SetBoundsDirect(bounds_in_parent); | 110 window_state->SetBoundsDirect(bounds_in_parent); |
91 } | 111 } |
92 | 112 |
93 MaximizeModeWindowState::MaximizeModeWindowState( | 113 MaximizeModeWindowState::MaximizeModeWindowState( |
94 WmWindow* window, | 114 WmWindow* window, |
95 MaximizeModeWindowManager* creator) | 115 MaximizeModeWindowManager* creator) |
96 : window_(window), | 116 : window_(window), |
97 creator_(creator), | 117 creator_(creator), |
98 current_state_type_(window->GetWindowState()->GetStateType()), | 118 current_state_type_(window->GetWindowState()->GetStateType()), |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 window_state->SetRestoreBoundsInParent(bounds_in_parent); | 193 window_state->SetRestoreBoundsInParent(bounds_in_parent); |
174 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && | 194 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
175 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && | 195 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && |
176 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED && | 196 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED && |
177 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { | 197 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
178 // In all other cases (except for minimized windows) we respect the | 198 // In all other cases (except for minimized windows) we respect the |
179 // requested bounds and center it to a fully visible area on the screen. | 199 // requested bounds and center it to a fully visible area on the screen. |
180 gfx::Rect bounds_in_parent = | 200 gfx::Rect bounds_in_parent = |
181 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); | 201 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); |
182 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); | 202 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); |
183 if (bounds_in_parent != window_state->window()->GetBounds()) { | 203 if (bounds_in_parent != window_state->window()->bounds()) { |
184 if (window_state->window()->IsVisible()) | 204 if (window_state->window()->IsVisible()) |
185 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 205 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
186 else | 206 else |
187 window_state->SetBoundsDirect(bounds_in_parent); | 207 window_state->SetBoundsDirect(bounds_in_parent); |
188 } | 208 } |
189 } | 209 } |
190 break; | 210 break; |
191 case wm::WM_EVENT_ADDED_TO_WORKSPACE: | 211 case wm::WM_EVENT_ADDED_TO_WORKSPACE: |
192 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && | 212 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
193 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && | 213 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && |
(...skipping 21 matching lines...) Expand all Loading... |
215 | 235 |
216 void MaximizeModeWindowState::AttachState( | 236 void MaximizeModeWindowState::AttachState( |
217 wm::WindowState* window_state, | 237 wm::WindowState* window_state, |
218 wm::WindowState::State* previous_state) { | 238 wm::WindowState::State* previous_state) { |
219 current_state_type_ = previous_state->GetType(); | 239 current_state_type_ = previous_state->GetType(); |
220 | 240 |
221 gfx::Rect restore_bounds = GetRestoreBounds(window_state); | 241 gfx::Rect restore_bounds = GetRestoreBounds(window_state); |
222 if (!restore_bounds.IsEmpty()) { | 242 if (!restore_bounds.IsEmpty()) { |
223 // We do not want to do a session restore to our window states. Therefore | 243 // We do not want to do a session restore to our window states. Therefore |
224 // we tell the window to use the current default states instead. | 244 // we tell the window to use the current default states instead. |
225 window_state->window()->SetRestoreOverrides(restore_bounds, | 245 SetWindowRestoreOverrides(window_state->window(), restore_bounds, |
226 window_state->GetShowState()); | 246 window_state->GetShowState()); |
227 } | 247 } |
228 | 248 |
229 // Initialize the state to a good preset. | 249 // Initialize the state to a good preset. |
230 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && | 250 if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && |
231 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && | 251 current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && |
232 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && | 252 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && |
233 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED && | 253 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED && |
234 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { | 254 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
235 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), | 255 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), |
236 true); | 256 true); |
237 } | 257 } |
238 | 258 |
239 window_state->set_can_be_dragged(false); | 259 window_state->set_can_be_dragged(false); |
240 } | 260 } |
241 | 261 |
242 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { | 262 void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { |
243 // From now on, we can use the default session restore mechanism again. | 263 // From now on, we can use the default session restore mechanism again. |
244 window_state->window()->SetRestoreOverrides(gfx::Rect(), | 264 SetWindowRestoreOverrides(window_state->window(), gfx::Rect(), |
245 ui::SHOW_STATE_NORMAL); | 265 ui::SHOW_STATE_NORMAL); |
246 window_state->set_can_be_dragged(true); | 266 window_state->set_can_be_dragged(true); |
247 } | 267 } |
248 | 268 |
249 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, | 269 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, |
250 wm::WindowStateType target_state, | 270 wm::WindowStateType target_state, |
251 bool animated) { | 271 bool animated) { |
252 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || | 272 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || |
253 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || | 273 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || |
254 target_state == wm::WINDOW_STATE_TYPE_PINNED || | 274 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
255 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || | 275 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || |
256 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && | 276 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && |
257 !window_state->CanMaximize()) || | 277 !window_state->CanMaximize()) || |
258 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); | 278 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); |
259 | 279 |
260 if (current_state_type_ == target_state) { | 280 if (current_state_type_ == target_state) { |
261 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) | 281 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) |
262 return; | 282 return; |
263 // If the state type did not change, update it accordingly. | 283 // If the state type did not change, update it accordingly. |
264 UpdateBounds(window_state, animated); | 284 UpdateBounds(window_state, animated); |
265 return; | 285 return; |
266 } | 286 } |
267 | 287 |
268 const wm::WindowStateType old_state_type = current_state_type_; | 288 const wm::WindowStateType old_state_type = current_state_type_; |
269 current_state_type_ = target_state; | 289 current_state_type_ = target_state; |
270 window_state->UpdateWindowPropertiesFromStateType(); | 290 window_state->UpdateWindowPropertiesFromStateType(); |
271 window_state->NotifyPreStateTypeChange(old_state_type); | 291 window_state->NotifyPreStateTypeChange(old_state_type); |
272 | 292 |
273 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { | 293 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { |
274 window_state->window()->SetVisibilityAnimationType( | 294 ::wm::SetWindowVisibilityAnimationType( |
275 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 295 window_state->window(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
276 window_state->window()->Hide(); | 296 window_state->window()->Hide(); |
277 if (window_state->IsActive()) | 297 if (window_state->IsActive()) |
278 window_state->Deactivate(); | 298 window_state->Deactivate(); |
279 } else { | 299 } else { |
280 UpdateBounds(window_state, animated); | 300 UpdateBounds(window_state, animated); |
281 } | 301 } |
282 | 302 |
283 window_state->NotifyPostStateTypeChange(old_state_type); | 303 window_state->NotifyPostStateTypeChange(old_state_type); |
284 | 304 |
285 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || | 305 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || |
286 target_state == wm::WINDOW_STATE_TYPE_PINNED || | 306 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
287 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || | 307 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || |
288 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { | 308 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
289 Shell::Get()->screen_pinning_controller()->SetPinnedWindow( | 309 Shell::Get()->screen_pinning_controller()->SetPinnedWindow( |
290 window_state->window()); | 310 WmWindow::Get(window_state->window())); |
291 } | 311 } |
292 | 312 |
293 if ((window_state->window()->GetTargetVisibility() || | 313 if ((window_state->window()->layer()->GetTargetVisibility() || |
294 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && | 314 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && |
295 !window_state->window()->GetLayer()->visible()) { | 315 !window_state->window()->layer()->visible()) { |
296 // The layer may be hidden if the window was previously minimized. Make | 316 // The layer may be hidden if the window was previously minimized. Make |
297 // sure it's visible. | 317 // sure it's visible. |
298 window_state->window()->Show(); | 318 window_state->window()->Show(); |
299 } | 319 } |
300 } | 320 } |
301 | 321 |
302 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( | 322 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( |
303 wm::WindowState* window_state) { | 323 wm::WindowState* window_state) { |
304 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED | 324 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED |
305 : wm::WINDOW_STATE_TYPE_NORMAL; | 325 : wm::WINDOW_STATE_TYPE_NORMAL; |
306 } | 326 } |
307 | 327 |
308 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, | 328 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, |
309 bool animated) { | 329 bool animated) { |
310 if (defer_bounds_updates_) | 330 if (defer_bounds_updates_) |
311 return; | 331 return; |
312 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); | 332 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); |
313 // If we have a target bounds rectangle, we center it and set it | 333 // If we have a target bounds rectangle, we center it and set it |
314 // accordingly. | 334 // accordingly. |
315 if (!bounds_in_parent.IsEmpty() && | 335 if (!bounds_in_parent.IsEmpty() && |
316 bounds_in_parent != window_state->window()->GetBounds()) { | 336 bounds_in_parent != window_state->window()->bounds()) { |
317 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || | 337 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || |
318 !window_state->window()->IsVisible() || !animated) { | 338 !window_state->window()->IsVisible() || !animated) { |
319 window_state->SetBoundsDirect(bounds_in_parent); | 339 window_state->SetBoundsDirect(bounds_in_parent); |
320 } else { | 340 } else { |
321 // If we animate (to) maximized mode, we want to use the cross fade to | 341 // If we animate (to) maximized mode, we want to use the cross fade to |
322 // avoid flashing. | 342 // avoid flashing. |
323 if (window_state->IsMaximized()) | 343 if (window_state->IsMaximized()) |
324 window_state->SetBoundsDirectCrossFade(bounds_in_parent); | 344 window_state->SetBoundsDirectCrossFade(bounds_in_parent); |
325 else | 345 else |
326 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 346 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
327 } | 347 } |
328 } | 348 } |
329 } | 349 } |
330 | 350 |
331 } // namespace ash | 351 } // namespace ash |
OLD | NEW |