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

Side by Side Diff: ui/events/blink/blink_event_util.cc

Issue 1187273004: Pass MotionEvent tilt angles to Blink on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // MSVC++ requires this to be set before any other includes to get M_PI. 5 // MSVC++ requires this to be set before any other includes to get M_PI.
6 #define _USE_MATH_DEFINES 6 #define _USE_MATH_DEFINES
7 7
8 #include "ui/events/blink/blink_event_util.h" 8 #include "ui/events/blink/blink_event_util.h"
9 9
10 #include <cmath> 10 #include <cmath>
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 // using two radii along x- & y-axes and a positive acute rotation angle in 112 // using two radii along x- & y-axes and a positive acute rotation angle in
113 // degrees. See: 113 // degrees. See:
114 // http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html 114 // http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html
115 115
116 float major_radius = event.GetTouchMajor(pointer_index) / 2.f; 116 float major_radius = event.GetTouchMajor(pointer_index) / 2.f;
117 float minor_radius = event.GetTouchMinor(pointer_index) / 2.f; 117 float minor_radius = event.GetTouchMinor(pointer_index) / 2.f;
118 118
119 DCHECK_LE(minor_radius, major_radius); 119 DCHECK_LE(minor_radius, major_radius);
120 DCHECK_IMPLIES(major_radius, minor_radius); 120 DCHECK_IMPLIES(major_radius, minor_radius);
121 121
122 float orientation_deg = event.GetOrientation(pointer_index) * 180.f / M_PI; 122 float orientation_rad = event.GetOrientation(pointer_index);
123 float orientation_deg = orientation_rad * 180.f / M_PI;
123 DCHECK_GE(major_radius, 0); 124 DCHECK_GE(major_radius, 0);
124 DCHECK_GE(minor_radius, 0); 125 DCHECK_GE(minor_radius, 0);
125 DCHECK_GE(major_radius, minor_radius); 126 DCHECK_GE(major_radius, minor_radius);
126 if (event.GetToolType(pointer_index) == MotionEvent::TOOL_TYPE_STYLUS) { 127 if (event.GetToolType(pointer_index) == MotionEvent::TOOL_TYPE_STYLUS) {
127 // Orientation lies in [-180, 180] for a stylus. Normalise to [-90, 90). 128 // Orientation lies in [-180, 180] for a stylus. Normalise to [-90, 90).
128 // Allow a small bound tolerance to account for floating point conversion. 129 // Allow a small bound tolerance to account for floating point conversion.
129 // TODO(e_hakkinen): crbug.com/493728: Pass also unaltered orientation
130 // to touch in order not to lose quadrant information.
131 DCHECK_GT(orientation_deg, -180.01f); 130 DCHECK_GT(orientation_deg, -180.01f);
132 DCHECK_LT(orientation_deg, 180.01f); 131 DCHECK_LT(orientation_deg, 180.01f);
133 if (orientation_deg >= 90.f) 132 if (orientation_deg >= 90.f)
134 orientation_deg -= 180.f; 133 orientation_deg -= 180.f;
135 else if (orientation_deg < -90.f) 134 else if (orientation_deg < -90.f)
136 orientation_deg += 180.f; 135 orientation_deg += 180.f;
136
137 // A stylus points to a direction specified by orientation and tilts to
jdduke (slow) 2015/08/12 17:00:13 Same here, I think we want some basic smoke test c
138 // the opposite direction. Coordinate system is left-handed.
139 float tilt_rad = event.GetTilt(pointer_index);
140 float r = sin(tilt_rad);
141 float z = cos(tilt_rad);
142 touch.tiltX = atan2(sin(-orientation_rad) * r, z) * 180.f / M_PI;
143 touch.tiltY = atan2(cos(-orientation_rad) * r, z) * 180.f / M_PI;
137 } else { 144 } else {
138 // Orientation lies in [-90, 90] for a touch. Normalise to [-90, 90). 145 // Orientation lies in [-90, 90] for a touch. Normalise to [-90, 90).
139 // Allow a small bound tolerance to account for floating point conversion. 146 // Allow a small bound tolerance to account for floating point conversion.
140 DCHECK_GT(orientation_deg, -90.01f); 147 DCHECK_GT(orientation_deg, -90.01f);
141 DCHECK_LT(orientation_deg, 90.01f); 148 DCHECK_LT(orientation_deg, 90.01f);
142 if (orientation_deg >= 90.f) 149 if (orientation_deg >= 90.f)
143 orientation_deg -= 180.f; 150 orientation_deg -= 180.f;
151
152 touch.tiltX = touch.tiltY = 0;
144 } 153 }
145 if (orientation_deg >= 0) { 154 if (orientation_deg >= 0) {
146 // The case orientation_deg == 0 is handled here on purpose: although the 155 // The case orientation_deg == 0 is handled here on purpose: although the
147 // 'else' block is equivalent in this case, we want to pass the 0 value 156 // 'else' block is equivalent in this case, we want to pass the 0 value
148 // unchanged (and 0 is the default value for many devices that don't 157 // unchanged (and 0 is the default value for many devices that don't
149 // report elliptical touches). 158 // report elliptical touches).
150 touch.radiusX = minor_radius; 159 touch.radiusX = minor_radius;
151 touch.radiusY = major_radius; 160 touch.radiusY = major_radius;
152 touch.rotationAngle = orientation_deg; 161 touch.rotationAngle = orientation_deg;
153 } else { 162 } else {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 339 }
331 340
332 WebGestureEvent CreateWebGestureEventFromGestureEventData( 341 WebGestureEvent CreateWebGestureEventFromGestureEventData(
333 const GestureEventData& data) { 342 const GestureEventData& data) {
334 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(), 343 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(),
335 gfx::PointF(data.x, data.y), 344 gfx::PointF(data.x, data.y),
336 gfx::PointF(data.raw_x, data.raw_y), data.flags); 345 gfx::PointF(data.raw_x, data.raw_y), data.flags);
337 } 346 }
338 347
339 } // namespace ui 348 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698