OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 #ifndef UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ |
| 6 #define UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ |
| 7 |
| 8 #include "base/basictypes.h" |
| 9 #include "ui/events/gesture_detection/gesture_detection_export.h" |
| 10 |
| 11 namespace ui { |
| 12 |
| 13 class MotionEvent; |
| 14 class ZoomManager; |
| 15 |
| 16 // Port of SnapScrollController.java from Chromium |
| 17 // Controls the scroll snapping behavior based on scroll updates. |
| 18 class SnapScrollController { |
| 19 public: |
| 20 struct GESTURE_DETECTION_EXPORT Config { |
| 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(); |
| 30 |
| 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 |
| 33 // behavior is reset. |
| 34 void UpdateSnapScrollMode(float distance_x, float distance_y); |
| 35 |
| 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); |
| 39 |
| 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; } |
| 44 |
| 45 private: |
| 46 enum SnapMode { |
| 47 SNAP_NONE, |
| 48 SNAP_HORIZ, |
| 49 SNAP_VERT |
| 50 }; |
| 51 |
| 52 static float CalculateChannelDistance(const Config& config); |
| 53 |
| 54 float channel_distance_; |
| 55 SnapMode snap_scroll_mode_; |
| 56 float first_touch_x_; |
| 57 float first_touch_y_; |
| 58 float distance_x_; |
| 59 float distance_y_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); |
| 62 }; |
| 63 |
| 64 } // namespace ui |
| 65 |
| 66 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ |
OLD | NEW |