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"
16 // Port of SnapScrollController.java from Chromium
17 // Controls the scroll snapping behavior based on scroll updates.
18 class SnapScrollController
{
20 struct GESTURE_DETECTION_EXPORT Config
{
23 int screen_width_pixels
;
24 int screen_height_pixels
;
25 float device_scale_factor
;
28 explicit SnapScrollController(const Config
& config
);
29 ~SnapScrollController();
31 // Updates the snap scroll mode based on the given X and Y distance to be
32 // moved on scroll. If the scroll update is above a threshold, the snapping
34 void UpdateSnapScrollMode(float distance_x
, float distance_y
);
36 // Sets the snap scroll mode based on the event type.
37 void SetSnapScrollingMode(const MotionEvent
& event
,
38 bool is_scale_gesture_detection_in_progress
);
40 void ResetSnapScrollMode() { snap_scroll_mode_
= SNAP_NONE
; }
41 bool IsSnapVertical() const { return snap_scroll_mode_
== SNAP_VERT
; }
42 bool IsSnapHorizontal() const { return snap_scroll_mode_
== SNAP_HORIZ
; }
43 bool IsSnappingScrolls() const { return snap_scroll_mode_
!= SNAP_NONE
; }
52 static float CalculateChannelDistance(const Config
& config
);
54 float channel_distance_
;
55 SnapMode snap_scroll_mode_
;
61 DISALLOW_COPY_AND_ASSIGN(SnapScrollController
);
66 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_