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_ash.h" | 8 #include "ash/screen_ash.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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 views::Widget::InitParams params; | 143 views::Widget::InitParams params; |
144 params.type = views::Widget::InitParams::TYPE_POPUP; | 144 params.type = views::Widget::InitParams::TYPE_POPUP; |
145 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 145 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
146 params.can_activate = false; | 146 params.can_activate = false; |
147 params.keep_on_top = false; | 147 params.keep_on_top = false; |
148 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 148 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
149 params.parent = parent; | 149 params.parent = parent; |
150 params.accept_events = false; | 150 params.accept_events = false; |
151 set_focus_on_creation(false); | 151 set_focus_on_creation(false); |
152 Init(params); | 152 Init(params); |
153 SetVisibilityChangedAnimationsEnabled(false); | |
153 GetNativeWindow()->SetProperty(internal::kStayInSameRootWindowKey, true); | 154 GetNativeWindow()->SetProperty(internal::kStayInSameRootWindowKey, true); |
154 opaque_background_.SetColor(SK_ColorBLACK); | 155 opaque_background_.SetColor(SK_ColorBLACK); |
155 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); | 156 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); |
156 opaque_background_.SetOpacity(0.0f); | 157 opaque_background_.SetOpacity(0.0f); |
157 GetNativeWindow()->layer()->Add(&opaque_background_); | 158 GetNativeWindow()->layer()->Add(&opaque_background_); |
158 Hide(); | 159 Hide(); |
159 | 160 |
160 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 161 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
161 gfx::ImageSkia shelf_background = | 162 gfx::ImageSkia shelf_background = |
162 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); | 163 *rb.GetImageSkiaNamed(IDR_AURA_LAUNCHER_BACKGROUND); |
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 if (is_dragged_window_docked_) | 458 if (is_dragged_window_docked_) |
458 OnDraggedWindowUndocked(); | 459 OnDraggedWindowUndocked(); |
459 DCHECK (!is_dragged_window_docked_); | 460 DCHECK (!is_dragged_window_docked_); |
460 // Stop observing a window unless it is docked container's child in which | 461 // Stop observing a window unless it is docked container's child in which |
461 // case it needs to keep being observed after the drag completes. | 462 // case it needs to keep being observed after the drag completes. |
462 if (dragged_window_->parent() != dock_container_) { | 463 if (dragged_window_->parent() != dock_container_) { |
463 dragged_window_->RemoveObserver(this); | 464 dragged_window_->RemoveObserver(this); |
464 wm::GetWindowState(dragged_window_)->RemoveObserver(this); | 465 wm::GetWindowState(dragged_window_)->RemoveObserver(this); |
465 if (last_active_window_ == dragged_window_) | 466 if (last_active_window_ == dragged_window_) |
466 last_active_window_ = NULL; | 467 last_active_window_ = NULL; |
468 | |
469 views::corewm::SetWindowShowAnimationDuration(dragged_window_, | |
470 base::TimeDelta()); | |
varkha
2014/01/02 22:26:41
nit: Could this be called once after if-else?
pkotwicz
2014/01/02 22:45:51
Given that the two durations are different, I do n
| |
467 } else { | 471 } else { |
468 // A window is no longer dragged and is a child. | 472 // A window is no longer dragged and is a child. |
469 // When a window becomes a child at drag start this is | 473 // When a window becomes a child at drag start this is |
470 // the only opportunity we will have to enforce a window | 474 // the only opportunity we will have to enforce a window |
471 // count limit so do it here. | 475 // count limit so do it here. |
472 MaybeMinimizeChildrenExcept(dragged_window_); | 476 MaybeMinimizeChildrenExcept(dragged_window_); |
477 | |
478 views::corewm::SetWindowShowAnimationDuration(dragged_window_, | |
479 base::TimeDelta::FromMilliseconds(kFadeDurationMs)); | |
473 } | 480 } |
474 dragged_window_ = NULL; | 481 dragged_window_ = NULL; |
475 dragged_bounds_ = gfx::Rect(); | 482 dragged_bounds_ = gfx::Rect(); |
476 Relayout(); | 483 Relayout(); |
477 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 484 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
478 RecordUmaAction(action, source); | 485 RecordUmaAction(action, source); |
479 } | 486 } |
480 | 487 |
481 void DockedWindowLayoutManager::SetShelf(Shelf* shelf) { | 488 void DockedWindowLayoutManager::SetShelf(Shelf* shelf) { |
482 DCHECK(!shelf_); | 489 DCHECK(!shelf_); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
596 // If this is the first window getting docked - update alignment. | 603 // If this is the first window getting docked - update alignment. |
597 if (alignment_ == DOCKED_ALIGNMENT_NONE) { | 604 if (alignment_ == DOCKED_ALIGNMENT_NONE) { |
598 alignment_ = GetAlignmentOfWindow(child); | 605 alignment_ = GetAlignmentOfWindow(child); |
599 DCHECK(alignment_ != DOCKED_ALIGNMENT_NONE); | 606 DCHECK(alignment_ != DOCKED_ALIGNMENT_NONE); |
600 } | 607 } |
601 MaybeMinimizeChildrenExcept(child); | 608 MaybeMinimizeChildrenExcept(child); |
602 child->AddObserver(this); | 609 child->AddObserver(this); |
603 wm::GetWindowState(child)->AddObserver(this); | 610 wm::GetWindowState(child)->AddObserver(this); |
604 Relayout(); | 611 Relayout(); |
605 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 612 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
613 views::corewm::SetWindowShowAnimationDuration(child, | |
614 base::TimeDelta::FromMilliseconds(kFadeDurationMs)); | |
606 } | 615 } |
607 | 616 |
608 void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { | 617 void DockedWindowLayoutManager::OnWindowRemovedFromLayout(aura::Window* child) { |
609 if (IsPopupOrTransient(child)) | 618 if (IsPopupOrTransient(child)) |
610 return; | 619 return; |
611 // Dragged windows are stopped being observed by FinishDragging and do not | 620 // Dragged windows are stopped being observed by FinishDragging and do not |
612 // change alignment during the drag. They also cannot be set to be the | 621 // change alignment during the drag. They also cannot be set to be the |
613 // |last_active_window_|. | 622 // |last_active_window_|. |
614 if (child == dragged_window_) | 623 if (child == dragged_window_) |
615 return; | 624 return; |
616 // If this is the last window, set alignment and maximize the workspace. | 625 // If this is the last window, set alignment and maximize the workspace. |
617 if (!IsAnyWindowDocked()) { | 626 if (!IsAnyWindowDocked()) { |
618 alignment_ = DOCKED_ALIGNMENT_NONE; | 627 alignment_ = DOCKED_ALIGNMENT_NONE; |
619 UpdateDockedWidth(0); | 628 UpdateDockedWidth(0); |
620 } | 629 } |
621 if (last_active_window_ == child) | 630 if (last_active_window_ == child) |
622 last_active_window_ = NULL; | 631 last_active_window_ = NULL; |
623 child->RemoveObserver(this); | 632 child->RemoveObserver(this); |
624 wm::GetWindowState(child)->RemoveObserver(this); | 633 wm::GetWindowState(child)->RemoveObserver(this); |
625 Relayout(); | 634 Relayout(); |
626 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); | 635 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); |
636 views::corewm::SetWindowShowAnimationDuration(child, base::TimeDelta()); | |
627 } | 637 } |
628 | 638 |
629 void DockedWindowLayoutManager::OnChildWindowVisibilityChanged( | 639 void DockedWindowLayoutManager::OnChildWindowVisibilityChanged( |
630 aura::Window* child, | 640 aura::Window* child, |
631 bool visible) { | 641 bool visible) { |
632 if (IsPopupOrTransient(child)) | 642 if (IsPopupOrTransient(child)) |
633 return; | 643 return; |
634 if (visible) | 644 if (visible) |
635 wm::GetWindowState(child)->Restore(); | 645 wm::GetWindowState(child)->Restore(); |
636 Relayout(); | 646 Relayout(); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
755 | 765 |
756 void DockedWindowLayoutManager::OnWindowBoundsChanged( | 766 void DockedWindowLayoutManager::OnWindowBoundsChanged( |
757 aura::Window* window, | 767 aura::Window* window, |
758 const gfx::Rect& old_bounds, | 768 const gfx::Rect& old_bounds, |
759 const gfx::Rect& new_bounds) { | 769 const gfx::Rect& new_bounds) { |
760 // Only relayout if the dragged window would get docked. | 770 // Only relayout if the dragged window would get docked. |
761 if (window == dragged_window_ && is_dragged_window_docked_) | 771 if (window == dragged_window_ && is_dragged_window_docked_) |
762 Relayout(); | 772 Relayout(); |
763 } | 773 } |
764 | 774 |
765 void DockedWindowLayoutManager::OnWindowVisibilityChanging( | |
766 aura::Window* window, bool visible) { | |
767 if (IsPopupOrTransient(window)) | |
768 return; | |
769 int animation_type = views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT; | |
770 if (visible) { | |
771 animation_type = views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DROP; | |
772 views::corewm::SetWindowVisibilityAnimationDuration( | |
773 window, base::TimeDelta::FromMilliseconds(kFadeDurationMs)); | |
774 } else if (wm::GetWindowState(window)->IsMinimized()) { | |
775 animation_type = WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE; | |
776 } | |
777 views::corewm::SetWindowVisibilityAnimationType(window, animation_type); | |
778 } | |
779 | |
780 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { | 775 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { |
781 if (dragged_window_ == window) { | 776 if (dragged_window_ == window) { |
782 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); | 777 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); |
783 DCHECK(!dragged_window_); | 778 DCHECK(!dragged_window_); |
784 DCHECK (!is_dragged_window_docked_); | 779 DCHECK (!is_dragged_window_docked_); |
785 } | 780 } |
786 if (window == last_active_window_) | 781 if (window == last_active_window_) |
787 last_active_window_ = NULL; | 782 last_active_window_ = NULL; |
788 RecordUmaAction(DOCKED_ACTION_CLOSE, DOCKED_ACTION_SOURCE_UNKNOWN); | 783 RecordUmaAction(DOCKED_ACTION_CLOSE, DOCKED_ACTION_SOURCE_UNKNOWN); |
789 } | 784 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
825 aura::Window::Windows children(dock_container_->children()); | 820 aura::Window::Windows children(dock_container_->children()); |
826 aura::Window::Windows::const_reverse_iterator iter = children.rbegin(); | 821 aura::Window::Windows::const_reverse_iterator iter = children.rbegin(); |
827 while (iter != children.rend()) { | 822 while (iter != children.rend()) { |
828 aura::Window* window(*iter++); | 823 aura::Window* window(*iter++); |
829 if (window == child || !IsUsedByLayout(window)) | 824 if (window == child || !IsUsedByLayout(window)) |
830 continue; | 825 continue; |
831 int room_needed = GetWindowHeightCloseTo(window, 0) + kMinDockGap; | 826 int room_needed = GetWindowHeightCloseTo(window, 0) + kMinDockGap; |
832 if (available_room > room_needed) { | 827 if (available_room > room_needed) { |
833 available_room -= room_needed; | 828 available_room -= room_needed; |
834 } else { | 829 } else { |
835 // Slow down minimizing animations. Lock duration so that it is not | 830 // Slow down the minimize animation. |
836 // overridden by other ScopedLayerAnimationSettings down the stack. | 831 views::corewm::SetWindowHideAnimationDuration( |
837 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); | 832 window, |
838 settings.SetTransitionDuration( | |
839 base::TimeDelta::FromMilliseconds(kMinimizeDurationMs)); | 833 base::TimeDelta::FromMilliseconds(kMinimizeDurationMs)); |
840 settings.LockTransitionDuration(); | |
841 wm::GetWindowState(window)->Minimize(); | 834 wm::GetWindowState(window)->Minimize(); |
835 views::corewm::SetWindowHideAnimationDuration(window, base::TimeDelta()); | |
842 } | 836 } |
843 } | 837 } |
844 } | 838 } |
845 | 839 |
846 void DockedWindowLayoutManager::MinimizeDockedWindow( | 840 void DockedWindowLayoutManager::MinimizeDockedWindow( |
847 wm::WindowState* window_state) { | 841 wm::WindowState* window_state) { |
848 DCHECK(!IsPopupOrTransient(window_state->window())); | 842 aura::Window* window = window_state->window(); |
849 window_state->window()->Hide(); | 843 DCHECK(!IsPopupOrTransient(window)); |
844 views::corewm::SetWindowVisibilityAnimationType(window, | |
845 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_MINIMIZE); | |
846 window->Hide(); | |
847 views::corewm::SetWindowVisibilityAnimationType(window, | |
848 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_DEFAULT); | |
850 if (window_state->IsActive()) | 849 if (window_state->IsActive()) |
851 window_state->Deactivate(); | 850 window_state->Deactivate(); |
852 RecordUmaAction(DOCKED_ACTION_MINIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN); | 851 RecordUmaAction(DOCKED_ACTION_MINIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN); |
853 } | 852 } |
854 | 853 |
855 void DockedWindowLayoutManager::RestoreDockedWindow( | 854 void DockedWindowLayoutManager::RestoreDockedWindow( |
856 wm::WindowState* window_state) { | 855 wm::WindowState* window_state) { |
857 aura::Window* window = window_state->window(); | 856 aura::Window* window = window_state->window(); |
858 DCHECK(!IsPopupOrTransient(window)); | 857 DCHECK(!IsPopupOrTransient(window)); |
859 // Always place restored window at the bottom shuffling the other windows up. | 858 // Always place restored window at the bottom shuffling the other windows up. |
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1239 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1238 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
1240 const gfx::Rect& keyboard_bounds) { | 1239 const gfx::Rect& keyboard_bounds) { |
1241 // This bounds change will have caused a change to the Shelf which does not | 1240 // This bounds change will have caused a change to the Shelf which does not |
1242 // propagate automatically to this class, so manually recalculate bounds. | 1241 // propagate automatically to this class, so manually recalculate bounds. |
1243 Relayout(); | 1242 Relayout(); |
1244 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1243 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
1245 } | 1244 } |
1246 | 1245 |
1247 } // namespace internal | 1246 } // namespace internal |
1248 } // namespace ash | 1247 } // namespace ash |
OLD | NEW |