| 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/resources/grit/ui_resources.h" | 22 #include "ui/resources/grit/ui_resources.h" |
| 23 #include "ui/views/view_model.h" | 23 #include "ui/views/view_model.h" |
| 24 #include "ui/views/view_model_utils.h" | 24 #include "ui/views/view_model_utils.h" |
| 25 | 25 |
| 26 namespace app_list { | 26 namespace app_list { |
| 27 | 27 |
| 28 namespace { | |
| 29 | |
| 30 const int kMinMouseWheelToSwitchPage = 20; | |
| 31 const int kMinScrollToSwitchPage = 20; | |
| 32 const int kMinHorizVelocityToSwitchPage = 800; | |
| 33 | |
| 34 const double kFinishTransitionThreshold = 0.33; | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 ContentsView::ContentsView(AppListMainView* app_list_main_view) | 28 ContentsView::ContentsView(AppListMainView* app_list_main_view) |
| 39 : search_results_view_(NULL), | 29 : search_results_view_(NULL), |
| 40 start_page_view_(NULL), | 30 start_page_view_(NULL), |
| 41 app_list_main_view_(app_list_main_view), | 31 app_list_main_view_(app_list_main_view), |
| 42 contents_switcher_view_(NULL), | 32 contents_switcher_view_(NULL), |
| 43 view_model_(new views::ViewModel), | 33 view_model_(new views::ViewModel), |
| 44 page_before_search_(0) { | 34 page_before_search_(0) { |
| 45 pagination_model_.AddObserver(this); | 35 pagination_model_.AddObserver(this); |
| 46 } | 36 } |
| 47 | 37 |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 229 |
| 240 PaginationModel* ContentsView::GetAppsPaginationModel() { | 230 PaginationModel* ContentsView::GetAppsPaginationModel() { |
| 241 return apps_container_view_->apps_grid_view()->pagination_model(); | 231 return apps_container_view_->apps_grid_view()->pagination_model(); |
| 242 } | 232 } |
| 243 | 233 |
| 244 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 234 void ContentsView::ShowFolderContent(AppListFolderItem* item) { |
| 245 apps_container_view_->ShowActiveFolder(item); | 235 apps_container_view_->ShowActiveFolder(item); |
| 246 } | 236 } |
| 247 | 237 |
| 248 void ContentsView::Prerender() { | 238 void ContentsView::Prerender() { |
| 249 const int selected_page = | 239 apps_container_view_->apps_grid_view()->Prerender(); |
| 250 std::max(0, GetAppsPaginationModel()->selected_page()); | |
| 251 apps_container_view_->apps_grid_view()->Prerender(selected_page); | |
| 252 } | 240 } |
| 253 | 241 |
| 254 views::View* ContentsView::GetPageView(int index) { | 242 views::View* ContentsView::GetPageView(int index) { |
| 255 return view_model_->view_at(index); | 243 return view_model_->view_at(index); |
| 256 } | 244 } |
| 257 | 245 |
| 258 void ContentsView::AddBlankPageForTesting() { | 246 void ContentsView::AddBlankPageForTesting() { |
| 259 AddLauncherPage(new views::View, 0); | 247 AddLauncherPage(new views::View, 0); |
| 260 } | 248 } |
| 261 | 249 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 for (int i = 0; i < view_model_->view_size(); ++i) { | 294 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 307 view_model_->view_at(i)->SetBoundsRect( | 295 view_model_->view_at(i)->SetBoundsRect( |
| 308 i == pagination_model_.SelectedTargetPage() ? rect : offscreen_target); | 296 i == pagination_model_.SelectedTargetPage() ? rect : offscreen_target); |
| 309 } | 297 } |
| 310 } | 298 } |
| 311 | 299 |
| 312 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { | 300 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { |
| 313 return view_model_->view_at(GetActivePageIndex())->OnKeyPressed(event); | 301 return view_model_->view_at(GetActivePageIndex())->OnKeyPressed(event); |
| 314 } | 302 } |
| 315 | 303 |
| 316 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { | |
| 317 if (!IsNamedPageActive(NAMED_PAGE_APPS)) | |
| 318 return false; | |
| 319 | |
| 320 int offset; | |
| 321 if (abs(event.x_offset()) > abs(event.y_offset())) | |
| 322 offset = event.x_offset(); | |
| 323 else | |
| 324 offset = event.y_offset(); | |
| 325 | |
| 326 if (abs(offset) > kMinMouseWheelToSwitchPage) { | |
| 327 if (!GetAppsPaginationModel()->has_transition()) { | |
| 328 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | |
| 329 } | |
| 330 return true; | |
| 331 } | |
| 332 | |
| 333 return false; | |
| 334 } | |
| 335 | |
| 336 void ContentsView::TotalPagesChanged() { | 304 void ContentsView::TotalPagesChanged() { |
| 337 } | 305 } |
| 338 | 306 |
| 339 void ContentsView::SelectedPageChanged(int old_selected, int new_selected) { | 307 void ContentsView::SelectedPageChanged(int old_selected, int new_selected) { |
| 340 } | 308 } |
| 341 | 309 |
| 342 void ContentsView::TransitionStarted() { | 310 void ContentsView::TransitionStarted() { |
| 343 } | 311 } |
| 344 | 312 |
| 345 void ContentsView::TransitionChanged() { | 313 void ContentsView::TransitionChanged() { |
| 346 UpdatePageBounds(); | 314 UpdatePageBounds(); |
| 347 } | 315 } |
| 348 | 316 |
| 349 void ContentsView::OnGestureEvent(ui::GestureEvent* event) { | |
| 350 if (!IsNamedPageActive(NAMED_PAGE_APPS)) | |
| 351 return; | |
| 352 | |
| 353 switch (event->type()) { | |
| 354 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 355 GetAppsPaginationModel()->StartScroll(); | |
| 356 event->SetHandled(); | |
| 357 return; | |
| 358 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 359 // event->details.scroll_x() > 0 means moving contents to right. That is, | |
| 360 // transitioning to previous page. | |
| 361 GetAppsPaginationModel()->UpdateScroll(event->details().scroll_x() / | |
| 362 GetContentsBounds().width()); | |
| 363 event->SetHandled(); | |
| 364 return; | |
| 365 case ui::ET_GESTURE_SCROLL_END: | |
| 366 GetAppsPaginationModel()->EndScroll( | |
| 367 GetAppsPaginationModel()->transition().progress < | |
| 368 kFinishTransitionThreshold); | |
| 369 event->SetHandled(); | |
| 370 return; | |
| 371 case ui::ET_SCROLL_FLING_START: { | |
| 372 GetAppsPaginationModel()->EndScroll(true); | |
| 373 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { | |
| 374 GetAppsPaginationModel()->SelectPageRelative( | |
| 375 event->details().velocity_x() < 0 ? 1 : -1, true); | |
| 376 } | |
| 377 event->SetHandled(); | |
| 378 return; | |
| 379 } | |
| 380 default: | |
| 381 break; | |
| 382 } | |
| 383 } | |
| 384 | |
| 385 void ContentsView::OnScrollEvent(ui::ScrollEvent* event) { | |
| 386 if (!IsNamedPageActive(NAMED_PAGE_APPS) || | |
| 387 event->type() == ui::ET_SCROLL_FLING_CANCEL) { | |
| 388 return; | |
| 389 } | |
| 390 | |
| 391 float offset; | |
| 392 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) | |
| 393 offset = event->x_offset(); | |
| 394 else | |
| 395 offset = event->y_offset(); | |
| 396 | |
| 397 if (std::abs(offset) > kMinScrollToSwitchPage) { | |
| 398 if (!GetAppsPaginationModel()->has_transition()) { | |
| 399 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | |
| 400 } | |
| 401 event->SetHandled(); | |
| 402 event->StopPropagation(); | |
| 403 } | |
| 404 } | |
| 405 | |
| 406 } // namespace app_list | 317 } // namespace app_list |
| OLD | NEW |