summaryrefslogtreecommitdiffstats
path: root/ui/events/gesture_detection/motion_event_generic.cc
diff options
context:
space:
mode:
Diffstat (limited to 'ui/events/gesture_detection/motion_event_generic.cc')
-rw-r--r--ui/events/gesture_detection/motion_event_generic.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/ui/events/gesture_detection/motion_event_generic.cc b/ui/events/gesture_detection/motion_event_generic.cc
index 2f2c34b..a90c72a 100644
--- a/ui/events/gesture_detection/motion_event_generic.cc
+++ b/ui/events/gesture_detection/motion_event_generic.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 "ui/events/gesture_detection/motion_event_generic.h"
+#include <cmath>
+
#include "base/logging.h"
#include "ui/events/base_event_utils.h"
@@ -42,6 +47,37 @@ PointerProperties::PointerProperties(const MotionEvent& event,
source_device_id(0) {
}
+void PointerProperties::SetAxesAndOrientation(float radius_x,
+ float radius_y,
+ float rotation_angle_degree) {
+ DCHECK(!touch_major && !touch_minor && !orientation);
+ float rotation_angle_rad = rotation_angle_degree * M_PI / 180.f;
+ DCHECK_GE(radius_x, 0) << "Unexpected x-radius < 0 (" << radius_x << ")";
+ DCHECK_GE(radius_y, 0) << "Unexpected y-radius < 0 (" << radius_y << ")";
+ DCHECK(0 <= rotation_angle_rad && rotation_angle_rad < M_PI)
+ << "Unexpected touch rotation angle " << rotation_angle_rad << " rad";
+
+ // 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.
+ touch_major = 2.f * radius_x;
+ touch_minor = 2.f * radius_y;
+ orientation = rotation_angle_rad - M_PI_2;
+ } else {
+ touch_major = 2.f * radius_y;
+ touch_minor = 2.f * radius_x;
+ orientation = rotation_angle_rad;
+ }
+}
+
MotionEventGeneric::MotionEventGeneric(Action action,
base::TimeTicks event_time,
const PointerProperties& pointer)