Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2405)

Unified Diff: ui/app_list/views/apps_container_view.cc

Issue 497413003: Refactor app list event handling and prerendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved some app-grid-specific logic from ContentsView to AppsGridView. Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/app_list/views/apps_container_view.cc
diff --git a/ui/app_list/views/apps_container_view.cc b/ui/app_list/views/apps_container_view.cc
index 4d6fdaba35dd99961639d1c1970218efaf9edf9f..15743474913ec47bfe9c9ade0220af5d297fab87 100644
--- a/ui/app_list/views/apps_container_view.cc
+++ b/ui/app_list/views/apps_container_view.cc
@@ -11,6 +11,7 @@
#include "ui/app_list/app_list_constants.h"
#include "ui/app_list/app_list_folder_item.h"
#include "ui/app_list/app_list_switches.h"
+#include "ui/app_list/pagination_model.h"
#include "ui/app_list/views/app_list_folder_view.h"
#include "ui/app_list/views/app_list_item_view.h"
#include "ui/app_list/views/app_list_main_view.h"
@@ -20,6 +21,16 @@
namespace app_list {
+namespace {
+
+const int kMinMouseWheelToSwitchPage = 20;
+const int kMinScrollToSwitchPage = 20;
+const int kMinHorizVelocityToSwitchPage = 800;
+
+const double kFinishTransitionThreshold = 0.33;
+
+} // namespace
+
AppsContainerView::AppsContainerView(AppListMainView* app_list_main_view,
AppListModel* model)
: model_(model),
@@ -137,6 +148,75 @@ bool AppsContainerView::OnKeyPressed(const ui::KeyEvent& event) {
return app_list_folder_view_->OnKeyPressed(event);
}
+bool AppsContainerView::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 (!GetPaginationModel()->has_transition()) {
+ GetPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true);
+ }
+ return true;
+ }
+
+ return false;
+}
+
+void AppsContainerView::OnGestureEvent(ui::GestureEvent* event) {
+ switch (event->type()) {
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ GetPaginationModel()->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.
+ GetPaginationModel()->UpdateScroll(event->details().scroll_x() /
+ GetContentsBounds().width());
+ event->SetHandled();
+ return;
+ case ui::ET_GESTURE_SCROLL_END:
+ GetPaginationModel()->EndScroll(
+ GetPaginationModel()->transition().progress <
+ kFinishTransitionThreshold);
+ event->SetHandled();
+ return;
+ case ui::ET_SCROLL_FLING_START: {
+ GetPaginationModel()->EndScroll(true);
+ if (fabs(event->details().velocity_x()) > kMinHorizVelocityToSwitchPage) {
+ GetPaginationModel()->SelectPageRelative(
+ event->details().velocity_x() < 0 ? 1 : -1, true);
+ }
+ event->SetHandled();
+ return;
+ }
+ default:
+ break;
+ }
+}
+
+void AppsContainerView::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 (!GetPaginationModel()->has_transition()) {
+ GetPaginationModel()->SelectPageRelative(offset > 0 ? -1 : 1, true);
+ }
+ event->SetHandled();
+ event->StopPropagation();
+ }
+}
+
void AppsContainerView::OnTopIconAnimationsComplete() {
--top_icon_animation_pending_count_;
@@ -200,6 +280,10 @@ Rects AppsContainerView::GetTopItemIconBoundsInActiveFolder() {
return AppListFolderItem::GetTopIconsBounds(to_container);
}
+PaginationModel* AppsContainerView::GetPaginationModel() {
+ return apps_grid_view_->pagination_model();
+}
+
void AppsContainerView::CreateViewsForFolderTopItemsAnimation(
AppListFolderItem* active_folder,
bool open_folder) {

Powered by Google App Engine
This is Rietveld 408576698