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/apps_container_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/pagination_model.h" |
| 10 #include "ui/app_list/views/app_list_folder_view.h" |
| 11 #include "ui/app_list/views/app_list_main_view.h" |
| 12 #include "ui/app_list/views/apps_grid_view.h" |
| 13 |
| 14 namespace app_list { |
| 15 |
| 16 AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view, |
| 17 PaginationModel* pagination_model, |
| 18 AppListModel* model, |
| 19 content::WebContents* start_page_contents) |
| 20 : model_(model), |
| 21 show_state_(SHOW_APPS) { |
| 22 apps_grid_view_ = new AppsGridView( |
| 23 app_list_main_view, pagination_model, start_page_contents); |
| 24 apps_grid_view_->SetLayout(kPreferredIconDimension, |
| 25 kPreferredCols, |
| 26 kPreferredRows); |
| 27 AddChildView(apps_grid_view_); |
| 28 |
| 29 app_list_folder_view_ = new AppListFolderView( |
| 30 this, |
| 31 model, |
| 32 app_list_main_view, |
| 33 start_page_contents); |
| 34 AddChildView(app_list_folder_view_); |
| 35 |
| 36 apps_grid_view_->SetModel(model_); |
| 37 apps_grid_view_->SetApps(model_->apps()); |
| 38 } |
| 39 |
| 40 AppsContainerView::~AppsContainerView() { |
| 41 } |
| 42 |
| 43 void AppsContainerView::ShowActiveFolder(AppListFolderItem* folder_item) { |
| 44 app_list_folder_view_->SetAppListFolderItem(folder_item); |
| 45 SetShowState(SHOW_ACTIVE_FOLDER); |
| 46 } |
| 47 |
| 48 void AppsContainerView::ShowApps() { |
| 49 SetShowState(SHOW_APPS); |
| 50 } |
| 51 |
| 52 gfx::Size AppsContainerView::GetPreferredSize() { |
| 53 const gfx::Size grid_size = apps_grid_view_->GetPreferredSize(); |
| 54 const gfx::Size folder_view_size = app_list_folder_view_->GetPreferredSize(); |
| 55 |
| 56 int width = std::max(grid_size.width(), folder_view_size.width()); |
| 57 int height = std::max(grid_size.height(), folder_view_size.height()); |
| 58 return gfx::Size(width, height); |
| 59 } |
| 60 |
| 61 void AppsContainerView::Layout() { |
| 62 gfx::Rect rect(GetContentsBounds()); |
| 63 if (rect.IsEmpty()) |
| 64 return; |
| 65 |
| 66 switch(show_state_) { |
| 67 case SHOW_APPS: |
| 68 app_list_folder_view_->SetVisible(false); |
| 69 apps_grid_view_->SetBoundsRect(rect); |
| 70 apps_grid_view_->SetVisible(true); |
| 71 break; |
| 72 case SHOW_ACTIVE_FOLDER: |
| 73 apps_grid_view_->SetVisible(false); |
| 74 app_list_folder_view_->SetBoundsRect(rect); |
| 75 app_list_folder_view_->SetVisible(true); |
| 76 break; |
| 77 default: |
| 78 NOTREACHED(); |
| 79 } |
| 80 } |
| 81 |
| 82 void AppsContainerView::SetShowState(ShowState show_state) { |
| 83 if (show_state_ == show_state) |
| 84 return; |
| 85 |
| 86 show_state_ = show_state; |
| 87 Layout(); |
| 88 } |
| 89 |
| 90 } // namespace app_list |
| 91 |
| 92 |
| 93 |
OLD | NEW |