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/screen_util.h" | 9 #include "ash/screen_util.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/shell_port.h" | 11 #include "ash/shell_port.h" |
12 #include "ash/wm/screen_pinning_controller.h" | 12 #include "ash/wm/screen_pinning_controller.h" |
13 #include "ash/wm/window_animation_types.h" | 13 #include "ash/wm/window_animation_types.h" |
14 #include "ash/wm/window_parenting_utils.h" | 14 #include "ash/wm/window_parenting_utils.h" |
15 #include "ash/wm/window_positioning_utils.h" | 15 #include "ash/wm/window_positioning_utils.h" |
16 #include "ash/wm/window_state.h" | 16 #include "ash/wm/window_state.h" |
17 #include "ash/wm/window_state_delegate.h" | 17 #include "ash/wm/window_state_delegate.h" |
18 #include "ash/wm/window_state_util.h" | 18 #include "ash/wm/window_state_util.h" |
19 #include "ash/wm/wm_event.h" | 19 #include "ash/wm/wm_event.h" |
20 #include "ash/wm_window.h" | 20 #include "ash/wm_window.h" |
21 #include "ui/aura/client/aura_constants.h" | |
21 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
22 #include "ui/display/display.h" | 23 #include "ui/display/display.h" |
23 #include "ui/display/screen.h" | 24 #include "ui/display/screen.h" |
24 | 25 |
25 namespace ash { | 26 namespace ash { |
26 namespace wm { | 27 namespace wm { |
27 namespace { | 28 namespace { |
28 | 29 |
29 // This specifies how much percent (30%) of a window rect | 30 // This specifies how much percent (30%) of a window rect |
30 // must be visible when the window is added to the workspace. | 31 // must be visible when the window is added to the workspace. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
162 NOTREACHED() << "Compound event should not reach here:" << event; | 163 NOTREACHED() << "Compound event should not reach here:" << event; |
163 return; | 164 return; |
164 case WM_EVENT_ADDED_TO_WORKSPACE: | 165 case WM_EVENT_ADDED_TO_WORKSPACE: |
165 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: | 166 case WM_EVENT_WORKAREA_BOUNDS_CHANGED: |
166 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: | 167 case WM_EVENT_DISPLAY_BOUNDS_CHANGED: |
167 NOTREACHED() << "Workspace event should not reach here:" << event; | 168 NOTREACHED() << "Workspace event should not reach here:" << event; |
168 return; | 169 return; |
169 } | 170 } |
170 | 171 |
171 if (next_state_type == current_state_type && window_state->IsSnapped()) { | 172 if (next_state_type == current_state_type && window_state->IsSnapped()) { |
173 aura::Window* window = window_state->window()->aura_window(); | |
172 gfx::Rect snapped_bounds = | 174 gfx::Rect snapped_bounds = |
173 event->type() == WM_EVENT_SNAP_LEFT | 175 event->type() == WM_EVENT_SNAP_LEFT |
174 ? GetDefaultLeftSnappedWindowBoundsInParent(window_state->window()) | 176 ? GetDefaultLeftSnappedWindowBoundsInParent(window) |
175 : GetDefaultRightSnappedWindowBoundsInParent( | 177 : GetDefaultRightSnappedWindowBoundsInParent(window); |
176 window_state->window()); | |
177 window_state->SetBoundsDirectAnimated(snapped_bounds); | 178 window_state->SetBoundsDirectAnimated(snapped_bounds); |
178 return; | 179 return; |
179 } | 180 } |
180 | 181 |
181 if (event->type() == WM_EVENT_SNAP_LEFT || | 182 if (event->type() == WM_EVENT_SNAP_LEFT || |
182 event->type() == WM_EVENT_SNAP_RIGHT) { | 183 event->type() == WM_EVENT_SNAP_RIGHT) { |
183 window_state->set_bounds_changed_by_user(true); | 184 window_state->set_bounds_changed_by_user(true); |
184 } | 185 } |
185 | 186 |
186 EnterToNextState(window_state, next_state_type); | 187 EnterToNextState(window_state, next_state_type); |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
577 if (!stored_restore_bounds_.IsEmpty()) | 578 if (!stored_restore_bounds_.IsEmpty()) |
578 window_state->SetRestoreBoundsInParent(stored_restore_bounds_); | 579 window_state->SetRestoreBoundsInParent(stored_restore_bounds_); |
579 else | 580 else |
580 window_state->ClearRestoreBounds(); | 581 window_state->ClearRestoreBounds(); |
581 | 582 |
582 window_state->NotifyPostStateTypeChange(previous_state_type); | 583 window_state->NotifyPostStateTypeChange(previous_state_type); |
583 } | 584 } |
584 | 585 |
585 void DefaultState::UpdateBoundsFromState(WindowState* window_state, | 586 void DefaultState::UpdateBoundsFromState(WindowState* window_state, |
586 WindowStateType previous_state_type) { | 587 WindowStateType previous_state_type) { |
587 WmWindow* window = window_state->window(); | 588 aura::Window* window = window_state->window()->aura_window(); |
588 gfx::Rect bounds_in_parent; | 589 gfx::Rect bounds_in_parent; |
589 switch (state_type_) { | 590 switch (state_type_) { |
590 case WINDOW_STATE_TYPE_LEFT_SNAPPED: | 591 case WINDOW_STATE_TYPE_LEFT_SNAPPED: |
591 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: | 592 case WINDOW_STATE_TYPE_RIGHT_SNAPPED: |
592 bounds_in_parent = | 593 bounds_in_parent = |
593 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED | 594 state_type_ == WINDOW_STATE_TYPE_LEFT_SNAPPED |
594 ? GetDefaultLeftSnappedWindowBoundsInParent(window) | 595 ? GetDefaultLeftSnappedWindowBoundsInParent(window) |
595 : GetDefaultRightSnappedWindowBoundsInParent(window); | 596 : GetDefaultRightSnappedWindowBoundsInParent(window); |
596 break; | 597 break; |
597 | 598 |
598 case WINDOW_STATE_TYPE_DEFAULT: | 599 case WINDOW_STATE_TYPE_DEFAULT: |
599 case WINDOW_STATE_TYPE_NORMAL: { | 600 case WINDOW_STATE_TYPE_NORMAL: { |
600 gfx::Rect work_area_in_parent = | 601 gfx::Rect work_area_in_parent = |
601 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); | 602 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window); |
602 if (window_state->HasRestoreBounds()) { | 603 if (window_state->HasRestoreBounds()) { |
603 bounds_in_parent = window_state->GetRestoreBoundsInParent(); | 604 bounds_in_parent = window_state->GetRestoreBoundsInParent(); |
604 // Check if the |window|'s restored size is bigger than the working area | 605 // Check if the |window|'s restored size is bigger than the working area |
605 // This may happen if a window was resized to maximized bounds or if the | 606 // This may happen if a window was resized to maximized bounds or if the |
606 // display resolution changed while the window was maximized. | 607 // display resolution changed while the window was maximized. |
607 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED && | 608 if (previous_state_type == WINDOW_STATE_TYPE_MAXIMIZED && |
608 bounds_in_parent.width() >= work_area_in_parent.width() && | 609 bounds_in_parent.width() >= work_area_in_parent.width() && |
609 bounds_in_parent.height() >= work_area_in_parent.height()) { | 610 bounds_in_parent.height() >= work_area_in_parent.height()) { |
610 bounds_in_parent = work_area_in_parent; | 611 bounds_in_parent = work_area_in_parent; |
611 bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset, | 612 bounds_in_parent.Inset(kMaximizedWindowInset, kMaximizedWindowInset, |
612 kMaximizedWindowInset, kMaximizedWindowInset); | 613 kMaximizedWindowInset, kMaximizedWindowInset); |
613 } | 614 } |
614 } else { | 615 } else { |
615 bounds_in_parent = window->GetBounds(); | 616 bounds_in_parent = window->bounds(); |
616 } | 617 } |
617 // Make sure that part of the window is always visible. | 618 // Make sure that part of the window is always visible. |
618 if (!window_state->is_dragged()) { | 619 if (!window_state->is_dragged()) { |
619 // Avoid doing this while the window is being dragged as its root | 620 // Avoid doing this while the window is being dragged as its root |
620 // window hasn't been updated yet in the case of dragging to another | 621 // window hasn't been updated yet in the case of dragging to another |
621 // display. crbug.com/666836. | 622 // display. crbug.com/666836. |
622 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, | 623 wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_in_parent, |
623 &bounds_in_parent); | 624 &bounds_in_parent); |
624 } | 625 } |
625 break; | 626 break; |
626 } | 627 } |
627 case WINDOW_STATE_TYPE_MAXIMIZED: | 628 case WINDOW_STATE_TYPE_MAXIMIZED: |
628 bounds_in_parent = | 629 bounds_in_parent = ScreenUtil::GetMaximizedWindowBoundsInParent(window); |
629 ScreenUtil::GetMaximizedWindowBoundsInParent(window->aura_window()); | |
630 break; | 630 break; |
631 | 631 |
632 case WINDOW_STATE_TYPE_FULLSCREEN: | 632 case WINDOW_STATE_TYPE_FULLSCREEN: |
633 case WINDOW_STATE_TYPE_PINNED: | 633 case WINDOW_STATE_TYPE_PINNED: |
634 case WINDOW_STATE_TYPE_TRUSTED_PINNED: | 634 case WINDOW_STATE_TYPE_TRUSTED_PINNED: |
635 bounds_in_parent = | 635 bounds_in_parent = ScreenUtil::GetDisplayBoundsInParent(window); |
636 ScreenUtil::GetDisplayBoundsInParent(window->aura_window()); | |
637 break; | 636 break; |
638 | 637 |
639 case WINDOW_STATE_TYPE_MINIMIZED: | 638 case WINDOW_STATE_TYPE_MINIMIZED: |
640 break; | 639 break; |
641 case WINDOW_STATE_TYPE_INACTIVE: | 640 case WINDOW_STATE_TYPE_INACTIVE: |
642 case WINDOW_STATE_TYPE_END: | 641 case WINDOW_STATE_TYPE_END: |
643 case WINDOW_STATE_TYPE_AUTO_POSITIONED: | 642 case WINDOW_STATE_TYPE_AUTO_POSITIONED: |
644 return; | 643 return; |
645 } | 644 } |
646 | 645 |
(...skipping 10 matching lines...) Expand all Loading... | |
657 // TODO(oshima): Consider fixing it and reenable the animation. | 656 // TODO(oshima): Consider fixing it and reenable the animation. |
658 window_state->SetBoundsDirect(bounds_in_parent); | 657 window_state->SetBoundsDirect(bounds_in_parent); |
659 } else { | 658 } else { |
660 window_state->SetBoundsDirectAnimated(bounds_in_parent); | 659 window_state->SetBoundsDirectAnimated(bounds_in_parent); |
661 } | 660 } |
662 } | 661 } |
663 | 662 |
664 if (window_state->IsMinimized()) { | 663 if (window_state->IsMinimized()) { |
665 // Save the previous show state so that we can correctly restore it after | 664 // Save the previous show state so that we can correctly restore it after |
666 // exiting the minimized mode. | 665 // exiting the minimized mode. |
667 window->SetPreMinimizedShowState(ToWindowShowState(previous_state_type)); | 666 window->SetProperty(aura::client::kPreMinimizedShowStateKey, |
msw
2017/05/22 19:26:11
optional nit: you can eliminate this WmWindow help
sky
2017/05/22 19:50:58
Done.
| |
668 window->SetVisibilityAnimationType( | 667 ToWindowShowState(previous_state_type)); |
669 WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | 668 ::wm::SetWindowVisibilityAnimationType( |
669 window, WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | |
670 | 670 |
671 // Hide the window. | |
672 window->Hide(); | 671 window->Hide(); |
673 // Activate another window. | |
674 if (window_state->IsActive()) | 672 if (window_state->IsActive()) |
675 window_state->Deactivate(); | 673 window_state->Deactivate(); |
676 } else if ((window->GetTargetVisibility() || | 674 } else if ((window->layer()->GetTargetVisibility() || |
677 IsMinimizedWindowState(previous_state_type)) && | 675 IsMinimizedWindowState(previous_state_type)) && |
678 !window->GetLayerVisible()) { | 676 !window->layer()->visible()) { |
679 // The layer may be hidden if the window was previously minimized. Make | 677 // The layer may be hidden if the window was previously minimized. Make |
680 // sure it's visible. | 678 // sure it's visible. |
681 window->Show(); | 679 window->Show(); |
682 if (IsMinimizedWindowState(previous_state_type) && | 680 if (IsMinimizedWindowState(previous_state_type) && |
683 !window_state->IsMaximizedOrFullscreenOrPinned()) { | 681 !window_state->IsMaximizedOrFullscreenOrPinned()) { |
684 window_state->set_unminimize_to_restore_bounds(false); | 682 window_state->set_unminimize_to_restore_bounds(false); |
685 } | 683 } |
686 } | 684 } |
687 } | 685 } |
688 | 686 |
(...skipping 15 matching lines...) Expand all Loading... | |
704 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); | 702 ScreenUtil::GetDisplayWorkAreaBoundsInParent(window->aura_window()); |
705 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); | 703 center_in_parent.ClampToCenteredSize(window->GetBounds().size()); |
706 window_state->SetBoundsDirectAnimated(center_in_parent); | 704 window_state->SetBoundsDirectAnimated(center_in_parent); |
707 } | 705 } |
708 // Centering window is treated as if a user moved and resized the window. | 706 // Centering window is treated as if a user moved and resized the window. |
709 window_state->set_bounds_changed_by_user(true); | 707 window_state->set_bounds_changed_by_user(true); |
710 } | 708 } |
711 | 709 |
712 } // namespace wm | 710 } // namespace wm |
713 } // namespace ash | 711 } // namespace ash |
OLD | NEW |