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/splitview/split_view_controller.h" |
14 #include "ash/wm/window_animation_types.h" | 15 #include "ash/wm/window_animation_types.h" |
15 #include "ash/wm/window_properties.h" | 16 #include "ash/wm/window_properties.h" |
16 #include "ash/wm/window_state_util.h" | 17 #include "ash/wm/window_state_util.h" |
17 #include "ash/wm/wm_event.h" | 18 #include "ash/wm/wm_event.h" |
18 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 20 #include "ui/aura/window_delegate.h" |
20 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
21 #include "ui/gfx/geometry/rect.h" | 22 #include "ui/gfx/geometry/rect.h" |
22 | 23 |
23 namespace ash { | 24 namespace ash { |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 61 |
61 // 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. |
62 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent, | 63 gfx::Rect GetCenteredBounds(const gfx::Rect& bounds_in_parent, |
63 wm::WindowState* state_object) { | 64 wm::WindowState* state_object) { |
64 gfx::Rect work_area_in_parent = | 65 gfx::Rect work_area_in_parent = |
65 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window()); | 66 ScreenUtil::GetDisplayWorkAreaBoundsInParent(state_object->window()); |
66 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); | 67 work_area_in_parent.ClampToCenteredSize(bounds_in_parent.size()); |
67 return work_area_in_parent; | 68 return work_area_in_parent; |
68 } | 69 } |
69 | 70 |
| 71 // Returns true if the window can snap in maximized mode. |
| 72 bool CanSnap(wm::WindowState* window_state) { |
| 73 // If split view mode is not allowed in maximized mode, do not allow snap |
| 74 // window. |
| 75 if (!SplitViewController::ShouldAllowSplitView()) |
| 76 return false; |
| 77 return window_state->CanSnap(); |
| 78 } |
| 79 |
70 // Returns the maximized/full screen and/or centered bounds of a window. | 80 // Returns the maximized/full screen and/or centered bounds of a window. |
71 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { | 81 gfx::Rect GetBoundsInMaximizedMode(wm::WindowState* state_object) { |
72 if (state_object->IsFullscreen() || state_object->IsPinned()) | 82 if (state_object->IsFullscreen() || state_object->IsPinned()) |
73 return ScreenUtil::GetDisplayBoundsInParent(state_object->window()); | 83 return ScreenUtil::GetDisplayBoundsInParent(state_object->window()); |
74 | 84 |
| 85 if (state_object->GetStateType() == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED) { |
| 86 DCHECK(CanSnap(state_object)); |
| 87 return Shell::Get() |
| 88 ->split_view_controller() |
| 89 ->GetSnappedWindowBoundsInParent(state_object->window(), |
| 90 SplitViewController::LEFT_SNAPPED); |
| 91 } |
| 92 |
| 93 if (state_object->GetStateType() == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) { |
| 94 DCHECK(CanSnap(state_object)); |
| 95 return Shell::Get() |
| 96 ->split_view_controller() |
| 97 ->GetSnappedWindowBoundsInParent(state_object->window(), |
| 98 SplitViewController::RIGHT_SNAPPED); |
| 99 } |
| 100 |
75 gfx::Rect bounds_in_parent; | 101 gfx::Rect bounds_in_parent; |
76 // Make the window as big as possible. | 102 // Make the window as big as possible. |
77 if (state_object->CanMaximize() || state_object->CanResize()) { | 103 if (state_object->CanMaximize() || state_object->CanResize()) { |
78 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); | 104 bounds_in_parent.set_size(GetMaximumSizeOfWindow(state_object)); |
79 } else { | 105 } else { |
80 // We prefer the user given window dimensions over the current windows | 106 // We prefer the user given window dimensions over the current windows |
81 // dimensions since they are likely to be the result from some other state | 107 // dimensions since they are likely to be the result from some other state |
82 // object logic. | 108 // object logic. |
83 if (state_object->HasRestoreBounds()) | 109 if (state_object->HasRestoreBounds()) |
84 bounds_in_parent = state_object->GetRestoreBoundsInParent(); | 110 bounds_in_parent = state_object->GetRestoreBoundsInParent(); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 if (!Shell::Get()->screen_pinning_controller()->IsPinned()) | 188 if (!Shell::Get()->screen_pinning_controller()->IsPinned()) |
163 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_TRUSTED_PINNED, true); | 189 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_TRUSTED_PINNED, true); |
164 break; | 190 break; |
165 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: | 191 case wm::WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
166 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: | 192 case wm::WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
167 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: | 193 case wm::WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
168 case wm::WM_EVENT_TOGGLE_MAXIMIZE: | 194 case wm::WM_EVENT_TOGGLE_MAXIMIZE: |
169 case wm::WM_EVENT_CYCLE_SNAP_LEFT: | 195 case wm::WM_EVENT_CYCLE_SNAP_LEFT: |
170 case wm::WM_EVENT_CYCLE_SNAP_RIGHT: | 196 case wm::WM_EVENT_CYCLE_SNAP_RIGHT: |
171 case wm::WM_EVENT_CENTER: | 197 case wm::WM_EVENT_CENTER: |
172 case wm::WM_EVENT_SNAP_LEFT: | |
173 case wm::WM_EVENT_SNAP_RIGHT: | |
174 case wm::WM_EVENT_NORMAL: | 198 case wm::WM_EVENT_NORMAL: |
175 case wm::WM_EVENT_MAXIMIZE: | 199 case wm::WM_EVENT_MAXIMIZE: |
176 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), | 200 UpdateWindow(window_state, GetMaximizedOrCenteredWindowType(window_state), |
177 true); | 201 true); |
178 return; | 202 return; |
| 203 case wm::WM_EVENT_SNAP_LEFT: |
| 204 UpdateWindow(window_state, |
| 205 GetSnappedWindowStateType( |
| 206 window_state, wm::WINDOW_STATE_TYPE_LEFT_SNAPPED), |
| 207 true); |
| 208 return; |
| 209 case wm::WM_EVENT_SNAP_RIGHT: |
| 210 UpdateWindow(window_state, |
| 211 GetSnappedWindowStateType( |
| 212 window_state, wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED), |
| 213 true); |
| 214 return; |
179 case wm::WM_EVENT_MINIMIZE: | 215 case wm::WM_EVENT_MINIMIZE: |
180 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED, true); | 216 UpdateWindow(window_state, wm::WINDOW_STATE_TYPE_MINIMIZED, true); |
181 return; | 217 return; |
182 case wm::WM_EVENT_SHOW_INACTIVE: | 218 case wm::WM_EVENT_SHOW_INACTIVE: |
183 return; | 219 return; |
184 case wm::WM_EVENT_SET_BOUNDS: | 220 case wm::WM_EVENT_SET_BOUNDS: |
185 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) { | 221 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MAXIMIZED) { |
186 // Having a maximized window, it could have been created with an empty | 222 // Having a maximized window, it could have been created with an empty |
187 // size and the caller should get his size upon leaving the maximized | 223 // size and the caller should get his size upon leaving the maximized |
188 // mode. As such we set the restore bounds to the requested bounds. | 224 // mode. As such we set the restore bounds to the requested bounds. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 303 |
268 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, | 304 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, |
269 wm::WindowStateType target_state, | 305 wm::WindowStateType target_state, |
270 bool animated) { | 306 bool animated) { |
271 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || | 307 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || |
272 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || | 308 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || |
273 target_state == wm::WINDOW_STATE_TYPE_PINNED || | 309 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
274 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || | 310 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || |
275 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && | 311 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && |
276 !window_state->CanMaximize()) || | 312 !window_state->CanMaximize()) || |
277 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); | 313 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN || |
| 314 target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || |
| 315 target_state == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); |
278 | 316 |
279 if (current_state_type_ == target_state) { | 317 if (current_state_type_ == target_state) { |
280 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) | 318 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) |
281 return; | 319 return; |
282 // If the state type did not change, update it accordingly. | 320 // If the state type did not change, update it accordingly. |
283 UpdateBounds(window_state, animated); | 321 UpdateBounds(window_state, animated); |
284 return; | 322 return; |
285 } | 323 } |
286 | 324 |
287 const wm::WindowStateType old_state_type = current_state_type_; | 325 const wm::WindowStateType old_state_type = current_state_type_; |
288 current_state_type_ = target_state; | 326 current_state_type_ = target_state; |
289 window_state->UpdateWindowPropertiesFromStateType(); | 327 window_state->UpdateWindowPropertiesFromStateType(); |
290 window_state->NotifyPreStateTypeChange(old_state_type); | 328 window_state->NotifyPreStateTypeChange(old_state_type); |
291 | 329 |
292 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { | 330 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { |
293 ::wm::SetWindowVisibilityAnimationType( | 331 ::wm::SetWindowVisibilityAnimationType( |
294 window_state->window(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 332 window_state->window(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); |
295 window_state->window()->Hide(); | 333 window_state->window()->Hide(); |
296 if (window_state->IsActive()) | 334 if (window_state->IsActive()) |
297 window_state->Deactivate(); | 335 window_state->Deactivate(); |
| 336 } else if (target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED) { |
| 337 window_state->SetBoundsDirectAnimated( |
| 338 Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInParent( |
| 339 window_state->window(), SplitViewController::LEFT_SNAPPED)); |
| 340 } else if (target_state == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) { |
| 341 window_state->SetBoundsDirectAnimated( |
| 342 Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInParent( |
| 343 window_state->window(), SplitViewController::RIGHT_SNAPPED)); |
298 } else { | 344 } else { |
299 UpdateBounds(window_state, animated); | 345 UpdateBounds(window_state, animated); |
300 } | 346 } |
301 | 347 |
302 window_state->NotifyPostStateTypeChange(old_state_type); | 348 window_state->NotifyPostStateTypeChange(old_state_type); |
303 | 349 |
304 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || | 350 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || |
305 target_state == wm::WINDOW_STATE_TYPE_PINNED || | 351 target_state == wm::WINDOW_STATE_TYPE_PINNED || |
306 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || | 352 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || |
307 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { | 353 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { |
308 Shell::Get()->screen_pinning_controller()->SetPinnedWindow( | 354 Shell::Get()->screen_pinning_controller()->SetPinnedWindow( |
309 window_state->window()); | 355 window_state->window()); |
310 } | 356 } |
311 | 357 |
312 if ((window_state->window()->layer()->GetTargetVisibility() || | 358 if ((window_state->window()->layer()->GetTargetVisibility() || |
313 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && | 359 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && |
314 !window_state->window()->layer()->visible()) { | 360 !window_state->window()->layer()->visible()) { |
315 // The layer may be hidden if the window was previously minimized. Make | 361 // The layer may be hidden if the window was previously minimized. Make |
316 // sure it's visible. | 362 // sure it's visible. |
317 window_state->window()->Show(); | 363 window_state->window()->Show(); |
318 } | 364 } |
319 } | 365 } |
320 | 366 |
321 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( | 367 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( |
322 wm::WindowState* window_state) { | 368 wm::WindowState* window_state) { |
323 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED | 369 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED |
324 : wm::WINDOW_STATE_TYPE_NORMAL; | 370 : wm::WINDOW_STATE_TYPE_NORMAL; |
325 } | 371 } |
326 | 372 |
| 373 wm::WindowStateType MaximizeModeWindowState::GetSnappedWindowStateType( |
| 374 wm::WindowState* window_state, |
| 375 wm::WindowStateType target_state) { |
| 376 DCHECK(target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED || |
| 377 target_state == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED); |
| 378 return CanSnap(window_state) ? target_state |
| 379 : GetMaximizedOrCenteredWindowType(window_state); |
| 380 } |
| 381 |
327 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, | 382 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, |
328 bool animated) { | 383 bool animated) { |
329 if (defer_bounds_updates_) | 384 if (defer_bounds_updates_) |
330 return; | 385 return; |
331 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); | 386 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); |
332 // If we have a target bounds rectangle, we center it and set it | 387 // If we have a target bounds rectangle, we center it and set it |
333 // accordingly. | 388 // accordingly. |
334 if (!bounds_in_parent.IsEmpty() && | 389 if (!bounds_in_parent.IsEmpty() && |
335 bounds_in_parent != window_state->window()->bounds()) { | 390 bounds_in_parent != window_state->window()->bounds()) { |
336 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || | 391 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || |
337 !window_state->window()->IsVisible() || !animated) { | 392 !window_state->window()->IsVisible() || !animated) { |
338 window_state->SetBoundsDirect(bounds_in_parent); | 393 window_state->SetBoundsDirect(bounds_in_parent); |
339 } else { | 394 } else { |
340 // If we animate (to) maximized mode, we want to use the cross fade to | 395 // If we animate (to) maximized mode, we want to use the cross fade to |
341 // avoid flashing. | 396 // avoid flashing. |
342 if (window_state->IsMaximized()) | 397 if (window_state->IsMaximized()) |
343 window_state->SetBoundsDirectCrossFade(bounds_in_parent); | 398 window_state->SetBoundsDirectCrossFade(bounds_in_parent); |
344 else | 399 else |
345 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 400 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
346 } | 401 } |
347 } | 402 } |
348 } | 403 } |
349 | 404 |
350 } // namespace ash | 405 } // namespace ash |
OLD | NEW |