diff options
author | mustaq <mustaq@chromium.org> | 2015-01-21 12:48:50 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-01-21 20:49:46 +0000 |
commit | 2598c69a3c184095cdcc911b24cb47930b66c5ec (patch) | |
tree | 2783c283eae3aac99e8791f65bc8b6aabcddf6d1 /ui/events/gestures | |
parent | 5ea0476b1f36f6678c5d78d3fc13674b05c369e2 (diff) | |
download | chromium_src-2598c69a3c184095cdcc911b24cb47930b66c5ec.zip chromium_src-2598c69a3c184095cdcc911b24cb47930b66c5ec.tar.gz chromium_src-2598c69a3c184095cdcc911b24cb47930b66c5ec.tar.bz2 |
Fixed ui::TouchEvent rotation angle out-of-bound issue.
The rotation angle in ui::TouchEvent should lie within 0 and 90 as per
the spec:
https://dvcs.w3.org/hg/webevents/raw-file/default/touchevents.html
We have seen cases where the angle we got from hardware is not within
the limits. This CL keeps the angle value sane.
BUG=438256
Review URL: https://codereview.chromium.org/800163005
Cr-Commit-Position: refs/heads/master@{#312447}
Diffstat (limited to 'ui/events/gestures')
-rw-r--r-- | ui/events/gestures/motion_event_aura.cc | 10 | ||||
-rw-r--r-- | ui/events/gestures/motion_event_aura_unittest.cc | 66 |
2 files changed, 57 insertions, 19 deletions
diff --git a/ui/events/gestures/motion_event_aura.cc b/ui/events/gestures/motion_event_aura.cc index 1f4d285..2f532e7 100644 --- a/ui/events/gestures/motion_event_aura.cc +++ b/ui/events/gestures/motion_event_aura.cc @@ -28,11 +28,19 @@ PointerProperties GetPointerPropertiesFromTouchEvent(const TouchEvent& touch) { 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) + 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 diff --git a/ui/events/gestures/motion_event_aura_unittest.cc b/ui/events/gestures/motion_event_aura_unittest.cc index b1ce027..57ee6ce 100644 --- a/ui/events/gestures/motion_event_aura_unittest.cc +++ b/ui/events/gestures/motion_event_aura_unittest.cc @@ -108,7 +108,7 @@ TEST(MotionEventAuraTest, PointerCountAndIds) { EXPECT_EQ(ids[2], event.GetPointerId(1)); // Test cloning of pointer count and id information. - // TODO(mustaq): Make a separate clone test + // TODO(mustaq): Make a separate clone test, crbug.com/450655 scoped_ptr<MotionEvent> clone = event.Clone(); EXPECT_EQ(2U, clone->GetPointerCount()); EXPECT_EQ(ids[0], clone->GetPointerId(0)); @@ -207,14 +207,12 @@ TEST(MotionEventAuraTest, PointerLocations) { // Test cloning of pointer location information. scoped_ptr<MotionEvent> clone = event.Clone(); - { - EXPECT_EQ(test::ToString(event), test::ToString(*clone)); - EXPECT_EQ(2U, clone->GetPointerCount()); - EXPECT_FLOAT_EQ(x, clone->GetX(1)); - EXPECT_FLOAT_EQ(y, clone->GetY(1)); - EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); - EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); - } + EXPECT_EQ(test::ToString(event), test::ToString(*clone)); + EXPECT_EQ(2U, clone->GetPointerCount()); + EXPECT_FLOAT_EQ(x, clone->GetX(1)); + EXPECT_FLOAT_EQ(y, clone->GetY(1)); + EXPECT_FLOAT_EQ(raw_x, clone->GetRawX(1)); + EXPECT_FLOAT_EQ(raw_y, clone->GetRawY(1)); x = 27.9f; y = 22.3f; @@ -247,13 +245,14 @@ TEST(MotionEventAuraTest, TapParams) { // Test that touch params are stored correctly. MotionEventAura event; - int ids[] = {15, 13}; + int ids[] = {15, 13, 25, 23}; float radius_x; float radius_y; float rotation_angle; float pressure; + // Test case: radius_x > radius_y, rotation_angle < 90 radius_x = 123.45f; radius_y = 67.89f; rotation_angle = 23.f; @@ -268,6 +267,7 @@ TEST(MotionEventAuraTest, TapParams) { EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(0) * 180 / M_PI + 90); EXPECT_FLOAT_EQ(pressure, event.GetPressure(0)); + // Test case: radius_x < radius_y, rotation_angle < 90 radius_x = 67.89f; radius_y = 123.45f; rotation_angle = 46.f; @@ -283,16 +283,16 @@ TEST(MotionEventAuraTest, TapParams) { EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); // Test cloning of tap params + // TODO(mustaq): Make a separate clone test, crbug.com/450655 scoped_ptr<MotionEvent> clone = event.Clone(); - { - EXPECT_EQ(test::ToString(event), test::ToString(*clone)); - EXPECT_EQ(2U, clone->GetPointerCount()); - EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); - EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); - EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); - EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); - } + EXPECT_EQ(test::ToString(event), test::ToString(*clone)); + EXPECT_EQ(2U, clone->GetPointerCount()); + EXPECT_FLOAT_EQ(radius_y, clone->GetTouchMajor(1) / 2); + EXPECT_FLOAT_EQ(radius_x, clone->GetTouchMinor(1) / 2); + EXPECT_FLOAT_EQ(rotation_angle, clone->GetOrientation(1) * 180 / M_PI); + EXPECT_FLOAT_EQ(pressure, clone->GetPressure(1)); + // TODO(mustaq): The move test seems out-of-scope here, crbug.com/450655 radius_x = 76.98f; radius_y = 321.54f; rotation_angle = 64.f; @@ -307,6 +307,36 @@ TEST(MotionEventAuraTest, TapParams) { EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(1) / 2); EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(1) * 180 / M_PI); EXPECT_FLOAT_EQ(pressure, event.GetPressure(1)); + + // Test case: radius_x > radius_y, rotation_angle > 90 + radius_x = 123.45f; + radius_y = 67.89f; + rotation_angle = 92.f; + pressure = 0.789f; + TouchEvent press2 = TouchWithTapParams( + ET_TOUCH_PRESSED, ids[2], radius_x, radius_y, rotation_angle, pressure); + EXPECT_TRUE(event.OnTouch(press2)); + + EXPECT_EQ(3U, event.GetPointerCount()); + EXPECT_FLOAT_EQ(radius_x, event.GetTouchMajor(2) / 2); + EXPECT_FLOAT_EQ(radius_y, event.GetTouchMinor(2) / 2); + EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(2) * 180 / M_PI + 90); + EXPECT_FLOAT_EQ(pressure, event.GetPressure(2)); + + // Test case: radius_x < radius_y, rotation_angle > 90 + radius_x = 67.89f; + radius_y = 123.45f; + rotation_angle = 135.f; + pressure = 0.012f; + TouchEvent press3 = TouchWithTapParams( + ET_TOUCH_PRESSED, ids[3], radius_x, radius_y, rotation_angle, pressure); + EXPECT_TRUE(event.OnTouch(press3)); + + EXPECT_EQ(4U, event.GetPointerCount()); + EXPECT_FLOAT_EQ(radius_y, event.GetTouchMajor(3) / 2); + EXPECT_FLOAT_EQ(radius_x, event.GetTouchMinor(3) / 2); + EXPECT_FLOAT_EQ(rotation_angle, event.GetOrientation(3) * 180 / M_PI + 180); + EXPECT_FLOAT_EQ(pressure, event.GetPressure(3)); } TEST(MotionEventAuraTest, Timestamps) { |