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 = |
168 AppListItemModel* item = model_->apps()->GetItemAt(i); | 168 model_->GetAppItemsForPage(selected_page); |
| 169 for (size_t i = 0; i < apps.item_count(); ++i) { |
| 170 AppListItemModel* item = model_->GetItemAt(selected_page, i); |
169 if (item->icon().HasRepresentation(scale)) | 171 if (item->icon().HasRepresentation(scale)) |
170 continue; | 172 continue; |
171 | 173 |
172 pending_icon_loaders_.push_back(new IconLoader(this, item, scale)); | 174 pending_icon_loaders_.push_back(new IconLoader(this, item, scale)); |
173 } | 175 } |
174 } | 176 } |
175 | 177 |
176 void AppListMainView::OnIconLoadingWaitTimer() { | 178 void AppListMainView::OnIconLoadingWaitTimer() { |
177 GetWidget()->Show(); | 179 GetWidget()->Show(); |
178 } | 180 } |
(...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 | 241 // Resubmit the query via a posted task so that all observers for the |
240 // uninstall notification are notified. | 242 // uninstall notification are notified. |
241 base::MessageLoop::current()->PostTask( | 243 base::MessageLoop::current()->PostTask( |
242 FROM_HERE, | 244 FROM_HERE, |
243 base::Bind(&AppListMainView::QueryChanged, | 245 base::Bind(&AppListMainView::QueryChanged, |
244 weak_ptr_factory_.GetWeakPtr(), | 246 weak_ptr_factory_.GetWeakPtr(), |
245 search_box_view_)); | 247 search_box_view_)); |
246 } | 248 } |
247 | 249 |
248 } // namespace app_list | 250 } // namespace app_list |
OLD | NEW |