Commit 8dc8e7ab authored by tdresser@chromium.org's avatar tdresser@chromium.org

Fix bounding box calculation for touches with radius of 0.

BUG=None
TEST=GestureProviderTest.ZeroRadiusBoundingBox

Review URL: https://codereview.chromium.org/464013002

Cr-Commit-Position: refs/heads/master@{#289151}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289151 0039d316-1c4b-4281-b951-d872f2087c98
parent 86d6c759
...@@ -31,15 +31,21 @@ const char* GetMotionEventActionName(MotionEvent::Action action) { ...@@ -31,15 +31,21 @@ const char* GetMotionEventActionName(MotionEvent::Action action) {
} }
gfx::RectF GetBoundingBox(const MotionEvent& event) { 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) { for (size_t i = 0; i < event.GetPointerCount(); ++i) {
float diameter = event.GetTouchMajor(i); float diameter = event.GetTouchMajor(i);
bounds.Union(gfx::RectF(event.GetX(i) - diameter / 2, float x = event.GetX(i) - diameter / 2;
event.GetY(i) - diameter / 2, float y = event.GetY(i) - diameter / 2;
diameter, left = std::min(left, x);
diameter)); right = std::max(right, x + diameter);
} top = std::min(top, y);
return bounds; bottom = std::max(bottom, y + diameter);
}
return gfx::RectF(left, top, right - left, bottom - top);
} }
GestureEventData CreateGesture(const GestureEventDetails& details, GestureEventData CreateGesture(const GestureEventDetails& details,
......
...@@ -823,7 +823,7 @@ TEST_F(GestureProviderTest, FractionalScroll) { ...@@ -823,7 +823,7 @@ TEST_F(GestureProviderTest, FractionalScroll) {
// Verify that the event co-ordinates are still the precise values we // Verify that the event co-ordinates are still the precise values we
// supplied. // supplied.
EXPECT_EQ(kFakeCoordX + delta_x * i, gesture.x); 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 // Verify that we're scrolling vertically by the expected amount
// (modulo rounding). // (modulo rounding).
...@@ -2340,4 +2340,27 @@ TEST_F(GestureProviderTest, MaxGestureBoundsLength) { ...@@ -2340,4 +2340,27 @@ TEST_F(GestureProviderTest, MaxGestureBoundsLength) {
GetMostRecentGestureEvent().details.bounding_box_f().height()); 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 } // namespace ui
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment