Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(842)

Unified Diff: content/browser/renderer_host/input/gestures/snap_scroll_controller.h

Issue 128613003: [Tracking Patch] Unified gesture detection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/gestures/snap_scroll_controller.h
diff --git a/content/browser/renderer_host/input/gestures/snap_scroll_controller.h b/content/browser/renderer_host/input/gestures/snap_scroll_controller.h
new file mode 100644
index 0000000000000000000000000000000000000000..fd653c7cb0bb68924a1afabe84ff3ca8eaaafff3
--- /dev/null
+++ b/content/browser/renderer_host/input/gestures/snap_scroll_controller.h
@@ -0,0 +1,68 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_BROWSER_RENDERER_HOST_INPUT_SNAP_SCROLL_CONTROLLER_H_
+#define CONTENT_BROWSER_RENDERER_HOST_INPUT_SNAP_SCROLL_CONTROLLER_H_
+
+#include "base/basictypes.h"
+
+namespace content {
+
+class MotionEvent;
+class ZoomManager;
+
+// Port of SnapScrollController.java from Chromium
tdresser 2014/01/08 19:18:21 Will we still need the java version once this has
+// * Changes to this class should be cosmetic only, easing fork maintenance.
+// Controls the scroll snapping behavior based on scroll updates.
+class SnapScrollController {
+ public:
+ struct Config {
+ Config();
+ ~Config();
+ int screen_width_pixels;
+ int screen_height_pixels;
+ int density_dpi;
+ float density; // 160 DPI ~ 1, 120 DPI ~ 0.75, etc...
+ };
+
+ SnapScrollController(Config config, ZoomManager* zoom_manager);
+ ~SnapScrollController();
+
+ // Updates the snap scroll mode based on the given X and Y distance to be
+ // moved on scroll. If the scroll update is above a threshold, the snapping
+ // behavior is reset.
+ void UpdateSnapScrollMode(float distance_x, float distance_y);
+
+ // Sets the snap scroll mode based on the event type.
+ void SetSnapScrollingMode(const MotionEvent& event);
+
+ void ResetSnapScrollMode() { snap_scroll_mode_ = SNAP_NONE; }
+ bool IsSnapVertical() const { return snap_scroll_mode_ == SNAP_VERT; }
+ bool IsSnapHorizontal() const { return snap_scroll_mode_ == SNAP_HORIZ; }
+ bool IsSnappingScrolls() const { return snap_scroll_mode_ != SNAP_NONE; }
+
+ private:
+ enum SnapMode {
+ SNAP_NONE,
+ SNAP_HORIZ,
+ SNAP_VERT,
+ };
+
+ void CalculateChannelDistance(Config config);
+
+ ZoomManager* const zoom_manager_;
+
+ float channel_distance_;
+ SnapMode snap_scroll_mode_;
+ int first_touch_x_;
+ int first_touch_y_;
+ float distance_x_;
+ float distance_y_;
+
+ DISALLOW_COPY_AND_ASSIGN(SnapScrollController);
+};
+
+} // namespace content
+
+#endif // CONTENT_BROWSER_RENDERER_HOST_INPUT_SNAP_SCROLL_CONTROLLER_H_

Powered by Google App Engine
This is Rietveld 408576698