| 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::STATE_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( |
| 69 search_results_view_, 0, AppListModel::STATE_SEARCH_RESULTS); |
| 69 search_results_view_->SetResults(model->results()); | 70 search_results_view_->SetResults(model->results()); |
| 70 } | 71 } |
| 71 | 72 |
| 72 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); | 73 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); |
| 73 | 74 |
| 74 AddLauncherPage( | 75 AddLauncherPage( |
| 75 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); | 76 apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::STATE_APPS); |
| 76 | 77 |
| 77 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 78 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() |
| 78 ? GetPageIndexForNamedPage(NAMED_PAGE_START) | 79 ? GetPageIndexForState(AppListModel::STATE_START) |
| 79 : GetPageIndexForNamedPage(NAMED_PAGE_APPS); | 80 : GetPageIndexForState(AppListModel::STATE_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::IsStateActive(AppListModel::State 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 GetPageIndexForState(state) == active_page_index; |
| 126 } | 127 } |
| 127 | 128 |
| 128 int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const { | 129 int ContentsView::GetPageIndexForState(AppListModel::State state) const { |
| 129 // Find the index of the view corresponding to the given named_page. | 130 // Find the index of the view corresponding to the given state. |
| 130 std::map<NamedPage, int>::const_iterator it = | 131 std::map<AppListModel::State, int>::const_iterator it = |
| 131 named_page_to_view_.find(named_page); | 132 state_to_view_.find(state); |
| 132 if (it == named_page_to_view_.end()) | 133 if (it == state_to_view_.end()) |
| 133 return -1; | 134 return -1; |
| 134 | 135 |
| 135 return it->second; | 136 return it->second; |
| 136 } | 137 } |
| 137 | 138 |
| 138 int ContentsView::NumLauncherPages() const { | 139 int ContentsView::NumLauncherPages() const { |
| 139 return pagination_model_.total_pages(); | 140 return pagination_model_.total_pages(); |
| 140 } | 141 } |
| 141 | 142 |
| 142 void ContentsView::SetActivePageInternal(int page_index, | 143 void ContentsView::SetActivePageInternal(int page_index, |
| 143 bool show_search_results) { | 144 bool show_search_results) { |
| 144 if (!show_search_results) | 145 if (!show_search_results) |
| 145 page_before_search_ = page_index; | 146 page_before_search_ = page_index; |
| 146 // Start animating to the new page. | 147 // Start animating to the new page. |
| 147 pagination_model_.SelectPage(page_index, true); | 148 pagination_model_.SelectPage(page_index, true); |
| 148 ActivePageChanged(show_search_results); | 149 ActivePageChanged(show_search_results); |
| 149 } | 150 } |
| 150 | 151 |
| 151 void ContentsView::ActivePageChanged(bool show_search_results) { | 152 void ContentsView::ActivePageChanged(bool show_search_results) { |
| 152 // TODO(xiyuan): Highlight default match instead of the first. | 153 // TODO(xiyuan): Highlight default match instead of the first. |
| 153 if (IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS) && | 154 if (IsStateActive(AppListModel::STATE_SEARCH_RESULTS) && |
| 154 search_results_view_->visible()) { | 155 search_results_view_->visible()) { |
| 155 search_results_view_->SetSelectedIndex(0); | 156 search_results_view_->SetSelectedIndex(0); |
| 156 } | 157 } |
| 157 if (search_results_view_) | 158 if (search_results_view_) |
| 158 search_results_view_->UpdateAutoLaunchState(); | 159 search_results_view_->UpdateAutoLaunchState(); |
| 159 | 160 |
| 160 if (IsNamedPageActive(NAMED_PAGE_START)) { | 161 if (IsStateActive(AppListModel::STATE_START)) { |
| 161 if (show_search_results) | 162 if (show_search_results) |
| 162 start_page_view_->ShowSearchResults(); | 163 start_page_view_->ShowSearchResults(); |
| 163 else | 164 else |
| 164 start_page_view_->Reset(); | 165 start_page_view_->Reset(); |
| 165 } | 166 } |
| 166 | 167 |
| 167 // Notify parent AppListMainView of the page change. | 168 // Notify parent AppListMainView of the page change. |
| 168 app_list_main_view_->UpdateSearchBoxVisibility(); | 169 app_list_main_view_->UpdateSearchBoxVisibility(); |
| 169 } | 170 } |
| 170 | 171 |
| 171 void ContentsView::ShowSearchResults(bool show) { | 172 void ContentsView::ShowSearchResults(bool show) { |
| 172 int search_page = GetPageIndexForNamedPage( | 173 int search_page = |
| 173 app_list::switches::IsExperimentalAppListEnabled() | 174 GetPageIndexForState(app_list::switches::IsExperimentalAppListEnabled() |
| 174 ? NAMED_PAGE_START | 175 ? AppListModel::STATE_START |
| 175 : NAMED_PAGE_SEARCH_RESULTS); | 176 : AppListModel::STATE_SEARCH_RESULTS); |
| 176 DCHECK_GE(search_page, 0); | 177 DCHECK_GE(search_page, 0); |
| 177 | 178 |
| 178 SetActivePageInternal(show ? search_page : page_before_search_, show); | 179 SetActivePageInternal(show ? search_page : page_before_search_, show); |
| 179 } | 180 } |
| 180 | 181 |
| 181 bool ContentsView::IsShowingSearchResults() const { | 182 bool ContentsView::IsShowingSearchResults() const { |
| 182 return app_list::switches::IsExperimentalAppListEnabled() | 183 return app_list::switches::IsExperimentalAppListEnabled() |
| 183 ? IsNamedPageActive(NAMED_PAGE_START) && | 184 ? IsStateActive(AppListModel::STATE_START) && |
| 184 start_page_view_->IsShowingSearchResults() | 185 start_page_view_->IsShowingSearchResults() |
| 185 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); | 186 : IsStateActive(AppListModel::STATE_SEARCH_RESULTS); |
| 186 } | 187 } |
| 187 | 188 |
| 188 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { | 189 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { |
| 189 gfx::Rect bounds(GetContentsBounds()); | 190 gfx::Rect bounds(GetContentsBounds()); |
| 190 // The start page and search page origins are above; all other pages' origins | 191 // The start page and search page origins are above; all other pages' origins |
| 191 // are below. | 192 // are below. |
| 192 int page_height = bounds.height(); | 193 int page_height = bounds.height(); |
| 193 bool origin_above = | 194 bool origin_above = |
| 194 GetPageIndexForNamedPage(NAMED_PAGE_START) == page_index || | 195 GetPageIndexForState(AppListModel::STATE_START) == page_index || |
| 195 GetPageIndexForNamedPage(NAMED_PAGE_SEARCH_RESULTS) == page_index; | 196 GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index; |
| 196 bounds.set_y(origin_above ? -page_height : page_height); | 197 bounds.set_y(origin_above ? -page_height : page_height); |
| 197 return bounds; | 198 return bounds; |
| 198 } | 199 } |
| 199 | 200 |
| 200 void ContentsView::UpdatePageBounds() { | 201 void ContentsView::UpdatePageBounds() { |
| 201 // The bounds calculations will potentially be mid-transition (depending on | 202 // The bounds calculations will potentially be mid-transition (depending on |
| 202 // the state of the PaginationModel). | 203 // the state of the PaginationModel). |
| 203 int current_page = std::max(0, pagination_model_.selected_page()); | 204 int current_page = std::max(0, pagination_model_.selected_page()); |
| 204 int target_page = current_page; | 205 int target_page = current_page; |
| 205 double progress = 1; | 206 double progress = 1; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 AddChildView(view); | 252 AddChildView(view); |
| 252 view_model_->Add(view, page_index); | 253 view_model_->Add(view, page_index); |
| 253 if (contents_switcher_view_ && resource_id) | 254 if (contents_switcher_view_ && resource_id) |
| 254 contents_switcher_view_->AddSwitcherButton(resource_id, page_index); | 255 contents_switcher_view_->AddSwitcherButton(resource_id, page_index); |
| 255 pagination_model_.SetTotalPages(view_model_->view_size()); | 256 pagination_model_.SetTotalPages(view_model_->view_size()); |
| 256 return page_index; | 257 return page_index; |
| 257 } | 258 } |
| 258 | 259 |
| 259 int ContentsView::AddLauncherPage(views::View* view, | 260 int ContentsView::AddLauncherPage(views::View* view, |
| 260 int resource_id, | 261 int resource_id, |
| 261 NamedPage named_page) { | 262 AppListModel::State state) { |
| 262 int page_index = AddLauncherPage(view, resource_id); | 263 int page_index = AddLauncherPage(view, resource_id); |
| 263 named_page_to_view_.insert(std::pair<NamedPage, int>(named_page, page_index)); | 264 state_to_view_.insert(std::pair<AppListModel::State, int>(state, page_index)); |
| 264 return page_index; | 265 return page_index; |
| 265 } | 266 } |
| 266 | 267 |
| 267 gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const { | 268 gfx::Rect ContentsView::GetDefaultSearchBoxBounds() const { |
| 268 gfx::Rect search_box_bounds( | 269 gfx::Rect search_box_bounds( |
| 269 0, | 270 0, |
| 270 0, | 271 0, |
| 271 GetDefaultContentsSize().width(), | 272 GetDefaultContentsSize().width(), |
| 272 app_list_main_view_->search_box_view()->GetPreferredSize().height()); | 273 app_list_main_view_->search_box_view()->GetPreferredSize().height()); |
| 273 if (switches::IsExperimentalAppListEnabled()) { | 274 if (switches::IsExperimentalAppListEnabled()) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 } | 337 } |
| 337 | 338 |
| 338 void ContentsView::TransitionStarted() { | 339 void ContentsView::TransitionStarted() { |
| 339 } | 340 } |
| 340 | 341 |
| 341 void ContentsView::TransitionChanged() { | 342 void ContentsView::TransitionChanged() { |
| 342 UpdatePageBounds(); | 343 UpdatePageBounds(); |
| 343 } | 344 } |
| 344 | 345 |
| 345 } // namespace app_list | 346 } // namespace app_list |
| OLD | NEW |