Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: ash/wm/maximize_mode/maximize_mode_window_state.cc

Issue 2960843004: CrOS Tablet Window management - Split Screen part I (Closed)
Patch Set: nit. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
varkha 2017/06/30 14:29:34 nit: 'do not snap the window' or 'do not allow sna
xdai1 2017/07/05 20:18:22 Done.
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
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.
189 gfx::Rect bounds_in_parent = 225 gfx::Rect bounds_in_parent =
190 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); 226 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds();
191 if (!bounds_in_parent.IsEmpty()) 227 if (!bounds_in_parent.IsEmpty())
192 window_state->SetRestoreBoundsInParent(bounds_in_parent); 228 window_state->SetRestoreBoundsInParent(bounds_in_parent);
193 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && 229 } else if (current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED &&
194 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN && 230 current_state_type_ != wm::WINDOW_STATE_TYPE_FULLSCREEN &&
195 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED && 231 current_state_type_ != wm::WINDOW_STATE_TYPE_PINNED &&
196 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { 232 current_state_type_ != wm::WINDOW_STATE_TYPE_TRUSTED_PINNED &&
233 current_state_type_ != wm::WINDOW_STATE_TYPE_LEFT_SNAPPED &&
234 current_state_type_ != wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) {
197 // In all other cases (except for minimized windows) we respect the 235 // In all other cases (except for minimized windows) we respect the
198 // requested bounds and center it to a fully visible area on the screen. 236 // requested bounds and center it to a fully visible area on the screen.
199 gfx::Rect bounds_in_parent = 237 gfx::Rect bounds_in_parent =
200 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds(); 238 (static_cast<const wm::SetBoundsEvent*>(event))->requested_bounds();
201 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state); 239 bounds_in_parent = GetCenteredBounds(bounds_in_parent, window_state);
202 if (bounds_in_parent != window_state->window()->bounds()) { 240 if (bounds_in_parent != window_state->window()->bounds()) {
203 if (window_state->window()->IsVisible()) 241 if (window_state->window()->IsVisible())
204 window_state->SetBoundsDirectAnimated(bounds_in_parent); 242 window_state->SetBoundsDirectAnimated(bounds_in_parent);
205 else 243 else
206 window_state->SetBoundsDirect(bounds_in_parent); 244 window_state->SetBoundsDirect(bounds_in_parent);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 305
268 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state, 306 void MaximizeModeWindowState::UpdateWindow(wm::WindowState* window_state,
269 wm::WindowStateType target_state, 307 wm::WindowStateType target_state,
270 bool animated) { 308 bool animated) {
271 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED || 309 DCHECK(target_state == wm::WINDOW_STATE_TYPE_MINIMIZED ||
272 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED || 310 target_state == wm::WINDOW_STATE_TYPE_MAXIMIZED ||
273 target_state == wm::WINDOW_STATE_TYPE_PINNED || 311 target_state == wm::WINDOW_STATE_TYPE_PINNED ||
274 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || 312 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED ||
275 (target_state == wm::WINDOW_STATE_TYPE_NORMAL && 313 (target_state == wm::WINDOW_STATE_TYPE_NORMAL &&
276 !window_state->CanMaximize()) || 314 !window_state->CanMaximize()) ||
277 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN); 315 target_state == wm::WINDOW_STATE_TYPE_FULLSCREEN ||
316 target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ||
317 target_state == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED);
278 318
279 if (current_state_type_ == target_state) { 319 if (current_state_type_ == target_state) {
280 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) 320 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED)
281 return; 321 return;
282 // If the state type did not change, update it accordingly. 322 // If the state type did not change, update it accordingly.
283 UpdateBounds(window_state, animated); 323 UpdateBounds(window_state, animated);
284 return; 324 return;
285 } 325 }
286 326
287 const wm::WindowStateType old_state_type = current_state_type_; 327 const wm::WindowStateType old_state_type = current_state_type_;
288 current_state_type_ = target_state; 328 current_state_type_ = target_state;
289 window_state->UpdateWindowPropertiesFromStateType(); 329 window_state->UpdateWindowPropertiesFromStateType();
290 window_state->NotifyPreStateTypeChange(old_state_type); 330 window_state->NotifyPreStateTypeChange(old_state_type);
291 331
292 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) { 332 if (target_state == wm::WINDOW_STATE_TYPE_MINIMIZED) {
293 ::wm::SetWindowVisibilityAnimationType( 333 ::wm::SetWindowVisibilityAnimationType(
294 window_state->window(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); 334 window_state->window(), wm::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE);
295 window_state->window()->Hide(); 335 window_state->window()->Hide();
296 if (window_state->IsActive()) 336 if (window_state->IsActive())
297 window_state->Deactivate(); 337 window_state->Deactivate();
338 } else if (target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED) {
339 window_state->SetBoundsDirectAnimated(
340 Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInParent(
341 window_state->window(), SplitViewController::LEFT_SNAPPED));
342 } else if (target_state == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED) {
343 window_state->SetBoundsDirectAnimated(
344 Shell::Get()->split_view_controller()->GetSnappedWindowBoundsInParent(
345 window_state->window(), SplitViewController::RIGHT_SNAPPED));
298 } else { 346 } else {
299 UpdateBounds(window_state, animated); 347 UpdateBounds(window_state, animated);
300 } 348 }
301 349
302 window_state->NotifyPostStateTypeChange(old_state_type); 350 window_state->NotifyPostStateTypeChange(old_state_type);
303 351
304 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED || 352 if (old_state_type == wm::WINDOW_STATE_TYPE_PINNED ||
305 target_state == wm::WINDOW_STATE_TYPE_PINNED || 353 target_state == wm::WINDOW_STATE_TYPE_PINNED ||
306 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED || 354 old_state_type == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED ||
307 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) { 355 target_state == wm::WINDOW_STATE_TYPE_TRUSTED_PINNED) {
308 Shell::Get()->screen_pinning_controller()->SetPinnedWindow( 356 Shell::Get()->screen_pinning_controller()->SetPinnedWindow(
309 window_state->window()); 357 window_state->window());
310 } 358 }
311 359
312 if ((window_state->window()->layer()->GetTargetVisibility() || 360 if ((window_state->window()->layer()->GetTargetVisibility() ||
313 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) && 361 old_state_type == wm::WINDOW_STATE_TYPE_MINIMIZED) &&
314 !window_state->window()->layer()->visible()) { 362 !window_state->window()->layer()->visible()) {
315 // The layer may be hidden if the window was previously minimized. Make 363 // The layer may be hidden if the window was previously minimized. Make
316 // sure it's visible. 364 // sure it's visible.
317 window_state->window()->Show(); 365 window_state->window()->Show();
318 } 366 }
319 } 367 }
320 368
321 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType( 369 wm::WindowStateType MaximizeModeWindowState::GetMaximizedOrCenteredWindowType(
322 wm::WindowState* window_state) { 370 wm::WindowState* window_state) {
323 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED 371 return window_state->CanMaximize() ? wm::WINDOW_STATE_TYPE_MAXIMIZED
324 : wm::WINDOW_STATE_TYPE_NORMAL; 372 : wm::WINDOW_STATE_TYPE_NORMAL;
325 } 373 }
326 374
375 wm::WindowStateType MaximizeModeWindowState::GetSnappedWindowStateType(
376 wm::WindowState* window_state,
377 wm::WindowStateType target_state) {
378 DCHECK(target_state == wm::WINDOW_STATE_TYPE_LEFT_SNAPPED ||
379 target_state == wm::WINDOW_STATE_TYPE_RIGHT_SNAPPED);
380 return CanSnap(window_state) ? target_state
381 : GetMaximizedOrCenteredWindowType(window_state);
382 }
383
327 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state, 384 void MaximizeModeWindowState::UpdateBounds(wm::WindowState* window_state,
328 bool animated) { 385 bool animated) {
329 if (defer_bounds_updates_) 386 if (defer_bounds_updates_)
330 return; 387 return;
331 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state); 388 gfx::Rect bounds_in_parent = GetBoundsInMaximizedMode(window_state);
332 // If we have a target bounds rectangle, we center it and set it 389 // If we have a target bounds rectangle, we center it and set it
333 // accordingly. 390 // accordingly.
334 if (!bounds_in_parent.IsEmpty() && 391 if (!bounds_in_parent.IsEmpty() &&
335 bounds_in_parent != window_state->window()->bounds()) { 392 bounds_in_parent != window_state->window()->bounds()) {
336 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED || 393 if (current_state_type_ == wm::WINDOW_STATE_TYPE_MINIMIZED ||
337 !window_state->window()->IsVisible() || !animated) { 394 !window_state->window()->IsVisible() || !animated) {
338 window_state->SetBoundsDirect(bounds_in_parent); 395 window_state->SetBoundsDirect(bounds_in_parent);
339 } else { 396 } else {
340 // If we animate (to) maximized mode, we want to use the cross fade to 397 // If we animate (to) maximized mode, we want to use the cross fade to
341 // avoid flashing. 398 // avoid flashing.
342 if (window_state->IsMaximized()) 399 if (window_state->IsMaximized())
343 window_state->SetBoundsDirectCrossFade(bounds_in_parent); 400 window_state->SetBoundsDirectCrossFade(bounds_in_parent);
344 else 401 else
345 window_state->SetBoundsDirectAnimated(bounds_in_parent); 402 window_state->SetBoundsDirectAnimated(bounds_in_parent);
346 } 403 }
347 } 404 }
348 } 405 }
349 406
350 } // namespace ash 407 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698