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

Side by Side Diff: ui/app_list/pagination_controller.cc

Issue 524503003: Refactor app list scrolling: introduce the PaginationController class. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ares-appgrid-vertical-scroll
Patch Set: Rebase. Created 6 years, 3 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/app_list/pagination_controller.h"
6
7 #include "ui/app_list/pagination_model.h"
8 #include "ui/events/event.h"
9 #include "ui/gfx/geometry/point.h"
10 #include "ui/gfx/geometry/rect.h"
11
12 namespace app_list {
13
14 namespace {
15
16 // Constants for dealing with scroll events.
17 const int kMinScrollToSwitchPage = 20;
18 const int kMinHorizVelocityToSwitchPage = 800;
19
20 const double kFinishTransitionThreshold = 0.33;
21
22 } // namespace
23
24 PaginationController::PaginationController(PaginationModel* model,
25 ScrollAxis scroll_axis)
26 : pagination_model_(model), scroll_axis_(scroll_axis) {
27 }
28
29 bool PaginationController::OnScroll(const gfx::Point& offset) {
30 int offset_magnitude;
31 if (scroll_axis_ == SCROLL_AXIS_HORIZONTAL) {
32 // If the view scrolls horizontally, both horizontal and vertical scroll
33 // events are valid (since most mouse wheels only have vertical scrolling).
34 if (abs(offset.x()) > abs(offset.y()))
calamity 2014/09/01 01:49:30 Ternary operator?
Matt Giuca 2014/09/01 03:02:26 Mmkay (even though it would have been better to do
35 offset_magnitude = offset.x();
36 else
37 offset_magnitude = offset.y();
38 } else {
39 // If the view scrolls vertically, only vertical scroll events are valid.
40 offset_magnitude = offset.y();
41 }
42
43 if (abs(offset_magnitude) > kMinScrollToSwitchPage) {
44 if (!pagination_model_->has_transition()) {
45 pagination_model_->SelectPageRelative(offset_magnitude > 0 ? -1 : 1,
46 true);
47 }
48 return true;
49 }
50
51 return false;
52 }
53
54 void PaginationController::OnGestureEvent(ui::GestureEvent* event,
55 const gfx::Rect& bounds) {
56 const ui::GestureEventDetails& details = event->details();
57 switch (event->type()) {
58 case ui::ET_GESTURE_SCROLL_BEGIN:
59 pagination_model_->StartScroll();
60 event->SetHandled();
61 return;
62 case ui::ET_GESTURE_SCROLL_UPDATE: {
63 float scroll = scroll_axis_ == SCROLL_AXIS_HORIZONTAL
64 ? details.scroll_x()
65 : details.scroll_y();
66 int width = scroll_axis_ == SCROLL_AXIS_HORIZONTAL ? bounds.width()
67 : bounds.height();
68 // scroll > 0 means moving contents right or down. That is, transitioning
69 // to the previous page.
70 pagination_model_->UpdateScroll(scroll / width);
71 event->SetHandled();
72 return;
73 }
74 case ui::ET_GESTURE_SCROLL_END:
75 pagination_model_->EndScroll(pagination_model_->transition().progress <
76 kFinishTransitionThreshold);
77 event->SetHandled();
78 return;
79 case ui::ET_SCROLL_FLING_START: {
80 float velocity = scroll_axis_ == SCROLL_AXIS_HORIZONTAL
81 ? details.velocity_x()
82 : details.velocity_y();
83 pagination_model_->EndScroll(true);
84 if (fabs(velocity) > kMinHorizVelocityToSwitchPage)
85 pagination_model_->SelectPageRelative(velocity < 0 ? 1 : -1, true);
86 event->SetHandled();
87 return;
88 }
89 default:
90 break;
91 }
92 }
93
94 } // namespace app_list
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698