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 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
| 12 #include "ui/app_list/app_list_switches.h" | 12 #include "ui/app_list/app_list_switches.h" |
| 13 #include "ui/app_list/app_list_view_delegate.h" | 13 #include "ui/app_list/app_list_view_delegate.h" |
| 14 #include "ui/app_list/views/app_list_folder_view.h" | 14 #include "ui/app_list/views/app_list_folder_view.h" |
| 15 #include "ui/app_list/views/app_list_main_view.h" | 15 #include "ui/app_list/views/app_list_main_view.h" |
| 16 #include "ui/app_list/views/apps_container_view.h" | 16 #include "ui/app_list/views/apps_container_view.h" |
| 17 #include "ui/app_list/views/apps_grid_view.h" | 17 #include "ui/app_list/views/apps_grid_view.h" |
| 18 #include "ui/app_list/views/contents_animator.h" | |
| 18 #include "ui/app_list/views/contents_switcher_view.h" | 19 #include "ui/app_list/views/contents_switcher_view.h" |
| 19 #include "ui/app_list/views/search_box_view.h" | 20 #include "ui/app_list/views/search_box_view.h" |
| 20 #include "ui/app_list/views/search_result_list_view.h" | 21 #include "ui/app_list/views/search_result_list_view.h" |
| 21 #include "ui/app_list/views/start_page_view.h" | 22 #include "ui/app_list/views/start_page_view.h" |
| 22 #include "ui/events/event.h" | 23 #include "ui/events/event.h" |
| 23 #include "ui/gfx/animation/tween.h" | |
| 24 #include "ui/resources/grit/ui_resources.h" | 24 #include "ui/resources/grit/ui_resources.h" |
| 25 #include "ui/views/view_model.h" | 25 #include "ui/views/view_model.h" |
| 26 #include "ui/views/view_model_utils.h" | 26 #include "ui/views/view_model_utils.h" |
| 27 | 27 |
| 28 namespace app_list { | 28 namespace app_list { |
| 29 | 29 |
| 30 ContentsView::ContentsView(AppListMainView* app_list_main_view) | 30 ContentsView::ContentsView(AppListMainView* app_list_main_view) |
| 31 : search_results_view_(NULL), | 31 : search_results_view_(NULL), |
| 32 start_page_view_(NULL), | 32 start_page_view_(NULL), |
| 33 app_list_main_view_(app_list_main_view), | 33 app_list_main_view_(app_list_main_view), |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 AddLauncherPage( | 75 AddLauncherPage( |
| 76 apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::STATE_APPS); | 76 apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::STATE_APPS); |
| 77 | 77 |
| 78 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 78 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() |
| 79 ? GetPageIndexForState(AppListModel::STATE_START) | 79 ? GetPageIndexForState(AppListModel::STATE_START) |
| 80 : GetPageIndexForState(AppListModel::STATE_APPS); | 80 : GetPageIndexForState(AppListModel::STATE_APPS); |
| 81 DCHECK_GE(initial_page_index, 0); | 81 DCHECK_GE(initial_page_index, 0); |
| 82 | 82 |
| 83 page_before_search_ = initial_page_index; | 83 page_before_search_ = initial_page_index; |
| 84 pagination_model_.SelectPage(initial_page_index, false); | 84 pagination_model_.SelectPage(initial_page_index, false); |
| 85 | |
| 85 ActivePageChanged(false); | 86 ActivePageChanged(false); |
| 87 | |
| 88 // Populate the contents animators. | |
| 89 AddAnimator(GetPageIndexForState(AppListModel::STATE_START), | |
| 90 GetPageIndexForState(AppListModel::STATE_APPS), | |
| 91 new StartToAppsAnimator(this)); | |
| 92 default_animator_.reset(new DefaultAnimator(this)); | |
| 86 } | 93 } |
| 87 | 94 |
| 88 void ContentsView::CancelDrag() { | 95 void ContentsView::CancelDrag() { |
| 89 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 96 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
| 90 apps_container_view_->apps_grid_view()->EndDrag(true); | 97 apps_container_view_->apps_grid_view()->EndDrag(true); |
| 91 if (apps_container_view_->app_list_folder_view() | 98 if (apps_container_view_->app_list_folder_view() |
| 92 ->items_grid_view() | 99 ->items_grid_view() |
| 93 ->has_dragged_view()) { | 100 ->has_dragged_view()) { |
| 94 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( | 101 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( |
| 95 true); | 102 true); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 SetActivePageInternal(show ? search_page : page_before_search_, show); | 199 SetActivePageInternal(show ? search_page : page_before_search_, show); |
| 193 } | 200 } |
| 194 | 201 |
| 195 bool ContentsView::IsShowingSearchResults() const { | 202 bool ContentsView::IsShowingSearchResults() const { |
| 196 return app_list::switches::IsExperimentalAppListEnabled() | 203 return app_list::switches::IsExperimentalAppListEnabled() |
| 197 ? IsStateActive(AppListModel::STATE_START) && | 204 ? IsStateActive(AppListModel::STATE_START) && |
| 198 start_page_view_->IsShowingSearchResults() | 205 start_page_view_->IsShowingSearchResults() |
| 199 : IsStateActive(AppListModel::STATE_SEARCH_RESULTS); | 206 : IsStateActive(AppListModel::STATE_SEARCH_RESULTS); |
| 200 } | 207 } |
| 201 | 208 |
| 202 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { | |
| 203 gfx::Rect bounds(GetContentsBounds()); | |
| 204 // The start page and search page origins are above; all other pages' origins | |
| 205 // are below. | |
| 206 int page_height = bounds.height(); | |
| 207 bool origin_above = | |
| 208 GetPageIndexForState(AppListModel::STATE_START) == page_index || | |
| 209 GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index; | |
| 210 bounds.set_y(origin_above ? -page_height : page_height); | |
| 211 return bounds; | |
| 212 } | |
| 213 | |
| 214 void ContentsView::UpdatePageBounds() { | 209 void ContentsView::UpdatePageBounds() { |
| 215 // The bounds calculations will potentially be mid-transition (depending on | 210 // The bounds calculations will potentially be mid-transition (depending on |
| 216 // the state of the PaginationModel). | 211 // the state of the PaginationModel). |
| 217 int current_page = std::max(0, pagination_model_.selected_page()); | 212 int current_page = std::max(0, pagination_model_.selected_page()); |
| 218 int target_page = current_page; | 213 int target_page = current_page; |
| 219 double progress = 1; | 214 double progress = 1; |
| 220 if (pagination_model_.has_transition()) { | 215 if (pagination_model_.has_transition()) { |
| 221 const PaginationModel::Transition& transition = | 216 const PaginationModel::Transition& transition = |
| 222 pagination_model_.transition(); | 217 pagination_model_.transition(); |
| 223 if (pagination_model_.is_valid_page(transition.target_page)) { | 218 if (pagination_model_.is_valid_page(transition.target_page)) { |
| 224 target_page = transition.target_page; | 219 target_page = transition.target_page; |
| 225 progress = transition.progress; | 220 progress = transition.progress; |
| 226 } | 221 } |
| 227 } | 222 } |
| 228 | 223 |
| 229 // Move |current_page| from 0 to its origin. Move |target_page| from its | 224 bool reverse; |
| 230 // origin to 0. | 225 ContentsAnimator* animator = |
| 231 gfx::Rect on_screen(GetDefaultContentsBounds()); | 226 GetAnimatorForTransition(current_page, target_page, &reverse); |
| 232 gfx::Rect current_page_origin(GetOffscreenPageBounds(current_page)); | |
| 233 gfx::Rect target_page_origin(GetOffscreenPageBounds(target_page)); | |
| 234 gfx::Rect current_page_rect( | |
| 235 gfx::Tween::RectValueBetween(progress, on_screen, current_page_origin)); | |
| 236 gfx::Rect target_page_rect( | |
| 237 gfx::Tween::RectValueBetween(progress, target_page_origin, on_screen)); | |
| 238 | 227 |
| 239 view_model_->view_at(current_page)->SetBoundsRect(current_page_rect); | 228 if (reverse) |
|
calamity
2014/11/05 06:29:07
Mention that easing is handled by pagination_model
Matt Giuca
2014/11/06 00:32:59
Done.
| |
| 240 view_model_->view_at(target_page)->SetBoundsRect(target_page_rect); | 229 animator->Update(1 - progress, target_page, current_page); |
| 230 else | |
| 231 animator->Update(progress, current_page, target_page); | |
| 241 } | 232 } |
| 242 | 233 |
| 243 PaginationModel* ContentsView::GetAppsPaginationModel() { | 234 PaginationModel* ContentsView::GetAppsPaginationModel() { |
| 244 return apps_container_view_->apps_grid_view()->pagination_model(); | 235 return apps_container_view_->apps_grid_view()->pagination_model(); |
| 245 } | 236 } |
| 246 | 237 |
| 238 void ContentsView::AddAnimator(int from_page, | |
| 239 int to_page, | |
| 240 ContentsAnimator* animator) { | |
| 241 contents_animators_.insert( | |
| 242 std::make_pair(std::make_pair(from_page, to_page), | |
| 243 linked_ptr<ContentsAnimator>(animator))); | |
| 244 } | |
| 245 | |
| 246 ContentsAnimator* ContentsView::GetAnimatorForTransition(int from_page, | |
| 247 int to_page, | |
| 248 bool* reverse) const { | |
|
calamity
2014/11/05 06:29:07
Having this out var locks us into symmetrical anim
Matt Giuca
2014/11/06 00:32:59
As discussed, I think this is a good idea if we ne
calamity
2014/11/06 05:34:47
Acknowledged.
| |
| 249 auto it = contents_animators_.find(std::make_pair(from_page, to_page)); | |
| 250 if (it != contents_animators_.end()) { | |
| 251 *reverse = false; | |
| 252 return it->second.get(); | |
| 253 } | |
| 254 | |
| 255 it = contents_animators_.find(std::make_pair(to_page, from_page)); | |
| 256 if (it != contents_animators_.end()) { | |
| 257 *reverse = true; | |
| 258 return it->second.get(); | |
| 259 } | |
| 260 | |
| 261 return default_animator_.get(); | |
| 262 } | |
| 263 | |
| 247 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 264 void ContentsView::ShowFolderContent(AppListFolderItem* item) { |
| 248 apps_container_view_->ShowActiveFolder(item); | 265 apps_container_view_->ShowActiveFolder(item); |
| 249 } | 266 } |
| 250 | 267 |
| 251 void ContentsView::Prerender() { | 268 void ContentsView::Prerender() { |
| 252 apps_container_view_->apps_grid_view()->Prerender(); | 269 apps_container_view_->apps_grid_view()->Prerender(); |
| 253 } | 270 } |
| 254 | 271 |
| 255 views::View* ContentsView::GetPageView(int index) { | 272 views::View* ContentsView::GetPageView(int index) { |
| 256 return view_model_->view_at(index); | 273 return view_model_->view_at(index); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 } | 373 } |
| 357 | 374 |
| 358 void ContentsView::TransitionStarted() { | 375 void ContentsView::TransitionStarted() { |
| 359 } | 376 } |
| 360 | 377 |
| 361 void ContentsView::TransitionChanged() { | 378 void ContentsView::TransitionChanged() { |
| 362 UpdatePageBounds(); | 379 UpdatePageBounds(); |
| 363 } | 380 } |
| 364 | 381 |
| 365 } // namespace app_list | 382 } // namespace app_list |
| OLD | NEW |