Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / ui / events / gesture_detection / snap_scroll_controller.h
blob753c2bcb20103e383fef3a58d64f20900b6f3d8a
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.
5 #ifndef UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
6 #define UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "ui/events/gesture_detection/gesture_detection_export.h"
11 namespace gfx {
12 class Display;
15 namespace ui {
17 class MotionEvent;
18 class ZoomManager;
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();
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);
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);
36 void ResetSnapScrollMode() { snap_scroll_mode_ = SNAP_NONE; }
37 bool IsSnapVertical() const { return snap_scroll_mode_ == SNAP_VERT; }
38 bool IsSnapHorizontal() const { return snap_scroll_mode_ == SNAP_HORIZ; }
39 bool IsSnappingScrolls() const { return snap_scroll_mode_ != SNAP_NONE; }
41 private:
42 enum SnapMode {
43 SNAP_NONE,
44 SNAP_HORIZ,
45 SNAP_VERT
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_;
55 DISALLOW_COPY_AND_ASSIGN(SnapScrollController);
58 } // namespace ui
60 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_