diff options
| author | mgiuca <mgiuca@chromium.org> | 2014-08-29 01:45:04 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2014-08-29 08:46:32 +0000 |
| commit | e407013f55b72cb9e0a86aec541bd8eba5efe90f (patch) | |
| tree | 13471a2ead2fc22b0b605fa8dba2ca35e6b3a18f | |
| parent | 885fee17a8df62e0ab51c06742d55f459bae6ea8 (diff) | |
| download | chromium_src-e407013f55b72cb9e0a86aec541bd8eba5efe90f.zip chromium_src-e407013f55b72cb9e0a86aec541bd8eba5efe90f.tar.gz chromium_src-e407013f55b72cb9e0a86aec541bd8eba5efe90f.tar.bz2 | |
Refactor app list event handling and prerendering.
ContentsView should not be responsible for apps-grid-specific logic.
To this end, moved scroll and gesture event handling from ContentsView
to AppsGridView, removing the special cases for NAMED_PAGE_APPS. Also
moved some of the prerender logic from ContentsView to AppsGridView.
BUG=377381
Review URL: https://codereview.chromium.org/497413003
Cr-Commit-Position: refs/heads/master@{#292591}
| -rw-r--r-- | ui/app_list/views/apps_grid_view.cc | 81 | ||||
| -rw-r--r-- | ui/app_list/views/apps_grid_view.h | 9 | ||||
| -rw-r--r-- | ui/app_list/views/contents_view.cc | 91 | ||||
| -rw-r--r-- | ui/app_list/views/contents_view.h | 5 |
4 files changed, 86 insertions, 100 deletions
diff --git a/ui/app_list/views/apps_grid_view.cc b/ui/app_list/views/apps_grid_view.cc index f150eb6..1605c88 100644 --- a/ui/app_list/views/apps_grid_view.cc +++ b/ui/app_list/views/apps_grid_view.cc @@ -92,6 +92,12 @@ const int kFolderItemReparentDelay = 50; // UI. const int kFolderDroppingCircleRadius = 15; +// Constants for dealing with scroll events. +const int kMinMouseWheelToSwitchPage = 20; +const int kMinScrollToSwitchPage = 20; +const int kMinHorizVelocityToSwitchPage = 800; + +const double kFinishTransitionThreshold = 0.33; // RowMoveAnimationDelegate is used when moving an item into a different row. // Before running the animation, the item's layer is re-created and kept in @@ -846,11 +852,12 @@ void AppsGridView::SetDragAndDropHostOfCurrentAppList( drag_and_drop_host_ = drag_and_drop_host; } -void AppsGridView::Prerender(int page_index) { +void AppsGridView::Prerender() { Layout(); - int start = std::max(0, (page_index - kPrerenderPages) * tiles_per_page()); + int selected_page = std::max(0, pagination_model_.selected_page()); + int start = std::max(0, (selected_page - kPrerenderPages) * tiles_per_page()); int end = std::min(view_model_.view_size(), - (page_index + 1 + kPrerenderPages) * tiles_per_page()); + (selected_page + 1 + kPrerenderPages) * tiles_per_page()); for (int i = start; i < end; i++) { AppListItemView* v = static_cast<AppListItemView*>(view_model_.view_at(i)); v->Prerender(); @@ -953,6 +960,23 @@ bool AppsGridView::OnKeyReleased(const ui::KeyEvent& event) { return handled; } +bool AppsGridView::OnMouseWheel(const ui::MouseWheelEvent& event) { + int offset; + if (abs(event.x_offset()) > abs(event.y_offset())) + offset = event.x_offset(); + else + offset = event.y_offset(); + + if (abs(offset) > kMinMouseWheelToSwitchPage) { + if (!pagination_model_.has_transition()) { + pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); + } + return true; + } + + return false; +} + void AppsGridView::ViewHierarchyChanged( const ViewHierarchyChangedDetails& details) { if (!details.is_add && details.parent == this) { @@ -971,6 +995,57 @@ void AppsGridView::ViewHierarchyChanged( } } +void AppsGridView::OnGestureEvent(ui::GestureEvent* event) { + switch (event->type()) { + case ui::ET_GESTURE_SCROLL_BEGIN: + pagination_model_.StartScroll(); + event->SetHandled(); + return; + case ui::ET_GESTURE_SCROLL_UPDATE: + // event->details.scroll_x() > 0 means moving contents to right. That is, + // transitioning to previous page. + pagination_model_.UpdateScroll(event->details().scroll_x() / + GetContentsBounds().width()); + event->SetHandled(); + return; + case ui::ET_GESTURE_SCROLL_END: + pagination_model_.EndScroll(pagination_model_.transition().progress < + kFinishTransitionThreshold); + event->SetHandled(); + return; + case ui::ET_SCROLL_FLING_START: { + pagination_model_.EndScroll(true); + if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { + pagination_model_.SelectPageRelative( + event->details().velocity_x() < 0 ? 1 : -1, true); + } + event->SetHandled(); + return; + } + default: + break; + } +} + +void AppsGridView::OnScrollEvent(ui::ScrollEvent* event) { + if (event->type() == ui::ET_SCROLL_FLING_CANCEL) + return; + + float offset; + if (std::abs(event->x_offset()) > std::abs(event->y_offset())) + offset = event->x_offset(); + else + offset = event->y_offset(); + + if (std::abs(offset) > kMinScrollToSwitchPage) { + if (!pagination_model_.has_transition()) { + pagination_model_.SelectPageRelative(offset > 0 ? -1 : 1, true); + } + event->SetHandled(); + event->StopPropagation(); + } +} + void AppsGridView::Update() { DCHECK(!selected_view_ && !drag_view_); view_model_.Clear(); diff --git a/ui/app_list/views/apps_grid_view.h b/ui/app_list/views/apps_grid_view.h index 6a94e40..0e470a2 100644 --- a/ui/app_list/views/apps_grid_view.h +++ b/ui/app_list/views/apps_grid_view.h @@ -117,8 +117,8 @@ class APP_LIST_EXPORT AppsGridView : public views::View, void SetDragAndDropHostOfCurrentAppList( ApplicationDragAndDropHost* drag_and_drop_host); - // Prerenders the icons on and around |page_index|. - void Prerender(int page_index); + // Prerenders the icons on and around the currently selected page. + void Prerender(); // Return true if the |bounds_animator_| is animating |view|. bool IsAnimatingView(views::View* view); @@ -134,6 +134,7 @@ class APP_LIST_EXPORT AppsGridView : public views::View, virtual void Layout() OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; + virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; virtual void ViewHierarchyChanged( const ViewHierarchyChangedDetails& details) OVERRIDE; virtual bool GetDropFormats( @@ -142,6 +143,10 @@ class APP_LIST_EXPORT AppsGridView : public views::View, virtual bool CanDrop(const OSExchangeData& data) OVERRIDE; virtual int OnDragUpdated(const ui::DropTargetEvent& event) OVERRIDE; + // Overridden from ui::EventHandler: + virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; + virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; + // Stops the timer that triggers a page flip during a drag. void StopPageFlipTimer(); diff --git a/ui/app_list/views/contents_view.cc b/ui/app_list/views/contents_view.cc index e6ae0a8..86f7e7b5 100644 --- a/ui/app_list/views/contents_view.cc +++ b/ui/app_list/views/contents_view.cc @@ -25,16 +25,6 @@ namespace app_list { -namespace { - -const int kMinMouseWheelToSwitchPage = 20; -const int kMinScrollToSwitchPage = 20; -const int kMinHorizVelocityToSwitchPage = 800; - -const double kFinishTransitionThreshold = 0.33; - -} // namespace - ContentsView::ContentsView(AppListMainView* app_list_main_view) : search_results_view_(NULL), start_page_view_(NULL), @@ -236,9 +226,7 @@ void ContentsView::ShowFolderContent(AppListFolderItem* item) { } void ContentsView::Prerender() { - const int selected_page = - std::max(0, GetAppsPaginationModel()->selected_page()); - apps_container_view_->apps_grid_view()->Prerender(selected_page); + apps_container_view_->apps_grid_view()->Prerender(); } views::View* ContentsView::GetPageView(int index) { @@ -303,26 +291,6 @@ bool ContentsView::OnKeyPressed(const ui::KeyEvent& event) { return view_model_->view_at(GetActivePageIndex())->OnKeyPressed(event); } -bool ContentsView::OnMouseWheel(const ui::MouseWheelEvent& event) { - if (!IsNamedPageActive(NAMED_PAGE_APPS)) - return false; - - int offset; - if (abs(event.x_offset()) > abs(event.y_offset())) - offset = event.x_offset(); - else - offset = event.y_offset(); - - if (abs(offset) > kMinMouseWheelToSwitchPage) { - if (!GetAppsPaginationModel()->has_transition()) { - GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); - } - return true; - } - - return false; -} - void ContentsView::TotalPagesChanged() { } @@ -336,61 +304,4 @@ void ContentsView::TransitionChanged() { UpdatePageBounds(); } -void ContentsView::OnGestureEvent(ui::GestureEvent* event) { - if (!IsNamedPageActive(NAMED_PAGE_APPS)) - return; - - switch (event->type()) { - case ui::ET_GESTURE_SCROLL_BEGIN: - GetAppsPaginationModel()->StartScroll(); - event->SetHandled(); - return; - case ui::ET_GESTURE_SCROLL_UPDATE: - // event->details.scroll_x() > 0 means moving contents to right. That is, - // transitioning to previous page. - GetAppsPaginationModel()->UpdateScroll(event->details().scroll_x() / - GetContentsBounds().width()); - event->SetHandled(); - return; - case ui::ET_GESTURE_SCROLL_END: - GetAppsPaginationModel()->EndScroll( - GetAppsPaginationModel()->transition().progress < - kFinishTransitionThreshold); - event->SetHandled(); - return; - case ui::ET_SCROLL_FLING_START: { - GetAppsPaginationModel()->EndScroll(true); - if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) { - GetAppsPaginationModel()->SelectPageRelative( - event->details().velocity_x() < 0 ? 1 : -1, true); - } - event->SetHandled(); - return; - } - default: - break; - } -} - -void ContentsView::OnScrollEvent(ui::ScrollEvent* event) { - if (!IsNamedPageActive(NAMED_PAGE_APPS) || - event->type() == ui::ET_SCROLL_FLING_CANCEL) { - return; - } - - float offset; - if (std::abs(event->x_offset()) > std::abs(event->y_offset())) - offset = event->x_offset(); - else - offset = event->y_offset(); - - if (std::abs(offset) > kMinScrollToSwitchPage) { - if (!GetAppsPaginationModel()->has_transition()) { - GetAppsPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true); - } - event->SetHandled(); - event->StopPropagation(); - } -} - } // namespace app_list diff --git a/ui/app_list/views/contents_view.h b/ui/app_list/views/contents_view.h index b828490..17ecf93 100644 --- a/ui/app_list/views/contents_view.h +++ b/ui/app_list/views/contents_view.h @@ -103,7 +103,6 @@ class APP_LIST_EXPORT ContentsView : public views::View, virtual gfx::Size GetPreferredSize() const OVERRIDE; virtual void Layout() OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; - virtual bool OnMouseWheel(const ui::MouseWheelEvent& event) OVERRIDE; // Overridden from PaginationModelObserver: virtual void TotalPagesChanged() OVERRIDE; @@ -143,10 +142,6 @@ class APP_LIST_EXPORT ContentsView : public views::View, // launcher-page pagination. PaginationModel* GetAppsPaginationModel(); - // Overridden from ui::EventHandler: - virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; - virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; - // Special sub views of the ContentsView. All owned by the views hierarchy. AppsContainerView* apps_container_view_; SearchResultListView* search_results_view_; |
