| 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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 219 |
| 230 PaginationModel* ContentsView::GetAppsPaginationModel() { | 220 PaginationModel* ContentsView::GetAppsPaginationModel() { |
| 231 return apps_container_view_->apps_grid_view()->pagination_model(); | 221 return apps_container_view_->apps_grid_view()->pagination_model(); |
| 232 } | 222 } |
| 233 | 223 |
| 234 void ContentsView::ShowFolderContent(AppListFolderItem* item) { | 224 void ContentsView::ShowFolderContent(AppListFolderItem* item) { |
| 235 apps_container_view_->ShowActiveFolder(item); | 225 apps_container_view_->ShowActiveFolder(item); |
| 236 } | 226 } |
| 237 | 227 |
| 238 void ContentsView::Prerender() { | 228 void ContentsView::Prerender() { |
| 239 const int selected_page = | 229 apps_container_view_->apps_grid_view()->Prerender(); |
| 240 std::max(0, GetAppsPaginationModel()->selected_page()); | |
| 241 apps_container_view_->apps_grid_view()->Prerender(selected_page); | |
| 242 } | 230 } |
| 243 | 231 |
| 244 views::View* ContentsView::GetPageView(int index) { | 232 views::View* ContentsView::GetPageView(int index) { |
| 245 return view_model_->view_at(index); | 233 return view_model_->view_at(index); |
| 246 } | 234 } |
| 247 | 235 |
| 248 void ContentsView::AddBlankPageForTesting() { | 236 void ContentsView::AddBlankPageForTesting() { |
| 249 AddLauncherPage(new views::View, 0); | 237 AddLauncherPage(new views::View, 0); |
| 250 } | 238 } |
| 251 | 239 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 for (int i = 0; i < view_model_->view_size(); ++i) { | 284 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 297 view_model_->view_at(i)->SetBoundsRect( | 285 view_model_->view_at(i)->SetBoundsRect( |
| 298 i == pagination_model_.SelectedTargetPage() ? rect : offscreen_target); | 286 i == pagination_model_.SelectedTargetPage() ? rect : offscreen_target); |
| 299 } | 287 } |
| 300 } | 288 } |
| 301 | 289 |
| 302 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { | 290 bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { |
| 303 return view_model_->view_at(GetActivePageIndex())->OnKeyPressed(event); | 291 return view_model_->view_at(GetActivePageIndex())->OnKeyPressed(event); |
| 304 } | 292 } |
| 305 | 293 |
| 306 bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { | |
| 307 if (!IsNamedPageActive(NAMED_PAGE_APPS)) | |
| 308 return false; | |
| 309 | |
| 310 int offset; | |
| 311 if (abs(event.x_offset()) > abs(event.y_offset())) | |
| 312 offset = event.x_offset(); | |
| 313 else | |
| 314 offset = event.y_offset(); | |
| 315 | |
| 316 if (abs(offset) > kMinMouseWheelToSwitchPage) { | |
| 317 if (!GetAppsPaginationModel()->has_transition()) { | |
| 318 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | |
| 319 } | |
| 320 return true; | |
| 321 } | |
| 322 | |
| 323 return false; | |
| 324 } | |
| 325 | |
| 326 void ContentsView::TotalPagesChanged() { | 294 void ContentsView::TotalPagesChanged() { |
| 327 } | 295 } |
| 328 | 296 |
| 329 void ContentsView::SelectedPageChanged(int old_selected, int new_selected) { | 297 void ContentsView::SelectedPageChanged(int old_selected, int new_selected) { |
| 330 } | 298 } |
| 331 | 299 |
| 332 void ContentsView::TransitionStarted() { | 300 void ContentsView::TransitionStarted() { |
| 333 } | 301 } |
| 334 | 302 |
| 335 void ContentsView::TransitionChanged() { | 303 void ContentsView::TransitionChanged() { |
| 336 UpdatePageBounds(); | 304 UpdatePageBounds(); |
| 337 } | 305 } |
| 338 | 306 |
| 339 void ContentsView::OnGestureEvent(ui::GestureEvent* event) { | |
| 340 if (!IsNamedPageActive(NAMED_PAGE_APPS)) | |
| 341 return; | |
| 342 | |
| 343 switch (event->type()) { | |
| 344 case ui::ET_GESTURE_SCROLL_BEGIN: | |
| 345 GetAppsPaginationModel()->StartScroll(); | |
| 346 event->SetHandled(); | |
| 347 return; | |
| 348 case ui::ET_GESTURE_SCROLL_UPDATE: | |
| 349 // event->details.scroll_x() > 0 means moving contents to right. That is, | |
| 350 // transitioning to previous page. | |
| 351 GetAppsPaginationModel()->UpdateScroll(event->details().scroll_x() / | |
| 352 GetContentsBounds().width()); | |
| 353 event->SetHandled(); | |
| 354 return; | |
| 355 case ui::ET_GESTURE_SCROLL_END: | |
| 356 GetAppsPaginationModel()->EndScroll( | |
| 357 GetAppsPaginationModel()->transition().progress < | |
| 358 kFinishTransitionThreshold); | |
| 359 event->SetHandled(); | |
| 360 return; | |
| 361 case ui::ET_SCROLL_FLING_START: { | |
| 362 GetAppsPaginationModel()->EndScroll(true); | |
| 363 if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { | |
| 364 GetAppsPaginationModel()->SelectPageRelative( | |
| 365 event->details().velocity_x() < 0 ? 1 : -1, true); | |
| 366 } | |
| 367 event->SetHandled(); | |
| 368 return; | |
| 369 } | |
| 370 default: | |
| 371 break; | |
| 372 } | |
| 373 } | |
| 374 | |
| 375 void ContentsView::OnScrollEvent(ui::ScrollEvent* event) { | |
| 376 if (!IsNamedPageActive(NAMED_PAGE_APPS) || | |
| 377 event->type() == ui::ET_SCROLL_FLING_CANCEL) { | |
| 378 return; | |
| 379 } | |
| 380 | |
| 381 float offset; | |
| 382 if (std::abs(event->x_offset()) > std::abs(event->y_offset())) | |
| 383 offset = event->x_offset(); | |
| 384 else | |
| 385 offset = event->y_offset(); | |
| 386 | |
| 387 if (std::abs(offset) > kMinScrollToSwitchPage) { | |
| 388 if (!GetAppsPaginationModel()->has_transition()) { | |
| 389 GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); | |
| 390 } | |
| 391 event->SetHandled(); | |
| 392 event->StopPropagation(); | |
| 393 } | |
| 394 } | |
| 395 | |
| 396 } // namespace app_list | 307 } // namespace app_list |
| OLD | NEW |