diff options
author | eero.hakkinen <eero.hakkinen@intel.com> | 2015-11-02 15:50:11 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-02 23:50:56 +0000 |
commit | b39a02032b11742cc467f43026a77a0aba33d5c1 (patch) | |
tree | ff8055dfdbac6b638bc0c8c1df74de473bb809f5 /content/browser/renderer_host/input/motion_event_web.cc | |
parent | f10f3900fca497febec0cac5ef82a3337c041705 (diff) | |
download | chromium_src-b39a02032b11742cc467f43026a77a0aba33d5c1.zip chromium_src-b39a02032b11742cc467f43026a77a0aba33d5c1.tar.gz chromium_src-b39a02032b11742cc467f43026a77a0aba33d5c1.tar.bz2 |
Pass MotionEvent tilt angles to Blink on Android.
This extends event handlers to pass tilt angles from Android MotionEvent
to Blink touch points, so that on the Blink side, PointerEvent tiltX and
tiltY can be filled with real tilt angles.
This CL is a part of a patch series:
1. https://codereview.chromium.org/1253183005/
for new WebPointerProperties fields
2. https://codereview.chromium.org/1260693003/
for eventSender web pointer property support
3. https://codereview.chromium.org/1192563002/
for handling tilt in Blink event handlers
4. https://codereview.chromium.org/1417803002/
(this)
This CL is based on the abandoned CL at
https://codereview.chromium.org/1187273004/
BUG=514360
Review URL: https://codereview.chromium.org/1417803002
Cr-Commit-Position: refs/heads/master@{#357471}
Diffstat (limited to 'content/browser/renderer_host/input/motion_event_web.cc')
-rw-r--r-- | content/browser/renderer_host/input/motion_event_web.cc | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/content/browser/renderer_host/input/motion_event_web.cc b/content/browser/renderer_host/input/motion_event_web.cc index ddc3037..30f141b 100644 --- a/content/browser/renderer_host/input/motion_event_web.cc +++ b/content/browser/renderer_host/input/motion_event_web.cc @@ -130,26 +130,62 @@ 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]; + + if (pointer.tiltY <= 0 && pointer.tiltX < 0) { + // Stylus is tilted to the left away from the user or straight + // to the left thus the orientation should be within [pi/2,pi). + orientation_rad += static_cast<float>(M_PI_2); + } else if (pointer.tiltY < 0 && pointer.tiltX >= 0) { + // Stylus is tilted to the right away from the user or straight away + // from the user thus the orientation should be within [-pi,-pi/2). + orientation_rad -= static_cast<float>(M_PI); + } else if (pointer.tiltY >= 0 && pointer.tiltX > 0) { + // Stylus is tilted to the right towards the user or straight + // to the right thus the orientation should be within [-pi/2,0). + orientation_rad -= static_cast<float>(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; + // always seems to be set to zero) unchanged. + orientation_rad -= static_cast<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; + + 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 * |