OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ui/app_list/views/app_list_folder_view.h" | |
6 | |
7 #include "ui/app_list/app_list_constants.h" | |
8 #include "ui/app_list/app_list_folder_item.h" | |
9 #include "ui/app_list/app_list_model.h" | |
10 #include "ui/app_list/pagination_model.h" | |
11 #include "ui/app_list/views/app_list_main_view.h" | |
12 #include "ui/app_list/views/apps_container_view.h" | |
13 #include "ui/app_list/views/apps_grid_view.h" | |
14 #include "ui/app_list/views/contents_view.h" | |
15 #include "ui/app_list/views/folder_header_view.h" | |
16 #include "ui/views/view_model.h" | |
17 #include "ui/views/view_model_utils.h" | |
18 | |
19 namespace app_list { | |
20 | |
21 namespace { | |
22 | |
23 // Indexes of interesting views in ViewModel of AppListFolderView. | |
24 const int kIndexFolderHeader = 0; | |
25 const int kIndexChildItems = 1; | |
26 | |
27 } // namespace | |
28 | |
29 AppListFolderView::AppListFolderView(AppsContainerView* container_view, | |
30 AppListModel* model, | |
31 AppListMainView* app_list_main_view, | |
32 content::WebContents* start_page_contents) | |
33 : container_view_(container_view), | |
34 folder_header_view_(new FolderHeaderView(this)), | |
35 view_model_(new views::ViewModel), | |
36 folder_item_(NULL), | |
37 pagination_model_(new PaginationModel) { | |
38 AddChildView(folder_header_view_); | |
39 view_model_->Add(folder_header_view_, kIndexFolderHeader); | |
40 | |
41 items_grid_view_ = new AppsGridView( | |
42 app_list_main_view, pagination_model_.get(), NULL); | |
43 items_grid_view_->SetLayout(kPreferredIconDimension, | |
44 kPreferredCols, | |
45 kPreferredRows); | |
46 items_grid_view_->SetModel(model); | |
47 AddChildView(items_grid_view_); | |
48 view_model_->Add(items_grid_view_, kIndexChildItems); | |
49 } | |
50 | |
51 AppListFolderView::~AppListFolderView() { | |
xiyuan
2013/10/23 00:43:25
Add "RemoveAllChildViews(true);" here to explicitl
jennyz
2013/10/23 05:25:52
Thanks, fixed in a new patch since it is reverted
| |
52 } | |
53 | |
54 void AppListFolderView::SetAppListFolderItem(AppListFolderItem* folder) { | |
55 folder_item_ = folder; | |
56 items_grid_view_->SetApps(folder_item_->apps()); | |
57 folder_header_view_->SetFolderItem(folder_item_); | |
58 } | |
59 | |
60 gfx::Size AppListFolderView::GetPreferredSize() { | |
61 const gfx::Size header_size = folder_header_view_->GetPreferredSize(); | |
62 const gfx::Size grid_size = items_grid_view_->GetPreferredSize(); | |
63 int width = std::max(header_size.width(), grid_size.width()); | |
64 int height = header_size.height() + grid_size.height(); | |
65 return gfx::Size(width, height); | |
66 } | |
67 | |
68 void AppListFolderView::Layout() { | |
69 CalculateIdealBounds(); | |
70 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | |
71 } | |
72 | |
73 void AppListFolderView::CalculateIdealBounds() { | |
74 gfx::Rect rect(GetContentsBounds()); | |
75 if (rect.IsEmpty()) | |
76 return; | |
77 | |
78 gfx::Rect header_frame(rect); | |
79 gfx::Size size = folder_header_view_->GetPreferredSize(); | |
80 header_frame.set_height(size.height()); | |
81 view_model_->set_ideal_bounds(kIndexFolderHeader, header_frame); | |
82 | |
83 gfx::Rect grid_frame(rect); | |
84 grid_frame.set_y(header_frame.height()); | |
85 view_model_->set_ideal_bounds(kIndexChildItems, grid_frame); | |
86 } | |
87 | |
88 void AppListFolderView::NavigateBack(AppListFolderItem* item, | |
89 const ui::Event& event_flags) { | |
90 container_view_->ShowApps(); | |
91 } | |
92 | |
93 } // namespace app_list | |
94 | |
OLD | NEW |