cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / ui / app_list / pagination_controller.cc
blob26494eb24a18901b59922f0ee9bb5efe91cf0dd5
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.
5 #include "ui/app_list/pagination_controller.h"
7 #include "ui/app_list/pagination_model.h"
8 #include "ui/events/event.h"
9 #include "ui/gfx/geometry/rect.h"
10 #include "ui/gfx/geometry/vector2d.h"
12 namespace app_list {
14 namespace {
16 // Constants for dealing with scroll events.
17 const int kMinScrollToSwitchPage = 20;
18 const int kMinHorizVelocityToSwitchPage = 800;
20 const double kFinishTransitionThreshold = 0.33;
22 } // namespace
24 PaginationController::PaginationController(PaginationModel* model,
25 ScrollAxis scroll_axis)
26 : pagination_model_(model), scroll_axis_(scroll_axis) {
29 bool PaginationController::OnScroll(const gfx::Vector2d& offset,
30 ScrollEventType type) {
31 int offset_magnitude;
32 if (scroll_axis_ == SCROLL_AXIS_HORIZONTAL) {
33 // If the view scrolls horizontally, both horizontal and vertical scroll
34 // events are valid (since most mouse wheels only have vertical scrolling).
35 offset_magnitude =
36 abs(offset.x()) > abs(offset.y()) ? offset.x() : offset.y();
37 } else {
38 // If the view scrolls vertically, only vertical scroll events are valid.
39 offset_magnitude = offset.y();
42 // Do not scroll on very small touchpad events. Mouse wheel events should
43 // scroll, no matter how small the value change.
44 if (type == SCROLL_MOUSE_WHEEL ||
45 abs(offset_magnitude) > kMinScrollToSwitchPage) {
46 if (!pagination_model_->has_transition()) {
47 pagination_model_->SelectPageRelative(offset_magnitude > 0 ? -1 : 1,
48 true);
50 return true;
53 return false;
56 bool PaginationController::OnGestureEvent(const ui::GestureEvent& event,
57 const gfx::Rect& bounds) {
58 const ui::GestureEventDetails& details = event.details();
59 switch (event.type()) {
60 case ui::ET_GESTURE_SCROLL_BEGIN:
61 pagination_model_->StartScroll();
62 return true;
63 case ui::ET_GESTURE_SCROLL_UPDATE: {
64 float scroll = scroll_axis_ == SCROLL_AXIS_HORIZONTAL
65 ? details.scroll_x()
66 : details.scroll_y();
67 int width = scroll_axis_ == SCROLL_AXIS_HORIZONTAL ? bounds.width()
68 : bounds.height();
69 // scroll > 0 means moving contents right or down. That is, transitioning
70 // to the previous page.
71 pagination_model_->UpdateScroll(scroll / width);
72 return true;
74 case ui::ET_GESTURE_SCROLL_END:
75 pagination_model_->EndScroll(pagination_model_->transition().progress <
76 kFinishTransitionThreshold);
77 return true;
78 case ui::ET_SCROLL_FLING_START: {
79 float velocity = scroll_axis_ == SCROLL_AXIS_HORIZONTAL
80 ? details.velocity_x()
81 : details.velocity_y();
82 pagination_model_->EndScroll(true);
83 if (fabs(velocity) > kMinHorizVelocityToSwitchPage)
84 pagination_model_->SelectPageRelative(velocity < 0 ? 1 : -1, true);
85 return true;
87 default:
88 return false;
92 } // namespace app_list