OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "ui/app_list/views/app_list_folder_view.h" | 5 #include "ui/app_list/views/app_list_folder_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
10 #include "ui/app_list/app_list_folder_item.h" | 10 #include "ui/app_list/app_list_folder_item.h" |
11 #include "ui/app_list/app_list_model.h" | 11 #include "ui/app_list/app_list_model.h" |
12 #include "ui/app_list/pagination_model.h" | 12 #include "ui/app_list/pagination_model.h" |
| 13 #include "ui/app_list/views/app_list_item_view.h" |
13 #include "ui/app_list/views/app_list_main_view.h" | 14 #include "ui/app_list/views/app_list_main_view.h" |
14 #include "ui/app_list/views/apps_container_view.h" | 15 #include "ui/app_list/views/apps_container_view.h" |
15 #include "ui/app_list/views/apps_grid_view.h" | 16 #include "ui/app_list/views/apps_grid_view.h" |
16 #include "ui/app_list/views/contents_view.h" | 17 #include "ui/app_list/views/contents_view.h" |
17 #include "ui/app_list/views/folder_header_view.h" | 18 #include "ui/app_list/views/folder_header_view.h" |
| 19 #include "ui/compositor/scoped_layer_animation_settings.h" |
18 #include "ui/events/event.h" | 20 #include "ui/events/event.h" |
19 #include "ui/views/view_model.h" | 21 #include "ui/views/view_model.h" |
20 #include "ui/views/view_model_utils.h" | 22 #include "ui/views/view_model_utils.h" |
21 | 23 |
22 namespace app_list { | 24 namespace app_list { |
23 | 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 // Indexes of interesting views in ViewModel of AppListFolderView. | 28 // Indexes of interesting views in ViewModel of AppListFolderView. |
27 const int kIndexFolderHeader = 0; | 29 const int kIndexFolderHeader = 0; |
(...skipping 15 matching lines...) Expand all Loading... |
43 | 45 |
44 items_grid_view_ = new AppsGridView( | 46 items_grid_view_ = new AppsGridView( |
45 app_list_main_view, pagination_model_.get(), NULL); | 47 app_list_main_view, pagination_model_.get(), NULL); |
46 items_grid_view_->set_is_root_level(false); | 48 items_grid_view_->set_is_root_level(false); |
47 items_grid_view_->SetLayout(kPreferredIconDimension, | 49 items_grid_view_->SetLayout(kPreferredIconDimension, |
48 kPreferredCols, | 50 kPreferredCols, |
49 kPreferredRows); | 51 kPreferredRows); |
50 items_grid_view_->SetModel(model); | 52 items_grid_view_->SetModel(model); |
51 AddChildView(items_grid_view_); | 53 AddChildView(items_grid_view_); |
52 view_model_->Add(items_grid_view_, kIndexChildItems); | 54 view_model_->Add(items_grid_view_, kIndexChildItems); |
| 55 |
| 56 #if defined(USE_AURA) |
| 57 SetPaintToLayer(true); |
| 58 SetFillsBoundsOpaquely(false); |
| 59 #endif |
53 } | 60 } |
54 | 61 |
55 AppListFolderView::~AppListFolderView() { | 62 AppListFolderView::~AppListFolderView() { |
56 // Make sure |items_grid_view_| is deleted before |pagination_model_|. | 63 // Make sure |items_grid_view_| is deleted before |pagination_model_|. |
57 RemoveAllChildViews(true); | 64 RemoveAllChildViews(true); |
58 } | 65 } |
59 | 66 |
60 void AppListFolderView::SetAppListFolderItem(AppListFolderItem* folder) { | 67 void AppListFolderView::SetAppListFolderItem(AppListFolderItem* folder) { |
61 folder_item_ = folder; | 68 folder_item_ = folder; |
62 items_grid_view_->SetItemList(folder_item_->item_list()); | 69 items_grid_view_->SetItemList(folder_item_->item_list()); |
63 folder_header_view_->SetFolderItem(folder_item_); | 70 folder_header_view_->SetFolderItem(folder_item_); |
64 } | 71 } |
65 | 72 |
| 73 void AppListFolderView::ScheduleShowHideAnimation(bool show) { |
| 74 // Stop any previous animation. |
| 75 layer()->GetAnimator()->StopAnimating(); |
| 76 |
| 77 // Hide the top items temporarily if showing the view for opening the folder. |
| 78 if (show) |
| 79 items_grid_view_->SetTopItemViewsVisible(false); |
| 80 |
| 81 // Set initial state. |
| 82 SetVisible(true); |
| 83 layer()->SetOpacity(show ? 0.0f : 1.0f); |
| 84 |
| 85 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); |
| 86 animation.SetTweenType(gfx::Tween::EASE_IN_2); |
| 87 animation.AddObserver(this); |
| 88 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( |
| 89 show ? kFolderTransitionInDurationMs : kFolderTransitionOutDurationMs)); |
| 90 |
| 91 layer()->SetOpacity(show ? 1.0f : 0.0f); |
| 92 } |
| 93 |
66 gfx::Size AppListFolderView::GetPreferredSize() { | 94 gfx::Size AppListFolderView::GetPreferredSize() { |
67 const gfx::Size header_size = folder_header_view_->GetPreferredSize(); | 95 const gfx::Size header_size = folder_header_view_->GetPreferredSize(); |
68 const gfx::Size grid_size = items_grid_view_->GetPreferredSize(); | 96 const gfx::Size grid_size = items_grid_view_->GetPreferredSize(); |
69 int width = std::max(header_size.width(), grid_size.width()); | 97 int width = std::max(header_size.width(), grid_size.width()); |
70 int height = header_size.height() + grid_size.height(); | 98 int height = header_size.height() + grid_size.height(); |
71 return gfx::Size(width, height); | 99 return gfx::Size(width, height); |
72 } | 100 } |
73 | 101 |
74 void AppListFolderView::Layout() { | 102 void AppListFolderView::Layout() { |
75 CalculateIdealBounds(); | 103 CalculateIdealBounds(); |
76 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 104 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
77 } | 105 } |
78 | 106 |
79 bool AppListFolderView::OnKeyPressed(const ui::KeyEvent& event) { | 107 bool AppListFolderView::OnKeyPressed(const ui::KeyEvent& event) { |
80 return items_grid_view_->OnKeyPressed(event); | 108 return items_grid_view_->OnKeyPressed(event); |
81 } | 109 } |
82 | 110 |
| 111 void AppListFolderView::OnImplicitAnimationsCompleted() { |
| 112 // Show the top items when the opening folder animation is done. |
| 113 if (layer()->opacity() == 1.0f) |
| 114 items_grid_view_->SetTopItemViewsVisible(true); |
| 115 |
| 116 if (layer()->opacity() == 0.0f) |
| 117 SetVisible(false); |
| 118 } |
| 119 |
83 void AppListFolderView::CalculateIdealBounds() { | 120 void AppListFolderView::CalculateIdealBounds() { |
84 gfx::Rect rect(GetContentsBounds()); | 121 gfx::Rect rect(GetContentsBounds()); |
85 if (rect.IsEmpty()) | 122 if (rect.IsEmpty()) |
86 return; | 123 return; |
87 | 124 |
88 gfx::Rect header_frame(rect); | 125 gfx::Rect header_frame(rect); |
89 gfx::Size size = folder_header_view_->GetPreferredSize(); | 126 gfx::Size size = folder_header_view_->GetPreferredSize(); |
90 header_frame.set_height(size.height()); | 127 header_frame.set_height(size.height()); |
91 view_model_->set_ideal_bounds(kIndexFolderHeader, header_frame); | 128 view_model_->set_ideal_bounds(kIndexFolderHeader, header_frame); |
92 | 129 |
93 gfx::Rect grid_frame(rect); | 130 gfx::Rect grid_frame(rect); |
94 grid_frame.set_y(header_frame.height()); | 131 grid_frame.set_y(header_frame.height()); |
95 view_model_->set_ideal_bounds(kIndexChildItems, grid_frame); | 132 view_model_->set_ideal_bounds(kIndexChildItems, grid_frame); |
96 } | 133 } |
97 | 134 |
| 135 gfx::Rect AppListFolderView::GetItemIconBoundsAt(int index) { |
| 136 AppListItemView* item_view = items_grid_view_->GetItemViewAt(index); |
| 137 // Icon bounds relative to AppListItemView. |
| 138 const gfx::Rect icon_bounds = item_view->GetIconBounds(); |
| 139 gfx::Rect to_apps_grid_view = item_view->ConvertRectToParent(icon_bounds); |
| 140 gfx::Rect to_folder = |
| 141 items_grid_view_->ConvertRectToParent(to_apps_grid_view); |
| 142 |
| 143 // Get the icon image's bound. |
| 144 to_folder.ClampToCenteredSize( |
| 145 gfx::Size(kPreferredIconDimension, kPreferredIconDimension)); |
| 146 |
| 147 return to_folder; |
| 148 } |
| 149 |
98 void AppListFolderView::NavigateBack(AppListFolderItem* item, | 150 void AppListFolderView::NavigateBack(AppListFolderItem* item, |
99 const ui::Event& event_flags) { | 151 const ui::Event& event_flags) { |
100 container_view_->ShowApps(); | 152 container_view_->ShowApps(item); |
101 } | 153 } |
102 | 154 |
103 } // namespace app_list | 155 } // namespace app_list |
OLD | NEW |