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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « ui/events/gesture_detection/snap_scroll_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/events/gesture_detection/snap_scroll_controller.h" 5 #include "ui/events/gesture_detection/snap_scroll_controller.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 #include "ui/events/gesture_detection/motion_event.h" 9 #include "ui/events/gesture_detection/motion_event.h"
10 #include "ui/gfx/display.h"
10 11
11 namespace ui { 12 namespace ui {
12 namespace { 13 namespace {
13 const int kSnapBound = 16; 14 const int kSnapBound = 16;
15 const float kMinSnapChannelDistance = kSnapBound;
16 const float kMaxSnapChannelDistance = kMinSnapChannelDistance * 3.f;
17 const float kSnapChannelDipsPerScreenDip = kMinSnapChannelDistance / 480.f;
18
19 float CalculateChannelDistance(const gfx::Display& display) {
20 if (display.bounds().IsEmpty())
21 return kMinSnapChannelDistance;
22
23 float screen_size =
24 std::abs(hypot(static_cast<float>(display.bounds().width()),
25 static_cast<float>(display.bounds().height())));
26
27 float snap_channel_distance = screen_size * kSnapChannelDipsPerScreenDip;
28 return std::max(kMinSnapChannelDistance,
29 std::min(kMaxSnapChannelDistance, snap_channel_distance));
30 }
31
14 } // namespace 32 } // namespace
15 33
16 SnapScrollController::Config::Config()
17 : screen_width_pixels(1), screen_height_pixels(1), device_scale_factor(1) {}
18 34
19 SnapScrollController::Config::~Config() {} 35 SnapScrollController::SnapScrollController(const gfx::Display& display)
20 36 : channel_distance_(CalculateChannelDistance(display)),
21 SnapScrollController::SnapScrollController(const Config& config)
22 : channel_distance_(CalculateChannelDistance(config)),
23 snap_scroll_mode_(SNAP_NONE), 37 snap_scroll_mode_(SNAP_NONE),
24 first_touch_x_(-1), 38 first_touch_x_(-1),
25 first_touch_y_(-1), 39 first_touch_y_(-1),
26 distance_x_(0), 40 distance_x_(0),
27 distance_y_(0) {} 41 distance_y_(0) {}
28 42
29 SnapScrollController::~SnapScrollController() {} 43 SnapScrollController::~SnapScrollController() {}
30 44
31 void SnapScrollController::UpdateSnapScrollMode(float distance_x, 45 void SnapScrollController::UpdateSnapScrollMode(float distance_x,
32 float distance_y) { 46 float distance_y) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 first_touch_x_ = -1; 96 first_touch_x_ = -1;
83 first_touch_y_ = -1; 97 first_touch_y_ = -1;
84 distance_x_ = 0; 98 distance_x_ = 0;
85 distance_y_ = 0; 99 distance_y_ = 0;
86 break; 100 break;
87 default: 101 default:
88 break; 102 break;
89 } 103 }
90 } 104 }
91 105
92 // static
93 float SnapScrollController::CalculateChannelDistance(const Config& config) {
94 float channel_distance = 16.f;
95
96 const float screen_size = std::abs(
97 hypot((float)config.screen_width_pixels / config.device_scale_factor,
98 (float)config.screen_height_pixels / config.device_scale_factor));
99 if (screen_size < 480.f) {
100 channel_distance = 16.f;
101 } else if (screen_size < 800.f) {
102 channel_distance = 22.f;
103 } else if (screen_size < 1120.f) {
104 channel_distance = 28.f;
105 } else {
106 channel_distance = 34.f;
107 }
108 channel_distance = channel_distance * config.device_scale_factor;
109 if (channel_distance < 16.f)
110 channel_distance = 16.f;
111
112 return channel_distance;
113 }
114
115 } // namespace ui 106 } // namespace ui
OLDNEW
« 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