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

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

Issue 497413003: Refactor app list event handling and prerendering. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reorder in .cc file. 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
« no previous file with comments | « ui/app_list/views/apps_grid_view.h ('k') | ui/app_list/views/contents_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/app_list/views/apps_grid_view.cc
diff --git a/ui/app_list/views/apps_grid_view.cc b/ui/app_list/views/apps_grid_view.cc
index f150eb6b6802d80162520ddfe390c0bbcac19581..1605c885d833107002c8defcab91452918212c3c 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();
« no previous file with comments | « ui/app_list/views/apps_grid_view.h ('k') | ui/app_list/views/contents_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698