OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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. |
| 6 #define _USE_MATH_DEFINES |
| 7 |
5 #include "content/browser/renderer_host/input/web_input_event_util.h" | 8 #include "content/browser/renderer_host/input/web_input_event_util.h" |
6 | 9 |
| 10 #include <cmath> |
| 11 |
7 #include "base/strings/string_util.h" | 12 #include "base/strings/string_util.h" |
8 #include "content/common/input/web_touch_event_traits.h" | 13 #include "content/common/input/web_touch_event_traits.h" |
9 #include "ui/events/gesture_detection/gesture_event_data.h" | 14 #include "ui/events/gesture_detection/gesture_event_data.h" |
10 #include "ui/events/gesture_detection/motion_event.h" | 15 #include "ui/events/gesture_detection/motion_event.h" |
11 | 16 |
12 using blink::WebGestureEvent; | 17 using blink::WebGestureEvent; |
13 using blink::WebInputEvent; | 18 using blink::WebInputEvent; |
14 using blink::WebTouchEvent; | 19 using blink::WebTouchEvent; |
15 using blink::WebTouchPoint; | 20 using blink::WebTouchPoint; |
16 using ui::MotionEvent; | 21 using ui::MotionEvent; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
181 size_t pointer_index) { | 186 size_t pointer_index) { |
182 WebTouchPoint touch; | 187 WebTouchPoint touch; |
183 touch.id = event.GetPointerId(pointer_index); | 188 touch.id = event.GetPointerId(pointer_index); |
184 touch.state = ToWebTouchPointState( | 189 touch.state = ToWebTouchPointState( |
185 event.GetAction(), | 190 event.GetAction(), |
186 static_cast<int>(pointer_index) == event.GetActionIndex()); | 191 static_cast<int>(pointer_index) == event.GetActionIndex()); |
187 touch.position.x = event.GetX(pointer_index); | 192 touch.position.x = event.GetX(pointer_index); |
188 touch.position.y = event.GetY(pointer_index); | 193 touch.position.y = event.GetY(pointer_index); |
189 touch.screenPosition.x = event.GetRawX(pointer_index); | 194 touch.screenPosition.x = event.GetRawX(pointer_index); |
190 touch.screenPosition.y = event.GetRawY(pointer_index); | 195 touch.screenPosition.y = event.GetRawY(pointer_index); |
191 touch.radiusX = touch.radiusY = event.GetTouchMajor(pointer_index) * 0.5f; | 196 |
| 197 // A note on touch ellipse specifications: |
| 198 // |
| 199 // Android MotionEvent provides the major and minor axes of the touch ellipse, |
| 200 // as well as the orientation of the major axis clockwise from vertical, in |
| 201 // radians. See: |
| 202 // http://developer.android.com/reference/android/view/MotionEvent.html#getOri
entation() |
| 203 // |
| 204 // The proposed extension to W3C Touch Events specifies the touch ellipse |
| 205 // using two radii along x- & y-axes and a positive acute rotation angle in |
| 206 // degrees, where the x-axis makes the specified angle with vertical. See: |
| 207 // http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html |
| 208 |
| 209 float major_radius = event.GetTouchMajor(pointer_index) / 2.f; |
| 210 float minor_radius = event.GetTouchMinor(pointer_index) / 2.f; |
| 211 float orientation_deg = event.GetOrientation(pointer_index) * 180.f / M_PI; |
| 212 DCHECK_GE(major_radius, 0) << "Unexpected touch major < 0"; |
| 213 DCHECK_GE(minor_radius, 0) << "Unexpected touch minor < 0"; |
| 214 DCHECK_GE(major_radius, minor_radius) << "Unexpected major/minor touch radii"; |
| 215 DCHECK(-90 <= orientation_deg && orientation_deg <= 90) |
| 216 << "Unexpected touch orientation angle"; |
| 217 if (orientation_deg >= 0) { |
| 218 touch.radiusX = major_radius; |
| 219 touch.radiusY = minor_radius; |
| 220 touch.rotationAngle = orientation_deg; |
| 221 } else { |
| 222 touch.radiusX = minor_radius; |
| 223 touch.radiusY = major_radius; |
| 224 touch.rotationAngle = orientation_deg + 90; |
| 225 } |
| 226 |
192 touch.force = event.GetPressure(pointer_index); | 227 touch.force = event.GetPressure(pointer_index); |
193 | 228 |
194 return touch; | 229 return touch; |
195 } | 230 } |
196 | 231 |
197 } // namespace | 232 } // namespace |
198 | 233 |
199 namespace content { | 234 namespace content { |
200 | 235 |
201 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, | 236 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 break; | 365 break; |
331 default: | 366 default: |
332 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; | 367 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; |
333 break; | 368 break; |
334 } | 369 } |
335 | 370 |
336 return gesture; | 371 return gesture; |
337 } | 372 } |
338 | 373 |
339 } // namespace content | 374 } // namespace content |
OLD | NEW |