Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / events / gesture_detection / snap_scroll_controller.h
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 #include "ui/gfx/geometry/point_f.h"
11 #include "ui/gfx/geometry/size_f.h"
12 #include "ui/gfx/geometry/vector2d_f.h"
13
14 namespace ui {
15
16 class MotionEvent;
17
18 // Port of SnapScrollController.java from Chromium
19 // Controls the scroll snapping behavior based on scroll updates.
20 class GESTURE_DETECTION_EXPORT SnapScrollController {
21  public:
22   SnapScrollController(float snap_bound, const gfx::SizeF& display_size);
23   ~SnapScrollController();
24
25   // Sets the snap scroll mode based on the event type.
26   void SetSnapScrollMode(const MotionEvent& event,
27                          bool is_scale_gesture_detection_in_progress);
28
29   // 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   // behavior is reset.
32   void UpdateSnapScrollMode(float distance_x, float distance_y);
33
34   bool IsSnapVertical() const;
35   bool IsSnapHorizontal() const;
36   bool IsSnappingScrolls() const;
37
38  private:
39   enum SnapMode { SNAP_NONE, SNAP_PENDING, SNAP_HORIZ, SNAP_VERT };
40
41   const float snap_bound_;
42   const float channel_distance_;
43   SnapMode mode_;
44   gfx::PointF down_position_;
45   gfx::Vector2dF accumulated_distance_;
46
47   DISALLOW_COPY_AND_ASSIGN(SnapScrollController);
48 };
49
50 }  // namespace ui
51
52 #endif  // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_