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

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: Rebase. 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 | « ui/app_list/views/contents_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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)
36 AppListModel* model,
37 AppListViewDelegate* view_delegate)
38 : search_results_view_(NULL), 39 : search_results_view_(NULL),
39 start_page_view_(NULL), 40 start_page_view_(NULL),
40 app_list_main_view_(app_list_main_view), 41 app_list_main_view_(app_list_main_view),
42 contents_switcher_view_(NULL),
41 view_model_(new views::ViewModel) { 43 view_model_(new views::ViewModel) {
42 DCHECK(model);
43
44 if (app_list::switches::IsExperimentalAppListEnabled()) {
45 start_page_view_ = new StartPageView(app_list_main_view, view_delegate);
46 AddLauncherPage(start_page_view_, NAMED_PAGE_START);
47 } else {
48 search_results_view_ =
49 new SearchResultListView(app_list_main_view, view_delegate);
50 AddLauncherPage(search_results_view_, NAMED_PAGE_SEARCH_RESULTS);
51 search_results_view_->SetResults(model->results());
52 }
53
54 apps_container_view_ = new AppsContainerView(app_list_main_view, model);
55 int apps_page_index = AddLauncherPage(apps_container_view_, NAMED_PAGE_APPS);
56
57 pagination_model_.SelectPage(apps_page_index, false);
58 pagination_model_.AddObserver(this); 44 pagination_model_.AddObserver(this);
59 } 45 }
60 46
61 ContentsView::~ContentsView() { 47 ContentsView::~ContentsView() {
62 pagination_model_.RemoveObserver(this); 48 pagination_model_.RemoveObserver(this);
63 } 49 }
64 50
51 void ContentsView::InitNamedPages(AppListModel* model,
52 AppListViewDelegate* view_delegate) {
53 DCHECK(model);
54
55 if (app_list::switches::IsExperimentalAppListEnabled()) {
56 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate);
57 AddLauncherPage(
58 start_page_view_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START);
59 } else {
60 search_results_view_ =
61 new SearchResultListView(app_list_main_view_, view_delegate);
62 AddLauncherPage(search_results_view_, 0, NAMED_PAGE_SEARCH_RESULTS);
63 search_results_view_->SetResults(model->results());
64 }
65
66 apps_container_view_ = new AppsContainerView(app_list_main_view_, model);
67 int apps_page_index = AddLauncherPage(
68 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS);
69
70 pagination_model_.SelectPage(apps_page_index, false);
71 }
72
65 void ContentsView::CancelDrag() { 73 void ContentsView::CancelDrag() {
66 if (apps_container_view_->apps_grid_view()->has_dragged_view()) 74 if (apps_container_view_->apps_grid_view()->has_dragged_view())
67 apps_container_view_->apps_grid_view()->EndDrag(true); 75 apps_container_view_->apps_grid_view()->EndDrag(true);
68 if (apps_container_view_->app_list_folder_view() 76 if (apps_container_view_->app_list_folder_view()
69 ->items_grid_view() 77 ->items_grid_view()
70 ->has_dragged_view()) { 78 ->has_dragged_view()) {
71 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( 79 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag(
72 true); 80 true);
73 } 81 }
74 } 82 }
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 const int selected_page = 219 const int selected_page =
212 std::max(0, GetAppsPaginationModel()->selected_page()); 220 std::max(0, GetAppsPaginationModel()->selected_page());
213 apps_container_view_->apps_grid_view()->Prerender(selected_page); 221 apps_container_view_->apps_grid_view()->Prerender(selected_page);
214 } 222 }
215 223
216 views::View* ContentsView::GetPageView(int index) { 224 views::View* ContentsView::GetPageView(int index) {
217 return view_model_->view_at(index); 225 return view_model_->view_at(index);
218 } 226 }
219 227
220 void ContentsView::AddBlankPageForTesting() { 228 void ContentsView::AddBlankPageForTesting() {
221 AddLauncherPage(new views::View); 229 AddLauncherPage(new views::View, 0);
222 } 230 }
223 231
224 int ContentsView::AddLauncherPage(views::View* view) { 232 int ContentsView::AddLauncherPage(views::View* view, int resource_id) {
225 int page_index = view_model_->view_size(); 233 int page_index = view_model_->view_size();
226 AddChildView(view); 234 AddChildView(view);
227 view_model_->Add(view, page_index); 235 view_model_->Add(view, page_index);
228 pagination_model_.SetTotalPages(view_model_->view_size()); 236 pagination_model_.SetTotalPages(view_model_->view_size());
237 if (contents_switcher_view_)
238 contents_switcher_view_->AddSwitcherButton(resource_id, page_index);
229 return page_index; 239 return page_index;
230 } 240 }
231 241
232 int ContentsView::AddLauncherPage(views::View* view, NamedPage named_page) { 242 int ContentsView::AddLauncherPage(views::View* view,
233 int page_index = AddLauncherPage(view); 243 int resource_id,
244 NamedPage named_page) {
245 int page_index = AddLauncherPage(view, resource_id);
234 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); 246 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index));
235 return page_index; 247 return page_index;
236 } 248 }
237 249
238 gfx::Size ContentsView::GetPreferredSize() const { 250 gfx::Size ContentsView::GetPreferredSize() const {
239 const gfx::Size container_size = 251 const gfx::Size container_size =
240 apps_container_view_->apps_grid_view()->GetPreferredSize(); 252 apps_container_view_->apps_grid_view()->GetPreferredSize();
241 const gfx::Size results_size = search_results_view_ 253 const gfx::Size results_size = search_results_view_
242 ? search_results_view_->GetPreferredSize() 254 ? search_results_view_->GetPreferredSize()
243 : gfx::Size(); 255 : gfx::Size();
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 if (std::abs(offset) > kMinScrollToSwitchPage) { 367 if (std::abs(offset) > kMinScrollToSwitchPage) {
356 if (!GetAppsPaginationModel()->has_transition()) { 368 if (!GetAppsPaginationModel()->has_transition()) {
357 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); 369 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true);
358 } 370 }
359 event->SetHandled(); 371 event->SetHandled();
360 event->StopPropagation(); 372 event->StopPropagation();
361 } 373 }
362 } 374 }
363 375
364 } // namespace app_list 376 } // namespace app_list
OLDNEW
« no previous file with comments | « 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