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

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

Issue 1417803002: Pass MotionEvent tilt angles to Blink on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Flattened nested ifs, fixed a special case Created 5 years, 1 month 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // using two radii along x- & y-axes and a positive acute rotation angle in 118 // using two radii along x- & y-axes and a positive acute rotation angle in
119 // degrees. See: 119 // degrees. See:
120 // http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html 120 // http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html
121 121
122 float major_radius = event.GetTouchMajor(pointer_index) / 2.f; 122 float major_radius = event.GetTouchMajor(pointer_index) / 2.f;
123 float minor_radius = event.GetTouchMinor(pointer_index) / 2.f; 123 float minor_radius = event.GetTouchMinor(pointer_index) / 2.f;
124 124
125 DCHECK_LE(minor_radius, major_radius); 125 DCHECK_LE(minor_radius, major_radius);
126 DCHECK_IMPLIES(major_radius, minor_radius); 126 DCHECK_IMPLIES(major_radius, minor_radius);
127 127
128 float orientation_deg = event.GetOrientation(pointer_index) * 180.f / M_PI; 128 float orientation_rad = event.GetOrientation(pointer_index);
129 float orientation_deg = orientation_rad * 180.f / M_PI;
129 DCHECK_GE(major_radius, 0); 130 DCHECK_GE(major_radius, 0);
130 DCHECK_GE(minor_radius, 0); 131 DCHECK_GE(minor_radius, 0);
131 DCHECK_GE(major_radius, minor_radius); 132 DCHECK_GE(major_radius, minor_radius);
132 // Orientation lies in [-180, 180] for a stylus, and [-90, 90] for other 133 // Orientation lies in [-180, 180] for a stylus, and [-90, 90] for other
133 // touchscreen inputs. There are exceptions on Android when a device is 134 // touchscreen inputs. There are exceptions on Android when a device is
134 // rotated, yielding touch orientations in the range of [-180, 180]. 135 // rotated, yielding touch orientations in the range of [-180, 180].
135 // Regardless, normalise to [-90, 90), allowing a small tolerance to account 136 // Regardless, normalise to [-90, 90), allowing a small tolerance to account
136 // for floating point conversion. 137 // for floating point conversion.
137 // TODO(e_hakkinen): Also pass unaltered stylus orientation, avoiding loss of 138 // TODO(e_hakkinen): Also pass unaltered stylus orientation, avoiding loss of
138 // quadrant information, see crbug.com/493728. 139 // quadrant information, see crbug.com/493728.
(...skipping 12 matching lines...) Expand all
151 touch.radiusY = major_radius; 152 touch.radiusY = major_radius;
152 touch.rotationAngle = orientation_deg; 153 touch.rotationAngle = orientation_deg;
153 } else { 154 } else {
154 touch.radiusX = major_radius; 155 touch.radiusX = major_radius;
155 touch.radiusY = minor_radius; 156 touch.radiusY = minor_radius;
156 touch.rotationAngle = orientation_deg + 90; 157 touch.rotationAngle = orientation_deg + 90;
157 } 158 }
158 159
159 touch.force = event.GetPressure(pointer_index); 160 touch.force = event.GetPressure(pointer_index);
160 161
162 if (event.GetToolType(pointer_index) == MotionEvent::TOOL_TYPE_STYLUS) {
163 // A stylus points to a direction specified by orientation and tilts to
164 // the opposite direction. Coordinate system is left-handed.
165 float tilt_rad = event.GetTilt(pointer_index);
166 float r = sin(tilt_rad);
167 float z = cos(tilt_rad);
168 touch.tiltX = lround(atan2(sin(-orientation_rad) * r, z) * 180.f / M_PI);
169 touch.tiltY = lround(atan2(cos(-orientation_rad) * r, z) * 180.f / M_PI);
170 } else {
171 touch.tiltX = touch.tiltY = 0;
172 }
173
161 return touch; 174 return touch;
162 } 175 }
163 176
164 } // namespace 177 } // namespace
165 178
166 blink::WebTouchEvent CreateWebTouchEventFromMotionEvent( 179 blink::WebTouchEvent CreateWebTouchEventFromMotionEvent(
167 const MotionEvent& event, 180 const MotionEvent& event,
168 bool may_cause_scrolling) { 181 bool may_cause_scrolling) {
169 static_assert(static_cast<int>(MotionEvent::MAX_TOUCH_POINT_COUNT) == 182 static_assert(static_cast<int>(MotionEvent::MAX_TOUCH_POINT_COUNT) ==
170 static_cast<int>(blink::WebTouchEvent::touchesLengthCap), 183 static_cast<int>(blink::WebTouchEvent::touchesLengthCap),
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 } 345 }
333 346
334 WebGestureEvent CreateWebGestureEventFromGestureEventData( 347 WebGestureEvent CreateWebGestureEventFromGestureEventData(
335 const GestureEventData& data) { 348 const GestureEventData& data) {
336 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(), 349 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(),
337 gfx::PointF(data.x, data.y), 350 gfx::PointF(data.x, data.y),
338 gfx::PointF(data.raw_x, data.raw_y), data.flags); 351 gfx::PointF(data.raw_x, data.raw_y), data.flags);
339 } 352 }
340 353
341 } // namespace ui 354 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698