Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ui / events / gesture_detection / snap_scroll_controller.h
blob049bcd7a3610d2b4f50c44dd9dcc63209b3264a9
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 #ifndef UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
6 #define UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "ui/events/gesture_detection/gesture_detection_export.h"
10 #include "ui/gfx/geometry/point_f.h"
11 #include "ui/gfx/geometry/size_f.h"
12 #include "ui/gfx/geometry/vector2d_f.h"
14 namespace ui {
16 class MotionEvent;
18 // Port of SnapScrollController.java from Chromium
19 // Controls the scroll snapping behavior based on scroll updates.
20 class GESTURE_DETECTION_EXPORT SnapScrollController {
21 public:
22 SnapScrollController(float snap_bound, const gfx::SizeF& display_size);
23 ~SnapScrollController();
25 // Sets the snap scroll mode based on the event type.
26 void SetSnapScrollMode(const MotionEvent& event,
27 bool is_scale_gesture_detection_in_progress);
29 // Updates the snap scroll mode based on the given X and Y distance to be
30 // moved on scroll. If the scroll update is above a threshold, the snapping
31 // behavior is reset.
32 void UpdateSnapScrollMode(float distance_x, float distance_y);
34 bool IsSnapVertical() const;
35 bool IsSnapHorizontal() const;
36 bool IsSnappingScrolls() const;
38 private:
39 enum SnapMode { SNAP_NONE, SNAP_PENDING, SNAP_HORIZ, SNAP_VERT };
41 const float snap_bound_;
42 const float channel_distance_;
43 SnapMode mode_;
44 gfx::PointF down_position_;
45 gfx::Vector2dF accumulated_distance_;
47 DISALLOW_COPY_AND_ASSIGN(SnapScrollController);
50 } // namespace ui
52 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_