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 #ifndef UI_APP_LIST_PAGINATION_MODEL_H_ | 5 #ifndef UI_APP_LIST_PAGINATION_MODEL_H_ |
6 #define UI_APP_LIST_PAGINATION_MODEL_H_ | 6 #define UI_APP_LIST_PAGINATION_MODEL_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/observer_list.h" | 11 #include "base/observer_list.h" |
12 #include "base/time/time.h" | 12 #include "base/time/time.h" |
13 #include "ui/app_list/app_list_export.h" | 13 #include "ui/app_list/app_list_export.h" |
14 #include "ui/base/animation/animation_delegate.h" | 14 #include "ui/gfx/animation/animation_delegate.h" |
15 | 15 |
16 namespace ui { | 16 namespace gfx { |
17 class SlideAnimation; | 17 class SlideAnimation; |
18 } | 18 } |
19 | 19 |
20 namespace app_list { | 20 namespace app_list { |
21 | 21 |
22 class PaginationModelObserver; | 22 class PaginationModelObserver; |
23 | 23 |
24 // A simple pagination model that consists of two numbers: the total pages and | 24 // A simple pagination model that consists of two numbers: the total pages and |
25 // the currently selected page. The model is a single selection model that at | 25 // the currently selected page. The model is a single selection model that at |
26 // the most one page can become selected at any time. | 26 // the most one page can become selected at any time. |
27 class APP_LIST_EXPORT PaginationModel : public ui::AnimationDelegate { | 27 class APP_LIST_EXPORT PaginationModel : public gfx::AnimationDelegate { |
28 public: | 28 public: |
29 // Holds info for transition animation and touch scroll. | 29 // Holds info for transition animation and touch scroll. |
30 struct Transition { | 30 struct Transition { |
31 Transition(int target_page, double progress) | 31 Transition(int target_page, double progress) |
32 : target_page(target_page), | 32 : target_page(target_page), |
33 progress(progress) { | 33 progress(progress) { |
34 } | 34 } |
35 | 35 |
36 bool Equals(const Transition& rhs) const { | 36 bool Equals(const Transition& rhs) const { |
37 return target_page == rhs.target_page && progress == rhs.progress; | 37 return target_page == rhs.target_page && progress == rhs.progress; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 // When there is no transition, current page is the currently selected page. | 106 // When there is no transition, current page is the currently selected page. |
107 // If there is a transition, current page is the transition target page or the | 107 // If there is a transition, current page is the transition target page or the |
108 // pending transition target page. When current page + |delta| goes beyond | 108 // pending transition target page. When current page + |delta| goes beyond |
109 // valid range and |selected_page_| is at the range ends, invalid page number | 109 // valid range and |selected_page_| is at the range ends, invalid page number |
110 // -1 or |total_pages_| is returned to indicate the situation. | 110 // -1 or |total_pages_| is returned to indicate the situation. |
111 int CalculateTargetPage(int delta) const; | 111 int CalculateTargetPage(int delta) const; |
112 | 112 |
113 void StartTransitionAnimation(const Transition& transition); | 113 void StartTransitionAnimation(const Transition& transition); |
114 void ResetTransitionAnimation(); | 114 void ResetTransitionAnimation(); |
115 | 115 |
116 // ui::AnimationDelegate overrides: | 116 // gfx::AnimationDelegate overrides: |
117 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 117 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
118 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 118 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; |
119 | 119 |
120 int total_pages_; | 120 int total_pages_; |
121 int selected_page_; | 121 int selected_page_; |
122 | 122 |
123 Transition transition_; | 123 Transition transition_; |
124 | 124 |
125 // Pending selected page when SelectedPage is called during a transition. If | 125 // Pending selected page when SelectedPage is called during a transition. If |
126 // multiple SelectPage is called while a transition is in progress, only the | 126 // multiple SelectPage is called while a transition is in progress, only the |
127 // last target page is remembered here. | 127 // last target page is remembered here. |
128 int pending_selected_page_; | 128 int pending_selected_page_; |
129 | 129 |
130 scoped_ptr<ui::SlideAnimation> transition_animation_; | 130 scoped_ptr<gfx::SlideAnimation> transition_animation_; |
131 int transition_duration_ms_; // Transition duration in millisecond. | 131 int transition_duration_ms_; // Transition duration in millisecond. |
132 int overscroll_transition_duration_ms_; | 132 int overscroll_transition_duration_ms_; |
133 | 133 |
134 int last_overscroll_target_page_; | 134 int last_overscroll_target_page_; |
135 base::TimeTicks last_overscroll_animation_start_time_; | 135 base::TimeTicks last_overscroll_animation_start_time_; |
136 | 136 |
137 ObserverList<PaginationModelObserver> observers_; | 137 ObserverList<PaginationModelObserver> observers_; |
138 | 138 |
139 DISALLOW_COPY_AND_ASSIGN(PaginationModel); | 139 DISALLOW_COPY_AND_ASSIGN(PaginationModel); |
140 }; | 140 }; |
141 | 141 |
142 } // namespace app_list | 142 } // namespace app_list |
143 | 143 |
144 #endif // UI_APP_LIST_PAGINATION_MODEL_H_ | 144 #endif // UI_APP_LIST_PAGINATION_MODEL_H_ |
OLD | NEW |