1a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// found in the LICENSE file.
4a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
5a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#ifndef UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
6a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#define UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
7a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
8a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "base/basictypes.h"
9a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#include "ui/events/gesture_detection/gesture_detection_export.h"
10a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
11a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochnamespace gfx {
12a02191e04bc25c4935f804f2c080ae28663d096dBen Murdochclass Display;
13a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
14a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
15a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)namespace ui {
16a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
17a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class MotionEvent;
18a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class ZoomManager;
19a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
20a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Port of SnapScrollController.java from Chromium
21a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)// Controls the scroll snapping behavior based on scroll updates.
22a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)class SnapScrollController {
23a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) public:
24a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  explicit SnapScrollController(const gfx::Display& display);
25a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  ~SnapScrollController();
26a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
27a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Updates the snap scroll mode based on the given X and Y distance to be
28a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // moved on scroll.  If the scroll update is above a threshold, the snapping
29a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // behavior is reset.
30a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void UpdateSnapScrollMode(float distance_x, float distance_y);
31a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
32a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  // Sets the snap scroll mode based on the event type.
33a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void SetSnapScrollingMode(const MotionEvent& event,
34a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)                            bool is_scale_gesture_detection_in_progress);
35a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
36a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  void ResetSnapScrollMode() { snap_scroll_mode_ = SNAP_NONE; }
37a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool IsSnapVertical() const { return snap_scroll_mode_ == SNAP_VERT; }
38a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool IsSnapHorizontal() const { return snap_scroll_mode_ == SNAP_HORIZ; }
39a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  bool IsSnappingScrolls() const { return snap_scroll_mode_ != SNAP_NONE; }
40a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
41a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles) private:
42a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  enum SnapMode {
43a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    SNAP_NONE,
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    SNAP_HORIZ,
45a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)    SNAP_VERT
46a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  };
47a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
48a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  float channel_distance_;
49a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  SnapMode snap_scroll_mode_;
50a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  float first_touch_x_;
51a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  float first_touch_y_;
52a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  float distance_x_;
53a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  float distance_y_;
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
55a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(SnapScrollController);
56a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)};
57a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
58a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)}  // namespace ui
59a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)
60a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)#endif  // UI_EVENTS_GESTURE_DETECTION_SNAP_SCROLL_CONTROLLER_H_
61