OLD | NEW |
---|---|
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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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_deg = event.GetOrientation(pointer_index) * 180.f / M_PI; |
103 DCHECK_GE(major_radius, 0); | 103 DCHECK_GE(major_radius, 0); |
104 DCHECK_GE(minor_radius, 0); | 104 DCHECK_GE(minor_radius, 0); |
105 DCHECK_GE(major_radius, minor_radius); | 105 DCHECK_GE(major_radius, minor_radius); |
106 if (event.GetToolType(pointer_index) == MotionEvent::TOOL_TYPE_STYLUS) { | 106 if (event.GetToolType(pointer_index) == MotionEvent::TOOL_TYPE_STYLUS) { |
mustaq
2015/06/17 20:01:27
We should convert MotionEvent orientation+tilt to
USE eero AT chromium.org
2015/06/18 11:34:07
Done.
| |
107 // Orientation lies in [-180, 180] for a stylus. Normalise to [-90, 90). | 107 // Orientation lies in [-180, 180] for a stylus. Normalise to [-90, 90). |
108 // Allow a small bound tolerance to account for floating point conversion. | 108 // 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); | 109 DCHECK_GT(orientation_deg, -180.01f); |
112 DCHECK_LT(orientation_deg, 180.01f); | 110 DCHECK_LT(orientation_deg, 180.01f); |
113 if (orientation_deg >= 90.f) | 111 if (orientation_deg >= 90.f) |
114 orientation_deg -= 180.f; | 112 orientation_deg -= 180.f; |
115 else if (orientation_deg < -90.f) | 113 else if (orientation_deg < -90.f) |
116 orientation_deg += 180.f; | 114 orientation_deg += 180.f; |
117 } else { | 115 } else { |
118 // Orientation lies in [-90, 90] for a touch. Normalise to [-90, 90). | 116 // Orientation lies in [-90, 90] for a touch. Normalise to [-90, 90). |
119 // Allow a small bound tolerance to account for floating point conversion. | 117 // Allow a small bound tolerance to account for floating point conversion. |
120 DCHECK_GT(orientation_deg, -90.01f); | 118 DCHECK_GT(orientation_deg, -90.01f); |
121 DCHECK_LT(orientation_deg, 90.01f); | 119 DCHECK_LT(orientation_deg, 90.01f); |
122 if (orientation_deg >= 90.f) | 120 if (orientation_deg >= 90.f) |
123 orientation_deg -= 180.f; | 121 orientation_deg -= 180.f; |
124 } | 122 } |
125 if (orientation_deg >= 0) { | 123 if (orientation_deg >= 0) { |
126 // The case orientation_deg == 0 is handled here on purpose: although the | 124 // 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 | 125 // '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 | 126 // unchanged (and 0 is the default value for many devices that don't |
129 // report elliptical touches). | 127 // report elliptical touches). |
130 touch.radiusX = minor_radius; | 128 touch.radiusX = minor_radius; |
131 touch.radiusY = major_radius; | 129 touch.radiusY = major_radius; |
132 touch.rotationAngle = orientation_deg; | 130 touch.rotationAngle = orientation_deg; |
133 } else { | 131 } else { |
134 touch.radiusX = major_radius; | 132 touch.radiusX = major_radius; |
135 touch.radiusY = minor_radius; | 133 touch.radiusY = minor_radius; |
136 touch.rotationAngle = orientation_deg + 90; | 134 touch.rotationAngle = orientation_deg + 90; |
137 } | 135 } |
138 | 136 |
139 touch.force = event.GetPressure(pointer_index); | 137 touch.force = event.GetPressure(pointer_index); |
138 // TODO(e_hakkinen): Leave only either tilt and tiltOrientation, tiltRad and | |
139 // tiltOrientationRad or tiltX and tiltY. | |
140 touch.tilt = event.GetTilt(pointer_index) * 180.f / M_PI; | |
141 touch.tiltRad = event.GetTilt(pointer_index); | |
142 touch.tiltOrientation = | |
143 event.GetTiltOrientation(pointer_index) * 180.f / M_PI; | |
144 touch.tiltOrientationRad = event.GetTiltOrientation(pointer_index); | |
145 touch.tiltX = event.GetTiltX(pointer_index) * 180.f / M_PI; | |
146 touch.tiltY = event.GetTiltY(pointer_index) * 180.f / M_PI; | |
140 | 147 |
141 return touch; | 148 return touch; |
142 } | 149 } |
143 | 150 |
144 } // namespace | 151 } // namespace |
145 | 152 |
146 blink::WebTouchEvent CreateWebTouchEventFromMotionEvent( | 153 blink::WebTouchEvent CreateWebTouchEventFromMotionEvent( |
147 const MotionEvent& event, | 154 const MotionEvent& event, |
148 bool may_cause_scrolling) { | 155 bool may_cause_scrolling) { |
149 static_assert(static_cast<int>(MotionEvent::MAX_TOUCH_POINT_COUNT) == | 156 static_assert(static_cast<int>(MotionEvent::MAX_TOUCH_POINT_COUNT) == |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 } | 317 } |
311 | 318 |
312 WebGestureEvent CreateWebGestureEventFromGestureEventData( | 319 WebGestureEvent CreateWebGestureEventFromGestureEventData( |
313 const GestureEventData& data) { | 320 const GestureEventData& data) { |
314 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(), | 321 return CreateWebGestureEvent(data.details, data.time - base::TimeTicks(), |
315 gfx::PointF(data.x, data.y), | 322 gfx::PointF(data.x, data.y), |
316 gfx::PointF(data.raw_x, data.raw_y), data.flags); | 323 gfx::PointF(data.raw_x, data.raw_y), data.flags); |
317 } | 324 } |
318 | 325 |
319 } // namespace ui | 326 } // namespace ui |
OLD | NEW |