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