| 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               scoped_ptr<ContentsAnimator>(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   // Animate linearly (the PaginationModel handles easing). | 
| 240   view_model_->view_at(target_page)->SetBoundsRect(target_page_rect); | 229   if (reverse) | 
|  | 230     animator->Update(1 - progress, target_page, current_page); | 
|  | 231   else | 
|  | 232     animator->Update(progress, current_page, target_page); | 
| 241 } | 233 } | 
| 242 | 234 | 
| 243 PaginationModel* ContentsView::GetAppsPaginationModel() { | 235 PaginationModel* ContentsView::GetAppsPaginationModel() { | 
| 244   return apps_container_view_->apps_grid_view()->pagination_model(); | 236   return apps_container_view_->apps_grid_view()->pagination_model(); | 
| 245 } | 237 } | 
| 246 | 238 | 
|  | 239 void ContentsView::AddAnimator(int from_page, | 
|  | 240                                int to_page, | 
|  | 241                                scoped_ptr<ContentsAnimator> animator) { | 
|  | 242   contents_animators_.insert( | 
|  | 243       std::make_pair(std::make_pair(from_page, to_page), | 
|  | 244                      linked_ptr<ContentsAnimator>(animator.release()))); | 
|  | 245 } | 
|  | 246 | 
|  | 247 ContentsAnimator* ContentsView::GetAnimatorForTransition(int from_page, | 
|  | 248                                                          int to_page, | 
|  | 249                                                          bool* reverse) const { | 
|  | 250   auto it = contents_animators_.find(std::make_pair(from_page, to_page)); | 
|  | 251   if (it != contents_animators_.end()) { | 
|  | 252     *reverse = false; | 
|  | 253     return it->second.get(); | 
|  | 254   } | 
|  | 255 | 
|  | 256   it = contents_animators_.find(std::make_pair(to_page, from_page)); | 
|  | 257   if (it != contents_animators_.end()) { | 
|  | 258     *reverse = true; | 
|  | 259     return it->second.get(); | 
|  | 260   } | 
|  | 261 | 
|  | 262   return default_animator_.get(); | 
|  | 263 } | 
|  | 264 | 
| 247 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 265 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 
| 248   apps_container_view_->ShowActiveFolder(item); | 266   apps_container_view_->ShowActiveFolder(item); | 
| 249 } | 267 } | 
| 250 | 268 | 
| 251 void ContentsView::Prerender() { | 269 void ContentsView::Prerender() { | 
| 252   apps_container_view_->apps_grid_view()->Prerender(); | 270   apps_container_view_->apps_grid_view()->Prerender(); | 
| 253 } | 271 } | 
| 254 | 272 | 
| 255 views::View* ContentsView::GetPageView(int index) { | 273 views::View* ContentsView::GetPageView(int index) { | 
| 256   return view_model_->view_at(index); | 274   return view_model_->view_at(index); | 
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 356 } | 374 } | 
| 357 | 375 | 
| 358 void ContentsView::TransitionStarted() { | 376 void ContentsView::TransitionStarted() { | 
| 359 } | 377 } | 
| 360 | 378 | 
| 361 void ContentsView::TransitionChanged() { | 379 void ContentsView::TransitionChanged() { | 
| 362   UpdatePageBounds(); | 380   UpdatePageBounds(); | 
| 363 } | 381 } | 
| 364 | 382 | 
| 365 }  // namespace app_list | 383 }  // namespace app_list | 
| OLD | NEW | 
|---|