Chromium Code Reviews| 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 19c9dd93836895343e2c8637f186e69053dbf31e..f306ce427bb54d3090ede2b24f65e432e842a8af 100644 |
| --- a/ui/app_list/views/contents_view.cc |
| +++ b/ui/app_list/views/contents_view.cc |
| @@ -73,6 +73,7 @@ void ContentsView::InitNamedPages(AppListModel* model, |
| int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() |
| ? GetPageIndexForNamedPage(NAMED_PAGE_START) |
| : GetPageIndexForNamedPage(NAMED_PAGE_APPS); |
| + DCHECK_GE(initial_page_index, 0); |
| page_before_search_ = initial_page_index; |
| pagination_model_.SelectPage(initial_page_index, false); |
| @@ -118,20 +119,18 @@ int ContentsView::GetActivePageIndex() const { |
| } |
| bool ContentsView::IsNamedPageActive(NamedPage named_page) const { |
| - std::map<NamedPage, int>::const_iterator it = |
| - named_page_to_view_.find(named_page); |
| - if (it == named_page_to_view_.end()) |
| - return false; |
| - return it->second == GetActivePageIndex(); |
| + int active_page_index = GetActivePageIndex(); |
| + return active_page_index >= 0 && |
| + GetPageIndexForNamedPage(named_page) == active_page_index; |
| } |
| int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const { |
| // Find the index of the view corresponding to the given named_page. |
| std::map<NamedPage, int>::const_iterator it = |
| named_page_to_view_.find(named_page); |
| - // GetPageIndexForNamedPage should never be called on a named_page that does |
| - // not have a corresponding view. |
| - DCHECK(it != named_page_to_view_.end()); |
| + if (it == named_page_to_view_.end()) |
| + return -1; |
| + |
| return it->second; |
| } |
| @@ -173,6 +172,7 @@ void ContentsView::ShowSearchResults(bool show) { |
| app_list::switches::IsExperimentalAppListEnabled() |
| ? NAMED_PAGE_START |
| : NAMED_PAGE_SEARCH_RESULTS); |
| + DCHECK_GE(search_page, 0); |
| SetActivePageInternal(show ? search_page : page_before_search_, show); |
| } |
| @@ -184,11 +184,19 @@ bool ContentsView::IsShowingSearchResults() const { |
| : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); |
| } |
| -void ContentsView::UpdatePageBounds() { |
| - gfx::Rect rect(GetContentsBounds()); |
| - if (rect.IsEmpty()) |
| - return; |
| +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 = |
| + GetPageIndexForNamedPage(NAMED_PAGE_START) == page_index || |
| + GetPageIndexForNamedPage(NAMED_PAGE_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). |
| int current_page = std::max(0, pagination_model_.selected_page()); |
| @@ -203,20 +211,17 @@ void ContentsView::UpdatePageBounds() { |
| } |
| } |
| - gfx::Rect incoming_target(rect); |
| - gfx::Rect outgoing_target(rect); |
| - int dir = target_page > current_page ? -1 : 1; |
| - |
| - // Pages transition vertically. |
| - int page_height = rect.height(); |
| - int transition_offset = progress * page_height * dir; |
| - |
| - outgoing_target.set_y(transition_offset); |
| - incoming_target.set_y(dir < 0 ? transition_offset + page_height |
| - : transition_offset - page_height); |
| - |
| - view_model_->view_at(current_page)->SetBoundsRect(outgoing_target); |
| - view_model_->view_at(target_page)->SetBoundsRect(incoming_target); |
| + // Move |current_page| from 0 to its origin. Move |target_page| from its |
| + // origin to 0. |
| + gfx::Rect current_page_rect(GetOffscreenPageBounds(current_page)); |
| + gfx::Rect target_page_rect(GetOffscreenPageBounds(target_page)); |
| + current_page_rect.set_x(progress * current_page_rect.x()); |
| + current_page_rect.set_y(progress * current_page_rect.y()); |
| + target_page_rect.set_x((1 - progress) * target_page_rect.x()); |
| + target_page_rect.set_y((1 - progress) * target_page_rect.y()); |
|
calamity
2014/09/10 04:37:21
Use gfx::RectValueBetween().
Matt Giuca
2014/09/10 04:53:33
Done.
(Thanks, I was looking for something like t
|
| + |
| + view_model_->view_at(current_page)->SetBoundsRect(current_page_rect); |
| + view_model_->view_at(target_page)->SetBoundsRect(target_page_rect); |
| } |
| PaginationModel* ContentsView::GetAppsPaginationModel() { |