| 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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 kOverscrollPageTransitionDurationMs); | 38 kOverscrollPageTransitionDurationMs); |
| 39 pagination_model_.AddObserver(this); | 39 pagination_model_.AddObserver(this); |
| 40 } | 40 } |
| 41 | 41 |
| 42 ContentsView::~ContentsView() { | 42 ContentsView::~ContentsView() { |
| 43 pagination_model_.RemoveObserver(this); | 43 pagination_model_.RemoveObserver(this); |
| 44 if (contents_switcher_view_) | 44 if (contents_switcher_view_) |
| 45 pagination_model_.RemoveObserver(contents_switcher_view_); | 45 pagination_model_.RemoveObserver(contents_switcher_view_); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void ContentsView::InitNamedPages(AppListModel* model, | 48 void ContentsView::Init(AppListModel* model, |
| 49 AppListViewDelegate* view_delegate) { | 49 AppListViewDelegate* view_delegate) { |
| 50 DCHECK(model); | 50 DCHECK(model); |
| 51 | 51 |
| 52 if (app_list::switches::IsExperimentalAppListEnabled()) { | 52 if (app_list::switches::IsExperimentalAppListEnabled()) { |
| 53 std::vector<views::View*> custom_page_views = | 53 std::vector<views::View*> custom_page_views = |
| 54 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); | 54 view_delegate->CreateCustomPageWebViews(GetLocalBounds().size()); |
| 55 for (std::vector<views::View*>::const_iterator it = | 55 for (std::vector<views::View*>::const_iterator it = |
| 56 custom_page_views.begin(); | 56 custom_page_views.begin(); |
| 57 it != custom_page_views.end(); | 57 it != custom_page_views.end(); |
| 58 ++it) { | 58 ++it) { |
| 59 AddLauncherPage(*it, IDR_APP_LIST_NOTIFICATIONS_ICON); | 59 AddLauncherPage(*it, IDR_APP_LIST_NOTIFICATIONS_ICON); |
| 60 } | 60 } |
| 61 | 61 |
| 62 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); | 62 start_page_view_ = new StartPageView(app_list_main_view_, view_delegate); |
| 63 AddLauncherPage( | 63 AddLauncherPage( |
| 64 start_page_view_, IDR_APP_LIST_SEARCH_ICON, NAMED_PAGE_START); | 64 start_page_view_, IDR_APP_LIST_SEARCH_ICON, AppListModel::SHOW_START); |
| 65 } else { | 65 } else { |
| 66 search_results_view_ = | 66 search_results_view_ = |
| 67 new SearchResultListView(app_list_main_view_, view_delegate); | 67 new SearchResultListView(app_list_main_view_, view_delegate); |
| 68 AddLauncherPage(search_results_view_, 0, NAMED_PAGE_SEARCH_RESULTS); | 68 AddLauncherPage(search_results_view_, 0, AppListModel::SHOW_SEARCH_RESULTS); |
| 69 search_results_view_->SetResults(model->results()); | 69 search_results_view_->SetResults(model->results()); |
| 70 } | 70 } |
| 71 | 71 |
| 72 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); | 72 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); |
| 73 | 73 |
| 74 AddLauncherPage( | 74 AddLauncherPage( |
| 75 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); | 75 apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::SHOW_APPS); |
| 76 | 76 |
| 77 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 77 int initial_page_index = |
| 78 ? GetPageIndexForNamedPage(NAMED_PAGE_START) | 78 app_list::switches::IsExperimentalAppListEnabled() |
| 79 : GetPageIndexForNamedPage(NAMED_PAGE_APPS); | 79 ? GetPageIndexForShowState(AppListModel::SHOW_START) |
| 80 : GetPageIndexForShowState(AppListModel::SHOW_APPS); |
| 80 DCHECK_GE(initial_page_index, 0); | 81 DCHECK_GE(initial_page_index, 0); |
| 81 | 82 |
| 82 page_before_search_ = initial_page_index; | 83 page_before_search_ = initial_page_index; |
| 83 pagination_model_.SelectPage(initial_page_index, false); | 84 pagination_model_.SelectPage(initial_page_index, false); |
| 84 } | 85 } |
| 85 | 86 |
| 86 void ContentsView::CancelDrag() { | 87 void ContentsView::CancelDrag() { |
| 87 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 88 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
| 88 apps_container_view_->apps_grid_view()->EndDrag(true); | 89 apps_container_view_->apps_grid_view()->EndDrag(true); |
| 89 if (apps_container_view_->app_list_folder_view() | 90 if (apps_container_view_->app_list_folder_view() |
| (...skipping 22 matching lines...) Expand all Loading... |
| 112 return; | 113 return; |
| 113 | 114 |
| 114 SetActivePageInternal(page_index, false); | 115 SetActivePageInternal(page_index, false); |
| 115 } | 116 } |
| 116 | 117 |
| 117 int ContentsView::GetActivePageIndex() const { | 118 int ContentsView::GetActivePageIndex() const { |
| 118 // The active page is changed at the beginning of an animation, not the end. | 119 // The active page is changed at the beginning of an animation, not the end. |
| 119 return pagination_model_.SelectedTargetPage(); | 120 return pagination_model_.SelectedTargetPage(); |
| 120 } | 121 } |
| 121 | 122 |
| 122 bool ContentsView::IsNamedPageActive(NamedPage named_page) const { | 123 bool ContentsView::IsShowStateActive(AppListModel::ShowState show_state) const { |
| 123 int active_page_index = GetActivePageIndex(); | 124 int active_page_index = GetActivePageIndex(); |
| 124 return active_page_index >= 0 && | 125 return active_page_index >= 0 && |
| 125 GetPageIndexForNamedPage(named_page) == active_page_index; | 126 GetPageIndexForShowState(show_state) == active_page_index; |
| 126 } | 127 } |
| 127 | 128 |
| 128 int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const { | 129 int ContentsView::GetPageIndexForShowState( |
| 129 // Find the index of the view corresponding to the given named_page. | 130 AppListModel::ShowState show_state) const { |
| 130 std::map<NamedPage, int>::const_iterator it = | 131 // Find the index of the view corresponding to the given show state. |
| 131 named_page_to_view_.find(named_page); | 132 std::map<AppListModel::ShowState, int>::const_iterator it = |
| 132 if (it == named_page_to_view_.end()) | 133 show_state_to_view_.find(show_state); |
| 134 if (it == show_state_to_view_.end()) |
| 133 return -1; | 135 return -1; |
| 134 | 136 |
| 135 return it->second; | 137 return it->second; |
| 136 } | 138 } |
| 137 | 139 |
| 138 int ContentsView::NumLauncherPages() const { | 140 int ContentsView::NumLauncherPages() const { |
| 139 return pagination_model_.total_pages(); | 141 return pagination_model_.total_pages(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void ContentsView::SetActivePageInternal(int page_index, | 144 void ContentsView::SetActivePageInternal(int page_index, |
| 143 bool show_search_results) { | 145 bool show_search_results) { |
| 144 if (!show_search_results) | 146 if (!show_search_results) |
| 145 page_before_search_ = page_index; | 147 page_before_search_ = page_index; |
| 146 // Start animating to the new page. | 148 // Start animating to the new page. |
| 147 pagination_model_.SelectPage(page_index, true); | 149 pagination_model_.SelectPage(page_index, true); |
| 148 ActivePageChanged(show_search_results); | 150 ActivePageChanged(show_search_results); |
| 149 } | 151 } |
| 150 | 152 |
| 151 void ContentsView::ActivePageChanged(bool show_search_results) { | 153 void ContentsView::ActivePageChanged(bool show_search_results) { |
| 152 // TODO(xiyuan): Highlight default match instead of the first. | 154 // TODO(xiyuan): Highlight default match instead of the first. |
| 153 if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) && | 155 if (IsShowStateActive(AppListModel::SHOW_SEARCH_RESULTS) && |
| 154 search_results_view_->visible()) { | 156 search_results_view_->visible()) { |
| 155 search_results_view_->SetSelectedIndex(0); | 157 search_results_view_->SetSelectedIndex(0); |
| 156 } | 158 } |
| 157 if (search_results_view_) | 159 if (search_results_view_) |
| 158 search_results_view_->UpdateAutoLaunchState(); | 160 search_results_view_->UpdateAutoLaunchState(); |
| 159 | 161 |
| 160 if (IsNamedPageActive(NAMED_PAGE_START)) { | 162 if (IsShowStateActive(AppListModel::SHOW_START)) { |
| 161 if (show_search_results) | 163 if (show_search_results) |
| 162 start_page_view_->ShowSearchResults(); | 164 start_page_view_->ShowSearchResults(); |
| 163 else | 165 else |
| 164 start_page_view_->Reset(); | 166 start_page_view_->Reset(); |
| 165 } | 167 } |
| 166 | 168 |
| 167 // Notify parent AppListMainView of the page change. | 169 // Notify parent AppListMainView of the page change. |
| 168 app_list_main_view_->UpdateSearchBoxVisibility(); | 170 app_list_main_view_->UpdateSearchBoxVisibility(); |
| 169 } | 171 } |
| 170 | 172 |
| 171 void ContentsView::ShowSearchResults(bool show) { | 173 void ContentsView::ShowSearchResults(bool show) { |
| 172 int search_page = GetPageIndexForNamedPage( | 174 int search_page = GetPageIndexForShowState( |
| 173 app_list::switches::IsExperimentalAppListEnabled() | 175 app_list::switches::IsExperimentalAppListEnabled() |
| 174 ? NAMED_PAGE_START | 176 ? AppListModel::SHOW_START |
| 175 : NAMED_PAGE_SEARCH_RESULTS); | 177 : AppListModel::SHOW_SEARCH_RESULTS); |
| 176 DCHECK_GE(search_page, 0); | 178 DCHECK_GE(search_page, 0); |
| 177 | 179 |
| 178 SetActivePageInternal(show ? search_page : page_before_search_, show); | 180 SetActivePageInternal(show ? search_page : page_before_search_, show); |
| 179 } | 181 } |
| 180 | 182 |
| 181 bool ContentsView::IsShowingSearchResults() const { | 183 bool ContentsView::IsShowingSearchResults() const { |
| 182 return app_list::switches::IsExperimentalAppListEnabled() | 184 return app_list::switches::IsExperimentalAppListEnabled() |
| 183 ? IsNamedPageActive(NAMED_PAGE_START) && | 185 ? IsShowStateActive(AppListModel::SHOW_START) && |
| 184 start_page_view_->IsShowingSearchResults() | 186 start_page_view_->IsShowingSearchResults() |
| 185 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); | 187 : IsShowStateActive(AppListModel::SHOW_SEARCH_RESULTS); |
| 186 } | 188 } |
| 187 | 189 |
| 188 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { | 190 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { |
| 189 gfx::Rect bounds(GetContentsBounds()); | 191 gfx::Rect bounds(GetContentsBounds()); |
| 190 // The start page and search page origins are above; all other pages' origins | 192 // The start page and search page origins are above; all other pages' origins |
| 191 // are below. | 193 // are below. |
| 192 int page_height = bounds.height(); | 194 int page_height = bounds.height(); |
| 193 bool origin_above = | 195 bool origin_above = |
| 194 GetPageIndexForNamedPage(NAMED_PAGE_START) == page_index || | 196 GetPageIndexForShowState(AppListModel::SHOW_START) == page_index || |
| 195 GetPageIndexForNamedPage(NAMED_PAGE_SEARCH_RESULTS) == page_index; | 197 GetPageIndexForShowState(AppListModel::SHOW_SEARCH_RESULTS) == page_index; |
| 196 bounds.set_y(origin_above ? -page_height : page_height); | 198 bounds.set_y(origin_above ? -page_height : page_height); |
| 197 return bounds; | 199 return bounds; |
| 198 } | 200 } |
| 199 | 201 |
| 200 void ContentsView::UpdatePageBounds() { | 202 void ContentsView::UpdatePageBounds() { |
| 201 // The bounds calculations will potentially be mid-transition (depending on | 203 // The bounds calculations will potentially be mid-transition (depending on |
| 202 // the state of the PaginationModel). | 204 // the state of the PaginationModel). |
| 203 int current_page = std::max(0, pagination_model_.selected_page()); | 205 int current_page = std::max(0, pagination_model_.selected_page()); |
| 204 int target_page = current_page; | 206 int target_page = current_page; |
| 205 double progress = 1; | 207 double progress = 1; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 AddChildView(view); | 253 AddChildView(view); |
| 252 view_model_->Add(view, page_index); | 254 view_model_->Add(view, page_index); |
| 253 if (contents_switcher_view_ && resource_id) | 255 if (contents_switcher_view_ && resource_id) |
| 254 contents_switcher_view_->AddSwitcherButton(resource_id, page_index); | 256 contents_switcher_view_->AddSwitcherButton(resource_id, page_index); |
| 255 pagination_model_.SetTotalPages(view_model_->view_size()); | 257 pagination_model_.SetTotalPages(view_model_->view_size()); |
| 256 return page_index; | 258 return page_index; |
| 257 } | 259 } |
| 258 | 260 |
| 259 int ContentsView::AddLauncherPage(views::View* view, | 261 int ContentsView::AddLauncherPage(views::View* view, |
| 260 int resource_id, | 262 int resource_id, |
| 261 NamedPage named_page) { | 263 AppListModel::ShowState show_state) { |
| 262 int page_index = AddLauncherPage(view, resource_id); | 264 int page_index = AddLauncherPage(view, resource_id); |
| 263 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); | 265 show_state_to_view_.insert( |
| 266 std::pair<AppListModel::ShowState, int>(show_state, page_index)); |
| 264 return page_index; | 267 return page_index; |
| 265 } | 268 } |
| 266 | 269 |
| 267 gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const { | 270 gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const { |
| 268 gfx::Rect search_box_bounds( | 271 gfx::Rect search_box_bounds( |
| 269 0, | 272 0, |
| 270 0, | 273 0, |
| 271 GetDefaultContentsSize().width(), | 274 GetDefaultContentsSize().width(), |
| 272 app_list_main_view_->search_box_view()->GetPreferredSize().height()); | 275 app_list_main_view_->search_box_view()->GetPreferredSize().height()); |
| 273 if (switches::IsExperimentalAppListEnabled()) { | 276 if (switches::IsExperimentalAppListEnabled()) { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 } | 337 } |
| 335 | 338 |
| 336 void ContentsView::TransitionStarted() { | 339 void ContentsView::TransitionStarted() { |
| 337 } | 340 } |
| 338 | 341 |
| 339 void ContentsView::TransitionChanged() { | 342 void ContentsView::TransitionChanged() { |
| 340 UpdatePageBounds(); | 343 UpdatePageBounds(); |
| 341 } | 344 } |
| 342 | 345 |
| 343 } // namespace app_list | 346 } // namespace app_list |
| OLD | NEW |