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

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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 // using two radii along x- & y-axes and a positive acute rotation angle in 92 // using two radii along x- & y-axes and a positive acute rotation angle in
93 // degrees. See: 93 // degrees. See:
94 // http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html 94 // http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html
95 95
96 float major_radius = event.GetTouchMajor(pointer_index) / 2.f; 96 float major_radius = event.GetTouchMajor(pointer_index) / 2.f;
97 float minor_radius = event.GetTouchMinor(pointer_index) / 2.f; 97 float minor_radius = event.GetTouchMinor(pointer_index) / 2.f;
98 98
99 DCHECK_LE(minor_radius, major_radius); 99 DCHECK_LE(minor_radius, major_radius);
100 DCHECK_IMPLIES(major_radius, minor_radius); 100 DCHECK_IMPLIES(major_radius, minor_radius);
101 101
102 float orientation_deg = event.GetOrientation(pointer_index) * 180.f / M_PI; 102 float orientation_rad = event.GetOrientation(pointer_index);
103 float orientation_deg = orientation_rad * 180.f / M_PI;
103 DCHECK_GE(major_radius, 0); 104 DCHECK_GE(major_radius, 0);
104 DCHECK_GE(minor_radius, 0); 105 DCHECK_GE(minor_radius, 0);
105 DCHECK_GE(major_radius, minor_radius); 106 DCHECK_GE(major_radius, minor_radius);
106 if (event.GetToolType(pointer_index) == MotionEvent::TOOL_TYPE_STYLUS) { 107 if (event.GetToolType(pointer_index) == MotionEvent::TOOL_TYPE_STYLUS) {
107 // Orientation lies in [-180, 180] for a stylus. Normalise to [-90, 90). 108 // Orientation lies in [-180, 180] for a stylus. Normalise to [-90, 90).
108 // Allow a small bound tolerance to account for floating point conversion. 109 // Allow a small bound tolerance to account for floating point conversion.
109 // TODO(e_hakkinen): crbug.com/493728: Pass also unaltered orientation
110 // to touch in order not to lose quadrant information.
111 DCHECK_GT(orientation_deg, -180.01f); 110 DCHECK_GT(orientation_deg, -180.01f);
112 DCHECK_LT(orientation_deg, 180.01f); 111 DCHECK_LT(orientation_deg, 180.01f);
113 if (orientation_deg >= 90.f) 112 if (orientation_deg >= 90.f)
114 orientation_deg -= 180.f; 113 orientation_deg -= 180.f;
115 else if (orientation_deg < -90.f) 114 else if (orientation_deg < -90.f)
116 orientation_deg += 180.f; 115 orientation_deg += 180.f;
116
117 // A stylus points to a direction specified by orientation and tilts to
118 // the opposite direction. Coordinate system is left-handed.
119 float tilt_rad = event.GetTilt(pointer_index);
120 float r = sin(tilt_rad);
121 float z = cos(tilt_rad);
122 touch.tiltX = atan2(sin(-orientation_rad) * r, z) * 180.f / M_PI;
123 touch.tiltY = atan2(cos(-orientation_rad) * r, z) * 180.f / M_PI;
117 } else { 124 } else {
118 // Orientation lies in [-90, 90] for a touch. Normalise to [-90, 90). 125 // Orientation lies in [-90, 90] for a touch. Normalise to [-90, 90).
119 // Allow a small bound tolerance to account for floating point conversion. 126 // Allow a small bound tolerance to account for floating point conversion.
120 DCHECK_GT(orientation_deg, -90.01f); 127 DCHECK_GT(orientation_deg, -90.01f);
121 DCHECK_LT(orientation_deg, 90.01f); 128 DCHECK_LT(orientation_deg, 90.01f);
122 if (orientation_deg >= 90.f) 129 if (orientation_deg >= 90.f)
123 orientation_deg -= 180.f; 130 orientation_deg -= 180.f;
131
132 touch.tiltX = touch.tiltY = 0;
124 } 133 }
125 if (orientation_deg >= 0) { 134 if (orientation_deg >= 0) {
126 // The case orientation_deg == 0 is handled here on purpose: although the 135 // The case orientation_deg == 0 is handled here on purpose: although the
127 // 'else' block is equivalent in this case, we want to pass the 0 value 136 // 'else' block is equivalent in this case, we want to pass the 0 value
128 // unchanged (and 0 is the default value for many devices that don't 137 // unchanged (and 0 is the default value for many devices that don't
129 // report elliptical touches). 138 // report elliptical touches).
130 touch.radiusX = minor_radius; 139 touch.radiusX = minor_radius;
131 touch.radiusY = major_radius; 140 touch.radiusY = major_radius;
132 touch.rotationAngle = orientation_deg; 141 touch.rotationAngle = orientation_deg;
133 } else { 142 } else {
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } 319 }
311 320
312 WebGestureEvent CreateWebGestureEventFromGestureEventData( 321 WebGestureEvent CreateWebGestureEventFromGestureEventData(
313 const GestureEventData& data) { 322 const GestureEventData& data) {
314 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(), 323 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(),
315 gfx::PointF(data.x, data.y), 324 gfx::PointF(data.x, data.y),
316 gfx::PointF(data.raw_x, data.raw_y), data.flags); 325 gfx::PointF(data.raw_x, data.raw_y), data.flags);
317 } 326 }
318 327
319 } // namespace ui 328 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698