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

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

Issue 947903002: Change ContentsView::SetActivePage to use States rather than indexes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more_rebase Created 5 years, 9 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
« no previous file with comments | « ui/app_list/views/contents_view.h ('k') | ui/app_list/views/start_page_view.cc » ('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 (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 #include <vector> 8 #include <vector>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( 124 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag(
125 true); 125 true);
126 } 126 }
127 } 127 }
128 128
129 void ContentsView::SetDragAndDropHostOfCurrentAppList( 129 void ContentsView::SetDragAndDropHostOfCurrentAppList(
130 ApplicationDragAndDropHost* drag_and_drop_host) { 130 ApplicationDragAndDropHost* drag_and_drop_host) {
131 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); 131 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host);
132 } 132 }
133 133
134 void ContentsView::SetActivePage(int page_index) { 134 void ContentsView::SetActiveState(AppListModel::State state) {
135 SetActivePage(page_index, true); 135 SetActiveState(state, true);
136 } 136 }
137 137
138 void ContentsView::SetActivePage(int page_index, bool animate) { 138 void ContentsView::SetActiveState(AppListModel::State state, bool animate) {
139 if (GetActivePageIndex() == page_index) 139 if (IsStateActive(state))
140 return; 140 return;
141 141
142 SetActivePageInternal(page_index, false, animate); 142 SetActiveStateInternal(GetPageIndexForState(state), false, animate);
143 } 143 }
144 144
145 int ContentsView::GetActivePageIndex() const { 145 int ContentsView::GetActivePageIndex() const {
146 // The active page is changed at the beginning of an animation, not the end. 146 // The active page is changed at the beginning of an animation, not the end.
147 return pagination_model_.SelectedTargetPage(); 147 return pagination_model_.SelectedTargetPage();
148 } 148 }
149 149
150 AppListModel::State ContentsView::GetActiveState() const { 150 AppListModel::State ContentsView::GetActiveState() const {
151 return GetStateForPageIndex(GetActivePageIndex()); 151 return GetStateForPageIndex(GetActivePageIndex());
152 } 152 }
(...skipping 20 matching lines...) Expand all
173 if (it == view_to_state_.end()) 173 if (it == view_to_state_.end())
174 return AppListModel::INVALID_STATE; 174 return AppListModel::INVALID_STATE;
175 175
176 return it->second; 176 return it->second;
177 } 177 }
178 178
179 int ContentsView::NumLauncherPages() const { 179 int ContentsView::NumLauncherPages() const {
180 return pagination_model_.total_pages(); 180 return pagination_model_.total_pages();
181 } 181 }
182 182
183 void ContentsView::SetActivePageInternal(int page_index, 183 void ContentsView::SetActiveStateInternal(int page_index,
184 bool show_search_results, 184 bool show_search_results,
185 bool animate) { 185 bool animate) {
186 if (!GetPageView(page_index)->visible()) 186 if (!GetPageView(page_index)->visible())
187 return; 187 return;
188 188
189 if (!show_search_results) 189 if (!show_search_results)
190 page_before_search_ = page_index; 190 page_before_search_ = page_index;
191 // Start animating to the new page. 191 // Start animating to the new page.
192 pagination_model_.SelectPage(page_index, animate); 192 pagination_model_.SelectPage(page_index, animate);
193 ActivePageChanged(); 193 ActivePageChanged();
194 194
195 if (!animate) 195 if (!animate)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 if (custom_page_view_) { 230 if (custom_page_view_) {
231 custom_page_view_->SetFocusable(state == 231 custom_page_view_->SetFocusable(state ==
232 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); 232 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE);
233 } 233 }
234 } 234 }
235 235
236 void ContentsView::ShowSearchResults(bool show) { 236 void ContentsView::ShowSearchResults(bool show) {
237 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS); 237 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS);
238 DCHECK_GE(search_page, 0); 238 DCHECK_GE(search_page, 0);
239 239
240 SetActivePageInternal(show ? search_page : page_before_search_, show, true); 240 SetActiveStateInternal(show ? search_page : page_before_search_, show, true);
241 } 241 }
242 242
243 bool ContentsView::IsShowingSearchResults() const { 243 bool ContentsView::IsShowingSearchResults() const {
244 return IsStateActive(AppListModel::STATE_SEARCH_RESULTS); 244 return IsStateActive(AppListModel::STATE_SEARCH_RESULTS);
245 } 245 }
246 246
247 void ContentsView::NotifyCustomLauncherPageAnimationChanged(double progress, 247 void ContentsView::NotifyCustomLauncherPageAnimationChanged(double progress,
248 int current_page, 248 int current_page,
249 int target_page) { 249 int target_page) {
250 int custom_launcher_page_index = 250 int custom_launcher_page_index =
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 } 328 }
329 329
330 views::View* ContentsView::GetPageView(int index) const { 330 views::View* ContentsView::GetPageView(int index) const {
331 return view_model_->view_at(index); 331 return view_model_->view_at(index);
332 } 332 }
333 333
334 SearchBoxView* ContentsView::GetSearchBoxView() const { 334 SearchBoxView* ContentsView::GetSearchBoxView() const {
335 return app_list_main_view_->search_box_view(); 335 return app_list_main_view_->search_box_view();
336 } 336 }
337 337
338 void ContentsView::AddBlankPageForTesting() {
339 AddLauncherPage(new views::View);
340 pagination_model_.SetTotalPages(view_model_->view_size());
341 }
342
343 int ContentsView::AddLauncherPage(views::View* view) { 338 int ContentsView::AddLauncherPage(views::View* view) {
344 int page_index = view_model_->view_size(); 339 int page_index = view_model_->view_size();
345 AddChildView(view); 340 AddChildView(view);
346 view_model_->Add(view, page_index); 341 view_model_->Add(view, page_index);
347 return page_index; 342 return page_index;
348 } 343 }
349 344
350 int ContentsView::AddLauncherPage(views::View* view, 345 int ContentsView::AddLauncherPage(views::View* view,
351 AppListModel::State state) { 346 AppListModel::State state) {
352 int page_index = AddLauncherPage(view); 347 int page_index = AddLauncherPage(view);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 bool ContentsView::Back() { 420 bool ContentsView::Back() {
426 AppListModel::State state = view_to_state_[GetActivePageIndex()]; 421 AppListModel::State state = view_to_state_[GetActivePageIndex()];
427 switch (state) { 422 switch (state) {
428 case AppListModel::STATE_START: 423 case AppListModel::STATE_START:
429 // Close the app list when Back() is called from the start page. 424 // Close the app list when Back() is called from the start page.
430 return false; 425 return false;
431 case AppListModel::STATE_CUSTOM_LAUNCHER_PAGE: 426 case AppListModel::STATE_CUSTOM_LAUNCHER_PAGE:
432 if (app_list_main_view_->model()->PopCustomLauncherPageSubpage()) 427 if (app_list_main_view_->model()->PopCustomLauncherPageSubpage())
433 app_list_main_view_->view_delegate()->CustomLauncherPagePopSubpage(); 428 app_list_main_view_->view_delegate()->CustomLauncherPagePopSubpage();
434 else 429 else
435 SetActivePage(GetPageIndexForState(AppListModel::STATE_START)); 430 SetActiveState(AppListModel::STATE_START);
436 break; 431 break;
437 case AppListModel::STATE_APPS: 432 case AppListModel::STATE_APPS:
438 if (apps_container_view_->IsInFolderView()) 433 if (apps_container_view_->IsInFolderView())
439 apps_container_view_->app_list_folder_view()->CloseFolderPage(); 434 apps_container_view_->app_list_folder_view()->CloseFolderPage();
440 else 435 else
441 SetActivePage(GetPageIndexForState(AppListModel::STATE_START)); 436 SetActiveState(AppListModel::STATE_START);
442 break; 437 break;
443 case AppListModel::STATE_SEARCH_RESULTS: 438 case AppListModel::STATE_SEARCH_RESULTS:
444 GetSearchBoxView()->ClearSearch(); 439 GetSearchBoxView()->ClearSearch();
445 ShowSearchResults(false); 440 ShowSearchResults(false);
446 break; 441 break;
447 case AppListModel::INVALID_STATE: // Falls through. 442 case AppListModel::INVALID_STATE: // Falls through.
448 NOTREACHED(); 443 NOTREACHED();
449 break; 444 break;
450 } 445 }
451 return true; 446 return true;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } 542 }
548 543
549 void ContentsView::TransitionStarted() { 544 void ContentsView::TransitionStarted() {
550 } 545 }
551 546
552 void ContentsView::TransitionChanged() { 547 void ContentsView::TransitionChanged() {
553 UpdatePageBounds(); 548 UpdatePageBounds();
554 } 549 }
555 550
556 } // namespace app_list 551 } // namespace app_list
OLDNEW
« no previous file with comments | « ui/app_list/views/contents_view.h ('k') | ui/app_list/views/start_page_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698