Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: ui/app_list/views/app_list_main_view.cc

Issue 311753002: App Launcher: Preload the correct number of icons (don't assume 4x4). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ui/app_list/views/apps_grid_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
11 #include "base/files/file_path.h" 11 #include "base/files/file_path.h"
12 #include "base/message_loop/message_loop.h" 12 #include "base/message_loop/message_loop.h"
13 #include "base/strings/string_util.h" 13 #include "base/strings/string_util.h"
14 #include "ui/app_list/app_list_constants.h" 14 #include "ui/app_list/app_list_constants.h"
15 #include "ui/app_list/app_list_folder_item.h" 15 #include "ui/app_list/app_list_folder_item.h"
16 #include "ui/app_list/app_list_item.h" 16 #include "ui/app_list/app_list_item.h"
17 #include "ui/app_list/app_list_model.h" 17 #include "ui/app_list/app_list_model.h"
18 #include "ui/app_list/app_list_switches.h" 18 #include "ui/app_list/app_list_switches.h"
19 #include "ui/app_list/app_list_view_delegate.h" 19 #include "ui/app_list/app_list_view_delegate.h"
20 #include "ui/app_list/pagination_model.h" 20 #include "ui/app_list/pagination_model.h"
21 #include "ui/app_list/search_box_model.h" 21 #include "ui/app_list/search_box_model.h"
22 #include "ui/app_list/views/app_list_item_view.h" 22 #include "ui/app_list/views/app_list_item_view.h"
23 #include "ui/app_list/views/apps_container_view.h" 23 #include "ui/app_list/views/apps_container_view.h"
24 #include "ui/app_list/views/apps_grid_view.h"
24 #include "ui/app_list/views/contents_switcher_view.h" 25 #include "ui/app_list/views/contents_switcher_view.h"
25 #include "ui/app_list/views/contents_view.h" 26 #include "ui/app_list/views/contents_view.h"
26 #include "ui/app_list/views/search_box_view.h" 27 #include "ui/app_list/views/search_box_view.h"
27 #include "ui/views/controls/textfield/textfield.h" 28 #include "ui/views/controls/textfield/textfield.h"
28 #include "ui/views/layout/box_layout.h" 29 #include "ui/views/layout/box_layout.h"
29 #include "ui/views/widget/widget.h" 30 #include "ui/views/widget/widget.h"
30 31
31 namespace app_list { 32 namespace app_list {
32 33
33 namespace { 34 namespace {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 85
85 AppListMainView::AppListMainView(AppListViewDelegate* delegate, 86 AppListMainView::AppListMainView(AppListViewDelegate* delegate,
86 PaginationModel* pagination_model, 87 PaginationModel* pagination_model,
87 gfx::NativeView parent) 88 gfx::NativeView parent)
88 : delegate_(delegate), 89 : delegate_(delegate),
89 pagination_model_(pagination_model), 90 pagination_model_(pagination_model),
90 model_(delegate->GetModel()), 91 model_(delegate->GetModel()),
91 search_box_view_(NULL), 92 search_box_view_(NULL),
92 contents_view_(NULL), 93 contents_view_(NULL),
93 weak_ptr_factory_(this) { 94 weak_ptr_factory_(this) {
94 // Starts icon loading early.
95 PreloadIcons(parent);
96
97 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 95 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
98 kInnerPadding, 96 kInnerPadding,
99 kInnerPadding, 97 kInnerPadding,
100 kInnerPadding)); 98 kInnerPadding));
101 99
102 search_box_view_ = new SearchBoxView(this, delegate); 100 search_box_view_ = new SearchBoxView(this, delegate);
103 AddChildView(search_box_view_); 101 AddChildView(search_box_view_);
104 AddContentsView(); 102 AddContentsView();
105 if (app_list::switches::IsExperimentalAppListEnabled()) 103 if (app_list::switches::IsExperimentalAppListEnabled())
106 AddChildView(new ContentsSwitcherView(contents_view_)); 104 AddChildView(new ContentsSwitcherView(contents_view_));
105
106 // Starts icon loading early.
107 PreloadIcons(parent);
107 } 108 }
108 109
109 void AppListMainView::AddContentsView() { 110 void AppListMainView::AddContentsView() {
110 contents_view_ = new ContentsView( 111 contents_view_ = new ContentsView(
111 this, pagination_model_, model_, delegate_); 112 this, pagination_model_, model_, delegate_);
112 AddChildViewAt(contents_view_, kContentsViewIndex); 113 AddChildViewAt(contents_view_, kContentsViewIndex);
113 114
114 search_box_view_->set_contents_view(contents_view_); 115 search_box_view_->set_contents_view(contents_view_);
115 116
116 #if defined(USE_AURA) 117 #if defined(USE_AURA)
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 190
190 void AppListMainView::PreloadIcons(gfx::NativeView parent) { 191 void AppListMainView::PreloadIcons(gfx::NativeView parent) {
191 float scale_factor = 1.0f; 192 float scale_factor = 1.0f;
192 if (parent) 193 if (parent)
193 scale_factor = ui::GetScaleFactorForNativeView(parent); 194 scale_factor = ui::GetScaleFactorForNativeView(parent);
194 195
195 // |pagination_model| could have -1 as the initial selected page and 196 // |pagination_model| could have -1 as the initial selected page and
196 // assumes first page (i.e. index 0) will be used in this case. 197 // assumes first page (i.e. index 0) will be used in this case.
197 const int selected_page = std::max(0, pagination_model_->selected_page()); 198 const int selected_page = std::max(0, pagination_model_->selected_page());
198 199
199 const int tiles_per_page = kPreferredCols * kPreferredRows; 200 const AppsGridView* const apps_grid_view =
201 contents_view_->apps_container_view()->apps_grid_view();
202 const int tiles_per_page =
203 apps_grid_view->cols() * apps_grid_view->rows_per_page();
204
200 const int start_model_index = selected_page * tiles_per_page; 205 const int start_model_index = selected_page * tiles_per_page;
201 const int end_model_index = 206 const int end_model_index =
202 std::min(static_cast<int>(model_->top_level_item_list()->item_count()), 207 std::min(static_cast<int>(model_->top_level_item_list()->item_count()),
203 start_model_index + tiles_per_page); 208 start_model_index + tiles_per_page);
204 209
205 pending_icon_loaders_.clear(); 210 pending_icon_loaders_.clear();
206 for (int i = start_model_index; i < end_model_index; ++i) { 211 for (int i = start_model_index; i < end_model_index; ++i) {
207 AppListItem* item = model_->top_level_item_list()->item_at(i); 212 AppListItem* item = model_->top_level_item_list()->item_at(i);
208 if (item->icon().HasRepresentation(scale_factor)) 213 if (item->icon().HasRepresentation(scale_factor))
209 continue; 214 continue;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // Resubmit the query via a posted task so that all observers for the 276 // Resubmit the query via a posted task so that all observers for the
272 // uninstall notification are notified. 277 // uninstall notification are notified.
273 base::MessageLoop::current()->PostTask( 278 base::MessageLoop::current()->PostTask(
274 FROM_HERE, 279 FROM_HERE,
275 base::Bind(&AppListMainView::QueryChanged, 280 base::Bind(&AppListMainView::QueryChanged,
276 weak_ptr_factory_.GetWeakPtr(), 281 weak_ptr_factory_.GetWeakPtr(),
277 search_box_view_)); 282 search_box_view_));
278 } 283 }
279 284
280 } // namespace app_list 285 } // namespace app_list
OLDNEW
« no previous file with comments | « no previous file | ui/app_list/views/apps_grid_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698