Chromium Code Reviews| Index: ui/events/gestures/motion_event_aura.cc |
| diff --git a/ui/events/gestures/motion_event_aura.cc b/ui/events/gestures/motion_event_aura.cc |
| index c1c144653d10a73538c56cf4091f49deb1257a65..2f833731dec7bf94c050b0b2a2245049a070e442 100644 |
| --- a/ui/events/gestures/motion_event_aura.cc |
| +++ b/ui/events/gestures/motion_event_aura.cc |
| @@ -2,9 +2,11 @@ |
| // 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 |
|
tdresser
2014/08/27 18:31:35
#include <cmath>
mustaq
2014/08/27 20:51:08
Done.
|
| + |
| #include "ui/events/gestures/motion_event_aura.h" |
| -#include "base/logging.h" |
|
tdresser
2014/08/27 18:31:35
"base/logging.h" defines DCHECK.
Include what you
mustaq
2014/08/27 20:51:08
Done.
|
| #include "ui/events/gestures/gesture_configuration.h" |
| namespace ui { |
| @@ -40,11 +42,30 @@ MotionEventAura::PointData MotionEventAura::GetPointDataFromTouchEvent( |
| point_data.pressure = touch.force(); |
| point_data.source_device_id = touch.source_device_id(); |
| - // TODO(tdresser): at some point we should start using both radii if they are |
| - // available, but for now we use the max. |
| - point_data.major_radius = std::max(touch.radius_x(), touch.radius_y()); |
| - if (!point_data.major_radius) |
| + 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_2) |
| + << "Unexpected touch rotation angle"; |
| + |
| + if (radius_x >= radius_y) { |
| + point_data.major_radius = radius_x; |
| + point_data.minor_radius = radius_y; |
| + point_data.orientation = rotation_angle_rad; |
| + } else { |
| + point_data.major_radius = radius_y; |
| + point_data.minor_radius = radius_x; |
| + point_data.orientation = rotation_angle_rad - M_PI_2; |
| + } |
| + |
| + if (!point_data.major_radius) { |
| point_data.major_radius = GestureConfiguration::default_radius(); |
| + point_data.minor_radius = GestureConfiguration::default_radius(); |
| + point_data.orientation = 0; |
| + } |
| + |
| return point_data; |
| } |
| @@ -117,7 +138,17 @@ float MotionEventAura::GetRawY(size_t pointer_index) const { |
| float MotionEventAura::GetTouchMajor(size_t pointer_index) const { |
| DCHECK_LT(pointer_index, pointer_count_); |
| - return active_touches_[pointer_index].major_radius * 2; |
| + return active_touches_[pointer_index].major_radius * 2.f; |
| +} |
| + |
| +float MotionEventAura::GetTouchMinor(size_t pointer_index) const { |
| + DCHECK_LE(pointer_index, pointer_count_); |
| + return active_touches_[pointer_index].minor_radius * 2.f; |
| +} |
| + |
| +float MotionEventAura::GetOrientation(size_t pointer_index) const { |
| + DCHECK_LE(pointer_index, pointer_count_); |
| + return active_touches_[pointer_index].orientation; |
| } |
| float MotionEventAura::GetPressure(size_t pointer_index) const { |
| @@ -171,7 +202,9 @@ MotionEventAura::PointData::PointData() |
| touch_id(0), |
| pressure(0), |
| source_device_id(0), |
| - major_radius(0) { |
| + major_radius(0), |
| + minor_radius(0), |
| + orientation(0) { |
| } |
| int MotionEventAura::GetSourceDeviceId(size_t pointer_index) const { |