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

Unified Diff: content/browser/renderer_host/input/motion_event_web.cc

Issue 1187273004: Pass MotionEvent tilt angles to Blink on Android. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 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/motion_event_web.cc
diff --git a/content/browser/renderer_host/input/motion_event_web.cc b/content/browser/renderer_host/input/motion_event_web.cc
index 82b6ed7861b6cd2c5c3fbe0fe8cc853b8d7c7772..eeb2124901acd3de0185911b4f57b1f089731767 100644
--- a/content/browser/renderer_host/input/motion_event_web.cc
+++ b/content/browser/renderer_host/input/motion_event_web.cc
@@ -130,26 +130,58 @@ float MotionEventWeb::GetTouchMinor(size_t pointer_index) const {
float MotionEventWeb::GetOrientation(size_t pointer_index) const {
DCHECK_LT(pointer_index, GetPointerCount());
- float rotation_angle_rad = event_.touches[pointer_index].rotationAngle
+ float orientation_rad = event_.touches[pointer_index].rotationAngle
* M_PI / 180.f;
- DCHECK(0 <= rotation_angle_rad && rotation_angle_rad <= M_PI_2)
+ DCHECK(0 <= orientation_rad && orientation_rad <= M_PI_2)
<< "Unexpected touch rotation angle";
- if (event_.touches[pointer_index].radiusX
- > event_.touches[pointer_index].radiusY) {
+ if (GetToolType(pointer_index) == TOOL_TYPE_STYLUS) {
+ const WebPointerProperties& pointer = event_.touches[pointer_index];
+
jdduke (slow) 2015/08/12 17:00:12 I think we'll want some basic test coverage for th
+ if (pointer.tiltY < 0) {
+ if (pointer.tiltX < 0)
+ orientation_rad += M_PI_2;
+ else
+ orientation_rad -= M_PI;
+ } else {
+ if (pointer.tiltX > 0)
+ orientation_rad -= M_PI_2;
+ }
+ } else if (event_.touches[pointer_index].radiusX
+ > event_.touches[pointer_index].radiusY) {
// The case radiusX == radiusY is omitted from here on purpose: for circles,
// we want to pass the angle (which could be any value in such cases but
// always seem to be set to zero) unchanged.
- rotation_angle_rad -= (float) M_PI_2;
+ orientation_rad -= (float) M_PI_2;
}
- return rotation_angle_rad;
+ return orientation_rad;
}
float MotionEventWeb::GetPressure(size_t pointer_index) const {
return 0.f;
}
+float MotionEventWeb::GetTilt(size_t pointer_index) const {
+ DCHECK_LT(pointer_index, GetPointerCount());
+
+ if (GetToolType(pointer_index) != TOOL_TYPE_STYLUS)
+ return 0.f;
+
jdduke (slow) 2015/08/12 17:00:13 Same here, a few basic test cases would be nice. W
+ const WebPointerProperties& pointer = event_.touches[pointer_index];
+
+ float tilt_x_r = sin(pointer.tiltX * M_PI / 180.f);
+ float tilt_x_z = cos(pointer.tiltX * M_PI / 180.f);
+ float tilt_y_r = sin(pointer.tiltY * M_PI / 180.f);
+ float tilt_y_z = cos(pointer.tiltY * M_PI / 180.f);
+ float r_x = tilt_x_r * tilt_y_z;
+ float r_y = tilt_y_r * tilt_x_z;
+ float r = sqrt(r_x * r_x + r_y * r_y);
+ float z = tilt_x_z * tilt_y_z;
+
+ return atan2(r, z);
+}
+
base::TimeTicks MotionEventWeb::GetEventTime() const {
return base::TimeTicks() +
base::TimeDelta::FromMicroseconds(event_.timeStampSeconds *

Powered by Google App Engine
This is Rietveld 408576698