| 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 #include "ui/events/gesture_event_details.h" |
| 10 #include "ui/gfx/geometry/point_f.h" | 11 #include "ui/gfx/geometry/point_f.h" |
| 11 #include "ui/gfx/geometry/size_f.h" | 12 #include "ui/gfx/geometry/size_f.h" |
| 12 #include "ui/gfx/geometry/vector2d_f.h" | 13 #include "ui/gfx/geometry/vector2d_f.h" |
| 13 | 14 |
| 14 namespace ui { | 15 namespace ui { |
| 15 | 16 |
| 16 class MotionEvent; | 17 class MotionEvent; |
| 17 | 18 |
| 18 // Port of SnapScrollController.java from Chromium | 19 // Port of SnapScrollController.java from Chromium |
| 19 // Controls the scroll snapping behavior based on scroll updates. | 20 // Controls the scroll snapping behavior based on scroll updates. |
| 20 class GESTURE_DETECTION_EXPORT SnapScrollController { | 21 class GESTURE_DETECTION_EXPORT SnapScrollController { |
| 21 public: | 22 public: |
| 22 SnapScrollController(float snap_bound, const gfx::SizeF& display_size); | 23 SnapScrollController(float snap_bound, const gfx::SizeF& display_size); |
| 23 ~SnapScrollController(); | 24 ~SnapScrollController(); |
| 24 | 25 |
| 25 // Sets the snap scroll mode based on the event type. | 26 // Sets the snap scroll mode based on the event type. |
| 26 void SetSnapScrollMode(const MotionEvent& event, | 27 void SetSnapScrollMode(const MotionEvent& event, |
| 27 bool is_scale_gesture_detection_in_progress); | 28 bool is_scale_gesture_detection_in_progress); |
| 28 | 29 |
| 29 // Updates the snap scroll mode based on the given X and Y distance to be | 30 // 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 // moved on scroll. If the scroll update is above a threshold, the snapping |
| 31 // behavior is reset. | 32 // behavior is reset. |
| 32 void UpdateSnapScrollMode(float distance_x, float distance_y); | 33 void UpdateSnapScrollMode(float distance_x, float distance_y); |
| 33 | 34 |
| 35 GestureEventDetails::ScrollRailState ScrollRailState() const; |
| 36 // TODO(tdresser): remove as part of crbug.com/472223. |
| 34 bool IsSnapVertical() const; | 37 bool IsSnapVertical() const; |
| 35 bool IsSnapHorizontal() const; | 38 bool IsSnapHorizontal() const; |
| 36 bool IsSnappingScrolls() const; | 39 bool IsSnappingScrolls() const; |
| 37 | 40 |
| 38 private: | 41 private: |
| 39 enum SnapMode { SNAP_NONE, SNAP_PENDING, SNAP_HORIZ, SNAP_VERT }; | 42 enum SnapMode { SNAP_NONE, SNAP_PENDING, SNAP_HORIZ, SNAP_VERT }; |
| 40 | 43 |
| 41 const float snap_bound_; | 44 const float snap_bound_; |
| 42 const float channel_distance_; | 45 const float channel_distance_; |
| 43 SnapMode mode_; | 46 SnapMode mode_; |
| 44 gfx::PointF down_position_; | 47 gfx::PointF down_position_; |
| 45 gfx::Vector2dF accumulated_distance_; | 48 gfx::Vector2dF accumulated_distance_; |
| 46 | 49 |
| 47 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); | 50 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); |
| 48 }; | 51 }; |
| 49 | 52 |
| 50 } // namespace ui | 53 } // namespace ui |
| 51 | 54 |
| 52 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ | 55 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ |
| OLD | NEW |