Chromium Code Reviews| 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_); | |
| 49 } | 51 } |
| 50 | 52 |
| 51 void ContentsView::InitNamedPages(AppListModel* model, | 53 void ContentsView::InitNamedPages(AppListModel* model, |
| 52 AppListViewDelegate* view_delegate) { | 54 AppListViewDelegate* view_delegate) { |
| 53 DCHECK(model); | 55 DCHECK(model); |
| 54 | 56 |
| 55 if (app_list::switches::IsExperimentalAppListEnabled()) { | 57 if (app_list::switches::IsExperimentalAppListEnabled()) { |
| 56 views::View* custom_page_view = | 58 views::View* custom_page_view = |
| 57 view_delegate->CreateCustomPageWebView(GetLocalBounds().size()); | 59 view_delegate->CreateCustomPageWebView(GetLocalBounds().size()); |
| 58 if (custom_page_view) | 60 if (custom_page_view) |
| 59 AddLauncherPage(custom_page_view, IDR_APP_LIST_NOTIFICATIONS_ICON); | 61 AddLauncherPage(custom_page_view, IDR_APP_LIST_NOTIFICATIONS_ICON); |
| 60 | 62 |
| 61 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); | 63 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); |
| 62 AddLauncherPage( | 64 AddLauncherPage( |
| 63 start_page_view_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START); | 65 start_page_view_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START); |
| 64 } else { | 66 } else { |
| 65 search_results_view_ = | 67 search_results_view_ = |
| 66 new SearchResultListView(app_list_main_view_, view_delegate); | 68 new SearchResultListView(app_list_main_view_, view_delegate); |
| 67 AddLauncherPage(search_results_view_, 0, NAMED_PAGE_SEARCH_RESULTS); | 69 AddLauncherPage(search_results_view_, 0, NAMED_PAGE_SEARCH_RESULTS); |
| 68 search_results_view_->SetResults(model->results()); | 70 search_results_view_->SetResults(model->results()); |
| 69 } | 71 } |
| 70 | 72 |
| 71 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); | 73 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); |
| 72 | 74 |
| 73 int initial_page_index = AddLauncherPage( | 75 int initial_page_index = AddLauncherPage( |
| 74 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); | 76 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); |
| 75 if (app_list::switches::IsExperimentalAppListEnabled()) | 77 if (app_list::switches::IsExperimentalAppListEnabled()) |
| 76 initial_page_index = GetPageIndexForNamedPage(NAMED_PAGE_START); | 78 initial_page_index = GetPageIndexForNamedPage(NAMED_PAGE_START); |
| 77 | 79 |
| 80 pagination_model_.SetTransitionDurations(1500, 1500); | |
| 78 pagination_model_.SelectPage(initial_page_index, false); | 81 pagination_model_.SelectPage(initial_page_index, false); |
| 79 | 82 |
| 80 // Needed to update the main search box visibility. | 83 // Needed to update the main search box visibility. |
| 81 ActivePageChanged(false); | 84 ActivePageChanged(false); |
| 82 } | 85 } |
| 83 | 86 |
| 84 void ContentsView::CancelDrag() { | 87 void ContentsView::CancelDrag() { |
| 85 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 88 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
| 86 apps_container_view_->apps_grid_view()->EndDrag(true); | 89 apps_container_view_->apps_grid_view()->EndDrag(true); |
| 87 if (apps_container_view_->app_list_folder_view() | 90 if (apps_container_view_->app_list_folder_view() |
| 88 ->items_grid_view() | 91 ->items_grid_view() |
| 89 ->has_dragged_view()) { | 92 ->has_dragged_view()) { |
| 90 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( | 93 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( |
| 91 true); | 94 true); |
| 92 } | 95 } |
| 93 } | 96 } |
| 94 | 97 |
| 95 void ContentsView::SetDragAndDropHostOfCurrentAppList( | 98 void ContentsView::SetDragAndDropHostOfCurrentAppList( |
| 96 ApplicationDragAndDropHost* drag_and_drop_host) { | 99 ApplicationDragAndDropHost* drag_and_drop_host) { |
| 97 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); | 100 apps_container_view_->SetDragAndDropHostOfCurrentAppList(drag_and_drop_host); |
| 98 } | 101 } |
| 99 | 102 |
| 103 void ContentsView::set_contents_switcher_view( | |
| 104 ContentsSwitcherView* contents_switcher_view) { | |
| 105 contents_switcher_view_ = contents_switcher_view; | |
|
calamity
2014/07/10 03:59:36
Better DCHECK(!contents_switcher_view_) here now s
| |
| 106 if (contents_switcher_view_) | |
| 107 pagination_model_.AddObserver(contents_switcher_view_); | |
| 108 } | |
| 109 | |
| 100 void ContentsView::SetActivePage(int page_index) { | 110 void ContentsView::SetActivePage(int page_index) { |
| 101 if (GetActivePageIndex() == page_index) | 111 if (GetActivePageIndex() == page_index) |
| 102 return; | 112 return; |
| 103 | 113 |
| 104 SetActivePageInternal(page_index, false); | 114 SetActivePageInternal(page_index, false); |
| 105 } | 115 } |
| 106 | 116 |
| 107 int ContentsView::GetActivePageIndex() const { | 117 int ContentsView::GetActivePageIndex() const { |
| 108 // The active page is changed at the beginning of an animation, not the end. | 118 // The active page is changed at the beginning of an animation, not the end. |
| 109 return pagination_model_.SelectedTargetPage(); | 119 return pagination_model_.SelectedTargetPage(); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 237 } | 247 } |
| 238 | 248 |
| 239 void ContentsView::AddBlankPageForTesting() { | 249 void ContentsView::AddBlankPageForTesting() { |
| 240 AddLauncherPage(new views::View, 0); | 250 AddLauncherPage(new views::View, 0); |
| 241 } | 251 } |
| 242 | 252 |
| 243 int ContentsView::AddLauncherPage(views::View* view, int resource_id) { | 253 int ContentsView::AddLauncherPage(views::View* view, int resource_id) { |
| 244 int page_index = view_model_->view_size(); | 254 int page_index = view_model_->view_size(); |
| 245 AddChildView(view); | 255 AddChildView(view); |
| 246 view_model_->Add(view, page_index); | 256 view_model_->Add(view, page_index); |
| 247 pagination_model_.SetTotalPages(view_model_->view_size()); | |
| 248 if (contents_switcher_view_) | 257 if (contents_switcher_view_) |
| 249 contents_switcher_view_->AddSwitcherButton(resource_id, page_index); | 258 contents_switcher_view_->AddSwitcherButton(resource_id, page_index); |
| 259 pagination_model_.SetTotalPages(view_model_->view_size()); | |
| 250 return page_index; | 260 return page_index; |
| 251 } | 261 } |
| 252 | 262 |
| 253 int ContentsView::AddLauncherPage(views::View* view, | 263 int ContentsView::AddLauncherPage(views::View* view, |
| 254 int resource_id, | 264 int resource_id, |
| 255 NamedPage named_page) { | 265 NamedPage named_page) { |
| 256 int page_index = AddLauncherPage(view, resource_id); | 266 int page_index = AddLauncherPage(view, resource_id); |
| 257 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); | 267 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); |
| 258 return page_index; | 268 return page_index; |
| 259 } | 269 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 378 if (std::abs(offset) > kMinScrollToSwitchPage) { | 388 if (std::abs(offset) > kMinScrollToSwitchPage) { |
| 379 if (!GetAppsPaginationModel()->has_transition()) { | 389 if (!GetAppsPaginationModel()->has_transition()) { |
| 380 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | 390 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
| 381 } | 391 } |
| 382 event->SetHandled(); | 392 event->SetHandled(); |
| 383 event->StopPropagation(); | 393 event->StopPropagation(); |
| 384 } | 394 } |
| 385 } | 395 } |
| 386 | 396 |
| 387 } // namespace app_list | 397 } // namespace app_list |
| OLD | NEW |