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 gfx { 12 class Display; 13 } 14 15 namespace ui { 16 17 class MotionEvent; 18 class ZoomManager; 19 20 // Port of SnapScrollController.java from Chromium 21 // Controls the scroll snapping behavior based on scroll updates. 22 class SnapScrollController { 23 public: 24 explicit SnapScrollController(const gfx::Display& display); 25 ~SnapScrollController(); 26 27 // 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 29 // behavior is reset. 30 void UpdateSnapScrollMode(float distance_x, float distance_y); 31 32 // Sets the snap scroll mode based on the event type. 33 void SetSnapScrollingMode(const MotionEvent& event, 34 bool is_scale_gesture_detection_in_progress); 35 ResetSnapScrollMode()36 void ResetSnapScrollMode() { snap_scroll_mode_ = SNAP_NONE; } IsSnapVertical()37 bool IsSnapVertical() const { return snap_scroll_mode_ == SNAP_VERT; } IsSnapHorizontal()38 bool IsSnapHorizontal() const { return snap_scroll_mode_ == SNAP_HORIZ; } IsSnappingScrolls()39 bool IsSnappingScrolls() const { return snap_scroll_mode_ != SNAP_NONE; } 40 41 private: 42 enum SnapMode { 43 SNAP_NONE, 44 SNAP_HORIZ, 45 SNAP_VERT 46 }; 47 48 float channel_distance_; 49 SnapMode snap_scroll_mode_; 50 float first_touch_x_; 51 float first_touch_y_; 52 float distance_x_; 53 float distance_y_; 54 55 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); 56 }; 57 58 } // namespace ui 59 60 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_ 61