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

Side by Side Diff: content/browser/renderer_host/input/web_input_event_util.cc

Issue 494833003: Completed webkit radiusX, radiusY and rotationAngle handling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 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
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
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
192 touch.force = event.GetPressure(pointer_index); 231 touch.force = event.GetPressure(pointer_index);
193 232
194 return touch; 233 return touch;
195 } 234 }
196 235
197 } // namespace 236 } // namespace
198 237
199 namespace content { 238 namespace content {
200 239
201 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event, 240 void UpdateWindowsKeyCodeAndKeyIdentifier(blink::WebKeyboardEvent* event,
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 break; 369 break;
331 default: 370 default:
332 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event."; 371 NOTREACHED() << "ui::EventType provided wasn't a valid gesture event.";
333 break; 372 break;
334 } 373 }
335 374
336 return gesture; 375 return gesture;
337 } 376 }
338 377
339 } // namespace content 378 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698