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 #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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
66 } | 66 } |
67 | 67 |
68 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); | 68 apps_container_view_ = new AppsContainerView(app_list_main_view_, model); |
69 | 69 |
70 AddLauncherPage( | 70 AddLauncherPage( |
71 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); | 71 apps_container_view_, IDR_APP_LIST_APPS_ICON, NAMED_PAGE_APPS); |
72 | 72 |
73 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() | 73 int initial_page_index = app_list::switches::IsExperimentalAppListEnabled() |
74 ? GetPageIndexForNamedPage(NAMED_PAGE_START) | 74 ? GetPageIndexForNamedPage(NAMED_PAGE_START) |
75 : GetPageIndexForNamedPage(NAMED_PAGE_APPS); | 75 : GetPageIndexForNamedPage(NAMED_PAGE_APPS); |
76 DCHECK_GE(initial_page_index, 0); | |
76 | 77 |
77 page_before_search_ = initial_page_index; | 78 page_before_search_ = initial_page_index; |
78 pagination_model_.SelectPage(initial_page_index, false); | 79 pagination_model_.SelectPage(initial_page_index, false); |
79 | 80 |
80 // Needed to update the main search box visibility. | 81 // Needed to update the main search box visibility. |
81 ActivePageChanged(false); | 82 ActivePageChanged(false); |
82 } | 83 } |
83 | 84 |
84 void ContentsView::CancelDrag() { | 85 void ContentsView::CancelDrag() { |
85 if (apps_container_view_->apps_grid_view()->has_dragged_view()) | 86 if (apps_container_view_->apps_grid_view()->has_dragged_view()) |
(...skipping 25 matching lines...) Expand all Loading... | |
111 | 112 |
112 SetActivePageInternal(page_index, false); | 113 SetActivePageInternal(page_index, false); |
113 } | 114 } |
114 | 115 |
115 int ContentsView::GetActivePageIndex() const { | 116 int ContentsView::GetActivePageIndex() const { |
116 // The active page is changed at the beginning of an animation, not the end. | 117 // The active page is changed at the beginning of an animation, not the end. |
117 return pagination_model_.SelectedTargetPage(); | 118 return pagination_model_.SelectedTargetPage(); |
118 } | 119 } |
119 | 120 |
120 bool ContentsView::IsNamedPageActive(NamedPage named_page) const { | 121 bool ContentsView::IsNamedPageActive(NamedPage named_page) const { |
121 std::map<NamedPage, int>::const_iterator it = | 122 int active_page_index = GetActivePageIndex(); |
122 named_page_to_view_.find(named_page); | 123 return active_page_index >= 0 && |
123 if (it == named_page_to_view_.end()) | 124 GetPageIndexForNamedPage(named_page) == active_page_index; |
124 return false; | |
125 return it->second == GetActivePageIndex(); | |
126 } | 125 } |
127 | 126 |
128 int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const { | 127 int ContentsView::GetPageIndexForNamedPage(NamedPage named_page) const { |
129 // Find the index of the view corresponding to the given named_page. | 128 // Find the index of the view corresponding to the given named_page. |
130 std::map<NamedPage, int>::const_iterator it = | 129 std::map<NamedPage, int>::const_iterator it = |
131 named_page_to_view_.find(named_page); | 130 named_page_to_view_.find(named_page); |
132 // GetPageIndexForNamedPage should never be called on a named_page that does | 131 if (it == named_page_to_view_.end()) |
133 // not have a corresponding view. | 132 return -1; |
134 DCHECK(it != named_page_to_view_.end()); | 133 |
135 return it->second; | 134 return it->second; |
136 } | 135 } |
137 | 136 |
138 int ContentsView::NumLauncherPages() const { | 137 int ContentsView::NumLauncherPages() const { |
139 return pagination_model_.total_pages(); | 138 return pagination_model_.total_pages(); |
140 } | 139 } |
141 | 140 |
142 void ContentsView::SetActivePageInternal(int page_index, | 141 void ContentsView::SetActivePageInternal(int page_index, |
143 bool show_search_results) { | 142 bool show_search_results) { |
144 if (!show_search_results) | 143 if (!show_search_results) |
(...skipping 21 matching lines...) Expand all Loading... | |
166 | 165 |
167 // Notify parent AppListMainView of the page change. | 166 // Notify parent AppListMainView of the page change. |
168 app_list_main_view_->UpdateSearchBoxVisibility(); | 167 app_list_main_view_->UpdateSearchBoxVisibility(); |
169 } | 168 } |
170 | 169 |
171 void ContentsView::ShowSearchResults(bool show) { | 170 void ContentsView::ShowSearchResults(bool show) { |
172 int search_page = GetPageIndexForNamedPage( | 171 int search_page = GetPageIndexForNamedPage( |
173 app_list::switches::IsExperimentalAppListEnabled() | 172 app_list::switches::IsExperimentalAppListEnabled() |
174 ? NAMED_PAGE_START | 173 ? NAMED_PAGE_START |
175 : NAMED_PAGE_SEARCH_RESULTS); | 174 : NAMED_PAGE_SEARCH_RESULTS); |
175 DCHECK_GE(search_page, 0); | |
176 | 176 |
177 SetActivePageInternal(show ? search_page : page_before_search_, show); | 177 SetActivePageInternal(show ? search_page : page_before_search_, show); |
178 } | 178 } |
179 | 179 |
180 bool ContentsView::IsShowingSearchResults() const { | 180 bool ContentsView::IsShowingSearchResults() const { |
181 return app_list::switches::IsExperimentalAppListEnabled() | 181 return app_list::switches::IsExperimentalAppListEnabled() |
182 ? IsNamedPageActive(NAMED_PAGE_START) && | 182 ? IsNamedPageActive(NAMED_PAGE_START) && |
183 start_page_view_->IsShowingSearchResults() | 183 start_page_view_->IsShowingSearchResults() |
184 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); | 184 : IsNamedPageActive(NAMED_PAGE_SEARCH_RESULTS); |
185 } | 185 } |
186 | 186 |
187 gfx::Rect ContentsView::GetOffscreenPageBounds(int page_index) const { | |
188 gfx::Rect bounds(GetContentsBounds()); | |
189 // The start page and search page origins are above; all other pages' origins | |
190 // are below. | |
191 int page_height = bounds.height(); | |
192 bool origin_above = | |
193 GetPageIndexForNamedPage(NAMED_PAGE_START) == page_index || | |
194 GetPageIndexForNamedPage(NAMED_PAGE_SEARCH_RESULTS) == page_index; | |
195 bounds.set_y(origin_above ? -page_height : page_height); | |
196 return bounds; | |
197 } | |
198 | |
187 void ContentsView::UpdatePageBounds() { | 199 void ContentsView::UpdatePageBounds() { |
188 gfx::Rect rect(GetContentsBounds()); | |
189 if (rect.IsEmpty()) | |
190 return; | |
191 | |
192 // The bounds calculations will potentially be mid-transition (depending on | 200 // The bounds calculations will potentially be mid-transition (depending on |
193 // the state of the PaginationModel). | 201 // the state of the PaginationModel). |
194 int current_page = std::max(0, pagination_model_.selected_page()); | 202 int current_page = std::max(0, pagination_model_.selected_page()); |
195 int target_page = current_page; | 203 int target_page = current_page; |
196 double progress = 1; | 204 double progress = 1; |
197 if (pagination_model_.has_transition()) { | 205 if (pagination_model_.has_transition()) { |
198 const PaginationModel::Transition& transition = | 206 const PaginationModel::Transition& transition = |
199 pagination_model_.transition(); | 207 pagination_model_.transition(); |
200 if (pagination_model_.is_valid_page(transition.target_page)) { | 208 if (pagination_model_.is_valid_page(transition.target_page)) { |
201 target_page = transition.target_page; | 209 target_page = transition.target_page; |
202 progress = transition.progress; | 210 progress = transition.progress; |
203 } | 211 } |
204 } | 212 } |
205 | 213 |
206 gfx::Rect incoming_target(rect); | 214 // Move |current_page| from 0 to its origin. Move |target_page| from its |
207 gfx::Rect outgoing_target(rect); | 215 // origin to 0. |
208 int dir = target_page > current_page ? -1 : 1; | 216 gfx::Rect current_page_rect(GetOffscreenPageBounds(current_page)); |
217 gfx::Rect target_page_rect(GetOffscreenPageBounds(target_page)); | |
218 current_page_rect.set_x(progress * current_page_rect.x()); | |
219 current_page_rect.set_y(progress * current_page_rect.y()); | |
220 target_page_rect.set_x((1 - progress) * target_page_rect.x()); | |
221 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
| |
209 | 222 |
210 // Pages transition vertically. | 223 view_model_->view_at(current_page)->SetBoundsRect(current_page_rect); |
211 int page_height = rect.height(); | 224 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 } | 225 } |
221 | 226 |
222 PaginationModel* ContentsView::GetAppsPaginationModel() { | 227 PaginationModel* ContentsView::GetAppsPaginationModel() { |
223 return apps_container_view_->apps_grid_view()->pagination_model(); | 228 return apps_container_view_->apps_grid_view()->pagination_model(); |
224 } | 229 } |
225 | 230 |
226 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 231 void ContentsView::ShowFolderContent(AppListFolderItem* item) { |
227 apps_container_view_->ShowActiveFolder(item); | 232 apps_container_view_->ShowActiveFolder(item); |
228 } | 233 } |
229 | 234 |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 } | 305 } |
301 | 306 |
302 void ContentsView::TransitionStarted() { | 307 void ContentsView::TransitionStarted() { |
303 } | 308 } |
304 | 309 |
305 void ContentsView::TransitionChanged() { | 310 void ContentsView::TransitionChanged() { |
306 UpdatePageBounds(); | 311 UpdatePageBounds(); |
307 } | 312 } |
308 | 313 |
309 } // namespace app_list | 314 } // namespace app_list |
OLD | NEW |