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

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

Issue 2982453002: New AppListView Scroll Behavior. (Closed)
Patch Set: Removed unintended edit. Created 3 years, 5 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
« no previous file with comments | « ash/app_list/app_list_presenter_delegate_unittest.cc ('k') | ui/app_list/views/app_list_page.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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/pagination_controller.h" 5 #include "ui/app_list/pagination_controller.h"
6 6
7 #include "ui/app_list/pagination_model.h" 7 #include "ui/app_list/pagination_model.h"
8 #include "ui/events/event.h" 8 #include "ui/events/event.h"
9 #include "ui/gfx/geometry/rect.h" 9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/gfx/geometry/vector2d.h" 10 #include "ui/gfx/geometry/vector2d.h"
11 11
12 namespace app_list { 12 namespace app_list {
13 13
14 namespace { 14 namespace {
15 15
16 // Constants for dealing with scroll events. 16 // Constants for dealing with scroll events.
17 const int kMinScrollToSwitchPage = 20; 17 const int kMinScrollToSwitchPage = 20;
18 const int kMinHorizVelocityToSwitchPage = 800; 18 const int kMinHorizVelocityToSwitchPage = 800;
19 19
20 const double kFinishTransitionThreshold = 0.33; 20 const double kFinishTransitionThreshold = 0.33;
21 21
22 } // namespace 22 } // namespace
23 23
24 PaginationController::PaginationController(PaginationModel* model, 24 PaginationController::PaginationController(PaginationModel* model,
25 ScrollAxis scroll_axis) 25 ScrollAxis scroll_axis)
26 : pagination_model_(model), scroll_axis_(scroll_axis) { 26 : pagination_model_(model), scroll_axis_(scroll_axis) {}
27 }
28 27
29 bool PaginationController::OnScroll(const gfx::Vector2d& offset, 28 bool PaginationController::OnScroll(const gfx::Vector2d& offset,
30 ScrollEventType type) { 29 ScrollEventType type) {
31 int offset_magnitude; 30 int offset_magnitude;
32 if (scroll_axis_ == SCROLL_AXIS_HORIZONTAL) { 31 if (scroll_axis_ == SCROLL_AXIS_HORIZONTAL) {
33 // If the view scrolls horizontally, both horizontal and vertical scroll 32 // If the view scrolls horizontally, both horizontal and vertical scroll
34 // events are valid (since most mouse wheels only have vertical scrolling). 33 // events are valid (since most mouse wheels only have vertical scrolling).
35 offset_magnitude = 34 offset_magnitude =
36 abs(offset.x()) > abs(offset.y()) ? offset.x() : offset.y(); 35 abs(offset.x()) > abs(offset.y()) ? offset.x() : offset.y();
37 } else { 36 } else {
38 // If the view scrolls vertically, only vertical scroll events are valid. 37 // If the view scrolls vertically, only vertical scroll events are valid.
39 offset_magnitude = offset.y(); 38 offset_magnitude = offset.y();
40 } 39 }
41 40
42 // Do not scroll on very small events. 41 // Do not scroll on very small events.
43 // TODO(calamity): This should only apply on touchpad scroll but touchpad 42 // TODO(calamity): This should only apply on touchpad scroll but touchpad
44 // events are coming in as mousewheel events. See https://crbug.com/594264. 43 // events are coming in as mousewheel events. See https://crbug.com/594264.
45 if (abs(offset_magnitude) > kMinScrollToSwitchPage) { 44 if (abs(offset_magnitude) > kMinScrollToSwitchPage &&
46 if (!pagination_model_->has_transition()) { 45 !pagination_model_->has_transition()) {
47 pagination_model_->SelectPageRelative(offset_magnitude > 0 ? -1 : 1, 46 pagination_model_->SelectPageRelative(offset_magnitude > 0 ? -1 : 1, true);
48 true);
49 }
50 return true; 47 return true;
51 } 48 }
52 49
53 return false; 50 return false;
54 } 51 }
55 52
56 bool PaginationController::OnGestureEvent(const ui::GestureEvent& event, 53 bool PaginationController::OnGestureEvent(const ui::GestureEvent& event,
57 const gfx::Rect& bounds) { 54 const gfx::Rect& bounds) {
58 const ui::GestureEventDetails& details = event.details(); 55 const ui::GestureEventDetails& details = event.details();
59 switch (event.type()) { 56 switch (event.type()) {
(...skipping 23 matching lines...) Expand all
83 if (fabs(velocity) > kMinHorizVelocityToSwitchPage) 80 if (fabs(velocity) > kMinHorizVelocityToSwitchPage)
84 pagination_model_->SelectPageRelative(velocity < 0 ? 1 : -1, true); 81 pagination_model_->SelectPageRelative(velocity < 0 ? 1 : -1, true);
85 return true; 82 return true;
86 } 83 }
87 default: 84 default:
88 return false; 85 return false;
89 } 86 }
90 } 87 }
91 88
92 } // namespace app_list 89 } // namespace app_list
OLDNEW
« no previous file with comments | « ash/app_list/app_list_presenter_delegate_unittest.cc ('k') | ui/app_list/views/app_list_page.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698