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/default_state.h" | 5 #include "ash/wm/default_state.h" |
6 | 6 |
7 #include "ash/public/cpp/shell_window_ids.h" | 7 #include "ash/public/cpp/shell_window_ids.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/wm/screen_pinning_controller.h" | 10 #include "ash/wm/screen_pinning_controller.h" |
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
336 bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, | 336 bool DefaultState::ProcessWorkspaceEvents(WindowState* window_state, |
337 const WMEvent* event) { | 337 const WMEvent* event) { |
338 switch (event->type()) { | 338 switch (event->type()) { |
339 case WM_EVENT_ADDED_TO_WORKSPACE: { | 339 case WM_EVENT_ADDED_TO_WORKSPACE: { |
340 // When a window is dragged and dropped onto a different | 340 // When a window is dragged and dropped onto a different |
341 // root window, the bounds will be updated after they are added | 341 // root window, the bounds will be updated after they are added |
342 // to the root window. | 342 // to the root window. |
343 // If a window is opened as maximized or fullscreen, its bounds may be | 343 // If a window is opened as maximized or fullscreen, its bounds may be |
344 // empty, so update the bounds now before checking empty. | 344 // empty, so update the bounds now before checking empty. |
345 if (window_state->is_dragged() || | 345 if (window_state->is_dragged() || |
| 346 window_state->allow_set_bounds_direct() || |
346 SetMaximizedOrFullscreenBounds(window_state)) { | 347 SetMaximizedOrFullscreenBounds(window_state)) { |
347 return true; | 348 return true; |
348 } | 349 } |
349 | 350 |
350 WmWindow* window = window_state->window(); | 351 WmWindow* window = window_state->window(); |
351 gfx::Rect bounds = window->GetBounds(); | 352 gfx::Rect bounds = window->GetBounds(); |
352 | 353 |
353 // Don't adjust window bounds if the bounds are empty as this | 354 // Don't adjust window bounds if the bounds are empty as this |
354 // happens when a new views::Widget is created. | 355 // happens when a new views::Widget is created. |
355 if (bounds.IsEmpty()) | 356 if (bounds.IsEmpty()) |
(...skipping 14 matching lines...) Expand all Loading... |
370 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea; | 371 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea; |
371 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width, | 372 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width, |
372 min_height, &bounds); | 373 min_height, &bounds); |
373 window_state->AdjustSnappedBounds(&bounds); | 374 window_state->AdjustSnappedBounds(&bounds); |
374 if (window->GetBounds() != bounds) | 375 if (window->GetBounds() != bounds) |
375 window_state->SetBoundsConstrained(bounds); | 376 window_state->SetBoundsConstrained(bounds); |
376 return true; | 377 return true; |
377 } | 378 } |
378 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: { | 379 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: { |
379 if (window_state->is_dragged() || | 380 if (window_state->is_dragged() || |
| 381 window_state->allow_set_bounds_direct() || |
380 SetMaximizedOrFullscreenBounds(window_state)) { | 382 SetMaximizedOrFullscreenBounds(window_state)) { |
381 return true; | 383 return true; |
382 } | 384 } |
383 gfx::Rect work_area_in_parent = | 385 gfx::Rect work_area_in_parent = |
384 GetDisplayWorkAreaBoundsInParent(window_state->window()); | 386 GetDisplayWorkAreaBoundsInParent(window_state->window()); |
385 gfx::Rect bounds = window_state->window()->GetTargetBounds(); | 387 gfx::Rect bounds = window_state->window()->GetTargetBounds(); |
386 // When display bounds has changed, make sure the entire window is fully | 388 // When display bounds has changed, make sure the entire window is fully |
387 // visible. | 389 // visible. |
388 bounds.AdjustToFit(work_area_in_parent); | 390 bounds.AdjustToFit(work_area_in_parent); |
389 window_state->AdjustSnappedBounds(&bounds); | 391 window_state->AdjustSnappedBounds(&bounds); |
390 if (window_state->window()->GetTargetBounds() != bounds) | 392 if (window_state->window()->GetTargetBounds() != bounds) |
391 window_state->SetBoundsDirectAnimated(bounds); | 393 window_state->SetBoundsDirectAnimated(bounds); |
392 return true; | 394 return true; |
393 } | 395 } |
394 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: { | 396 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: { |
395 // Don't resize the maximized window when the desktop is covered | 397 // Don't resize the maximized window when the desktop is covered |
396 // by fullscreen window. crbug.com/504299. | 398 // by fullscreen window. crbug.com/504299. |
397 bool in_fullscreen = | 399 bool in_fullscreen = |
398 window_state->window() | 400 window_state->window() |
399 ->GetRootWindowController() | 401 ->GetRootWindowController() |
400 ->GetWorkspaceWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN; | 402 ->GetWorkspaceWindowState() == WORKSPACE_WINDOW_STATE_FULL_SCREEN; |
401 if (in_fullscreen && window_state->IsMaximized()) | 403 if (in_fullscreen && window_state->IsMaximized()) |
402 return true; | 404 return true; |
403 | 405 |
404 if (window_state->is_dragged() || | 406 if (window_state->is_dragged() || |
| 407 window_state->allow_set_bounds_direct() || |
405 SetMaximizedOrFullscreenBounds(window_state)) { | 408 SetMaximizedOrFullscreenBounds(window_state)) { |
406 return true; | 409 return true; |
407 } | 410 } |
408 gfx::Rect work_area_in_parent = | 411 gfx::Rect work_area_in_parent = |
409 GetDisplayWorkAreaBoundsInParent(window_state->window()); | 412 GetDisplayWorkAreaBoundsInParent(window_state->window()); |
410 gfx::Rect bounds = window_state->window()->GetTargetBounds(); | 413 gfx::Rect bounds = window_state->window()->GetTargetBounds(); |
411 if (!window_state->window()->GetTransientParent()) { | 414 if (!window_state->window()->GetTransientParent()) { |
412 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, | 415 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, |
413 &bounds); | 416 &bounds); |
414 } | 417 } |
(...skipping 21 matching lines...) Expand all Loading... |
436 case WM_EVENT_SET_BOUNDS: | 439 case WM_EVENT_SET_BOUNDS: |
437 case WM_EVENT_SHOW_INACTIVE: | 440 case WM_EVENT_SHOW_INACTIVE: |
438 break; | 441 break; |
439 } | 442 } |
440 return false; | 443 return false; |
441 } | 444 } |
442 | 445 |
443 // static | 446 // static |
444 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { | 447 bool DefaultState::SetMaximizedOrFullscreenBounds(WindowState* window_state) { |
445 DCHECK(!window_state->is_dragged()); | 448 DCHECK(!window_state->is_dragged()); |
| 449 DCHECK(!window_state->allow_set_bounds_direct()); |
446 if (window_state->IsMaximized()) { | 450 if (window_state->IsMaximized()) { |
447 window_state->SetBoundsDirect( | 451 window_state->SetBoundsDirect( |
448 GetMaximizedWindowBoundsInParent(window_state->window())); | 452 GetMaximizedWindowBoundsInParent(window_state->window())); |
449 return true; | 453 return true; |
450 } | 454 } |
451 if (window_state->IsFullscreen()) { | 455 if (window_state->IsFullscreen()) { |
452 window_state->SetBoundsDirect( | 456 window_state->SetBoundsDirect( |
453 GetDisplayBoundsInParent(window_state->window())); | 457 GetDisplayBoundsInParent(window_state->window())); |
454 return true; | 458 return true; |
455 } | 459 } |
456 return false; | 460 return false; |
457 } | 461 } |
458 | 462 |
459 // static | 463 // static |
460 void DefaultState::SetBounds(WindowState* window_state, | 464 void DefaultState::SetBounds(WindowState* window_state, |
461 const SetBoundsEvent* event) { | 465 const SetBoundsEvent* event) { |
462 if (window_state->is_dragged()) { | 466 if (window_state->is_dragged() || window_state->allow_set_bounds_direct()) { |
463 // TODO(oshima|varkha): Is this still needed? crbug.com/485612. | 467 // TODO(oshima|varkha): Is this still needed? crbug.com/485612. |
464 window_state->SetBoundsDirect(event->requested_bounds()); | 468 window_state->SetBoundsDirect(event->requested_bounds()); |
465 } else if (window_state->IsSnapped()) { | 469 } else if (window_state->IsSnapped()) { |
466 gfx::Rect work_area_in_parent = | 470 gfx::Rect work_area_in_parent = |
467 GetDisplayWorkAreaBoundsInParent(window_state->window()); | 471 GetDisplayWorkAreaBoundsInParent(window_state->window()); |
468 gfx::Rect child_bounds(event->requested_bounds()); | 472 gfx::Rect child_bounds(event->requested_bounds()); |
469 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); | 473 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); |
470 window_state->AdjustSnappedBounds(&child_bounds); | 474 window_state->AdjustSnappedBounds(&child_bounds); |
471 window_state->SetBoundsDirect(child_bounds); | 475 window_state->SetBoundsDirect(child_bounds); |
472 } else if (!SetMaximizedOrFullscreenBounds(window_state) || | 476 } else if (!SetMaximizedOrFullscreenBounds(window_state)) { |
473 window_state->allow_set_bounds_in_maximized()) { | |
474 window_state->SetBoundsConstrained(event->requested_bounds()); | 477 window_state->SetBoundsConstrained(event->requested_bounds()); |
475 } | 478 } |
476 } | 479 } |
477 | 480 |
478 void DefaultState::EnterToNextState(WindowState* window_state, | 481 void DefaultState::EnterToNextState(WindowState* window_state, |
479 WindowStateType next_state_type) { | 482 WindowStateType next_state_type) { |
480 // Do nothing if we're already in the same state. | 483 // Do nothing if we're already in the same state. |
481 if (state_type_ == next_state_type) | 484 if (state_type_ == next_state_type) |
482 return; | 485 return; |
483 | 486 |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
688 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); | 691 gfx::Rect center_in_parent = GetDisplayWorkAreaBoundsInParent(window); |
689 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); | 692 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); |
690 window_state->SetBoundsDirectAnimated(center_in_parent); | 693 window_state->SetBoundsDirectAnimated(center_in_parent); |
691 } | 694 } |
692 // Centering window is treated as if a user moved and resized the window. | 695 // Centering window is treated as if a user moved and resized the window. |
693 window_state->set_bounds_changed_by_user(true); | 696 window_state->set_bounds_changed_by_user(true); |
694 } | 697 } |
695 | 698 |
696 } // namespace wm | 699 } // namespace wm |
697 } // namespace ash | 700 } // namespace ash |
OLD | NEW |