OLD | NEW |
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 "grit/ui_resources.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 : search_results_view_(NULL), | 39 : search_results_view_(NULL), |
40 start_page_view_(NULL), | 40 start_page_view_(NULL), |
41 app_list_main_view_(app_list_main_view), | 41 app_list_main_view_(app_list_main_view), |
42 contents_switcher_view_(NULL), | 42 contents_switcher_view_(NULL), |
43 view_model_(new views::ViewModel) { | 43 view_model_(new views::ViewModel) { |
44 pagination_model_.AddObserver(this); | 44 pagination_model_.AddObserver(this); |
45 } | 45 } |
46 | 46 |
47 ContentsView::~ContentsView() { | 47 ContentsView::~ContentsView() { |
48 pagination_model_.RemoveObserver(this); | 48 pagination_model_.RemoveObserver(this); |
49 if (contents_switcher_view_) | |
50 pagination_model_.RemoveObserver(contents_switcher_view_); | |
51 } | 49 } |
52 | 50 |
53 void ContentsView::InitNamedPages(AppListModel* model, | 51 void ContentsView::InitNamedPages(AppListModel* model, |
54 AppListViewDelegate* view_delegate) { | 52 AppListViewDelegate* view_delegate) { |
55 DCHECK(model); | 53 DCHECK(model); |
56 | 54 |
57 if (app_list::switches::IsExperimentalAppListEnabled()) { | 55 if (app_list::switches::IsExperimentalAppListEnabled()) { |
58 views::View* custom_page_view = | 56 views::View* custom_page_view = |
59 view_delegate->CreateCustomPageWebView(GetLocalBounds().size()); | 57 view_delegate->CreateCustomPageWebView(GetLocalBounds().size()); |
60 if (custom_page_view) | 58 if (custom_page_view) |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( | 90 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( |
93 true); | 91 true); |
94 } | 92 } |
95 } | 93 } |
96 | 94 |
97 void ContentsView::SetDragAndDropHostOfCurrentAppList( | 95 void ContentsView::SetDragAndDropHostOfCurrentAppList( |
98 ApplicationDragAndDropHost* drag_and_drop_host) { | 96 ApplicationDragAndDropHost* drag_and_drop_host) { |
99 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 97 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
100 } | 98 } |
101 | 99 |
102 void ContentsView::SetContentsSwitcherView( | |
103 ContentsSwitcherView* contents_switcher_view) { | |
104 DCHECK(!contents_switcher_view_); | |
105 contents_switcher_view_ = contents_switcher_view; | |
106 if (contents_switcher_view_) | |
107 pagination_model_.AddObserver(contents_switcher_view_); | |
108 } | |
109 | |
110 void ContentsView::SetActivePage(int page_index) { | 100 void ContentsView::SetActivePage(int page_index) { |
111 if (GetActivePageIndex() == page_index) | 101 if (GetActivePageIndex() == page_index) |
112 return; | 102 return; |
113 | 103 |
114 SetActivePageInternal(page_index, false); | 104 SetActivePageInternal(page_index, false); |
115 } | 105 } |
116 | 106 |
117 int ContentsView::GetActivePageIndex() const { | 107 int ContentsView::GetActivePageIndex() const { |
118 // The active page is changed at the beginning of an animation, not the end. | 108 // The active page is changed at the beginning of an animation, not the end. |
119 return pagination_model_.SelectedTargetPage(); | 109 return pagination_model_.SelectedTargetPage(); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 } | 237 } |
248 | 238 |
249 void ContentsView::AddBlankPageForTesting() { | 239 void ContentsView::AddBlankPageForTesting() { |
250 AddLauncherPage(new views::View, 0); | 240 AddLauncherPage(new views::View, 0); |
251 } | 241 } |
252 | 242 |
253 int ContentsView::AddLauncherPage(views::View* view, int resource_id) { | 243 int ContentsView::AddLauncherPage(views::View* view, int resource_id) { |
254 int page_index = view_model_->view_size(); | 244 int page_index = view_model_->view_size(); |
255 AddChildView(view); | 245 AddChildView(view); |
256 view_model_->Add(view, page_index); | 246 view_model_->Add(view, page_index); |
| 247 pagination_model_.SetTotalPages(view_model_->view_size()); |
257 if (contents_switcher_view_) | 248 if (contents_switcher_view_) |
258 contents_switcher_view_->AddSwitcherButton(resource_id, page_index); | 249 contents_switcher_view_->AddSwitcherButton(resource_id, page_index); |
259 pagination_model_.SetTotalPages(view_model_->view_size()); | |
260 return page_index; | 250 return page_index; |
261 } | 251 } |
262 | 252 |
263 int ContentsView::AddLauncherPage(views::View* view, | 253 int ContentsView::AddLauncherPage(views::View* view, |
264 int resource_id, | 254 int resource_id, |
265 NamedPage named_page) { | 255 NamedPage named_page) { |
266 int page_index = AddLauncherPage(view, resource_id); | 256 int page_index = AddLauncherPage(view, resource_id); |
267 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); | 257 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); |
268 return page_index; | 258 return page_index; |
269 } | 259 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 if (std::abs(offset) > kMinScrollToSwitchPage) { | 378 if (std::abs(offset) > kMinScrollToSwitchPage) { |
389 if (!GetAppsPaginationModel()->has_transition()) { | 379 if (!GetAppsPaginationModel()->has_transition()) { |
390 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | 380 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
391 } | 381 } |
392 event->SetHandled(); | 382 event->SetHandled(); |
393 event->StopPropagation(); | 383 event->StopPropagation(); |
394 } | 384 } |
395 } | 385 } |
396 | 386 |
397 } // namespace app_list | 387 } // namespace app_list |
OLD | NEW |