OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_animator.h" | 5 #include "ui/app_list/views/contents_animator.h" |
6 | 6 |
7 #include "ui/app_list/app_list_constants.h" | 7 #include "ui/app_list/app_list_constants.h" |
8 #include "ui/app_list/app_list_switches.h" | 8 #include "ui/app_list/app_list_switches.h" |
9 #include "ui/app_list/views/app_list_main_view.h" | 9 #include "ui/app_list/views/app_list_main_view.h" |
10 #include "ui/app_list/views/contents_view.h" | 10 #include "ui/app_list/views/contents_view.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 | 29 |
30 // ContentsAnimator | 30 // ContentsAnimator |
31 | 31 |
32 ContentsAnimator::ContentsAnimator(ContentsView* contents_view) | 32 ContentsAnimator::ContentsAnimator(ContentsView* contents_view) |
33 : contents_view_(contents_view) { | 33 : contents_view_(contents_view) { |
34 } | 34 } |
35 | 35 |
36 ContentsAnimator::~ContentsAnimator() { | 36 ContentsAnimator::~ContentsAnimator() { |
37 } | 37 } |
38 | 38 |
39 gfx::Rect ContentsAnimator::GetOnscreenPageBounds(int page_index) const { | |
40 return contents_view_->GetPageIndexForState( | |
41 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) == page_index | |
42 ? contents_view_->GetContentsBounds() | |
43 : contents_view_->GetDefaultContentsBounds(); | |
44 } | |
45 | |
46 gfx::Rect ContentsAnimator::GetOffscreenPageBounds(int page_index) const { | |
47 gfx::Rect bounds(GetOnscreenPageBounds(page_index)); | |
48 // The start page and search page origins are above; all other pages' origins | |
49 // are below. | |
50 bool origin_above = contents_view_->GetPageIndexForState( | |
51 AppListModel::STATE_START) == page_index || | |
52 contents_view_->GetPageIndexForState( | |
53 AppListModel::STATE_SEARCH_RESULTS) == page_index; | |
54 bounds.set_y(origin_above | |
55 ? -bounds.height() | |
56 : contents_view_->GetContentsBounds().height() + bounds.y()); | |
57 return bounds; | |
58 } | |
59 | |
60 void ContentsAnimator::UpdateCustomPageForDefaultAnimation(double progress, | 39 void ContentsAnimator::UpdateCustomPageForDefaultAnimation(double progress, |
61 int from_page, | 40 int from_page, |
62 int to_page) const { | 41 int to_page) const { |
63 int custom_page_index = contents_view()->GetPageIndexForState( | 42 int custom_page_index = contents_view()->GetPageIndexForState( |
64 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); | 43 AppListModel::STATE_CUSTOM_LAUNCHER_PAGE); |
65 if (custom_page_index < 0) | 44 if (custom_page_index < 0) |
66 return; | 45 return; |
67 | 46 |
68 int start_page_index = | 47 int start_page_index = |
69 contents_view()->GetPageIndexForState(AppListModel::STATE_START); | 48 contents_view()->GetPageIndexForState(AppListModel::STATE_START); |
70 if (from_page != start_page_index && to_page != start_page_index) | 49 if (from_page != start_page_index && to_page != start_page_index) |
71 return; | 50 return; |
72 | 51 |
73 views::View* custom_page = contents_view()->GetPageView(custom_page_index); | 52 views::View* custom_page = contents_view()->GetPageView(custom_page_index); |
74 gfx::Rect custom_page_collapsed( | 53 gfx::Rect custom_page_collapsed( |
75 contents_view()->GetCustomPageCollapsedBounds()); | 54 contents_view()->GetCustomPageCollapsedBounds()); |
76 gfx::Rect custom_page_origin(GetOffscreenPageBounds(custom_page_index)); | 55 gfx::Rect custom_page_origin( |
| 56 contents_view()->GetOffscreenPageBounds(custom_page_index)); |
77 gfx::Rect custom_page_rect; | 57 gfx::Rect custom_page_rect; |
78 | 58 |
79 if (from_page == start_page_index) { | 59 if (from_page == start_page_index) { |
80 // When transitioning from start page -> any other page, move the custom | 60 // When transitioning from start page -> any other page, move the custom |
81 // page from collapsed to hidden. (This method is not used by the start page | 61 // page from collapsed to hidden. (This method is not used by the start page |
82 // -> custom page transition.) | 62 // -> custom page transition.) |
83 custom_page_rect = gfx::Tween::RectValueBetween( | 63 custom_page_rect = gfx::Tween::RectValueBetween( |
84 progress, custom_page_collapsed, custom_page_origin); | 64 progress, custom_page_collapsed, custom_page_origin); |
85 } else { | 65 } else { |
86 // When transitioning from any page -> start page, move the custom page from | 66 // When transitioning from any page -> start page, move the custom page from |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 : ContentsAnimator(contents_view) { | 130 : ContentsAnimator(contents_view) { |
151 } | 131 } |
152 | 132 |
153 std::string DefaultAnimator::NameForTests() const { | 133 std::string DefaultAnimator::NameForTests() const { |
154 return "DefaultAnimator"; | 134 return "DefaultAnimator"; |
155 } | 135 } |
156 | 136 |
157 void DefaultAnimator::Update(double progress, int from_page, int to_page) { | 137 void DefaultAnimator::Update(double progress, int from_page, int to_page) { |
158 // Move the from page from 0 to its origin. Move the to page from its origin | 138 // Move the from page from 0 to its origin. Move the to page from its origin |
159 // to 0. | 139 // to 0. |
160 gfx::Rect from_page_onscreen(GetOnscreenPageBounds(from_page)); | 140 gfx::Rect from_page_onscreen( |
161 gfx::Rect to_page_onscreen(GetOnscreenPageBounds(to_page)); | 141 contents_view()->GetOnscreenPageBounds(from_page)); |
162 gfx::Rect from_page_origin(GetOffscreenPageBounds(from_page)); | 142 gfx::Rect to_page_onscreen(contents_view()->GetOnscreenPageBounds(to_page)); |
163 gfx::Rect to_page_origin(GetOffscreenPageBounds(to_page)); | 143 gfx::Rect from_page_origin( |
| 144 contents_view()->GetOffscreenPageBounds(from_page)); |
| 145 gfx::Rect to_page_origin(contents_view()->GetOffscreenPageBounds(to_page)); |
164 gfx::Rect from_page_rect(gfx::Tween::RectValueBetween( | 146 gfx::Rect from_page_rect(gfx::Tween::RectValueBetween( |
165 progress, from_page_onscreen, from_page_origin)); | 147 progress, from_page_onscreen, from_page_origin)); |
166 gfx::Rect to_page_rect( | 148 gfx::Rect to_page_rect( |
167 gfx::Tween::RectValueBetween(progress, to_page_origin, to_page_onscreen)); | 149 gfx::Tween::RectValueBetween(progress, to_page_origin, to_page_onscreen)); |
168 | 150 |
169 contents_view()->GetPageView(from_page)->SetBoundsRect(from_page_rect); | 151 contents_view()->GetPageView(from_page)->SetBoundsRect(from_page_rect); |
170 ClipSearchResultsPageToOnscreenBounds(from_page, from_page_rect, | 152 ClipSearchResultsPageToOnscreenBounds(from_page, from_page_rect, |
171 from_page_onscreen); | 153 from_page_onscreen); |
172 | 154 |
173 contents_view()->GetPageView(to_page)->SetBoundsRect(to_page_rect); | 155 contents_view()->GetPageView(to_page)->SetBoundsRect(to_page_rect); |
(...skipping 12 matching lines...) Expand all Loading... |
186 | 168 |
187 std::string StartToAppsAnimator::NameForTests() const { | 169 std::string StartToAppsAnimator::NameForTests() const { |
188 return "StartToAppsAnimator"; | 170 return "StartToAppsAnimator"; |
189 } | 171 } |
190 | 172 |
191 void StartToAppsAnimator::Update(double progress, | 173 void StartToAppsAnimator::Update(double progress, |
192 int start_page, | 174 int start_page, |
193 int apps_page) { | 175 int apps_page) { |
194 // TODO(mgiuca): This is just a clone of DefaultAnimator's animation. Write a | 176 // TODO(mgiuca): This is just a clone of DefaultAnimator's animation. Write a |
195 // custom animation for the All Apps button on the Start page. | 177 // custom animation for the All Apps button on the Start page. |
196 gfx::Rect on_screen(contents_view()->GetDefaultContentsBounds()); | 178 gfx::Rect from_page_onscreen( |
197 gfx::Rect from_page_origin(GetOffscreenPageBounds(start_page)); | 179 contents_view()->GetOnscreenPageBounds(start_page)); |
198 gfx::Rect to_page_origin(GetOffscreenPageBounds(apps_page)); | 180 gfx::Rect to_page_onscreen(contents_view()->GetOnscreenPageBounds(apps_page)); |
199 gfx::Rect from_page_rect( | 181 gfx::Rect from_page_origin( |
200 gfx::Tween::RectValueBetween(progress, on_screen, from_page_origin)); | 182 contents_view()->GetOffscreenPageBounds(start_page)); |
| 183 gfx::Rect to_page_origin(contents_view()->GetOffscreenPageBounds(apps_page)); |
| 184 gfx::Rect from_page_rect(gfx::Tween::RectValueBetween( |
| 185 progress, from_page_onscreen, from_page_origin)); |
201 gfx::Rect to_page_rect( | 186 gfx::Rect to_page_rect( |
202 gfx::Tween::RectValueBetween(progress, to_page_origin, on_screen)); | 187 gfx::Tween::RectValueBetween(progress, to_page_origin, to_page_onscreen)); |
203 | 188 |
204 contents_view()->GetPageView(start_page)->SetBoundsRect(from_page_rect); | 189 contents_view()->GetPageView(start_page)->SetBoundsRect(from_page_rect); |
205 contents_view()->GetPageView(apps_page)->SetBoundsRect(to_page_rect); | 190 contents_view()->GetPageView(apps_page)->SetBoundsRect(to_page_rect); |
206 | 191 |
207 UpdateCustomPageForDefaultAnimation(progress, start_page, apps_page); | 192 UpdateCustomPageForDefaultAnimation(progress, start_page, apps_page); |
208 UpdateSearchBoxForDefaultAnimation(progress, start_page, apps_page); | 193 UpdateSearchBoxForDefaultAnimation(progress, start_page, apps_page); |
209 } | 194 } |
210 | 195 |
211 // StartToCustomAnimator | 196 // StartToCustomAnimator |
212 | 197 |
213 StartToCustomAnimator::StartToCustomAnimator(ContentsView* contents_view) | 198 StartToCustomAnimator::StartToCustomAnimator(ContentsView* contents_view) |
214 : ContentsAnimator(contents_view) { | 199 : ContentsAnimator(contents_view) { |
215 } | 200 } |
216 | 201 |
217 std::string StartToCustomAnimator::NameForTests() const { | 202 std::string StartToCustomAnimator::NameForTests() const { |
218 return "StartToCustomAnimator"; | 203 return "StartToCustomAnimator"; |
219 } | 204 } |
220 | 205 |
221 void StartToCustomAnimator::Update(double progress, | 206 void StartToCustomAnimator::Update(double progress, |
222 int start_page, | 207 int start_page, |
223 int custom_page) { | 208 int custom_page) { |
224 gfx::Rect start_page_on_screen(GetOnscreenPageBounds(start_page)); | 209 gfx::Rect start_page_on_screen( |
225 gfx::Rect custom_page_on_screen(GetOnscreenPageBounds(custom_page)); | 210 contents_view()->GetOnscreenPageBounds(start_page)); |
226 gfx::Rect start_page_origin(GetOffscreenPageBounds(start_page)); | 211 gfx::Rect custom_page_on_screen( |
| 212 contents_view()->GetOnscreenPageBounds(custom_page)); |
| 213 gfx::Rect start_page_origin( |
| 214 contents_view()->GetOffscreenPageBounds(start_page)); |
227 gfx::Rect custom_page_origin(contents_view()->GetCustomPageCollapsedBounds()); | 215 gfx::Rect custom_page_origin(contents_view()->GetCustomPageCollapsedBounds()); |
228 gfx::Rect start_page_rect(gfx::Tween::RectValueBetween( | 216 gfx::Rect start_page_rect(gfx::Tween::RectValueBetween( |
229 progress, start_page_on_screen, start_page_origin)); | 217 progress, start_page_on_screen, start_page_origin)); |
230 gfx::Rect custom_page_rect(gfx::Tween::RectValueBetween( | 218 gfx::Rect custom_page_rect(gfx::Tween::RectValueBetween( |
231 progress, custom_page_origin, custom_page_on_screen)); | 219 progress, custom_page_origin, custom_page_on_screen)); |
232 | 220 |
233 contents_view()->GetPageView(start_page)->SetBoundsRect(start_page_rect); | 221 contents_view()->GetPageView(start_page)->SetBoundsRect(start_page_rect); |
234 contents_view()->GetPageView(custom_page)->SetBoundsRect(custom_page_rect); | 222 contents_view()->GetPageView(custom_page)->SetBoundsRect(custom_page_rect); |
235 | 223 |
236 UpdateSearchBoxForDefaultAnimation(progress, start_page, custom_page); | 224 UpdateSearchBoxForDefaultAnimation(progress, start_page, custom_page); |
237 } | 225 } |
238 | 226 |
239 } // namespace app_list | 227 } // namespace app_list |
OLD | NEW |