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 | |
8 #include "content/browser/renderer_host/input/web_input_event_util.h" | 5 #include "content/browser/renderer_host/input/web_input_event_util.h" |
9 | 6 |
10 #include <cmath> | |
11 | |
12 #include "base/strings/string_util.h" | 7 #include "base/strings/string_util.h" |
13 #include "content/common/input/web_touch_event_traits.h" | 8 #include "content/common/input/web_touch_event_traits.h" |
14 #include "ui/events/gesture_detection/gesture_event_data.h" | 9 #include "ui/events/gesture_detection/gesture_event_data.h" |
15 #include "ui/events/gesture_detection/motion_event.h" | 10 #include "ui/events/gesture_detection/motion_event.h" |
16 | 11 |
17 using blink::WebGestureEvent; | 12 using blink::WebGestureEvent; |
18 using blink::WebInputEvent; | 13 using blink::WebInputEvent; |
19 using blink::WebTouchEvent; | 14 using blink::WebTouchEvent; |
20 using blink::WebTouchPoint; | 15 using blink::WebTouchPoint; |
21 using ui::MotionEvent; | 16 using ui::MotionEvent; |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 size_t pointer_index) { | 181 size_t pointer_index) { |
187 WebTouchPoint touch; | 182 WebTouchPoint touch; |
188 touch.id = event.GetPointerId(pointer_index); | 183 touch.id = event.GetPointerId(pointer_index); |
189 touch.state = ToWebTouchPointState( | 184 touch.state = ToWebTouchPointState( |
190 event.GetAction(), | 185 event.GetAction(), |
191 static_cast<int>(pointer_index) == event.GetActionIndex()); | 186 static_cast<int>(pointer_index) == event.GetActionIndex()); |
192 touch.position.x = event.GetX(pointer_index); | 187 touch.position.x = event.GetX(pointer_index); |
193 touch.position.y = event.GetY(pointer_index); | 188 touch.position.y = event.GetY(pointer_index); |
194 touch.screenPosition.x = event.GetRawX(pointer_index); | 189 touch.screenPosition.x = event.GetRawX(pointer_index); |
195 touch.screenPosition.y = event.GetRawY(pointer_index); | 190 touch.screenPosition.y = event.GetRawY(pointer_index); |
196 | 191 touch.radiusX = touch.radiusY = event.GetTouchMajor(pointer_index) * 0.5f; |
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 | |
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. 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 // The case orientation_deg == 0 is handled here on purpose: although the | |
219 // 'else' block is equivalent in this case, we want to pass the 0 value | |
220 // unchanged (and 0 is the default value for many devices that don't | |
221 // report elliptical touches). | |
222 touch.radiusX = minor_radius; | |
223 touch.radiusY = major_radius; | |
224 touch.rotationAngle = orientation_deg; | |
225 } else { | |
226 touch.radiusX = major_radius; | |
227 touch.radiusY = minor_radius; | |
228 touch.rotationAngle = orientation_deg + 90; | |
229 } | |
230 | |
231 touch.force = event.GetPressure(pointer_index); | 192 touch.force = event.GetPressure(pointer_index); |
232 | 193 |
233 return touch; | 194 return touch; |
234 } | 195 } |
235 | 196 |
236 } // namespace | 197 } // namespace |
237 | 198 |
238 namespace content { | 199 namespace content { |
239 | 200 |
240 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, | 201 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 break; | 330 break; |
370 default: | 331 default: |
371 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; | 332 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; |
372 break; | 333 break; |
373 } | 334 } |
374 | 335 |
375 return gesture; | 336 return gesture; |
376 } | 337 } |
377 | 338 |
378 } // namespace content | 339 } // namespace content |
OLD | NEW |