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

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

Issue 336313010: App List: Refactor ContentsSwitcherView so it doesn't hard-code pages. (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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/contents_view.h" 5 #include "ui/app_list/views/contents_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "grit/ui_resources.h"
10 #include "ui/app_list/app_list_constants.h" 11 #include "ui/app_list/app_list_constants.h"
11 #include "ui/app_list/app_list_switches.h" 12 #include "ui/app_list/app_list_switches.h"
12 #include "ui/app_list/app_list_view_delegate.h" 13 #include "ui/app_list/app_list_view_delegate.h"
13 #include "ui/app_list/views/app_list_folder_view.h" 14 #include "ui/app_list/views/app_list_folder_view.h"
14 #include "ui/app_list/views/app_list_main_view.h" 15 #include "ui/app_list/views/app_list_main_view.h"
15 #include "ui/app_list/views/apps_container_view.h" 16 #include "ui/app_list/views/apps_container_view.h"
16 #include "ui/app_list/views/apps_grid_view.h" 17 #include "ui/app_list/views/apps_grid_view.h"
18 #include "ui/app_list/views/contents_switcher_view.h"
17 #include "ui/app_list/views/search_result_list_view.h" 19 #include "ui/app_list/views/search_result_list_view.h"
18 #include "ui/app_list/views/start_page_view.h" 20 #include "ui/app_list/views/start_page_view.h"
21 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/events/event.h" 22 #include "ui/events/event.h"
20 #include "ui/views/view_model.h" 23 #include "ui/views/view_model.h"
21 #include "ui/views/view_model_utils.h" 24 #include "ui/views/view_model_utils.h"
22 25
23 namespace app_list { 26 namespace app_list {
24 27
25 namespace { 28 namespace {
26 29
27 const int kMinMouseWheelToSwitchPage = 20; 30 const int kMinMouseWheelToSwitchPage = 20;
28 const int kMinScrollToSwitchPage = 20; 31 const int kMinScrollToSwitchPage = 20;
29 const int kMinHorizVelocityToSwitchPage = 800; 32 const int kMinHorizVelocityToSwitchPage = 800;
30 33
31 const double kFinishTransitionThreshold = 0.33; 34 const double kFinishTransitionThreshold = 0.33;
32 35
33 } // namespace 36 } // namespace
34 37
35 ContentsView::ContentsView(AppListMainView* app_list_main_view, 38 ContentsView::ContentsView(AppListMainView* app_list_main_view,
39 ContentsSwitcherView* contents_switcher_view,
36 AppListModel* model, 40 AppListModel* model,
37 AppListViewDelegate* view_delegate) 41 AppListViewDelegate* view_delegate)
38 : search_results_view_(NULL), 42 : search_results_view_(NULL),
39 start_page_view_(NULL), 43 start_page_view_(NULL),
40 app_list_main_view_(app_list_main_view), 44 app_list_main_view_(app_list_main_view),
45 contents_switcher_view_(contents_switcher_view),
41 view_model_(new views::ViewModel) { 46 view_model_(new views::ViewModel) {
42 DCHECK(model); 47 DCHECK(model);
43 48
44 if (app_list::switches::IsExperimentalAppListEnabled()) { 49 if (app_list::switches::IsExperimentalAppListEnabled()) {
45 start_page_view_ = new StartPageView(app_list_main_view, view_delegate); 50 start_page_view_ = new StartPageView(app_list_main_view, view_delegate);
46 AddLauncherPage(start_page_view_, NAMED_PAGE_START); 51 AddLauncherPage(
52 start_page_view_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START);
47 } else { 53 } else {
48 search_results_view_ = 54 search_results_view_ =
49 new SearchResultListView(app_list_main_view, view_delegate); 55 new SearchResultListView(app_list_main_view, view_delegate);
50 AddLauncherPage(search_results_view_, NAMED_PAGE_SEARCH_RESULTS); 56 AddLauncherPage(search_results_view_, 0, NAMED_PAGE_SEARCH_RESULTS);
51 search_results_view_->SetResults(model->results()); 57 search_results_view_->SetResults(model->results());
52 } 58 }
53 59
54 apps_container_view_ = new AppsContainerView(app_list_main_view, model); 60 apps_container_view_ = new AppsContainerView(app_list_main_view, model);
55 int apps_page_index = AddLauncherPage(apps_container_view_, NAMED_PAGE_APPS); 61 int apps_page_index = AddLauncherPage(
62 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS);
56 63
57 pagination_model_.SelectPage(apps_page_index, false); 64 pagination_model_.SelectPage(apps_page_index, false);
58 pagination_model_.AddObserver(this); 65 pagination_model_.AddObserver(this);
59 } 66 }
60 67
61 ContentsView::~ContentsView() { 68 ContentsView::~ContentsView() {
62 pagination_model_.RemoveObserver(this); 69 pagination_model_.RemoveObserver(this);
63 } 70 }
64 71
65 void ContentsView::CancelDrag() { 72 void ContentsView::CancelDrag() {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 const int selected_page = 217 const int selected_page =
211 std::max(0, GetAppsPaginationModel()->selected_page()); 218 std::max(0, GetAppsPaginationModel()->selected_page());
212 apps_container_view_->apps_grid_view()->Prerender(selected_page); 219 apps_container_view_->apps_grid_view()->Prerender(selected_page);
213 } 220 }
214 221
215 views::View* ContentsView::GetPageView(int index) { 222 views::View* ContentsView::GetPageView(int index) {
216 return view_model_->view_at(index); 223 return view_model_->view_at(index);
217 } 224 }
218 225
219 void ContentsView::AddBlankPageForTesting() { 226 void ContentsView::AddBlankPageForTesting() {
220 AddLauncherPage(new views::View); 227 AddLauncherPage(new views::View, 0);
221 } 228 }
222 229
223 int ContentsView::AddLauncherPage(views::View* view) { 230 int ContentsView::AddLauncherPage(views::View* view, int resource_id) {
224 int page_index = view_model_->view_size(); 231 int page_index = view_model_->view_size();
225 AddChildView(view); 232 AddChildView(view);
226 view_model_->Add(view, page_index); 233 view_model_->Add(view, page_index);
227 pagination_model_.SetTotalPages(view_model_->view_size()); 234 pagination_model_.SetTotalPages(view_model_->view_size());
235 if (contents_switcher_view_)
236 contents_switcher_view_->AddSwitcherButton(resource_id, page_index);
228 return page_index; 237 return page_index;
229 } 238 }
230 239
231 int ContentsView::AddLauncherPage(views::View* view, NamedPage named_page) { 240 int ContentsView::AddLauncherPage(views::View* view,
232 int page_index = AddLauncherPage(view); 241 int resource_id,
242 NamedPage named_page) {
243 int page_index = AddLauncherPage(view, resource_id);
233 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); 244 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index));
234 return page_index; 245 return page_index;
235 } 246 }
236 247
237 gfx::Size ContentsView::GetPreferredSize() const { 248 gfx::Size ContentsView::GetPreferredSize() const {
238 const gfx::Size container_size = 249 const gfx::Size container_size =
239 apps_container_view_->apps_grid_view()->GetPreferredSize(); 250 apps_container_view_->apps_grid_view()->GetPreferredSize();
240 const gfx::Size results_size = search_results_view_ 251 const gfx::Size results_size = search_results_view_
241 ? search_results_view_->GetPreferredSize() 252 ? search_results_view_->GetPreferredSize()
242 : gfx::Size(); 253 : gfx::Size();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 if (std::abs(offset) > kMinScrollToSwitchPage) { 365 if (std::abs(offset) > kMinScrollToSwitchPage) {
355 if (!GetAppsPaginationModel()->has_transition()) { 366 if (!GetAppsPaginationModel()->has_transition()) {
356 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); 367 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true);
357 } 368 }
358 event->SetHandled(); 369 event->SetHandled();
359 event->StopPropagation(); 370 event->StopPropagation();
360 } 371 }
361 } 372 }
362 373
363 } // namespace app_list 374 } // namespace app_list
OLDNEW
« ui/app_list/views/contents_switcher_view.cc ('K') | « ui/app_list/views/contents_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698