summaryrefslogtreecommitdiffstats
path: root/ui/app_list/pagination_model.h
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-11 22:05:19 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-11 22:05:19 +0000
commit891217cb1efc819782cfd161155aa26bca1098d1 (patch)
tree1e86b2ced1afa0877dff815e6a87df3e45e530ee /ui/app_list/pagination_model.h
parentfc5a75b23b17983487d2182d2c1e35b1f558414f (diff)
downloadchromium_src-891217cb1efc819782cfd161155aa26bca1098d1.zip
chromium_src-891217cb1efc819782cfd161155aa26bca1098d1.tar.gz
chromium_src-891217cb1efc819782cfd161155aa26bca1098d1.tar.bz2
app_list: Add page transition animation for apps grid.
- Add transition data to PaginationModel to indicate a partial page switch; - Add transition animation to PaginationModel; - Add unit test for animated and non-animated SelectPage; BUG=129772 TEST=Verify page switch has a push left/right transition animation on the grid and blue color animates from one button to another. Review URL: https://chromiumcodereview.appspot.com/10535095 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@141522 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/app_list/pagination_model.h')
-rw-r--r--ui/app_list/pagination_model.h73
1 files changed, 62 insertions, 11 deletions
diff --git a/ui/app_list/pagination_model.h b/ui/app_list/pagination_model.h
index 39820d8..bcf6321 100644
--- a/ui/app_list/pagination_model.h
+++ b/ui/app_list/pagination_model.h
@@ -6,9 +6,16 @@
#define UI_APP_LIST_PAGINATION_MODEL_H_
#pragma once
-#include "ui/app_list/app_list_export.h"
#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/memory/scoped_ptr.h"
#include "base/observer_list.h"
+#include "ui/app_list/app_list_export.h"
+#include "ui/base/animation/animation_delegate.h"
+
+namespace ui {
+class SlideAnimation;
+}
namespace app_list {
@@ -17,28 +24,72 @@ class PaginationModelObserver;
// A simple pagination model that consists of two numbers: the total pages and
// the currently selected page. The model is a single selection model that at
// the most one page can become selected at any time.
-class APP_LIST_EXPORT PaginationModel {
+class APP_LIST_EXPORT PaginationModel : public ui::AnimationDelegate {
public:
+ // Holds info for transition animation and touch scroll.
+ struct Transition {
+ Transition(int target_page, double progress)
+ : target_page(target_page),
+ progress(progress) {
+ }
+
+ bool operator==(const Transition& rhs) const {
+ return target_page == rhs.target_page && progress == rhs.progress;
+ }
+
+ // Target page for the transition or -1 if there is no target page. For
+ // page switcher, this is the target selected page. For touch scroll,
+ // this is usually the previous or next page (or -1 when there is no
+ // previous or next page).
+ int target_page;
+
+ // A [0, 1] progress indicates how much of the current page is being
+ // transitioned.
+ double progress;
+ };
+
PaginationModel();
- ~PaginationModel();
+ virtual ~PaginationModel();
void SetTotalPages(int total_pages);
- void SelectPage(int page);
+
+ // Selects a page. |animate| is true if the transition should be animated.
+ void SelectPage(int page, bool animate);
+
+ void SetTransition(const Transition& transition);
+ void SetTransitionDuration(int duration_ms);
void AddObserver(PaginationModelObserver* observer);
void RemoveObserver(PaginationModelObserver* observer);
- int total_pages() const {
- return total_pages_;
- }
-
- int selected_page() const {
- return selected_page_;
- }
+ int total_pages() const { return total_pages_; }
+ int selected_page() const { return selected_page_; }
+ const Transition& transition() const { return transition_; }
private:
+ void NotifySelectedPageChanged(int old_selected, int new_selected);
+ void NotifyTransitionChanged();
+
+ void StartTranstionAnimation(int target_page);
+ void ResetTranstionAnimation();
+
+ // ui::AnimationDelegate overrides:
+ virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
+ virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
+
int total_pages_;
int selected_page_;
+
+ Transition transition_;
+
+ // Pending selected page when SelectedPage is called during a transition. If
+ // multiple SelectPage is called while a transition is in progress, only the
+ // last target page is remembered here.
+ int pending_selected_page_;
+
+ scoped_ptr<ui::SlideAnimation> transition_animation_;
+ int transition_duration_ms_; // Transition duration in millisecond.
+
ObserverList<PaginationModelObserver> observers_;
DISALLOW_COPY_AND_ASSIGN(PaginationModel);