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 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 model->view_at(kIndexSearchResults)); | 46 model->view_at(kIndexSearchResults)); |
47 } | 47 } |
48 | 48 |
49 StartPageView* GetStartPageView(views::ViewModel* model) { | 49 StartPageView* GetStartPageView(views::ViewModel* model) { |
50 return static_cast<StartPageView*>(model->view_at(kIndexStartPage)); | 50 return static_cast<StartPageView*>(model->view_at(kIndexStartPage)); |
51 } | 51 } |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 ContentsView::ContentsView(AppListMainView* app_list_main_view, | 55 ContentsView::ContentsView(AppListMainView* app_list_main_view, |
56 PaginationModel* pagination_model, | |
57 AppListModel* model, | 56 AppListModel* model, |
58 AppListViewDelegate* view_delegate) | 57 AppListViewDelegate* view_delegate) |
59 : show_state_(SHOW_APPS), | 58 : show_state_(SHOW_APPS), |
60 pagination_model_(pagination_model), | |
61 start_page_view_(NULL), | 59 start_page_view_(NULL), |
62 app_list_main_view_(app_list_main_view), | 60 app_list_main_view_(app_list_main_view), |
63 view_model_(new views::ViewModel), | 61 view_model_(new views::ViewModel), |
64 bounds_animator_(new views::BoundsAnimator(this)) { | 62 bounds_animator_(new views::BoundsAnimator(this)) { |
65 DCHECK(model); | 63 DCHECK(model); |
66 pagination_model_->SetTransitionDurations( | |
67 kPageTransitionDurationInMs, | |
68 kOverscrollPageTransitionDurationMs); | |
69 | 64 |
70 apps_container_view_ = | 65 apps_container_view_ = new AppsContainerView(app_list_main_view, model); |
71 new AppsContainerView(app_list_main_view, pagination_model, model); | |
72 AddChildView(apps_container_view_); | 66 AddChildView(apps_container_view_); |
73 view_model_->Add(apps_container_view_, kIndexAppsContainer); | 67 view_model_->Add(apps_container_view_, kIndexAppsContainer); |
74 | 68 |
75 SearchResultListView* search_results_view = new SearchResultListView( | 69 SearchResultListView* search_results_view = new SearchResultListView( |
76 app_list_main_view, view_delegate); | 70 app_list_main_view, view_delegate); |
77 AddChildView(search_results_view); | 71 AddChildView(search_results_view); |
78 view_model_->Add(search_results_view, kIndexSearchResults); | 72 view_model_->Add(search_results_view, kIndexSearchResults); |
79 | 73 |
80 if (app_list::switches::IsExperimentalAppListEnabled()) { | 74 if (app_list::switches::IsExperimentalAppListEnabled()) { |
81 start_page_view_ = new StartPageView(app_list_main_view, view_delegate); | 75 start_page_view_ = new StartPageView(app_list_main_view, view_delegate); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
187 } | 181 } |
188 | 182 |
189 void ContentsView::AnimateToIdealBounds() { | 183 void ContentsView::AnimateToIdealBounds() { |
190 CalculateIdealBounds(); | 184 CalculateIdealBounds(); |
191 for (int i = 0; i < view_model_->view_size(); ++i) { | 185 for (int i = 0; i < view_model_->view_size(); ++i) { |
192 bounds_animator_->AnimateViewTo(view_model_->view_at(i), | 186 bounds_animator_->AnimateViewTo(view_model_->view_at(i), |
193 view_model_->ideal_bounds(i)); | 187 view_model_->ideal_bounds(i)); |
194 } | 188 } |
195 } | 189 } |
196 | 190 |
| 191 PaginationModel* ContentsView::GetAppsPaginationModel() { |
| 192 return apps_container_view_->apps_grid_view()->pagination_model(); |
| 193 } |
| 194 |
197 void ContentsView::ShowSearchResults(bool show) { | 195 void ContentsView::ShowSearchResults(bool show) { |
198 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS); | 196 SetShowState(show ? SHOW_SEARCH_RESULTS : SHOW_APPS); |
199 } | 197 } |
200 | 198 |
201 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 199 void ContentsView::ShowFolderContent(AppListFolderItem* item) { |
202 apps_container_view_->ShowActiveFolder(item); | 200 apps_container_view_->ShowActiveFolder(item); |
203 } | 201 } |
204 | 202 |
205 void ContentsView::Prerender() { | 203 void ContentsView::Prerender() { |
206 const int selected_page = std::max(0, pagination_model_->selected_page()); | 204 const int selected_page = |
| 205 std::max(0, GetAppsPaginationModel()->selected_page()); |
207 apps_container_view_->apps_grid_view()->Prerender(selected_page); | 206 apps_container_view_->apps_grid_view()->Prerender(selected_page); |
208 } | 207 } |
209 | 208 |
210 gfx::Size ContentsView::GetPreferredSize() const { | 209 gfx::Size ContentsView::GetPreferredSize() const { |
211 const gfx::Size container_size = GetAppsContainerView(view_model_.get())-> | 210 const gfx::Size container_size = GetAppsContainerView(view_model_.get())-> |
212 apps_grid_view()->GetPreferredSize(); | 211 apps_grid_view()->GetPreferredSize(); |
213 const gfx::Size results_size = | 212 const gfx::Size results_size = |
214 GetSearchResultListView(view_model_.get())->GetPreferredSize(); | 213 GetSearchResultListView(view_model_.get())->GetPreferredSize(); |
215 | 214 |
216 int width = std::max(container_size.width(), results_size.width()); | 215 int width = std::max(container_size.width(), results_size.width()); |
(...skipping 24 matching lines...) Expand all Loading... |
241 if (show_state_ != SHOW_APPS) | 240 if (show_state_ != SHOW_APPS) |
242 return false; | 241 return false; |
243 | 242 |
244 int offset; | 243 int offset; |
245 if (abs(event.x_offset()) > abs(event.y_offset())) | 244 if (abs(event.x_offset()) > abs(event.y_offset())) |
246 offset = event.x_offset(); | 245 offset = event.x_offset(); |
247 else | 246 else |
248 offset = event.y_offset(); | 247 offset = event.y_offset(); |
249 | 248 |
250 if (abs(offset) > kMinMouseWheelToSwitchPage) { | 249 if (abs(offset) > kMinMouseWheelToSwitchPage) { |
251 if (!pagination_model_->has_transition()) { | 250 if (!GetAppsPaginationModel()->has_transition()) { |
252 pagination_model_->SelectPageRelative( | 251 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
253 offset > 0 ? -1 : 1, true); | |
254 } | 252 } |
255 return true; | 253 return true; |
256 } | 254 } |
257 | 255 |
258 return false; | 256 return false; |
259 } | 257 } |
260 | 258 |
261 void ContentsView::OnGestureEvent(ui::GestureEvent* event) { | 259 void ContentsView::OnGestureEvent(ui::GestureEvent* event) { |
262 if (show_state_ != SHOW_APPS) | 260 if (show_state_ != SHOW_APPS) |
263 return; | 261 return; |
264 | 262 |
265 switch (event->type()) { | 263 switch (event->type()) { |
266 case ui::ET_GESTURE_SCROLL_BEGIN: | 264 case ui::ET_GESTURE_SCROLL_BEGIN: |
267 pagination_model_->StartScroll(); | 265 GetAppsPaginationModel()->StartScroll(); |
268 event->SetHandled(); | 266 event->SetHandled(); |
269 return; | 267 return; |
270 case ui::ET_GESTURE_SCROLL_UPDATE: | 268 case ui::ET_GESTURE_SCROLL_UPDATE: |
271 // event->details.scroll_x() > 0 means moving contents to right. That is, | 269 // event->details.scroll_x() > 0 means moving contents to right. That is, |
272 // transitioning to previous page. | 270 // transitioning to previous page. |
273 pagination_model_->UpdateScroll( | 271 GetAppsPaginationModel()->UpdateScroll(event->details().scroll_x() / |
274 event->details().scroll_x() / GetContentsBounds().width()); | 272 GetContentsBounds().width()); |
275 event->SetHandled(); | 273 event->SetHandled(); |
276 return; | 274 return; |
277 case ui::ET_GESTURE_SCROLL_END: | 275 case ui::ET_GESTURE_SCROLL_END: |
278 pagination_model_->EndScroll(pagination_model_-> | 276 GetAppsPaginationModel()->EndScroll( |
279 transition().progress < kFinishTransitionThreshold); | 277 GetAppsPaginationModel()->transition().progress < |
| 278 kFinishTransitionThreshold); |
280 event->SetHandled(); | 279 event->SetHandled(); |
281 return; | 280 return; |
282 case ui::ET_SCROLL_FLING_START: { | 281 case ui::ET_SCROLL_FLING_START: { |
283 pagination_model_->EndScroll(true); | 282 GetAppsPaginationModel()->EndScroll(true); |
284 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { | 283 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { |
285 pagination_model_->SelectPageRelative( | 284 GetAppsPaginationModel()->SelectPageRelative( |
286 event->details().velocity_x() < 0 ? 1 : -1, | 285 event->details().velocity_x() < 0 ? 1 : -1, true); |
287 true); | |
288 } | 286 } |
289 event->SetHandled(); | 287 event->SetHandled(); |
290 return; | 288 return; |
291 } | 289 } |
292 default: | 290 default: |
293 break; | 291 break; |
294 } | 292 } |
295 } | 293 } |
296 | 294 |
297 void ContentsView::OnScrollEvent(ui::ScrollEvent* event) { | 295 void ContentsView::OnScrollEvent(ui::ScrollEvent* event) { |
298 if (show_state_ != SHOW_APPS || | 296 if (show_state_ != SHOW_APPS || |
299 event->type() == ui::ET_SCROLL_FLING_CANCEL) { | 297 event->type() == ui::ET_SCROLL_FLING_CANCEL) { |
300 return; | 298 return; |
301 } | 299 } |
302 | 300 |
303 float offset; | 301 float offset; |
304 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) | 302 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) |
305 offset = event->x_offset(); | 303 offset = event->x_offset(); |
306 else | 304 else |
307 offset = event->y_offset(); | 305 offset = event->y_offset(); |
308 | 306 |
309 if (std::abs(offset) > kMinScrollToSwitchPage) { | 307 if (std::abs(offset) > kMinScrollToSwitchPage) { |
310 if (!pagination_model_->has_transition()) { | 308 if (!GetAppsPaginationModel()->has_transition()) { |
311 pagination_model_->SelectPageRelative(offset > 0 ? -1 : 1, | 309 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); |
312 true); | |
313 } | 310 } |
314 event->SetHandled(); | 311 event->SetHandled(); |
315 event->StopPropagation(); | 312 event->StopPropagation(); |
316 } | 313 } |
317 } | 314 } |
318 | 315 |
319 } // namespace app_list | 316 } // namespace app_list |
OLD | NEW |