Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Unified Diff: ui/app_list/views/contents_view.cc

Issue 701773002: App list: Added contents view custom animation framework. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Respond to comments. Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/app_list/views/contents_view.cc
diff --git a/ui/app_list/views/contents_view.cc b/ui/app_list/views/contents_view.cc
index c9ea27655c55962d62d45ed9a73f2db58491bcb9..655b652c89510fd3d5fb9cd73e35760f0bbd7ea4 100644
--- a/ui/app_list/views/contents_view.cc
+++ b/ui/app_list/views/contents_view.cc
@@ -15,12 +15,12 @@
#include "ui/app_list/views/app_list_main_view.h"
#include "ui/app_list/views/apps_container_view.h"
#include "ui/app_list/views/apps_grid_view.h"
+#include "ui/app_list/views/contents_animator.h"
#include "ui/app_list/views/contents_switcher_view.h"
#include "ui/app_list/views/search_box_view.h"
#include "ui/app_list/views/search_result_list_view.h"
#include "ui/app_list/views/start_page_view.h"
#include "ui/events/event.h"
-#include "ui/gfx/animation/tween.h"
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/view_model.h"
#include "ui/views/view_model_utils.h"
@@ -82,7 +82,14 @@ void ContentsView::Init(AppListModel* model,
page_before_search_ = initial_page_index;
pagination_model_.SelectPage(initial_page_index, false);
+
ActivePageChanged(false);
+
+ // Populate the contents animators.
+ AddAnimator(GetPageIndexForState(AppListModel::STATE_START),
+ GetPageIndexForState(AppListModel::STATE_APPS),
+ scoped_ptr<ContentsAnimator>(new StartToAppsAnimator(this)));
+ default_animator_.reset(new DefaultAnimator(this));
}
void ContentsView::CancelDrag() {
@@ -199,18 +206,6 @@ bool ContentsView::IsShowingSearchResults() const {
: IsStateActive(AppListModel::STATE_SEARCH_RESULTS);
}
-gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const {
- gfx::Rect bounds(GetContentsBounds());
- // The start page and search page origins are above; all other pages' origins
- // are below.
- int page_height = bounds.height();
- bool origin_above =
- GetPageIndexForState(AppListModel::STATE_START) == page_index ||
- GetPageIndexForState(AppListModel::STATE_SEARCH_RESULTS) == page_index;
- bounds.set_y(origin_above ? -page_height : page_height);
- return bounds;
-}
-
void ContentsView::UpdatePageBounds() {
// The bounds calculations will potentially be mid-transition (depending on
// the state of the PaginationModel).
@@ -226,24 +221,47 @@ void ContentsView::UpdatePageBounds() {
}
}
- // Move |current_page| from 0 to its origin. Move |target_page| from its
- // origin to 0.
- gfx::Rect on_screen(GetDefaultContentsBounds());
- gfx::Rect current_page_origin(GetOffscreenPageBounds(current_page));
- gfx::Rect target_page_origin(GetOffscreenPageBounds(target_page));
- gfx::Rect current_page_rect(
- gfx::Tween::RectValueBetween(progress, on_screen, current_page_origin));
- gfx::Rect target_page_rect(
- gfx::Tween::RectValueBetween(progress, target_page_origin, on_screen));
+ bool reverse;
+ ContentsAnimator* animator =
+ GetAnimatorForTransition(current_page, target_page, &reverse);
- view_model_->view_at(current_page)->SetBoundsRect(current_page_rect);
- view_model_->view_at(target_page)->SetBoundsRect(target_page_rect);
+ // Animate linearly (the PaginationModel handles easing).
+ if (reverse)
+ animator->Update(1 - progress, target_page, current_page);
+ else
+ animator->Update(progress, current_page, target_page);
}
PaginationModel* ContentsView::GetAppsPaginationModel() {
return apps_container_view_->apps_grid_view()->pagination_model();
}
+void ContentsView::AddAnimator(int from_page,
+ int to_page,
+ scoped_ptr<ContentsAnimator> animator) {
+ contents_animators_.insert(
+ std::make_pair(std::make_pair(from_page, to_page),
+ linked_ptr<ContentsAnimator>(animator.release())));
+}
+
+ContentsAnimator* ContentsView::GetAnimatorForTransition(int from_page,
+ int to_page,
+ bool* reverse) const {
+ auto it = contents_animators_.find(std::make_pair(from_page, to_page));
+ if (it != contents_animators_.end()) {
+ *reverse = false;
+ return it->second.get();
+ }
+
+ it = contents_animators_.find(std::make_pair(to_page, from_page));
+ if (it != contents_animators_.end()) {
+ *reverse = true;
+ return it->second.get();
+ }
+
+ return default_animator_.get();
+}
+
void ContentsView::ShowFolderContent(AppListFolderItem* item) {
apps_container_view_->ShowActiveFolder(item);
}

Powered by Google App Engine
This is Rietveld 408576698