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

Unified 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: Tweaked NaN checks Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/input/web_input_event_util.cc
diff --git a/content/browser/renderer_host/input/web_input_event_util.cc b/content/browser/renderer_host/input/web_input_event_util.cc
index 303a8d0844c86fa99f345dc34908ac808d600193..3cb7f1130b090d9ded5e629e1743277eda29d763 100644
--- a/content/browser/renderer_host/input/web_input_event_util.cc
+++ b/content/browser/renderer_host/input/web_input_event_util.cc
@@ -2,8 +2,13 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+// MSVC++ requires this to be set before any other includes to get M_PI.
+#define _USE_MATH_DEFINES
+
#include "content/browser/renderer_host/input/web_input_event_util.h"
+#include <cmath>
+
#include "base/strings/string_util.h"
#include "content/common/input/web_touch_event_traits.h"
#include "ui/events/gesture_detection/gesture_event_data.h"
@@ -188,7 +193,37 @@ WebTouchPoint CreateWebTouchPoint(const MotionEvent& event,
touch.position.y = event.GetY(pointer_index);
touch.screenPosition.x = event.GetRawX(pointer_index);
touch.screenPosition.y = event.GetRawY(pointer_index);
- touch.radiusX = touch.radiusY = event.GetTouchMajor(pointer_index) * 0.5f;
+
+ // A note on touch ellipse specifications:
+ //
+ // Android MotionEvent provides the major and minor axes of the touch ellipse,
+ // as well as the orientation of the major axis clockwise from vertical, in
+ // radians. See:
+ // http://developer.android.com/reference/android/view/MotionEvent.html
+ //
+ // The proposed extension to W3C Touch Events specifies the touch ellipse
+ // using two radii along x- & y-axes and a positive acute rotation angle in
+ // degrees. See:
+ // http://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html
+
+ float major_radius = event.GetTouchMajor(pointer_index) / 2.f;
+ float minor_radius = event.GetTouchMinor(pointer_index) / 2.f;
+ float orientation_deg = event.GetOrientation(pointer_index) * 180.f / M_PI;
+ DCHECK_GE(major_radius, 0) << "Unexpected touch major < 0";
+ DCHECK_GE(minor_radius, 0) << "Unexpected touch minor < 0";
+ DCHECK_GE(major_radius, minor_radius) << "Unexpected major/minor touch radii";
+ DCHECK(-90 <= orientation_deg && orientation_deg <= 90)
+ << "Unexpected touch orientation angle";
+ if (orientation_deg >= 0) {
+ touch.radiusX = minor_radius;
+ touch.radiusY = major_radius;
+ touch.rotationAngle = orientation_deg;
+ } else {
+ touch.radiusX = major_radius;
+ touch.radiusY = minor_radius;
+ touch.rotationAngle = orientation_deg + 90;
+ }
+
touch.force = event.GetPressure(pointer_index);
return touch;

Powered by Google App Engine
This is Rietveld 408576698