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

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

Issue 302803002: Refactor app list so AppsGridView owns the PaginationModel. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Respond to review comments (tapted and xiyuan). 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
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 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 AppListMainView* owner_; 77 AppListMainView* owner_;
77 AppListItem* item_; 78 AppListItem* item_;
78 79
79 DISALLOW_COPY_AND_ASSIGN(IconLoader); 80 DISALLOW_COPY_AND_ASSIGN(IconLoader);
80 }; 81 };
81 82
82 //////////////////////////////////////////////////////////////////////////////// 83 ////////////////////////////////////////////////////////////////////////////////
83 // AppListMainView: 84 // AppListMainView:
84 85
85 AppListMainView::AppListMainView(AppListViewDelegate* delegate, 86 AppListMainView::AppListMainView(AppListViewDelegate* delegate,
86 PaginationModel* pagination_model,
87 gfx::NativeView parent) 87 gfx::NativeView parent)
88 : delegate_(delegate), 88 : delegate_(delegate),
89 pagination_model_(pagination_model),
90 model_(delegate->GetModel()), 89 model_(delegate->GetModel()),
91 search_box_view_(NULL), 90 search_box_view_(NULL),
92 contents_view_(NULL), 91 contents_view_(NULL),
93 weak_ptr_factory_(this) { 92 weak_ptr_factory_(this) {
94 // Starts icon loading early.
95 PreloadIcons(parent);
96
97 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 93 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical,
98 kInnerPadding, 94 kInnerPadding,
99 kInnerPadding, 95 kInnerPadding,
100 kInnerPadding)); 96 kInnerPadding));
101 97
102 search_box_view_ = new SearchBoxView(this, delegate); 98 search_box_view_ = new SearchBoxView(this, delegate);
103 AddChildView(search_box_view_); 99 AddChildView(search_box_view_);
104 AddContentsView(); 100 AddContentsView();
105 if (app_list::switches::IsExperimentalAppListEnabled()) 101 if (app_list::switches::IsExperimentalAppListEnabled())
106 AddChildView(new ContentsSwitcherView(contents_view_)); 102 AddChildView(new ContentsSwitcherView(contents_view_));
103
104 // Starts icon loading early.
105 PreloadIcons(parent);
107 } 106 }
108 107
109 void AppListMainView::AddContentsView() { 108 void AppListMainView::AddContentsView() {
110 contents_view_ = new ContentsView( 109 contents_view_ = new ContentsView(this, model_, delegate_);
111 this, pagination_model_, model_, delegate_);
112 AddChildViewAt(contents_view_, kContentsViewIndex); 110 AddChildViewAt(contents_view_, kContentsViewIndex);
113 111
114 search_box_view_->set_contents_view(contents_view_); 112 search_box_view_->set_contents_view(contents_view_);
115 113
116 #if defined(USE_AURA) 114 #if defined(USE_AURA)
117 contents_view_->SetPaintToLayer(true); 115 contents_view_->SetPaintToLayer(true);
118 contents_view_->SetFillsBoundsOpaquely(false); 116 contents_view_->SetFillsBoundsOpaquely(false);
119 contents_view_->layer()->SetMasksToBounds(true); 117 contents_view_->layer()->SetMasksToBounds(true);
120 #endif 118 #endif
121 } 119 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 void AppListMainView::Prerender() { 153 void AppListMainView::Prerender() {
156 contents_view_->Prerender(); 154 contents_view_->Prerender();
157 } 155 }
158 156
159 void AppListMainView::ModelChanged() { 157 void AppListMainView::ModelChanged() {
160 pending_icon_loaders_.clear(); 158 pending_icon_loaders_.clear();
161 model_ = delegate_->GetModel(); 159 model_ = delegate_->GetModel();
162 search_box_view_->ModelChanged(); 160 search_box_view_->ModelChanged();
163 delete contents_view_; 161 delete contents_view_;
164 contents_view_ = NULL; 162 contents_view_ = NULL;
165 pagination_model_->SelectPage(0, false /* animate */);
166 AddContentsView(); 163 AddContentsView();
167 Layout(); 164 Layout();
168 } 165 }
169 166
170 void AppListMainView::OnContentsViewShowStateChanged() { 167 void AppListMainView::OnContentsViewShowStateChanged() {
171 search_box_view_->SetVisible(contents_view_->show_state() != 168 search_box_view_->SetVisible(contents_view_->show_state() !=
172 ContentsView::SHOW_START_PAGE); 169 ContentsView::SHOW_START_PAGE);
173 } 170 }
174 171
175 void AppListMainView::OnStartPageSearchButtonPressed() { 172 void AppListMainView::OnStartPageSearchButtonPressed() {
176 search_box_view_->SetVisible(true); 173 search_box_view_->SetVisible(true);
177 search_box_view_->search_box()->SetText(base::string16()); 174 search_box_view_->search_box()->SetText(base::string16());
178 search_box_view_->RequestFocus(); 175 search_box_view_->RequestFocus();
179 } 176 }
180 177
181 void AppListMainView::SetDragAndDropHostOfCurrentAppList( 178 void AppListMainView::SetDragAndDropHostOfCurrentAppList(
182 ApplicationDragAndDropHost* drag_and_drop_host) { 179 ApplicationDragAndDropHost* drag_and_drop_host) {
183 contents_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 180 contents_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
184 } 181 }
185 182
186 bool AppListMainView::ShouldCenterWindow() const { 183 bool AppListMainView::ShouldCenterWindow() const {
187 return delegate_->ShouldCenterWindow(); 184 return delegate_->ShouldCenterWindow();
188 } 185 }
189 186
187 PaginationModel* AppListMainView::GetAppsPaginationModel() {
188 return contents_view_->apps_container_view()
189 ->apps_grid_view()
190 ->pagination_model();
191 }
192
190 void AppListMainView::PreloadIcons(gfx::NativeView parent) { 193 void AppListMainView::PreloadIcons(gfx::NativeView parent) {
191 float scale_factor = 1.0f; 194 float scale_factor = 1.0f;
192 if (parent) 195 if (parent)
193 scale_factor = ui::GetScaleFactorForNativeView(parent); 196 scale_factor = ui::GetScaleFactorForNativeView(parent);
194 197
195 // |pagination_model| could have -1 as the initial selected page and 198 // The PaginationModel could have -1 as the initial selected page and
196 // assumes first page (i.e. index 0) will be used in this case. 199 // 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()); 200 const int selected_page =
201 std::max(0, GetAppsPaginationModel()->selected_page());
198 202
199 const int tiles_per_page = kPreferredCols * kPreferredRows; 203 const int tiles_per_page = kPreferredCols * kPreferredRows;
200 const int start_model_index = selected_page * tiles_per_page; 204 const int start_model_index = selected_page * tiles_per_page;
201 const int end_model_index = 205 const int end_model_index =
202 std::min(static_cast<int>(model_->top_level_item_list()->item_count()), 206 std::min(static_cast<int>(model_->top_level_item_list()->item_count()),
203 start_model_index + tiles_per_page); 207 start_model_index + tiles_per_page);
204 208
205 pending_icon_loaders_.clear(); 209 pending_icon_loaders_.clear();
206 for (int i = start_model_index; i < end_model_index; ++i) { 210 for (int i = start_model_index; i < end_model_index; ++i) {
207 AppListItem* item = model_->top_level_item_list()->item_at(i); 211 AppListItem* item = model_->top_level_item_list()->item_at(i);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
271 // Resubmit the query via a posted task so that all observers for the 275 // Resubmit the query via a posted task so that all observers for the
272 // uninstall notification are notified. 276 // uninstall notification are notified.
273 base::MessageLoop::current()->PostTask( 277 base::MessageLoop::current()->PostTask(
274 FROM_HERE, 278 FROM_HERE,
275 base::Bind(&AppListMainView::QueryChanged, 279 base::Bind(&AppListMainView::QueryChanged,
276 weak_ptr_factory_.GetWeakPtr(), 280 weak_ptr_factory_.GetWeakPtr(),
277 search_box_view_)); 281 search_box_view_));
278 } 282 }
279 283
280 } // namespace app_list 284 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698