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

Unified Diff: ui/events/gesture_detection/snap_scroll_controller.cc

Issue 220063002: [Android] Use DIP coordinates with MotionEventAndroid (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes Created 6 years, 8 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
« no previous file with comments | « ui/events/gesture_detection/snap_scroll_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/events/gesture_detection/snap_scroll_controller.cc
diff --git a/ui/events/gesture_detection/snap_scroll_controller.cc b/ui/events/gesture_detection/snap_scroll_controller.cc
index 85ac432aa321a527b02330e3720eba0a3ba002ff..bde5a35602d6579cef87173f6fe7ed44c6755cf6 100644
--- a/ui/events/gesture_detection/snap_scroll_controller.cc
+++ b/ui/events/gesture_detection/snap_scroll_controller.cc
@@ -7,19 +7,33 @@
#include <cmath>
#include "ui/events/gesture_detection/motion_event.h"
+#include "ui/gfx/display.h"
namespace ui {
namespace {
const int kSnapBound = 16;
-} // namespace
+const float kMinSnapChannelDistance = kSnapBound;
+const float kMaxSnapChannelDistance = kMinSnapChannelDistance * 3.f;
+const float kSnapChannelDipsPerScreenDip = kMinSnapChannelDistance / 480.f;
+
+float CalculateChannelDistance(const gfx::Display& display) {
+ if (display.bounds().IsEmpty())
+ return kMinSnapChannelDistance;
+
+ float screen_size =
+ std::abs(hypot(static_cast<float>(display.bounds().width()),
+ static_cast<float>(display.bounds().height())));
-SnapScrollController::Config::Config()
- : screen_width_pixels(1), screen_height_pixels(1), device_scale_factor(1) {}
+ float snap_channel_distance = screen_size * kSnapChannelDipsPerScreenDip;
+ return std::max(kMinSnapChannelDistance,
+ std::min(kMaxSnapChannelDistance, snap_channel_distance));
+}
+
+} // namespace
-SnapScrollController::Config::~Config() {}
-SnapScrollController::SnapScrollController(const Config& config)
- : channel_distance_(CalculateChannelDistance(config)),
+SnapScrollController::SnapScrollController(const gfx::Display& display)
+ : channel_distance_(CalculateChannelDistance(display)),
snap_scroll_mode_(SNAP_NONE),
first_touch_x_(-1),
first_touch_y_(-1),
@@ -89,27 +103,4 @@ void SnapScrollController::SetSnapScrollingMode(
}
}
-// static
-float SnapScrollController::CalculateChannelDistance(const Config& config) {
- float channel_distance = 16.f;
-
- const float screen_size = std::abs(
- hypot((float)config.screen_width_pixels / config.device_scale_factor,
- (float)config.screen_height_pixels / config.device_scale_factor));
- if (screen_size < 480.f) {
- channel_distance = 16.f;
- } else if (screen_size < 800.f) {
- channel_distance = 22.f;
- } else if (screen_size < 1120.f) {
- channel_distance = 28.f;
- } else {
- channel_distance = 34.f;
- }
- channel_distance = channel_distance * config.device_scale_factor;
- if (channel_distance < 16.f)
- channel_distance = 16.f;
-
- return channel_distance;
-}
-
} // namespace ui
« no previous file with comments | « ui/events/gesture_detection/snap_scroll_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698