| 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/launcher/launcher.h" | 8 #include "ash/launcher/launcher.h" |
| 9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
| 10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // static | 38 // static |
| 39 const int DockedWindowLayoutManager::kMaxDockWidth = 360; | 39 const int DockedWindowLayoutManager::kMaxDockWidth = 360; |
| 40 // static | 40 // static |
| 41 const int DockedWindowLayoutManager::kMinDockWidth = 200; | 41 const int DockedWindowLayoutManager::kMinDockWidth = 200; |
| 42 // static | 42 // static |
| 43 const int DockedWindowLayoutManager::kMinDockGap = 2; | 43 const int DockedWindowLayoutManager::kMinDockGap = 2; |
| 44 // static | 44 // static |
| 45 const int DockedWindowLayoutManager::kIdealWidth = 250; | 45 const int DockedWindowLayoutManager::kIdealWidth = 250; |
| 46 const int kMinimumHeight = 250; | 46 const int kMinimumHeight = 250; |
| 47 const int kSlideDurationMs = 120; | 47 const int kSlideDurationMs = 120; |
| 48 const int kFadeDurationMs = 720; | 48 const int kFadeDurationMs = 60; |
| 49 const int kMinimizeDurationMs = 720; |
| 49 | 50 |
| 50 namespace { | 51 namespace { |
| 51 | 52 |
| 52 const SkColor kDockBackgroundColor = SkColorSetARGB(0xff, 0x10, 0x10, 0x10); | 53 const SkColor kDockBackgroundColor = SkColorSetARGB(0xff, 0x10, 0x10, 0x10); |
| 53 const float kDockBackgroundOpacity = 0.5f; | 54 const float kDockBackgroundOpacity = 0.5f; |
| 54 | 55 |
| 55 class DockedBackgroundWidget : public views::Widget { | 56 class DockedBackgroundWidget : public views::Widget { |
| 56 public: | 57 public: |
| 57 explicit DockedBackgroundWidget(aura::Window* container) { | 58 explicit DockedBackgroundWidget(aura::Window* container) { |
| 58 InitWidget(container); | 59 InitWidget(container); |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 if (child) | 647 if (child) |
| 647 available_room -= (GetWindowHeightCloseTo(child, 0) + kMinDockGap); | 648 available_room -= (GetWindowHeightCloseTo(child, 0) + kMinDockGap); |
| 648 // Use a copy of children array because a call to Minimize can change order. | 649 // Use a copy of children array because a call to Minimize can change order. |
| 649 aura::Window::Windows children(dock_container_->children()); | 650 aura::Window::Windows children(dock_container_->children()); |
| 650 aura::Window::Windows::const_reverse_iterator iter = children.rbegin(); | 651 aura::Window::Windows::const_reverse_iterator iter = children.rbegin(); |
| 651 while (iter != children.rend()) { | 652 while (iter != children.rend()) { |
| 652 aura::Window* window(*iter++); | 653 aura::Window* window(*iter++); |
| 653 if (window == child || !IsUsedByLayout(window)) | 654 if (window == child || !IsUsedByLayout(window)) |
| 654 continue; | 655 continue; |
| 655 int room_needed = GetWindowHeightCloseTo(window, 0) + kMinDockGap; | 656 int room_needed = GetWindowHeightCloseTo(window, 0) + kMinDockGap; |
| 656 if (available_room > room_needed) | 657 if (available_room > room_needed) { |
| 657 available_room -= room_needed; | 658 available_room -= room_needed; |
| 658 else | 659 } else { |
| 660 // Slow down minimizing animations. Lock duration so that it is not |
| 661 // overridden by other ScopedLayerAnimationSettings down the stack. |
| 662 ui::ScopedLayerAnimationSettings settings(window->layer()->GetAnimator()); |
| 663 settings.SetTransitionDuration( |
| 664 base::TimeDelta::FromMilliseconds(kMinimizeDurationMs)); |
| 665 settings.LockTransitionDuration(); |
| 659 wm::GetWindowState(window)->Minimize(); | 666 wm::GetWindowState(window)->Minimize(); |
| 667 } |
| 660 } | 668 } |
| 661 } | 669 } |
| 662 | 670 |
| 663 void DockedWindowLayoutManager::MinimizeDockedWindow( | 671 void DockedWindowLayoutManager::MinimizeDockedWindow( |
| 664 wm::WindowState* window_state) { | 672 wm::WindowState* window_state) { |
| 665 DCHECK(!IsPopupOrTransient(window_state->window())); | 673 DCHECK(!IsPopupOrTransient(window_state->window())); |
| 666 window_state->window()->Hide(); | 674 window_state->window()->Hide(); |
| 667 if (window_state->IsActive()) | 675 if (window_state->IsActive()) |
| 668 window_state->Deactivate(); | 676 window_state->Deactivate(); |
| 669 RecordUmaAction(DOCKED_ACTION_MINIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN); | 677 RecordUmaAction(DOCKED_ACTION_MINIMIZE, DOCKED_ACTION_SOURCE_UNKNOWN); |
| 670 } | 678 } |
| 671 | 679 |
| 672 void DockedWindowLayoutManager::RestoreDockedWindow( | 680 void DockedWindowLayoutManager::RestoreDockedWindow( |
| 673 wm::WindowState* window_state) { | 681 wm::WindowState* window_state) { |
| 674 aura::Window* window = window_state->window(); | 682 aura::Window* window = window_state->window(); |
| 675 DCHECK(!IsPopupOrTransient(window)); | 683 DCHECK(!IsPopupOrTransient(window)); |
| 676 // Always place restored window at the top shuffling the other windows down. | 684 // Always place restored window at the bottom shuffling the other windows up. |
| 677 // TODO(varkha): add a separate container for docked windows to keep track | 685 // TODO(varkha): add a separate container for docked windows to keep track |
| 678 // of ordering. | 686 // of ordering. |
| 679 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( | 687 gfx::Display display = Shell::GetScreen()->GetDisplayNearestWindow( |
| 680 dock_container_); | 688 dock_container_); |
| 681 const gfx::Rect work_area = display.work_area(); | 689 const gfx::Rect work_area = display.work_area(); |
| 682 | 690 |
| 683 // Evict the window if it can no longer be docked because of its height. | 691 // Evict the window if it can no longer be docked because of its height. |
| 684 if (!CanDockWindow(window, SNAP_NONE)) { | 692 if (!CanDockWindow(window, SNAP_NONE)) { |
| 685 UndockWindow(window); | 693 UndockWindow(window); |
| 686 RecordUmaAction(DOCKED_ACTION_EVICT, DOCKED_ACTION_SOURCE_UNKNOWN); | 694 RecordUmaAction(DOCKED_ACTION_EVICT, DOCKED_ACTION_SOURCE_UNKNOWN); |
| 687 return; | 695 return; |
| 688 } | 696 } |
| 689 gfx::Rect bounds(window->bounds()); | 697 gfx::Rect bounds(window->bounds()); |
| 690 bounds.set_y(work_area.y() - bounds.height()); | 698 bounds.set_y(work_area.bottom()); |
| 691 window->SetBounds(bounds); | 699 window->SetBounds(bounds); |
| 692 window->Show(); | 700 window->Show(); |
| 693 MaybeMinimizeChildrenExcept(window); | 701 MaybeMinimizeChildrenExcept(window); |
| 694 RecordUmaAction(DOCKED_ACTION_RESTORE, DOCKED_ACTION_SOURCE_UNKNOWN); | 702 RecordUmaAction(DOCKED_ACTION_RESTORE, DOCKED_ACTION_SOURCE_UNKNOWN); |
| 695 } | 703 } |
| 696 | 704 |
| 697 void DockedWindowLayoutManager::RecordUmaAction(DockedAction action, | 705 void DockedWindowLayoutManager::RecordUmaAction(DockedAction action, |
| 698 DockedActionSource source) { | 706 DockedActionSource source) { |
| 699 if (action == DOCKED_ACTION_NONE) | 707 if (action == DOCKED_ACTION_NONE) |
| 700 return; | 708 return; |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1054 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( | 1062 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( |
| 1055 const gfx::Rect& keyboard_bounds) { | 1063 const gfx::Rect& keyboard_bounds) { |
| 1056 // This bounds change will have caused a change to the Shelf which does not | 1064 // This bounds change will have caused a change to the Shelf which does not |
| 1057 // propagate automatically to this class, so manually recalculate bounds. | 1065 // propagate automatically to this class, so manually recalculate bounds. |
| 1058 Relayout(); | 1066 Relayout(); |
| 1059 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); | 1067 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); |
| 1060 } | 1068 } |
| 1061 | 1069 |
| 1062 } // namespace internal | 1070 } // namespace internal |
| 1063 } // namespace ash | 1071 } // namespace ash |
| OLD | NEW |