OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/dock/docked_window_layout_manager.h" | 5 #include "ash/wm/dock/docked_window_layout_manager.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/screen_util.h" | 8 #include "ash/screen_util.h" |
9 #include "ash/shelf/shelf.h" | 9 #include "ash/shelf/shelf.h" |
10 #include "ash/shelf/shelf_constants.h" | 10 #include "ash/shelf/shelf_constants.h" |
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
515 if (is_dragged_window_docked_) | 515 if (is_dragged_window_docked_) |
516 OnDraggedWindowUndocked(); | 516 OnDraggedWindowUndocked(); |
517 DCHECK (!is_dragged_window_docked_); | 517 DCHECK (!is_dragged_window_docked_); |
518 // Stop observing a window unless it is docked container's child in which | 518 // Stop observing a window unless it is docked container's child in which |
519 // case it needs to keep being observed after the drag completes. | 519 // case it needs to keep being observed after the drag completes. |
520 if (dragged_window_->parent() != dock_container_) { | 520 if (dragged_window_->parent() != dock_container_) { |
521 dragged_window_->RemoveObserver(this); | 521 dragged_window_->RemoveObserver(this); |
522 wm::GetWindowState(dragged_window_)->RemoveObserver(this); | 522 wm::GetWindowState(dragged_window_)->RemoveObserver(this); |
523 if (last_active_window_ == dragged_window_) | 523 if (last_active_window_ == dragged_window_) |
524 last_active_window_ = NULL; | 524 last_active_window_ = NULL; |
525 | |
526 views::corewm::SetWindowShowAnimationDuration(dragged_window_, | |
527 base::TimeDelta()); | |
528 } else { | 525 } else { |
529 // If this is the first window that got docked by a move update alignment. | 526 // If this is the first window that got docked by a move update alignment. |
530 if (alignment_ == DOCKED_ALIGNMENT_NONE) | 527 if (alignment_ == DOCKED_ALIGNMENT_NONE) |
531 alignment_ = GetEdgeNearestWindow(dragged_window_); | 528 alignment_ = GetEdgeNearestWindow(dragged_window_); |
532 // A window is no longer dragged and is a child. | 529 // A window is no longer dragged and is a child. |
533 // When a window becomes a child at drag start this is | 530 // When a window becomes a child at drag start this is |
534 // the only opportunity we will have to enforce a window | 531 // the only opportunity we will have to enforce a window |
535 // count limit so do it here. | 532 // count limit so do it here. |
536 MaybeMinimizeChildrenExcept(dragged_window_); | 533 MaybeMinimizeChildrenExcept(dragged_window_); |
537 | |
538 views::corewm::SetWindowShowAnimationDuration(dragged_window_, | |
539 base::TimeDelta::FromMilliseconds(kFadeDurationMs)); | |
540 } | 534 } |
541 dragged_window_ = NULL; | 535 dragged_window_ = NULL; |
542 dragged_bounds_ = gfx::Rect(); | 536 dragged_bounds_ = gfx::Rect(); |
543 Relayout(); | 537 Relayout(); |
544 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 538 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
545 RecordUmaAction(action, source); | 539 RecordUmaAction(action, source); |
546 } | 540 } |
547 | 541 |
548 void DockedWindowLayoutManager::SetShelf(Shelf* shelf) { | 542 void DockedWindowLayoutManager::SetShelf(Shelf* shelf) { |
549 DCHECK(!shelf_); | 543 DCHECK(!shelf_); |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 // A window can be added without proper bounds when window is moved to another | 660 // A window can be added without proper bounds when window is moved to another |
667 // display via API or due to display configuration change, so the alignment | 661 // display via API or due to display configuration change, so the alignment |
668 // is set based on which edge is closer in the new display. | 662 // is set based on which edge is closer in the new display. |
669 if (alignment_ == DOCKED_ALIGNMENT_NONE) | 663 if (alignment_ == DOCKED_ALIGNMENT_NONE) |
670 alignment_ = GetEdgeNearestWindow(child); | 664 alignment_ = GetEdgeNearestWindow(child); |
671 MaybeMinimizeChildrenExcept(child); | 665 MaybeMinimizeChildrenExcept(child); |
672 child->AddObserver(this); | 666 child->AddObserver(this); |
673 wm::GetWindowState(child)->AddObserver(this); | 667 wm::GetWindowState(child)->AddObserver(this); |
674 Relayout(); | 668 Relayout(); |
675 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 669 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
676 views::corewm::SetWindowShowAnimationDuration(child, | |
677 base::TimeDelta::FromMilliseconds(kFadeDurationMs)); | |
678 } | 670 } |
679 | 671 |
680 void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 672 void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
681 if (IsPopupOrTransient(child)) | 673 if (IsPopupOrTransient(child)) |
682 return; | 674 return; |
683 // Dragged windows are stopped being observed by FinishDragging and do not | 675 // Dragged windows are stopped being observed by FinishDragging and do not |
684 // change alignment during the drag. They also cannot be set to be the | 676 // change alignment during the drag. They also cannot be set to be the |
685 // |last_active_window_|. | 677 // |last_active_window_|. |
686 if (child == dragged_window_) | 678 if (child == dragged_window_) |
687 return; | 679 return; |
688 // If this is the last window, set alignment and maximize the workspace. | 680 // If this is the last window, set alignment and maximize the workspace. |
689 if (!IsAnyWindowDocked()) { | 681 if (!IsAnyWindowDocked()) { |
690 alignment_ = DOCKED_ALIGNMENT_NONE; | 682 alignment_ = DOCKED_ALIGNMENT_NONE; |
691 UpdateDockedWidth(0); | 683 UpdateDockedWidth(0); |
692 } | 684 } |
693 if (last_active_window_ == child) | 685 if (last_active_window_ == child) |
694 last_active_window_ = NULL; | 686 last_active_window_ = NULL; |
695 child->RemoveObserver(this); | 687 child->RemoveObserver(this); |
696 wm::GetWindowState(child)->RemoveObserver(this); | 688 wm::GetWindowState(child)->RemoveObserver(this); |
697 Relayout(); | 689 Relayout(); |
698 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 690 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
699 views::corewm::SetWindowShowAnimationDuration(child, base::TimeDelta()); | |
700 } | 691 } |
701 | 692 |
702 void DockedWindowLayoutManager::OnChildWindowVisibilityChanged( | 693 void DockedWindowLayoutManager::OnChildWindowVisibilityChanged( |
703 aura::Window* child, | 694 aura::Window* child, |
704 bool visible) { | 695 bool visible) { |
705 if (IsPopupOrTransient(child)) | 696 if (IsPopupOrTransient(child)) |
706 return; | 697 return; |
707 if (visible) | 698 if (visible) |
708 wm::GetWindowState(child)->Restore(); | 699 wm::GetWindowState(child)->Restore(); |
709 Relayout(); | 700 Relayout(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 | 819 |
829 void DockedWindowLayoutManager::OnWindowBoundsChanged( | 820 void DockedWindowLayoutManager::OnWindowBoundsChanged( |
830 aura::Window* window, | 821 aura::Window* window, |
831 const gfx::Rect& old_bounds, | 822 const gfx::Rect& old_bounds, |
832 const gfx::Rect& new_bounds) { | 823 const gfx::Rect& new_bounds) { |
833 // Only relayout if the dragged window would get docked. | 824 // Only relayout if the dragged window would get docked. |
834 if (window == dragged_window_ && is_dragged_window_docked_) | 825 if (window == dragged_window_ && is_dragged_window_docked_) |
835 Relayout(); | 826 Relayout(); |
836 } | 827 } |
837 | 828 |
| 829 void DockedWindowLayoutManager::OnWindowVisibilityChanging( |
| 830 aura::Window* window, bool visible) { |
| 831 if (IsPopupOrTransient(window)) |
| 832 return; |
| 833 int animation_type = views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT; |
| 834 if (visible) { |
| 835 animation_type = views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DROP; |
| 836 views::corewm::SetWindowVisibilityAnimationDuration( |
| 837 window, base::TimeDelta::FromMilliseconds(kFadeDurationMs)); |
| 838 } else if (wm::GetWindowState(window)->IsMinimized()) { |
| 839 animation_type = WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE; |
| 840 } |
| 841 views::corewm::SetWindowVisibilityAnimationType(window, animation_type); |
| 842 } |
| 843 |
838 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { | 844 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { |
839 if (dragged_window_ == window) { | 845 if (dragged_window_ == window) { |
840 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); | 846 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); |
841 DCHECK(!dragged_window_); | 847 DCHECK(!dragged_window_); |
842 DCHECK(!is_dragged_window_docked_); | 848 DCHECK(!is_dragged_window_docked_); |
843 } | 849 } |
844 if (window == last_active_window_) | 850 if (window == last_active_window_) |
845 last_active_window_ = NULL; | 851 last_active_window_ = NULL; |
846 RecordUmaAction(DOCKED_ACTION_CLOSE, DOCKED_ACTION_SOURCE_UNKNOWN); | 852 RecordUmaAction(DOCKED_ACTION_CLOSE, DOCKED_ACTION_SOURCE_UNKNOWN); |
847 } | 853 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 while (iter != children.rend()) { | 892 while (iter != children.rend()) { |
887 aura::Window* window(*iter++); | 893 aura::Window* window(*iter++); |
888 if (window == child || !IsUsedByLayout(window)) | 894 if (window == child || !IsUsedByLayout(window)) |
889 continue; | 895 continue; |
890 int room_needed = GetWindowHeightCloseTo(window, 0) + | 896 int room_needed = GetWindowHeightCloseTo(window, 0) + |
891 (gap_needed ? kMinDockGap : 0); | 897 (gap_needed ? kMinDockGap : 0); |
892 gap_needed = true; | 898 gap_needed = true; |
893 if (available_room > room_needed) { | 899 if (available_room > room_needed) { |
894 available_room -= room_needed; | 900 available_room -= room_needed; |
895 } else { | 901 } else { |
896 // Slow down the minimize animation. | 902 // Slow down minimizing animations. Lock duration so that it is not |
897 views::corewm::SetWindowHideAnimationDuration( | 903 // overridden by other ScopedLayerAnimationSettings down the stack. |
898 window, | 904 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 905 settings.SetTransitionDuration( |
899 base::TimeDelta::FromMilliseconds(kMinimizeDurationMs)); | 906 base::TimeDelta::FromMilliseconds(kMinimizeDurationMs)); |
| 907 settings.LockTransitionDuration(); |
900 wm::GetWindowState(window)->Minimize(); | 908 wm::GetWindowState(window)->Minimize(); |
901 views::corewm::SetWindowHideAnimationDuration(window, base::TimeDelta()); | |
902 } | 909 } |
903 } | 910 } |
904 } | 911 } |
905 | 912 |
906 void DockedWindowLayoutManager::MinimizeDockedWindow( | 913 void DockedWindowLayoutManager::MinimizeDockedWindow( |
907 wm::WindowState* window_state) { | 914 wm::WindowState* window_state) { |
908 aura::Window* window = window_state->window(); | 915 DCHECK(!IsPopupOrTransient(window_state->window())); |
909 DCHECK(!IsPopupOrTransient(window)); | 916 window_state->window()->Hide(); |
910 views::corewm::SetWindowVisibilityAnimationType(window, | |
911 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | |
912 window->Hide(); | |
913 views::corewm::SetWindowVisibilityAnimationType(window, | |
914 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); | |
915 if (window_state->IsActive()) | 917 if (window_state->IsActive()) |
916 window_state->Deactivate(); | 918 window_state->Deactivate(); |
917 RecordUmaAction(DOCKED_ACTION_MINIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN); | 919 RecordUmaAction(DOCKED_ACTION_MINIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN); |
918 } | 920 } |
919 | 921 |
920 void DockedWindowLayoutManager::RestoreDockedWindow( | 922 void DockedWindowLayoutManager::RestoreDockedWindow( |
921 wm::WindowState* window_state) { | 923 wm::WindowState* window_state) { |
922 aura::Window* window = window_state->window(); | 924 aura::Window* window = window_state->window(); |
923 DCHECK(!IsPopupOrTransient(window)); | 925 DCHECK(!IsPopupOrTransient(window)); |
924 // Always place restored window at the bottom shuffling the other windows up. | 926 // Always place restored window at the bottom shuffling the other windows up. |
(...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1307 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1309 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
1308 const gfx::Rect& keyboard_bounds) { | 1310 const gfx::Rect& keyboard_bounds) { |
1309 // This bounds change will have caused a change to the Shelf which does not | 1311 // This bounds change will have caused a change to the Shelf which does not |
1310 // propagate automatically to this class, so manually recalculate bounds. | 1312 // propagate automatically to this class, so manually recalculate bounds. |
1311 Relayout(); | 1313 Relayout(); |
1312 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1314 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
1313 } | 1315 } |
1314 | 1316 |
1315 } // namespace internal | 1317 } // namespace internal |
1316 } // namespace ash | 1318 } // namespace ash |
OLD | NEW |