| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 contents_view_->Prerender(); | 141 contents_view_->Prerender(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 void AppListMainView::SetDragAndDropHostOfCurrentAppList( | 144 void AppListMainView::SetDragAndDropHostOfCurrentAppList( |
| 145 ApplicationDragAndDropHost* drag_and_drop_host) { | 145 ApplicationDragAndDropHost* drag_and_drop_host) { |
| 146 contents_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 146 contents_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void AppListMainView::PreloadIcons(PaginationModel* pagination_model, | 149 void AppListMainView::PreloadIcons(PaginationModel* pagination_model, |
| 150 gfx::NativeView parent) { | 150 gfx::NativeView parent) { |
| 151 if (model_->GetNumAppPages() == 0) |
| 152 return; |
| 153 |
| 151 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P; | 154 ui::ScaleFactor scale_factor = ui::SCALE_FACTOR_100P; |
| 152 if (parent) | 155 if (parent) |
| 153 scale_factor = ui::GetScaleFactorForNativeView(parent); | 156 scale_factor = ui::GetScaleFactorForNativeView(parent); |
| 154 | 157 |
| 155 float scale = ui::GetImageScale(scale_factor); | 158 float scale = ui::GetImageScale(scale_factor); |
| 156 // |pagination_model| could have -1 as the initial selected page and | 159 // |pagination_model| could have -1 as the initial selected page and |
| 157 // assumes first page (i.e. index 0) will be used in this case. | 160 // assumes first page (i.e. index 0) will be used in this case. |
| 158 const int selected_page = std::max(0, pagination_model->selected_page()); | 161 size_t selected_page = 0; |
| 159 | 162 if (pagination_model->selected_page() > 0) { |
| 160 const int tiles_per_page = kPreferredCols * kPreferredRows; | 163 selected_page = static_cast<size_t>(pagination_model->selected_page()); |
| 161 const int start_model_index = selected_page * tiles_per_page; | 164 selected_page = std::min(selected_page, model_->GetNumAppPages() - 1); |
| 162 const int end_model_index = std::min( | 165 } |
| 163 static_cast<int>(model_->apps()->item_count()), | |
| 164 start_model_index + tiles_per_page); | |
| 165 | |
| 166 pending_icon_loaders_.clear(); | 166 pending_icon_loaders_.clear(); |
| 167 for (int i = start_model_index; i < end_model_index; ++i) { | 167 const AppListModel::AppItems& apps = model_->GetAppItems(selected_page); |
| 168 AppListItemModel* item = model_->apps()->GetItemAt(i); | 168 for (size_t i = 0; i < apps.item_count(); ++i) { |
| 169 AppListItemModel* item = model_->GetItemAt(selected_page, i); |
| 169 if (item->icon().HasRepresentation(scale)) | 170 if (item->icon().HasRepresentation(scale)) |
| 170 continue; | 171 continue; |
| 171 | 172 |
| 172 pending_icon_loaders_.push_back(new IconLoader(this, item, scale)); | 173 pending_icon_loaders_.push_back(new IconLoader(this, item, scale)); |
| 173 } | 174 } |
| 174 } | 175 } |
| 175 | 176 |
| 176 void AppListMainView::OnIconLoadingWaitTimer() { | 177 void AppListMainView::OnIconLoadingWaitTimer() { |
| 177 GetWidget()->Show(); | 178 GetWidget()->Show(); |
| 178 } | 179 } |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 // Resubmit the query via a posted task so that all observers for the | 240 // Resubmit the query via a posted task so that all observers for the |
| 240 // uninstall notification are notified. | 241 // uninstall notification are notified. |
| 241 base::MessageLoop::current()->PostTask( | 242 base::MessageLoop::current()->PostTask( |
| 242 FROM_HERE, | 243 FROM_HERE, |
| 243 base::Bind(&AppListMainView::QueryChanged, | 244 base::Bind(&AppListMainView::QueryChanged, |
| 244 weak_ptr_factory_.GetWeakPtr(), | 245 weak_ptr_factory_.GetWeakPtr(), |
| 245 search_box_view_)); | 246 search_box_view_)); |
| 246 } | 247 } |
| 247 | 248 |
| 248 } // namespace app_list | 249 } // namespace app_list |
| OLD | NEW |