snap_scroll_controller.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #ifndef UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
  5. #define UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
  6. #include "ui/events/gesture_detection/gesture_detection_export.h"
  7. #include "ui/gfx/geometry/point_f.h"
  8. #include "ui/gfx/geometry/size_f.h"
  9. #include "ui/gfx/geometry/vector2d_f.h"
  10. namespace ui {
  11. class MotionEvent;
  12. // Port of SnapScrollController.java from Chromium
  13. // Controls the scroll snapping behavior based on scroll updates.
  14. class GESTURE_DETECTION_EXPORT SnapScrollController {
  15. public:
  16. SnapScrollController(float snap_bound, const gfx::SizeF& display_size);
  17. SnapScrollController(const SnapScrollController&) = delete;
  18. SnapScrollController& operator=(const SnapScrollController&) = delete;
  19. ~SnapScrollController();
  20. // Sets the snap scroll mode based on the event type.
  21. void SetSnapScrollMode(const MotionEvent& event,
  22. bool is_scale_gesture_detection_in_progress);
  23. // Updates the snap scroll mode based on the given X and Y distance to be
  24. // moved on scroll. If the scroll update is above a threshold, the snapping
  25. // behavior is reset.
  26. void UpdateSnapScrollMode(float distance_x, float distance_y);
  27. bool IsSnapVertical() const;
  28. bool IsSnapHorizontal() const;
  29. bool IsSnappingScrolls() const;
  30. private:
  31. enum SnapMode { SNAP_NONE, SNAP_PENDING, SNAP_HORIZ, SNAP_VERT };
  32. const float snap_bound_;
  33. const float channel_distance_;
  34. SnapMode mode_;
  35. gfx::PointF down_position_;
  36. gfx::Vector2dF accumulated_distance_;
  37. };
  38. } // namespace ui
  39. #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_