Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 CONTENT_BROWSER_RENDERER_HOST_INPUT_SNAP_SCROLL_CONTROLLER_H_ | |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_INPUT_SNAP_SCROLL_CONTROLLER_H_ | |
| 7 | |
| 8 #include "base/basictypes.h" | |
| 9 | |
| 10 namespace content { | |
| 11 | |
| 12 class MotionEvent; | |
| 13 class ZoomManager; | |
| 14 | |
| 15 // Port of SnapScrollController.java from Chromium | |
|
tdresser
2014/01/08 19:18:21
Will we still need the java version once this has
| |
| 16 // * Changes to this class should be cosmetic only, easing fork maintenance. | |
| 17 // Controls the scroll snapping behavior based on scroll updates. | |
| 18 class SnapScrollController { | |
| 19 public: | |
| 20 struct Config { | |
| 21 Config(); | |
| 22 ~Config(); | |
| 23 int screen_width_pixels; | |
| 24 int screen_height_pixels; | |
| 25 int density_dpi; | |
| 26 float density; // 160 DPI ~ 1, 120 DPI ~ 0.75, etc... | |
| 27 }; | |
| 28 | |
| 29 SnapScrollController(Config config, ZoomManager* zoom_manager); | |
| 30 ~SnapScrollController(); | |
| 31 | |
| 32 // Updates the snap scroll mode based on the given X and Y distance to be | |
| 33 // moved on scroll. If the scroll update is above a threshold, the snapping | |
| 34 // behavior is reset. | |
| 35 void UpdateSnapScrollMode(float distance_x, float distance_y); | |
| 36 | |
| 37 // Sets the snap scroll mode based on the event type. | |
| 38 void SetSnapScrollingMode(const MotionEvent& event); | |
| 39 | |
| 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; } | |
| 44 | |
| 45 private: | |
| 46 enum SnapMode { | |
| 47 SNAP_NONE, | |
| 48 SNAP_HORIZ, | |
| 49 SNAP_VERT, | |
| 50 }; | |
| 51 | |
| 52 void CalculateChannelDistance(Config config); | |
| 53 | |
| 54 ZoomManager* const zoom_manager_; | |
| 55 | |
| 56 float channel_distance_; | |
| 57 SnapMode snap_scroll_mode_; | |
| 58 int first_touch_x_; | |
| 59 int first_touch_y_; | |
| 60 float distance_x_; | |
| 61 float distance_y_; | |
| 62 | |
| 63 DISALLOW_COPY_AND_ASSIGN(SnapScrollController); | |
| 64 }; | |
| 65 | |
| 66 } // namespace content | |
| 67 | |
| 68 #endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SNAP_SCROLL_CONTROLLER_H_ | |
| OLD | NEW |