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 |
| 11 namespace gfx { |
| 12 class Display; |
| 13 } |
| 14 |
11 namespace ui { | 15 namespace ui { |
12 | 16 |
13 class MotionEvent; | 17 class MotionEvent; |
14 class ZoomManager; | 18 class ZoomManager; |
15 | 19 |
16 // Port of SnapScrollController.java from Chromium | 20 // Port of SnapScrollController.java from Chromium |
17 // Controls the scroll snapping behavior based on scroll updates. | 21 // Controls the scroll snapping behavior based on scroll updates. |
18 class SnapScrollController { | 22 class SnapScrollController { |
19 public: | 23 public: |
20 struct GESTURE_DETECTION_EXPORT Config { | 24 explicit SnapScrollController(const gfx::Display& display); |
21 Config(); | |
22 ~Config(); | |
23 int screen_width_pixels; | |
24 int screen_height_pixels; | |
25 float device_scale_factor; | |
26 }; | |
27 | |
28 explicit SnapScrollController(const Config& config); | |
29 ~SnapScrollController(); | 25 ~SnapScrollController(); |
30 | 26 |
31 // Updates the snap scroll mode based on the given X and Y distance to be | 27 // 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 | 28 // moved on scroll. If the scroll update is above a threshold, the snapping |
33 // behavior is reset. | 29 // behavior is reset. |
34 void UpdateSnapScrollMode(float distance_x, float distance_y); | 30 void UpdateSnapScrollMode(float distance_x, float distance_y); |
35 | 31 |
36 // Sets the snap scroll mode based on the event type. | 32 // Sets the snap scroll mode based on the event type. |
37 void SetSnapScrollingMode(const MotionEvent& event, | 33 void SetSnapScrollingMode(const MotionEvent& event, |
38 bool is_scale_gesture_detection_in_progress); | 34 bool is_scale_gesture_detection_in_progress); |
39 | 35 |
40 void ResetSnapScrollMode() { snap_scroll_mode_ = SNAP_NONE; } | 36 void ResetSnapScrollMode() { snap_scroll_mode_ = SNAP_NONE; } |
41 bool IsSnapVertical() const { return snap_scroll_mode_ == SNAP_VERT; } | 37 bool IsSnapVertical() const { return snap_scroll_mode_ == SNAP_VERT; } |
42 bool IsSnapHorizontal() const { return snap_scroll_mode_ == SNAP_HORIZ; } | 38 bool IsSnapHorizontal() const { return snap_scroll_mode_ == SNAP_HORIZ; } |
43 bool IsSnappingScrolls() const { return snap_scroll_mode_ != SNAP_NONE; } | 39 bool IsSnappingScrolls() const { return snap_scroll_mode_ != SNAP_NONE; } |
44 | 40 |
45 private: | 41 private: |
46 enum SnapMode { | 42 enum SnapMode { |
47 SNAP_NONE, | 43 SNAP_NONE, |
48 SNAP_HORIZ, | 44 SNAP_HORIZ, |
49 SNAP_VERT | 45 SNAP_VERT |
50 }; | 46 }; |
51 | 47 |
52 static float CalculateChannelDistance(const Config& config); | |
53 | |
54 float channel_distance_; | 48 float channel_distance_; |
55 SnapMode snap_scroll_mode_; | 49 SnapMode snap_scroll_mode_; |
56 float first_touch_x_; | 50 float first_touch_x_; |
57 float first_touch_y_; | 51 float first_touch_y_; |
58 float distance_x_; | 52 float distance_x_; |
59 float distance_y_; | 53 float distance_y_; |
60 | 54 |
61 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); | 55 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); |
62 }; | 56 }; |
63 | 57 |
64 } // namespace ui | 58 } // namespace ui |
65 | 59 |
66 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ | 60 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ |
OLD | NEW |