diff options
author | sadrul <sadrul@chromium.org> | 2015-06-25 10:25:31 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-06-25 17:26:04 +0000 |
commit | db5aa7abc8a6ed76f6497e25821c8a2f3e27f5af (patch) | |
tree | c8f2fed596e96fbf0ab93ec3d56bbfadb3447286 /ui/events/gestures | |
parent | 716f37a898600a21c90ebd942983afb3aa38b747 (diff) | |
download | chromium_src-db5aa7abc8a6ed76f6497e25821c8a2f3e27f5af.zip chromium_src-db5aa7abc8a6ed76f6497e25821c8a2f3e27f5af.tar.gz chromium_src-db5aa7abc8a6ed76f6497e25821c8a2f3e27f5af.tar.bz2 |
html_viewer: Correctly set axis and orientation of MotionEvent.
MotionEvent's orientation is in radian, and it falls within [-π/2, π/2). However,
TouchEvent's rotation-angle is in degrees, and it falls within [0, 180). So make
sure the conversion from rotation-angle to orientation happens correctly. Add
PointerProperties::SetAxisAndOrientation() as a convenience function to do this
correctly.
This fixes a crash in mandoline when touching the screen in landspace mode.
BUG=none
Review URL: https://codereview.chromium.org/1202283005
Cr-Commit-Position: refs/heads/master@{#336187}
Diffstat (limited to 'ui/events/gestures')
-rw-r--r-- | ui/events/gestures/motion_event_aura.cc | 36 |
1 files changed, 2 insertions, 34 deletions
diff --git a/ui/events/gestures/motion_event_aura.cc b/ui/events/gestures/motion_event_aura.cc index 01df3f6..8c345f8 100644 --- a/ui/events/gestures/motion_event_aura.cc +++ b/ui/events/gestures/motion_event_aura.cc @@ -2,13 +2,8 @@ // 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 "ui/events/gestures/motion_event_aura.h" -#include <cmath> - #include "base/logging.h" #include "ui/events/gesture_detection/gesture_configuration.h" @@ -25,35 +20,8 @@ PointerProperties GetPointerPropertiesFromTouchEvent(const TouchEvent& touch) { pointer_properties.pressure = touch.force(); pointer_properties.source_device_id = touch.source_device_id(); - float radius_x = touch.radius_x(); - float radius_y = touch.radius_y(); - float rotation_angle_rad = touch.rotation_angle() * M_PI / 180.f; - - DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0"; - DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0"; - DCHECK(0 <= rotation_angle_rad && rotation_angle_rad < M_PI) - << "Unexpected touch rotation angle"; - - // Make the angle acute to ease subsequent logic. The angle range effectively - // changes from [0, pi) to [0, pi/2). - if (rotation_angle_rad >= M_PI_2) { - rotation_angle_rad -= static_cast<float>(M_PI_2); - std::swap(radius_x, radius_y); - } - - if (radius_x > radius_y) { - // The case radius_x == radius_y 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. - pointer_properties.touch_major = 2.f * radius_x; - pointer_properties.touch_minor = 2.f * radius_y; - pointer_properties.orientation = rotation_angle_rad - M_PI_2; - } else { - pointer_properties.touch_major = 2.f * radius_y; - pointer_properties.touch_minor = 2.f * radius_x; - pointer_properties.orientation = rotation_angle_rad; - } - + pointer_properties.SetAxesAndOrientation(touch.radius_x(), touch.radius_y(), + touch.rotation_angle()); if (!pointer_properties.touch_major) { pointer_properties.touch_major = 2.f * GestureConfiguration::GetInstance()->default_radius(); |