| 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/search_result_page_view.h" | 22 #include "ui/app_list/views/search_result_page_view.h" |
| 22 #include "ui/app_list/views/start_page_view.h" | 23 #include "ui/app_list/views/start_page_view.h" |
| 23 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
| 24 #include "ui/gfx/animation/tween.h" | |
| 25 #include "ui/resources/grit/ui_resources.h" | 25 #include "ui/resources/grit/ui_resources.h" |
| 26 #include "ui/views/view_model.h" | 26 #include "ui/views/view_model.h" |
| 27 #include "ui/views/view_model_utils.h" | 27 #include "ui/views/view_model_utils.h" |
| 28 | 28 |
| 29 namespace app_list { | 29 namespace app_list { |
| 30 | 30 |
| 31 ContentsView::ContentsView(AppListMainView* app_list_main_view) | 31 ContentsView::ContentsView(AppListMainView* app_list_main_view) |
| 32 : apps_container_view_(nullptr), | 32 : apps_container_view_(nullptr), |
| 33 search_results_list_view_(nullptr), | 33 search_results_list_view_(nullptr), |
| 34 search_results_page_view_(nullptr), | 34 search_results_page_view_(nullptr), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 AddLauncherPage( | 91 AddLauncherPage( |
| 92 apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::STATE_APPS); | 92 apps_container_view_, IDR_APP_LIST_APPS_ICON, AppListModel::STATE_APPS); |
| 93 | 93 |
| 94 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 94 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() |
| 95 ? GetPageIndexForState(AppListModel::STATE_START) | 95 ? GetPageIndexForState(AppListModel::STATE_START) |
| 96 : GetPageIndexForState(AppListModel::STATE_APPS); | 96 : GetPageIndexForState(AppListModel::STATE_APPS); |
| 97 DCHECK_GE(initial_page_index, 0); | 97 DCHECK_GE(initial_page_index, 0); |
| 98 | 98 |
| 99 page_before_search_ = initial_page_index; | 99 page_before_search_ = initial_page_index; |
| 100 pagination_model_.SelectPage(initial_page_index, false); | 100 pagination_model_.SelectPage(initial_page_index, false); |
| 101 |
| 101 ActivePageChanged(); | 102 ActivePageChanged(); |
| 103 |
| 104 // Populate the contents animators. |
| 105 AddAnimator(AppListModel::STATE_START, AppListModel::STATE_APPS, |
| 106 scoped_ptr<ContentsAnimator>(new StartToAppsAnimator(this))); |
| 107 default_animator_.reset(new DefaultAnimator(this)); |
| 102 } | 108 } |
| 103 | 109 |
| 104 void ContentsView::CancelDrag() { | 110 void ContentsView::CancelDrag() { |
| 105 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 111 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
| 106 apps_container_view_->apps_grid_view()->EndDrag(true); | 112 apps_container_view_->apps_grid_view()->EndDrag(true); |
| 107 if (apps_container_view_->app_list_folder_view() | 113 if (apps_container_view_->app_list_folder_view() |
| 108 ->items_grid_view() | 114 ->items_grid_view() |
| 109 ->has_dragged_view()) { | 115 ->has_dragged_view()) { |
| 110 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( | 116 apps_container_view_->app_list_folder_view()->items_grid_view()->EndDrag( |
| 111 true); | 117 true); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS); | 202 int search_page = GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS); |
| 197 DCHECK_GE(search_page, 0); | 203 DCHECK_GE(search_page, 0); |
| 198 | 204 |
| 199 SetActivePageInternal(show ? search_page : page_before_search_, show); | 205 SetActivePageInternal(show ? search_page : page_before_search_, show); |
| 200 } | 206 } |
| 201 | 207 |
| 202 bool ContentsView::IsShowingSearchResults() const { | 208 bool ContentsView::IsShowingSearchResults() const { |
| 203 return IsStateActive(AppListModel::STATE_SEARCH_RESULTS); | 209 return IsStateActive(AppListModel::STATE_SEARCH_RESULTS); |
| 204 } | 210 } |
| 205 | 211 |
| 206 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { | |
| 207 gfx::Rect bounds(GetContentsBounds()); | |
| 208 // The start page and search page origins are above; all other pages' origins | |
| 209 // are below. | |
| 210 int page_height = bounds.height(); | |
| 211 bool origin_above = | |
| 212 GetPageIndexForState(AppListModel::STATE_START) == page_index || | |
| 213 GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index; | |
| 214 bounds.set_y(origin_above ? -page_height : page_height); | |
| 215 return bounds; | |
| 216 } | |
| 217 | |
| 218 void ContentsView::NotifyCustomLauncherPageAnimationChanged(double progress, | 212 void ContentsView::NotifyCustomLauncherPageAnimationChanged(double progress, |
| 219 int current_page, | 213 int current_page, |
| 220 int target_page) { | 214 int target_page) { |
| 221 int custom_launcher_page_index = | 215 int custom_launcher_page_index = |
| 222 GetPageIndexForState(AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 216 GetPageIndexForState(AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
| 223 if (custom_launcher_page_index == target_page) { | 217 if (custom_launcher_page_index == target_page) { |
| 224 app_list_main_view_->view_delegate()->CustomLauncherPageAnimationChanged( | 218 app_list_main_view_->view_delegate()->CustomLauncherPageAnimationChanged( |
| 225 progress); | 219 progress); |
| 226 } else if (custom_launcher_page_index == current_page) { | 220 } else if (custom_launcher_page_index == current_page) { |
| 227 app_list_main_view_->view_delegate()->CustomLauncherPageAnimationChanged( | 221 app_list_main_view_->view_delegate()->CustomLauncherPageAnimationChanged( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 239 const PaginationModel::Transition& transition = | 233 const PaginationModel::Transition& transition = |
| 240 pagination_model_.transition(); | 234 pagination_model_.transition(); |
| 241 if (pagination_model_.is_valid_page(transition.target_page)) { | 235 if (pagination_model_.is_valid_page(transition.target_page)) { |
| 242 target_page = transition.target_page; | 236 target_page = transition.target_page; |
| 243 progress = transition.progress; | 237 progress = transition.progress; |
| 244 } | 238 } |
| 245 } | 239 } |
| 246 | 240 |
| 247 NotifyCustomLauncherPageAnimationChanged(progress, current_page, target_page); | 241 NotifyCustomLauncherPageAnimationChanged(progress, current_page, target_page); |
| 248 | 242 |
| 249 // Move |current_page| from 0 to its origin. Move |target_page| from its | 243 bool reverse; |
| 250 // origin to 0. | 244 ContentsAnimator* animator = |
| 251 gfx::Rect on_screen(GetDefaultContentsBounds()); | 245 GetAnimatorForTransition(current_page, target_page, &reverse); |
| 252 gfx::Rect current_page_origin(GetOffscreenPageBounds(current_page)); | |
| 253 gfx::Rect target_page_origin(GetOffscreenPageBounds(target_page)); | |
| 254 gfx::Rect current_page_rect( | |
| 255 gfx::Tween::RectValueBetween(progress, on_screen, current_page_origin)); | |
| 256 gfx::Rect target_page_rect( | |
| 257 gfx::Tween::RectValueBetween(progress, target_page_origin, on_screen)); | |
| 258 | 246 |
| 259 view_model_->view_at(current_page)->SetBoundsRect(current_page_rect); | 247 // Animate linearly (the PaginationModel handles easing). |
| 260 view_model_->view_at(target_page)->SetBoundsRect(target_page_rect); | 248 if (reverse) |
| 249 animator->Update(1 - progress, target_page, current_page); |
| 250 else |
| 251 animator->Update(progress, current_page, target_page); |
| 261 } | 252 } |
| 262 | 253 |
| 263 PaginationModel* ContentsView::GetAppsPaginationModel() { | 254 PaginationModel* ContentsView::GetAppsPaginationModel() { |
| 264 return apps_container_view_->apps_grid_view()->pagination_model(); | 255 return apps_container_view_->apps_grid_view()->pagination_model(); |
| 265 } | 256 } |
| 266 | 257 |
| 258 void ContentsView::AddAnimator(AppListModel::State from_state, |
| 259 AppListModel::State to_state, |
| 260 scoped_ptr<ContentsAnimator> animator) { |
| 261 int from_page = GetPageIndexForState(from_state); |
| 262 int to_page = GetPageIndexForState(to_state); |
| 263 contents_animators_.insert( |
| 264 std::make_pair(std::make_pair(from_page, to_page), |
| 265 linked_ptr<ContentsAnimator>(animator.release()))); |
| 266 } |
| 267 |
| 268 ContentsAnimator* ContentsView::GetAnimatorForTransition(int from_page, |
| 269 int to_page, |
| 270 bool* reverse) const { |
| 271 auto it = contents_animators_.find(std::make_pair(from_page, to_page)); |
| 272 if (it != contents_animators_.end()) { |
| 273 *reverse = false; |
| 274 return it->second.get(); |
| 275 } |
| 276 |
| 277 it = contents_animators_.find(std::make_pair(to_page, from_page)); |
| 278 if (it != contents_animators_.end()) { |
| 279 *reverse = true; |
| 280 return it->second.get(); |
| 281 } |
| 282 |
| 283 *reverse = false; |
| 284 return default_animator_.get(); |
| 285 } |
| 286 |
| 267 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 287 void ContentsView::ShowFolderContent(AppListFolderItem* item) { |
| 268 apps_container_view_->ShowActiveFolder(item); | 288 apps_container_view_->ShowActiveFolder(item); |
| 269 } | 289 } |
| 270 | 290 |
| 271 void ContentsView::Prerender() { | 291 void ContentsView::Prerender() { |
| 272 apps_container_view_->apps_grid_view()->Prerender(); | 292 apps_container_view_->apps_grid_view()->Prerender(); |
| 273 } | 293 } |
| 274 | 294 |
| 275 views::View* ContentsView::GetPageView(int index) { | 295 views::View* ContentsView::GetPageView(int index) { |
| 276 return view_model_->view_at(index); | 296 return view_model_->view_at(index); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 } | 396 } |
| 377 | 397 |
| 378 void ContentsView::TransitionStarted() { | 398 void ContentsView::TransitionStarted() { |
| 379 } | 399 } |
| 380 | 400 |
| 381 void ContentsView::TransitionChanged() { | 401 void ContentsView::TransitionChanged() { |
| 382 UpdatePageBounds(); | 402 UpdatePageBounds(); |
| 383 } | 403 } |
| 384 | 404 |
| 385 } // namespace app_list | 405 } // namespace app_list |
| OLD | NEW |