| 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/display/window_tree_host_manager.h" | 7 #include "ash/display/window_tree_host_manager.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/screen_util.h" | 9 #include "ash/screen_util.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 12 #include "ash/wm/common/window_positioning_utils.h" |
| 12 #include "ash/wm/common/wm_event.h" | 13 #include "ash/wm/common/wm_event.h" |
| 13 #include "ash/wm/coordinate_conversion.h" | 14 #include "ash/wm/coordinate_conversion.h" |
| 14 #include "ash/wm/dock/docked_window_layout_manager.h" | 15 #include "ash/wm/dock/docked_window_layout_manager.h" |
| 15 #include "ash/wm/window_animations.h" | 16 #include "ash/wm/window_animations.h" |
| 16 #include "ash/wm/window_state.h" | 17 #include "ash/wm/window_state.h" |
| 17 #include "ash/wm/window_state_delegate.h" | 18 #include "ash/wm/window_state_delegate.h" |
| 18 #include "ash/wm/window_state_util.h" | 19 #include "ash/wm/window_state_util.h" |
| 19 #include "ash/wm/window_util.h" | 20 #include "ash/wm/window_util.h" |
| 20 #include "ash/wm/workspace/workspace_window_resizer.h" | 21 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 21 #include "ash/wm/workspace_controller.h" | 22 #include "ash/wm/workspace_controller.h" |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 // user and user should always be able to interact with them. Other | 434 // user and user should always be able to interact with them. Other |
| 434 // windows are positioned programmatically. | 435 // windows are positioned programmatically. |
| 435 if (!window_state->IsUserPositionable()) | 436 if (!window_state->IsUserPositionable()) |
| 436 return true; | 437 return true; |
| 437 | 438 |
| 438 // Use entire display instead of workarea because the workarea can | 439 // Use entire display instead of workarea because the workarea can |
| 439 // be further shrunk by the docked area. The logic ensures 30% | 440 // be further shrunk by the docked area. The logic ensures 30% |
| 440 // visibility which should be enough to see where the window gets | 441 // visibility which should be enough to see where the window gets |
| 441 // moved. | 442 // moved. |
| 442 gfx::Rect display_area = ScreenUtil::GetDisplayBoundsInParent(window); | 443 gfx::Rect display_area = ScreenUtil::GetDisplayBoundsInParent(window); |
| 443 int min_width = bounds.width() * kMinimumPercentOnScreenArea; | 444 int min_width = bounds.width() * wm::kMinimumPercentOnScreenArea; |
| 444 int min_height = bounds.height() * kMinimumPercentOnScreenArea; | 445 int min_height = bounds.height() * wm::kMinimumPercentOnScreenArea; |
| 445 AdjustBoundsToEnsureWindowVisibility( | 446 wm::AdjustBoundsToEnsureWindowVisibility(display_area, min_width, |
| 446 display_area, min_width, min_height, &bounds); | 447 min_height, &bounds); |
| 447 window_state->AdjustSnappedBounds(&bounds); | 448 window_state->AdjustSnappedBounds(&bounds); |
| 448 if (window->bounds() != bounds) | 449 if (window->bounds() != bounds) |
| 449 window_state->SetBoundsConstrained(bounds); | 450 window_state->SetBoundsConstrained(bounds); |
| 450 return true; | 451 return true; |
| 451 } | 452 } |
| 452 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: { | 453 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: { |
| 453 if (window_state->is_dragged() || | 454 if (window_state->is_dragged() || |
| 454 SetMaximizedOrFullscreenBounds(window_state)) { | 455 SetMaximizedOrFullscreenBounds(window_state)) { |
| 455 return true; | 456 return true; |
| 456 } | 457 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 477 return true; | 478 return true; |
| 478 | 479 |
| 479 if (window_state->is_dragged() || | 480 if (window_state->is_dragged() || |
| 480 SetMaximizedOrFullscreenBounds(window_state)) { | 481 SetMaximizedOrFullscreenBounds(window_state)) { |
| 481 return true; | 482 return true; |
| 482 } | 483 } |
| 483 gfx::Rect work_area_in_parent = | 484 gfx::Rect work_area_in_parent = |
| 484 ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 485 ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| 485 window_state->aura_window()); | 486 window_state->aura_window()); |
| 486 gfx::Rect bounds = window_state->aura_window()->bounds(); | 487 gfx::Rect bounds = window_state->aura_window()->bounds(); |
| 487 AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, &bounds); | 488 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, |
| 489 &bounds); |
| 488 window_state->AdjustSnappedBounds(&bounds); | 490 window_state->AdjustSnappedBounds(&bounds); |
| 489 if (window_state->aura_window()->bounds() != bounds) | 491 if (window_state->aura_window()->bounds() != bounds) |
| 490 window_state->SetBoundsDirectAnimated(bounds); | 492 window_state->SetBoundsDirectAnimated(bounds); |
| 491 return true; | 493 return true; |
| 492 } | 494 } |
| 493 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: | 495 case WM_EVENT_TOGGLE_MAXIMIZE_CAPTION: |
| 494 case WM_EVENT_TOGGLE_MAXIMIZE: | 496 case WM_EVENT_TOGGLE_MAXIMIZE: |
| 495 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: | 497 case WM_EVENT_TOGGLE_VERTICAL_MAXIMIZE: |
| 496 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: | 498 case WM_EVENT_TOGGLE_HORIZONTAL_MAXIMIZE: |
| 497 case WM_EVENT_TOGGLE_FULLSCREEN: | 499 case WM_EVENT_TOGGLE_FULLSCREEN: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 const SetBoundsEvent* event) { | 535 const SetBoundsEvent* event) { |
| 534 if (window_state->is_dragged()) { | 536 if (window_state->is_dragged()) { |
| 535 // TODO(oshima|varkha): This may be no longer needed, as the dragging | 537 // TODO(oshima|varkha): This may be no longer needed, as the dragging |
| 536 // happens in docked window container. crbug.com/485612. | 538 // happens in docked window container. crbug.com/485612. |
| 537 window_state->SetBoundsDirect(event->requested_bounds()); | 539 window_state->SetBoundsDirect(event->requested_bounds()); |
| 538 } else if (window_state->IsSnapped()) { | 540 } else if (window_state->IsSnapped()) { |
| 539 gfx::Rect work_area_in_parent = | 541 gfx::Rect work_area_in_parent = |
| 540 ScreenUtil::GetDisplayWorkAreaBoundsInParent( | 542 ScreenUtil::GetDisplayWorkAreaBoundsInParent( |
| 541 window_state->aura_window()); | 543 window_state->aura_window()); |
| 542 gfx::Rect child_bounds(event->requested_bounds()); | 544 gfx::Rect child_bounds(event->requested_bounds()); |
| 543 AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); | 545 wm::AdjustBoundsSmallerThan(work_area_in_parent.size(), &child_bounds); |
| 544 window_state->AdjustSnappedBounds(&child_bounds); | 546 window_state->AdjustSnappedBounds(&child_bounds); |
| 545 window_state->SetBoundsDirect(child_bounds); | 547 window_state->SetBoundsDirect(child_bounds); |
| 546 } else if (!SetMaximizedOrFullscreenBounds(window_state)) { | 548 } else if (!SetMaximizedOrFullscreenBounds(window_state)) { |
| 547 window_state->SetBoundsConstrained(event->requested_bounds()); | 549 window_state->SetBoundsConstrained(event->requested_bounds()); |
| 548 } | 550 } |
| 549 } | 551 } |
| 550 | 552 |
| 551 void DefaultState::EnterToNextState(WindowState* window_state, | 553 void DefaultState::EnterToNextState(WindowState* window_state, |
| 552 WindowStateType next_state_type) { | 554 WindowStateType next_state_type) { |
| 553 // Do nothing if we're already in the same state. | 555 // Do nothing if we're already in the same state. |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 bounds_in_parent.width() >= work_area_in_parent.width() && | 672 bounds_in_parent.width() >= work_area_in_parent.width() && |
| 671 bounds_in_parent.height() >= work_area_in_parent.height()) { | 673 bounds_in_parent.height() >= work_area_in_parent.height()) { |
| 672 bounds_in_parent = work_area_in_parent; | 674 bounds_in_parent = work_area_in_parent; |
| 673 bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset, | 675 bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset, |
| 674 kMaximizedWindowInset, kMaximizedWindowInset); | 676 kMaximizedWindowInset, kMaximizedWindowInset); |
| 675 } | 677 } |
| 676 } else { | 678 } else { |
| 677 bounds_in_parent = window->bounds(); | 679 bounds_in_parent = window->bounds(); |
| 678 } | 680 } |
| 679 // Make sure that part of the window is always visible. | 681 // Make sure that part of the window is always visible. |
| 680 AdjustBoundsToEnsureMinimumWindowVisibility( | 682 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, |
| 681 work_area_in_parent, &bounds_in_parent); | 683 &bounds_in_parent); |
| 682 break; | 684 break; |
| 683 } | 685 } |
| 684 case WINDOW_STATE_TYPE_MAXIMIZED: | 686 case WINDOW_STATE_TYPE_MAXIMIZED: |
| 685 bounds_in_parent = ScreenUtil::GetMaximizedWindowBoundsInParent(window); | 687 bounds_in_parent = ScreenUtil::GetMaximizedWindowBoundsInParent(window); |
| 686 break; | 688 break; |
| 687 | 689 |
| 688 case WINDOW_STATE_TYPE_FULLSCREEN: | 690 case WINDOW_STATE_TYPE_FULLSCREEN: |
| 689 bounds_in_parent = ScreenUtil::GetDisplayBoundsInParent(window); | 691 bounds_in_parent = ScreenUtil::GetDisplayBoundsInParent(window); |
| 690 break; | 692 break; |
| 691 | 693 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); | 761 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); |
| 760 center_in_parent.ClampToCenteredSize(window->bounds().size()); | 762 center_in_parent.ClampToCenteredSize(window->bounds().size()); |
| 761 window_state->SetBoundsDirectAnimated(center_in_parent); | 763 window_state->SetBoundsDirectAnimated(center_in_parent); |
| 762 } | 764 } |
| 763 // Centering window is treated as if a user moved and resized the window. | 765 // Centering window is treated as if a user moved and resized the window. |
| 764 window_state->set_bounds_changed_by_user(true); | 766 window_state->set_bounds_changed_by_user(true); |
| 765 } | 767 } |
| 766 | 768 |
| 767 } // namespace wm | 769 } // namespace wm |
| 768 } // namespace ash | 770 } // namespace ash |
| OLD | NEW |