Media Galleries API Metadata: Fix bugs in utility process cleanup.
[chromium-blink-merge.git] / ui / events / gesture_detection / snap_scroll_controller.h
blobed8717bf698c3c25a2b764e2705e9ba4b2d1d972
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 ui {
13 class MotionEvent;
14 class ZoomManager;
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;
28 explicit SnapScrollController(const Config& config);
29 ~SnapScrollController();
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);
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);
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; }
45 private:
46 enum SnapMode {
47 SNAP_NONE,
48 SNAP_HORIZ,
49 SNAP_VERT
52 static float CalculateChannelDistance(const Config& config);
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_;
61 DISALLOW_COPY_AND_ASSIGN(SnapScrollController);
64 } // namespace ui
66 #endif // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_