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

Side by Side Diff: ui/app_list/views/contents_view.cc

Issue 555753002: Experimental app list: Change transition animations of top-level pages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix crash for non-experimental app list and retain old behaviour. Created 6 years, 3 months 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 unified diff | Download patch
OLDNEW
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"
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 111
112 SetActivePageInternal(page_index, false); 112 SetActivePageInternal(page_index, false);
113 } 113 }
114 114
115 int ContentsView::GetActivePageIndex() const { 115 int ContentsView::GetActivePageIndex() const {
116 // The active page is changed at the beginning of an animation, not the end. 116 // The active page is changed at the beginning of an animation, not the end.
117 return pagination_model_.SelectedTargetPage(); 117 return pagination_model_.SelectedTargetPage();
118 } 118 }
119 119
120 bool ContentsView::IsNamedPageActive(NamedPage named_page) const { 120 bool ContentsView::IsNamedPageActive(NamedPage named_page) const {
121 return IndexIsNamedPage(GetActivePageIndex(), named_page);
122 }
123
124 bool ContentsView::IndexIsNamedPage(int page_index,
125 NamedPage named_page) const {
126 // Find the index of the view corresponding to the given named_page.
121 std::map<NamedPage, int>::const_iterator it = 127 std::map<NamedPage, int>::const_iterator it =
122 named_page_to_view_.find(named_page); 128 named_page_to_view_.find(named_page);
123 if (it == named_page_to_view_.end()) 129 if (it == named_page_to_view_.end())
124 return false; 130 return false;
125 return it->second == GetActivePageIndex(); 131 return it->second == page_index;
126 } 132 }
127 133
128 int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const { 134 int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const {
129 // Find the index of the view corresponding to the given named_page. 135 // Find the index of the view corresponding to the given named_page.
130 std::map<NamedPage, int>::const_iterator it = 136 std::map<NamedPage, int>::const_iterator it =
131 named_page_to_view_.find(named_page); 137 named_page_to_view_.find(named_page);
132 // GetPageIndexForNamedPage should never be called on a named_page that does 138 // GetPageIndexForNamedPage should never be called on a named_page that does
133 // not have a corresponding view. 139 // not have a corresponding view.
134 DCHECK(it != named_page_to_view_.end()); 140 DCHECK(it != named_page_to_view_.end());
135 return it->second; 141 return it->second;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 SetActivePageInternal(show ? search_page : page_before_search_, show); 183 SetActivePageInternal(show ? search_page : page_before_search_, show);
178 } 184 }
179 185
180 bool ContentsView::IsShowingSearchResults() const { 186 bool ContentsView::IsShowingSearchResults() const {
181 return app_list::switches::IsExperimentalAppListEnabled() 187 return app_list::switches::IsExperimentalAppListEnabled()
182 ? IsNamedPageActive(NAMED_PAGE_START) && 188 ? IsNamedPageActive(NAMED_PAGE_START) &&
183 start_page_view_->IsShowingSearchResults() 189 start_page_view_->IsShowingSearchResults()
184 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); 190 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS);
185 } 191 }
186 192
193 int ContentsView::PageOrigin(const gfx::Rect& bounds, int page_index) const {
calamity 2014/09/10 01:56:40 This is cleaner without |bounds| and I don't think
Matt Giuca 2014/09/10 03:15:30 Done.
194 // The start page and search page origins are above; all other pages' origins
195 // are below.
196 int page_height = bounds.height();
197 bool origin_above = IndexIsNamedPage(page_index, NAMED_PAGE_START) ||
198 IndexIsNamedPage(page_index, NAMED_PAGE_SEARCH_RESULTS);
199 return origin_above ? -page_height : page_height;
200 }
201
187 void ContentsView::UpdatePageBounds() { 202 void ContentsView::UpdatePageBounds() {
188 gfx::Rect rect(GetContentsBounds()); 203 gfx::Rect rect(GetContentsBounds());
189 if (rect.IsEmpty()) 204 if (rect.IsEmpty())
190 return; 205 return;
191 206
192 // The bounds calculations will potentially be mid-transition (depending on 207 // The bounds calculations will potentially be mid-transition (depending on
193 // the state of the PaginationModel). 208 // the state of the PaginationModel).
194 int current_page = std::max(0, pagination_model_.selected_page()); 209 int current_page = std::max(0, pagination_model_.selected_page());
195 int target_page = current_page; 210 int target_page = current_page;
196 double progress = 1; 211 double progress = 1;
197 if (pagination_model_.has_transition()) { 212 if (pagination_model_.has_transition()) {
198 const PaginationModel::Transition& transition = 213 const PaginationModel::Transition& transition =
199 pagination_model_.transition(); 214 pagination_model_.transition();
200 if (pagination_model_.is_valid_page(transition.target_page)) { 215 if (pagination_model_.is_valid_page(transition.target_page)) {
201 target_page = transition.target_page; 216 target_page = transition.target_page;
202 progress = transition.progress; 217 progress = transition.progress;
203 } 218 }
204 } 219 }
205 220
206 gfx::Rect incoming_target(rect); 221 // Move |current_page| from 0 to its origin. Move |target_page| from its
207 gfx::Rect outgoing_target(rect); 222 // origin to 0.
208 int dir = target_page > current_page ? -1 : 1; 223 gfx::Rect current_page_rect(rect);
224 gfx::Rect target_page_rect(rect);
225 int current_page_origin = PageOrigin(rect, current_page);
226 int target_page_origin = PageOrigin(rect, target_page);
227 current_page_rect.set_y(progress * current_page_origin);
228 target_page_rect.set_y((1 - progress) * target_page_origin);
209 229
210 // Pages transition vertically. 230 view_model_->view_at(current_page)->SetBoundsRect(current_page_rect);
211 int page_height = rect.height(); 231 view_model_->view_at(target_page)->SetBoundsRect(target_page_rect);
212 int transition_offset = progress * page_height * dir;
213
214 outgoing_target.set_y(transition_offset);
215 incoming_target.set_y(dir < 0 ? transition_offset + page_height
216 : transition_offset - page_height);
217
218 view_model_->view_at(current_page)->SetBoundsRect(outgoing_target);
219 view_model_->view_at(target_page)->SetBoundsRect(incoming_target);
220 } 232 }
221 233
222 PaginationModel* ContentsView::GetAppsPaginationModel() { 234 PaginationModel* ContentsView::GetAppsPaginationModel() {
223 return apps_container_view_->apps_grid_view()->pagination_model(); 235 return apps_container_view_->apps_grid_view()->pagination_model();
224 } 236 }
225 237
226 void ContentsView::ShowFolderContent(AppListFolderItem* item) { 238 void ContentsView::ShowFolderContent(AppListFolderItem* item) {
227 apps_container_view_->ShowActiveFolder(item); 239 apps_container_view_->ShowActiveFolder(item);
228 } 240 }
229 241
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 312 }
301 313
302 void ContentsView::TransitionStarted() { 314 void ContentsView::TransitionStarted() {
303 } 315 }
304 316
305 void ContentsView::TransitionChanged() { 317 void ContentsView::TransitionChanged() {
306 UpdatePageBounds(); 318 UpdatePageBounds();
307 } 319 }
308 320
309 } // namespace app_list 321 } // namespace app_list
OLDNEW
« ui/app_list/views/contents_view.h ('K') | « ui/app_list/views/contents_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698