| 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_main_view.h" | 5 #include "ui/app_list/views/app_list_main_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 AppListMainView* owner_; | 77 AppListMainView* owner_; |
| 78 AppListItem* item_; | 78 AppListItem* item_; |
| 79 | 79 |
| 80 DISALLOW_COPY_AND_ASSIGN(IconLoader); | 80 DISALLOW_COPY_AND_ASSIGN(IconLoader); |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 //////////////////////////////////////////////////////////////////////////////// | 83 //////////////////////////////////////////////////////////////////////////////// |
| 84 // AppListMainView: | 84 // AppListMainView: |
| 85 | 85 |
| 86 AppListMainView::AppListMainView(AppListViewDelegate* delegate, | 86 AppListMainView::AppListMainView(AppListViewDelegate* delegate, |
| 87 PaginationModel* pagination_model, | 87 int initial_apps_page, |
| 88 gfx::NativeView parent) | 88 gfx::NativeView parent) |
| 89 : delegate_(delegate), | 89 : delegate_(delegate), |
| 90 pagination_model_(pagination_model), | |
| 91 model_(delegate->GetModel()), | 90 model_(delegate->GetModel()), |
| 92 search_box_view_(NULL), | 91 search_box_view_(NULL), |
| 93 contents_view_(NULL), | 92 contents_view_(NULL), |
| 94 weak_ptr_factory_(this) { | 93 weak_ptr_factory_(this) { |
| 95 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, | 94 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, |
| 96 kInnerPadding, | 95 kInnerPadding, |
| 97 kInnerPadding, | 96 kInnerPadding, |
| 98 kInnerPadding)); | 97 kInnerPadding)); |
| 99 | 98 |
| 100 search_box_view_ = new SearchBoxView(this, delegate); | 99 search_box_view_ = new SearchBoxView(this, delegate); |
| 101 AddChildView(search_box_view_); | 100 AddChildView(search_box_view_); |
| 102 AddContentsView(); | 101 AddContentsView(); |
| 103 if (app_list::switches::IsExperimentalAppListEnabled()) | 102 if (app_list::switches::IsExperimentalAppListEnabled()) |
| 104 AddChildView(new ContentsSwitcherView(contents_view_)); | 103 AddChildView(new ContentsSwitcherView(contents_view_)); |
| 105 | 104 |
| 105 // Switch the apps grid view to the specified page. |
| 106 app_list::PaginationModel* pagination_model = GetAppsPaginationModel(); |
| 107 if (pagination_model->is_valid_page(initial_apps_page)) |
| 108 pagination_model->SelectPage(initial_apps_page, false); |
| 109 |
| 106 // Starts icon loading early. | 110 // Starts icon loading early. |
| 107 PreloadIcons(parent); | 111 PreloadIcons(parent); |
| 108 } | 112 } |
| 109 | 113 |
| 110 void AppListMainView::AddContentsView() { | 114 void AppListMainView::AddContentsView() { |
| 111 contents_view_ = new ContentsView( | 115 contents_view_ = new ContentsView(this, model_, delegate_); |
| 112 this, pagination_model_, model_, delegate_); | |
| 113 AddChildViewAt(contents_view_, kContentsViewIndex); | 116 AddChildViewAt(contents_view_, kContentsViewIndex); |
| 114 | 117 |
| 115 search_box_view_->set_contents_view(contents_view_); | 118 search_box_view_->set_contents_view(contents_view_); |
| 116 | 119 |
| 117 #if defined(USE_AURA) | 120 #if defined(USE_AURA) |
| 118 contents_view_->SetPaintToLayer(true); | 121 contents_view_->SetPaintToLayer(true); |
| 119 contents_view_->SetFillsBoundsOpaquely(false); | 122 contents_view_->SetFillsBoundsOpaquely(false); |
| 120 contents_view_->layer()->SetMasksToBounds(true); | 123 contents_view_->layer()->SetMasksToBounds(true); |
| 121 #endif | 124 #endif |
| 122 } | 125 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 void AppListMainView::Prerender() { | 159 void AppListMainView::Prerender() { |
| 157 contents_view_->Prerender(); | 160 contents_view_->Prerender(); |
| 158 } | 161 } |
| 159 | 162 |
| 160 void AppListMainView::ModelChanged() { | 163 void AppListMainView::ModelChanged() { |
| 161 pending_icon_loaders_.clear(); | 164 pending_icon_loaders_.clear(); |
| 162 model_ = delegate_->GetModel(); | 165 model_ = delegate_->GetModel(); |
| 163 search_box_view_->ModelChanged(); | 166 search_box_view_->ModelChanged(); |
| 164 delete contents_view_; | 167 delete contents_view_; |
| 165 contents_view_ = NULL; | 168 contents_view_ = NULL; |
| 166 pagination_model_->SelectPage(0, false /* animate */); | |
| 167 AddContentsView(); | 169 AddContentsView(); |
| 168 Layout(); | 170 Layout(); |
| 169 } | 171 } |
| 170 | 172 |
| 171 void AppListMainView::OnContentsViewShowStateChanged() { | 173 void AppListMainView::OnContentsViewShowStateChanged() { |
| 172 search_box_view_->SetVisible(contents_view_->show_state() != | 174 search_box_view_->SetVisible(contents_view_->show_state() != |
| 173 ContentsView::SHOW_START_PAGE); | 175 ContentsView::SHOW_START_PAGE); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void AppListMainView::OnStartPageSearchButtonPressed() { | 178 void AppListMainView::OnStartPageSearchButtonPressed() { |
| 177 search_box_view_->SetVisible(true); | 179 search_box_view_->SetVisible(true); |
| 178 search_box_view_->search_box()->SetText(base::string16()); | 180 search_box_view_->search_box()->SetText(base::string16()); |
| 179 search_box_view_->RequestFocus(); | 181 search_box_view_->RequestFocus(); |
| 180 } | 182 } |
| 181 | 183 |
| 182 void AppListMainView::SetDragAndDropHostOfCurrentAppList( | 184 void AppListMainView::SetDragAndDropHostOfCurrentAppList( |
| 183 ApplicationDragAndDropHost* drag_and_drop_host) { | 185 ApplicationDragAndDropHost* drag_and_drop_host) { |
| 184 contents_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 186 contents_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
| 185 } | 187 } |
| 186 | 188 |
| 187 bool AppListMainView::ShouldCenterWindow() const { | 189 bool AppListMainView::ShouldCenterWindow() const { |
| 188 return delegate_->ShouldCenterWindow(); | 190 return delegate_->ShouldCenterWindow(); |
| 189 } | 191 } |
| 190 | 192 |
| 193 PaginationModel* AppListMainView::GetAppsPaginationModel() { |
| 194 return contents_view_->apps_container_view() |
| 195 ->apps_grid_view() |
| 196 ->pagination_model(); |
| 197 } |
| 198 |
| 191 void AppListMainView::PreloadIcons(gfx::NativeView parent) { | 199 void AppListMainView::PreloadIcons(gfx::NativeView parent) { |
| 192 float scale_factor = 1.0f; | 200 float scale_factor = 1.0f; |
| 193 if (parent) | 201 if (parent) |
| 194 scale_factor = ui::GetScaleFactorForNativeView(parent); | 202 scale_factor = ui::GetScaleFactorForNativeView(parent); |
| 195 | 203 |
| 196 // |pagination_model| could have -1 as the initial selected page and | 204 // The PaginationModel could have -1 as the initial selected page and |
| 197 // assumes first page (i.e. index 0) will be used in this case. | 205 // assumes first page (i.e. index 0) will be used in this case. |
| 198 const int selected_page = std::max(0, pagination_model_->selected_page()); | 206 const int selected_page = |
| 207 std::max(0, GetAppsPaginationModel()->selected_page()); |
| 199 | 208 |
| 200 const AppsGridView* const apps_grid_view = | 209 const AppsGridView* const apps_grid_view = |
| 201 contents_view_->apps_container_view()->apps_grid_view(); | 210 contents_view_->apps_container_view()->apps_grid_view(); |
| 202 const int tiles_per_page = | 211 const int tiles_per_page = |
| 203 apps_grid_view->cols() * apps_grid_view->rows_per_page(); | 212 apps_grid_view->cols() * apps_grid_view->rows_per_page(); |
| 204 | 213 |
| 205 const int start_model_index = selected_page * tiles_per_page; | 214 const int start_model_index = selected_page * tiles_per_page; |
| 206 const int end_model_index = | 215 const int end_model_index = |
| 207 std::min(static_cast<int>(model_->top_level_item_list()->item_count()), | 216 std::min(static_cast<int>(model_->top_level_item_list()->item_count()), |
| 208 start_model_index + tiles_per_page); | 217 start_model_index + tiles_per_page); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 // Resubmit the query via a posted task so that all observers for the | 285 // Resubmit the query via a posted task so that all observers for the |
| 277 // uninstall notification are notified. | 286 // uninstall notification are notified. |
| 278 base::MessageLoop::current()->PostTask( | 287 base::MessageLoop::current()->PostTask( |
| 279 FROM_HERE, | 288 FROM_HERE, |
| 280 base::Bind(&AppListMainView::QueryChanged, | 289 base::Bind(&AppListMainView::QueryChanged, |
| 281 weak_ptr_factory_.GetWeakPtr(), | 290 weak_ptr_factory_.GetWeakPtr(), |
| 282 search_box_view_)); | 291 search_box_view_)); |
| 283 } | 292 } |
| 284 | 293 |
| 285 } // namespace app_list | 294 } // namespace app_list |
| OLD | NEW |