OLD | NEW |
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 #ifndef UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ | 5 #ifndef UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ |
6 #define UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ | 6 #define UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "ui/events/gesture_detection/gesture_detection_export.h" | 9 #include "ui/events/gesture_detection/gesture_detection_export.h" |
10 | 10 #include "ui/gfx/geometry/point_f.h" |
11 namespace gfx { | 11 #include "ui/gfx/geometry/size_f.h" |
12 class Display; | 12 #include "ui/gfx/geometry/vector2d_f.h" |
13 } | |
14 | 13 |
15 namespace ui { | 14 namespace ui { |
16 | 15 |
17 class MotionEvent; | 16 class MotionEvent; |
18 class ZoomManager; | |
19 | 17 |
20 // Port of SnapScrollController.java from Chromium | 18 // Port of SnapScrollController.java from Chromium |
21 // Controls the scroll snapping behavior based on scroll updates. | 19 // Controls the scroll snapping behavior based on scroll updates. |
22 class SnapScrollController { | 20 class GESTURE_DETECTION_EXPORT SnapScrollController { |
23 public: | 21 public: |
24 explicit SnapScrollController(const gfx::Display& display); | 22 SnapScrollController(float snap_bound, const gfx::SizeF& display_size); |
25 ~SnapScrollController(); | 23 ~SnapScrollController(); |
26 | 24 |
| 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); |
| 28 |
27 // Updates the snap scroll mode based on the given X and Y distance to be | 29 // Updates the snap scroll mode based on the given X and Y distance to be |
28 // moved on scroll. If the scroll update is above a threshold, the snapping | 30 // moved on scroll. If the scroll update is above a threshold, the snapping |
29 // behavior is reset. | 31 // behavior is reset. |
30 void UpdateSnapScrollMode(float distance_x, float distance_y); | 32 void UpdateSnapScrollMode(float distance_x, float distance_y); |
31 | 33 |
32 // Sets the snap scroll mode based on the event type. | 34 bool IsSnapVertical() const; |
33 void SetSnapScrollingMode(const MotionEvent& event, | 35 bool IsSnapHorizontal() const; |
34 bool is_scale_gesture_detection_in_progress); | 36 bool IsSnappingScrolls() const; |
35 | |
36 void ResetSnapScrollMode() { snap_scroll_mode_ = SNAP_NONE; } | |
37 bool IsSnapVertical() const { return snap_scroll_mode_ == SNAP_VERT; } | |
38 bool IsSnapHorizontal() const { return snap_scroll_mode_ == SNAP_HORIZ; } | |
39 bool IsSnappingScrolls() const { return snap_scroll_mode_ != SNAP_NONE; } | |
40 | 37 |
41 private: | 38 private: |
42 enum SnapMode { | 39 enum SnapMode { SNAP_NONE, SNAP_PENDING, SNAP_HORIZ, SNAP_VERT }; |
43 SNAP_NONE, | |
44 SNAP_HORIZ, | |
45 SNAP_VERT | |
46 }; | |
47 | 40 |
48 float channel_distance_; | 41 const float snap_bound_; |
49 SnapMode snap_scroll_mode_; | 42 const float channel_distance_; |
50 float first_touch_x_; | 43 SnapMode mode_; |
51 float first_touch_y_; | 44 gfx::PointF down_position_; |
52 float distance_x_; | 45 gfx::Vector2dF accumulated_distance_; |
53 float distance_y_; | |
54 | 46 |
55 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); | 47 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); |
56 }; | 48 }; |
57 | 49 |
58 } // namespace ui | 50 } // namespace ui |
59 | 51 |
60 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ | 52 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ |
OLD | NEW |