diff options
author | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-13 01:40:31 +0000 |
---|---|---|
committer | tdresser@chromium.org <tdresser@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-13 01:40:31 +0000 |
commit | 5210afb3d1c044f6131b7902a75f66d565dab609 (patch) | |
tree | 54614c0ad2c303938a3dff536d0830b58323f7c4 /ui/events | |
parent | 2be78c867f2068177e47f1be5dd1967131e8cd42 (diff) | |
download | chromium_src-5210afb3d1c044f6131b7902a75f66d565dab609.zip chromium_src-5210afb3d1c044f6131b7902a75f66d565dab609.tar.gz chromium_src-5210afb3d1c044f6131b7902a75f66d565dab609.tar.bz2 |
Fix bounding box calculation for touches with radius of 0.
BUG=None
TEST=GestureProviderTest.ZeroRadiusBoundingBox
Review URL: https://codereview.chromium.org/464013002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289151 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/events')
-rw-r--r-- | ui/events/gesture_detection/gesture_provider.cc | 20 | ||||
-rw-r--r-- | ui/events/gesture_detection/gesture_provider_unittest.cc | 25 |
2 files changed, 37 insertions, 8 deletions
diff --git a/ui/events/gesture_detection/gesture_provider.cc b/ui/events/gesture_detection/gesture_provider.cc index 603108a..9b4b597 100644 --- a/ui/events/gesture_detection/gesture_provider.cc +++ b/ui/events/gesture_detection/gesture_provider.cc @@ -31,15 +31,21 @@ const char* GetMotionEventActionName(MotionEvent::Action action) { } gfx::RectF GetBoundingBox(const MotionEvent& event) { - gfx::RectF bounds; + // Can't use gfx::RectF::Union, as it ignores touches with a radius of 0. + float left = std::numeric_limits<float>::max(); + float top = std::numeric_limits<float>::max(); + float right = -std::numeric_limits<float>::max(); + float bottom = -std::numeric_limits<float>::max(); for (size_t i = 0; i < event.GetPointerCount(); ++i) { float diameter = event.GetTouchMajor(i); - bounds.Union(gfx::RectF(event.GetX(i) - diameter / 2, - event.GetY(i) - diameter / 2, - diameter, - diameter)); - } - return bounds; + float x = event.GetX(i) - diameter / 2; + float y = event.GetY(i) - diameter / 2; + left = std::min(left, x); + right = std::max(right, x + diameter); + top = std::min(top, y); + bottom = std::max(bottom, y + diameter); + } + return gfx::RectF(left, top, right - left, bottom - top); } GestureEventData CreateGesture(const GestureEventDetails& details, diff --git a/ui/events/gesture_detection/gesture_provider_unittest.cc b/ui/events/gesture_detection/gesture_provider_unittest.cc index aeb1c24..aaaa0fd 100644 --- a/ui/events/gesture_detection/gesture_provider_unittest.cc +++ b/ui/events/gesture_detection/gesture_provider_unittest.cc @@ -823,7 +823,7 @@ TEST_F(GestureProviderTest, FractionalScroll) { // Verify that the event co-ordinates are still the precise values we // supplied. EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x); - EXPECT_EQ(kFakeCoordY + delta_y * i, gesture.y); + EXPECT_FLOAT_EQ(kFakeCoordY + delta_y * i, gesture.y); // Verify that we're scrolling vertically by the expected amount // (modulo rounding). @@ -2340,4 +2340,27 @@ TEST_F(GestureProviderTest, MaxGestureBoundsLength) { GetMostRecentGestureEvent().details.bounding_box_f().height()); } +TEST_F(GestureProviderTest, ZeroRadiusBoundingBox) { + base::TimeTicks event_time = base::TimeTicks::Now(); + MockMotionEvent event = + ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 10, 20); + event.SetTouchMajor(0); + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); + EXPECT_EQ(gfx::RectF(10, 20, 0, 0), + GetMostRecentGestureEvent().details.bounding_box()); + + event = ObtainMotionEvent( + event_time, MotionEvent::ACTION_POINTER_DOWN, 10, 20, 110, 120); + event.SetTouchMajor(0); + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); + + event = ObtainMotionEvent( + event_time, MotionEvent::ACTION_MOVE, 10, 20, 110, 150); + event.SetTouchMajor(0); + EXPECT_TRUE(gesture_provider_->OnTouchEvent(event)); + + EXPECT_EQ(gfx::RectF(10, 20, 100, 130), + GetMostRecentGestureEvent().details.bounding_box()); +} + } // namespace ui |