Chromium Code Reviews| 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; |
| 28 const int kIndexChildItems = 1; | 30 const int kIndexChildItems = 1; |
| 29 | 31 |
| 30 } // namespace | 32 } // namespace |
| 31 | 33 |
| 32 AppListFolderView::AppListFolderView(AppsContainerView* container_view, | 34 AppListFolderView::AppListFolderView(AppsContainerView* container_view, |
| 33 AppListModel* model, | 35 AppListModel* model, |
| 34 AppListMainView* app_list_main_view, | 36 AppListMainView* app_list_main_view, |
| 35 content::WebContents* start_page_contents) | 37 content::WebContents* start_page_contents) |
| 36 : container_view_(container_view), | 38 : container_view_(container_view), |
| 37 folder_header_view_(new FolderHeaderView(this)), | 39 folder_header_view_(new FolderHeaderView(this)), |
| 38 view_model_(new views::ViewModel), | 40 view_model_(new views::ViewModel), |
| 39 folder_item_(NULL), | 41 folder_item_(NULL), |
| 40 pagination_model_(new PaginationModel) { | 42 pagination_model_(new PaginationModel), |
| 43 animate_to_show_(false) { | |
| 41 AddChildView(folder_header_view_); | 44 AddChildView(folder_header_view_); |
| 42 view_model_->Add(folder_header_view_, kIndexFolderHeader); | 45 view_model_->Add(folder_header_view_, kIndexFolderHeader); |
| 43 | 46 |
| 44 items_grid_view_ = new AppsGridView( | 47 items_grid_view_ = new AppsGridView( |
| 45 app_list_main_view, pagination_model_.get(), NULL); | 48 app_list_main_view, pagination_model_.get(), NULL); |
| 46 items_grid_view_->set_is_root_level(false); | 49 items_grid_view_->set_is_root_level(false); |
| 47 items_grid_view_->SetLayout(kPreferredIconDimension, | 50 items_grid_view_->SetLayout(kPreferredIconDimension, |
| 48 kPreferredCols, | 51 kPreferredCols, |
| 49 kPreferredRows); | 52 kPreferredRows); |
| 50 items_grid_view_->SetModel(model); | 53 items_grid_view_->SetModel(model); |
| 51 AddChildView(items_grid_view_); | 54 AddChildView(items_grid_view_); |
| 52 view_model_->Add(items_grid_view_, kIndexChildItems); | 55 view_model_->Add(items_grid_view_, kIndexChildItems); |
| 56 | |
| 57 #if defined(USE_AURA) | |
| 58 SetPaintToLayer(true); | |
| 59 SetFillsBoundsOpaquely(false); | |
| 60 #endif | |
| 53 } | 61 } |
| 54 | 62 |
| 55 AppListFolderView::~AppListFolderView() { | 63 AppListFolderView::~AppListFolderView() { |
| 56 // Make sure |items_grid_view_| is deleted before |pagination_model_|. | 64 // Make sure |items_grid_view_| is deleted before |pagination_model_|. |
| 57 RemoveAllChildViews(true); | 65 RemoveAllChildViews(true); |
| 58 } | 66 } |
| 59 | 67 |
| 60 void AppListFolderView::SetAppListFolderItem(AppListFolderItem* folder) { | 68 void AppListFolderView::SetAppListFolderItem(AppListFolderItem* folder) { |
| 61 folder_item_ = folder; | 69 folder_item_ = folder; |
| 62 items_grid_view_->SetItemList(folder_item_->item_list()); | 70 items_grid_view_->SetItemList(folder_item_->item_list()); |
| 63 folder_header_view_->SetFolderItem(folder_item_); | 71 folder_header_view_->SetFolderItem(folder_item_); |
| 64 } | 72 } |
| 65 | 73 |
| 74 void AppListFolderView::ScheduleAnimationToShow(bool show) { | |
| 75 // Stop any previous animation. | |
| 76 layer()->GetAnimator()->StopAnimating(); | |
| 77 | |
| 78 animate_to_show_ = show; | |
| 79 | |
| 80 // Hide the top items temporarily if showing the view for opening the folder. | |
| 81 if (show) | |
| 82 items_grid_view_->ShowTopItemViews(false); | |
| 83 | |
| 84 // Set initial state. | |
| 85 SetVisible(true); | |
| 86 layer()->SetOpacity(show ? 0.0f : 1.0f); | |
| 87 | |
| 88 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator()); | |
| 89 animation.SetTweenType(gfx::Tween::EASE_IN_2); | |
| 90 animation.AddObserver(this); | |
| 91 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds( | |
| 92 show ? kFolderTransitionInDurationMs : kFolderTransitionOutDurationMs)); | |
| 93 | |
| 94 layer()->SetOpacity(show ? 1.0f : 0.0f); | |
| 95 } | |
| 96 | |
| 66 gfx::Size AppListFolderView::GetPreferredSize() { | 97 gfx::Size AppListFolderView::GetPreferredSize() { |
| 67 const gfx::Size header_size = folder_header_view_->GetPreferredSize(); | 98 const gfx::Size header_size = folder_header_view_->GetPreferredSize(); |
| 68 const gfx::Size grid_size = items_grid_view_->GetPreferredSize(); | 99 const gfx::Size grid_size = items_grid_view_->GetPreferredSize(); |
| 69 int width = std::max(header_size.width(), grid_size.width()); | 100 int width = std::max(header_size.width(), grid_size.width()); |
| 70 int height = header_size.height() + grid_size.height(); | 101 int height = header_size.height() + grid_size.height(); |
| 71 return gfx::Size(width, height); | 102 return gfx::Size(width, height); |
| 72 } | 103 } |
| 73 | 104 |
| 74 void AppListFolderView::Layout() { | 105 void AppListFolderView::Layout() { |
| 75 CalculateIdealBounds(); | 106 CalculateIdealBounds(); |
| 76 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 107 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
| 77 } | 108 } |
| 78 | 109 |
| 79 bool AppListFolderView::OnKeyPressed(const ui::KeyEvent& event) { | 110 bool AppListFolderView::OnKeyPressed(const ui::KeyEvent& event) { |
| 80 return items_grid_view_->OnKeyPressed(event); | 111 return items_grid_view_->OnKeyPressed(event); |
| 81 } | 112 } |
| 82 | 113 |
| 114 void AppListFolderView::OnImplicitAnimationsCompleted() { | |
| 115 // Show the top items when the opening folder animation is done. | |
| 116 if (animate_to_show_) { | |
|
xiyuan
2014/01/16 01:46:48
Can we check layer()->opacity to find it out? If s
jennyz
2014/01/16 17:49:52
Done.
| |
| 117 items_grid_view_->ShowTopItemViews(true); | |
| 118 } | |
| 119 | |
| 120 if (!animate_to_show_) | |
| 121 SetVisible(false); | |
| 122 } | |
| 123 | |
| 83 void AppListFolderView::CalculateIdealBounds() { | 124 void AppListFolderView::CalculateIdealBounds() { |
| 84 gfx::Rect rect(GetContentsBounds()); | 125 gfx::Rect rect(GetContentsBounds()); |
| 85 if (rect.IsEmpty()) | 126 if (rect.IsEmpty()) |
| 86 return; | 127 return; |
| 87 | 128 |
| 88 gfx::Rect header_frame(rect); | 129 gfx::Rect header_frame(rect); |
| 89 gfx::Size size = folder_header_view_->GetPreferredSize(); | 130 gfx::Size size = folder_header_view_->GetPreferredSize(); |
| 90 header_frame.set_height(size.height()); | 131 header_frame.set_height(size.height()); |
| 91 view_model_->set_ideal_bounds(kIndexFolderHeader, header_frame); | 132 view_model_->set_ideal_bounds(kIndexFolderHeader, header_frame); |
| 92 | 133 |
| 93 gfx::Rect grid_frame(rect); | 134 gfx::Rect grid_frame(rect); |
| 94 grid_frame.set_y(header_frame.height()); | 135 grid_frame.set_y(header_frame.height()); |
| 95 view_model_->set_ideal_bounds(kIndexChildItems, grid_frame); | 136 view_model_->set_ideal_bounds(kIndexChildItems, grid_frame); |
| 96 } | 137 } |
| 97 | 138 |
| 139 gfx::Rect AppListFolderView::GetItemIconBoundsAt(int index) { | |
| 140 AppListItemView* item_view = items_grid_view_->GetItemViewAt(index); | |
| 141 // Icon bounds relative to AppListItemView. | |
| 142 const gfx::Rect icon_bounds = item_view->GetIconBounds(); | |
| 143 gfx::Rect to_apps_grid_view = item_view->ConvertRectToParent(icon_bounds); | |
| 144 gfx::Rect to_folder = | |
| 145 items_grid_view_->ConvertRectToParent(to_apps_grid_view); | |
| 146 | |
| 147 // Get the icon image's bound. | |
| 148 to_folder.ClampToCenteredSize( | |
| 149 gfx::Size(kPreferredIconDimension, kPreferredIconDimension)); | |
| 150 | |
| 151 return to_folder; | |
| 152 } | |
| 153 | |
| 98 void AppListFolderView::NavigateBack(AppListFolderItem* item, | 154 void AppListFolderView::NavigateBack(AppListFolderItem* item, |
| 99 const ui::Event& event_flags) { | 155 const ui::Event& event_flags) { |
| 100 container_view_->ShowApps(); | 156 container_view_->ShowApps(item); |
| 101 } | 157 } |
| 102 | 158 |
| 103 } // namespace app_list | 159 } // namespace app_list |
| OLD | NEW |