Chromium Code Reviews| Index: ui/app_list/views/app_list_folder_view.cc |
| diff --git a/ui/app_list/views/app_list_folder_view.cc b/ui/app_list/views/app_list_folder_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a35fab31a76c8d4c69ca95d99b89303af2f570d2 |
| --- /dev/null |
| +++ b/ui/app_list/views/app_list_folder_view.cc |
| @@ -0,0 +1,93 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/app_list/views/app_list_folder_view.h" |
| + |
| +#include "ui/app_list/app_list_constants.h" |
| +#include "ui/app_list/app_list_folder_item.h" |
| +#include "ui/app_list/app_list_model.h" |
| +#include "ui/app_list/pagination_model.h" |
| +#include "ui/app_list/views/app_list_main_view.h" |
| +#include "ui/app_list/views/apps_grid_view.h" |
| +#include "ui/app_list/views/contents_view.h" |
| +#include "ui/app_list/views/folder_header_view.h" |
| +#include "ui/views/view_model.h" |
| +#include "ui/views/view_model_utils.h" |
| + |
| +namespace app_list { |
| + |
| +namespace { |
| + |
| +// Indexes of interesting views in ViewModel of AppListFolderView. |
| +const int kIndexFolderHeader = 0; |
| +const int kIndexChildItems = 1; |
| + |
| +} // namespace |
| + |
| +AppListFolderView::AppListFolderView(ContentsView* contents_view, |
| + AppListModel* model, |
| + AppListMainView* app_list_main_view, |
| + PaginationModel* pagination_model, |
| + content::WebContents* start_page_contents) |
| + : contents_view_(contents_view), |
| + folder_header_view_(new FolderHeaderView(this)), |
| + view_model_(new views::ViewModel), |
| + folder_item_(NULL) { |
| + AddChildView(folder_header_view_); |
| + view_model_->Add(folder_header_view_, kIndexFolderHeader); |
| + |
| + items_grid_view_ = new AppsGridView( |
| + app_list_main_view, pagination_model, start_page_contents); |
|
xiyuan
2013/10/17 23:50:30
AppsGridView needs a AppsGridViewDelegate to pass
jennyz
2013/10/18 22:09:02
Per our discussion, since the folder item activati
|
| + items_grid_view_->SetLayout(kPreferredIconDimension, |
| + kPreferredCols, |
| + kPreferredRows); |
| + items_grid_view_->SetModel(model); |
| + AddChildView(items_grid_view_); |
| + view_model_->Add(items_grid_view_, kIndexChildItems); |
| +} |
| + |
| +AppListFolderView::~AppListFolderView() { |
| +} |
| + |
| +void AppListFolderView::SetAppListFolderItem(AppListFolderItem* folder) { |
|
xiyuan
2013/10/17 23:50:30
Why not pass |folder| in constructor?
jennyz
2013/10/18 22:09:02
Since AppsListFolderView is constructed before it
|
| + folder_item_ = folder; |
| + items_grid_view_->SetApps(folder_item_->apps()); |
| + folder_header_view_->SetFolderItem(folder_item_); |
| +} |
| + |
| +void AppListFolderView::CalculateIdealBounds() { |
| + gfx::Rect rect(GetContentsBounds()); |
| + if (rect.IsEmpty()) |
| + return; |
| + |
| + gfx::Rect header_frame(rect); |
| + gfx::Size size = folder_header_view_->GetPreferredSize(); |
| + header_frame.set_height(size.height()); |
| + view_model_->set_ideal_bounds(kIndexFolderHeader, header_frame); |
| + |
| + gfx::Rect grid_frame(rect); |
| + grid_frame.set_y(header_frame.height()); |
| + view_model_->set_ideal_bounds(kIndexChildItems, grid_frame); |
| +} |
| + |
| +gfx::Size AppListFolderView::GetPreferredSize() { |
| + const gfx::Size header_size = folder_header_view_->GetPreferredSize(); |
| + const gfx::Size grid_size = items_grid_view_->GetPreferredSize(); |
| + int width = std::max(header_size.width(), grid_size.width()); |
| + int height = header_size.height() + grid_size.height(); |
| + return gfx::Size(width, height); |
| +} |
| + |
| +void AppListFolderView::Layout() { |
| + CalculateIdealBounds(); |
| + views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
| +} |
| + |
| +void AppListFolderView::ButtonPressed(views::Button* sender, |
|
xiyuan
2013/10/17 23:50:30
Move this into FolderHeaderView and use a delegate
jennyz
2013/10/18 22:09:02
Moved this into FolderHeaderView and make AppListF
|
| + const ui::Event& event) { |
| + contents_view_->ShowApps(); |
| +} |
| + |
| +} // namespace app_list |
| + |