| 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 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 const double kFinishTransitionThreshold = 0.33; | 34 const double kFinishTransitionThreshold = 0.33; |
| 35 | 35 |
| 36 } // namespace | 36 } // namespace |
| 37 | 37 |
| 38 ContentsView::ContentsView(AppListMainView* app_list_main_view) | 38 ContentsView::ContentsView(AppListMainView* app_list_main_view) |
| 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 page_before_search_(0) { |
| 44 pagination_model_.AddObserver(this); | 45 pagination_model_.AddObserver(this); |
| 45 } | 46 } |
| 46 | 47 |
| 47 ContentsView::~ContentsView() { | 48 ContentsView::~ContentsView() { |
| 48 pagination_model_.RemoveObserver(this); | 49 pagination_model_.RemoveObserver(this); |
| 49 if (contents_switcher_view_) | 50 if (contents_switcher_view_) |
| 50 pagination_model_.RemoveObserver(contents_switcher_view_); | 51 pagination_model_.RemoveObserver(contents_switcher_view_); |
| 51 } | 52 } |
| 52 | 53 |
| 53 void ContentsView::InitNamedPages(AppListModel* model, | 54 void ContentsView::InitNamedPages(AppListModel* model, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 70 search_results_view_->SetResults(model->results()); | 71 search_results_view_->SetResults(model->results()); |
| 71 } | 72 } |
| 72 | 73 |
| 73 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); | 74 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); |
| 74 | 75 |
| 75 int initial_page_index = AddLauncherPage( | 76 int initial_page_index = AddLauncherPage( |
| 76 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); | 77 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); |
| 77 if (app_list::switches::IsExperimentalAppListEnabled()) | 78 if (app_list::switches::IsExperimentalAppListEnabled()) |
| 78 initial_page_index = GetPageIndexForNamedPage(NAMED_PAGE_START); | 79 initial_page_index = GetPageIndexForNamedPage(NAMED_PAGE_START); |
| 79 | 80 |
| 81 page_before_search_ = initial_page_index; |
| 80 pagination_model_.SelectPage(initial_page_index, false); | 82 pagination_model_.SelectPage(initial_page_index, false); |
| 81 | 83 |
| 82 // Needed to update the main search box visibility. | 84 // Needed to update the main search box visibility. |
| 83 ActivePageChanged(false); | 85 ActivePageChanged(false); |
| 84 } | 86 } |
| 85 | 87 |
| 86 void ContentsView::CancelDrag() { | 88 void ContentsView::CancelDrag() { |
| 87 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 89 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
| 88 apps_container_view_->apps_grid_view()->EndDrag(true); | 90 apps_container_view_->apps_grid_view()->EndDrag(true); |
| 89 if (apps_container_view_->app_list_folder_view() | 91 if (apps_container_view_->app_list_folder_view() |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 DCHECK(it != named_page_to_view_.end()); | 138 DCHECK(it != named_page_to_view_.end()); |
| 137 return it->second; | 139 return it->second; |
| 138 } | 140 } |
| 139 | 141 |
| 140 int ContentsView::NumLauncherPages() const { | 142 int ContentsView::NumLauncherPages() const { |
| 141 return pagination_model_.total_pages(); | 143 return pagination_model_.total_pages(); |
| 142 } | 144 } |
| 143 | 145 |
| 144 void ContentsView::SetActivePageInternal(int page_index, | 146 void ContentsView::SetActivePageInternal(int page_index, |
| 145 bool show_search_results) { | 147 bool show_search_results) { |
| 148 if (!show_search_results) |
| 149 page_before_search_ = page_index; |
| 146 // Start animating to the new page. | 150 // Start animating to the new page. |
| 147 pagination_model_.SelectPage(page_index, true); | 151 pagination_model_.SelectPage(page_index, true); |
| 148 ActivePageChanged(show_search_results); | 152 ActivePageChanged(show_search_results); |
| 149 } | 153 } |
| 150 | 154 |
| 151 void ContentsView::ActivePageChanged(bool show_search_results) { | 155 void ContentsView::ActivePageChanged(bool show_search_results) { |
| 152 // TODO(xiyuan): Highlight default match instead of the first. | 156 // TODO(xiyuan): Highlight default match instead of the first. |
| 153 if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) && | 157 if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) && |
| 154 search_results_view_->visible()) { | 158 search_results_view_->visible()) { |
| 155 search_results_view_->SetSelectedIndex(0); | 159 search_results_view_->SetSelectedIndex(0); |
| 156 } | 160 } |
| 157 if (search_results_view_) | 161 if (search_results_view_) |
| 158 search_results_view_->UpdateAutoLaunchState(); | 162 search_results_view_->UpdateAutoLaunchState(); |
| 159 | 163 |
| 160 if (IsNamedPageActive(NAMED_PAGE_START)) { | 164 if (IsNamedPageActive(NAMED_PAGE_START)) { |
| 161 if (show_search_results) | 165 if (show_search_results) |
| 162 start_page_view_->ShowSearchResults(); | 166 start_page_view_->ShowSearchResults(); |
| 163 else | 167 else |
| 164 start_page_view_->Reset(); | 168 start_page_view_->Reset(); |
| 165 } | 169 } |
| 166 | 170 |
| 167 // Notify parent AppListMainView of the page change. | 171 // Notify parent AppListMainView of the page change. |
| 168 app_list_main_view_->UpdateSearchBoxVisibility(); | 172 app_list_main_view_->UpdateSearchBoxVisibility(); |
| 169 } | 173 } |
| 170 | 174 |
| 171 void ContentsView::ShowSearchResults(bool show) { | 175 void ContentsView::ShowSearchResults(bool show) { |
| 172 NamedPage new_named_page = show ? NAMED_PAGE_SEARCH_RESULTS : NAMED_PAGE_APPS; | 176 int search_page = GetPageIndexForNamedPage( |
| 173 if (app_list::switches::IsExperimentalAppListEnabled()) | 177 app_list::switches::IsExperimentalAppListEnabled() |
| 174 new_named_page = NAMED_PAGE_START; | 178 ? NAMED_PAGE_START |
| 179 : NAMED_PAGE_SEARCH_RESULTS); |
| 175 | 180 |
| 176 SetActivePageInternal(GetPageIndexForNamedPage(new_named_page), show); | 181 SetActivePageInternal(show ? search_page : page_before_search_, show); |
| 177 } | 182 } |
| 178 | 183 |
| 179 bool ContentsView::IsShowingSearchResults() const { | 184 bool ContentsView::IsShowingSearchResults() const { |
| 180 return app_list::switches::IsExperimentalAppListEnabled() | 185 return app_list::switches::IsExperimentalAppListEnabled() |
| 181 ? IsNamedPageActive(NAMED_PAGE_START) && | 186 ? IsNamedPageActive(NAMED_PAGE_START) && |
| 182 start_page_view_->IsShowingSearchResults() | 187 start_page_view_->IsShowingSearchResults() |
| 183 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); | 188 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); |
| 184 } | 189 } |
| 185 | 190 |
| 186 void ContentsView::UpdatePageBounds() { | 191 void ContentsView::UpdatePageBounds() { |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 if (std::abs(offset) > kMinScrollToSwitchPage) { | 393 if (std::abs(offset) > kMinScrollToSwitchPage) { |
| 389 if (!GetAppsPaginationModel()->has_transition()) { | 394 if (!GetAppsPaginationModel()->has_transition()) { |
| 390 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | 395 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
| 391 } | 396 } |
| 392 event->SetHandled(); | 397 event->SetHandled(); |
| 393 event->StopPropagation(); | 398 event->StopPropagation(); |
| 394 } | 399 } |
| 395 } | 400 } |
| 396 | 401 |
| 397 } // namespace app_list | 402 } // namespace app_list |
| OLD | NEW |