Commit 3057393e authored by sadrul@chromium.org's avatar sadrul@chromium.org

gesture recognizer: Make sure the pinch/scroll only when the finger is moved for real.

Change in the radius for any of the touch-points changes the bounding box of the points,
but in such cases, we do not want to trigger either scroll or pinch updates.

BUG=none
TBR=ben@chromium.org

Review URL: https://chromiumcodereview.appspot.com/10837107

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150400 0039d316-1c4b-4281-b951-d872f2087c98
parent f98d573d
...@@ -2516,5 +2516,55 @@ TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) { ...@@ -2516,5 +2516,55 @@ TEST_F(GestureRecognizerTest, TwoTapsWithDelayBetween) {
EXPECT_EQ(1, delegate->tap_count()); EXPECT_EQ(1, delegate->tap_count());
} }
// Checks that if the bounding-box of a gesture changes because of change in
// radius of a touch-point, and not because of change in position, then there
// are not gesture events from that.
TEST_F(GestureRecognizerTest, BoundingBoxRadiusChange) {
scoped_ptr<GestureEventConsumeDelegate> delegate(
new GestureEventConsumeDelegate());
const int kWindowWidth = 234;
const int kWindowHeight = 345;
const int kTouchId = 5, kTouchId2 = 7;
gfx::Rect bounds(100, 200, kWindowWidth, kWindowHeight);
scoped_ptr<aura::Window> window(CreateTestWindowWithDelegate(
delegate.get(), -1234, bounds, NULL));
TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(101, 201), kTouchId,
GetTime());
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press1);
EXPECT_TRUE(delegate->bounding_box().IsEmpty());
delegate->Reset();
TouchEvent press2(ui::ET_TOUCH_PRESSED, gfx::Point(201, 201), kTouchId2,
press1.time_stamp() + base::TimeDelta::FromMilliseconds(400));
press2.set_radius_x(5);
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press2);
EXPECT_FALSE(delegate->pinch_begin());
delegate->Reset();
TouchEvent move1(ui::ET_TOUCH_MOVED, gfx::Point(141, 201), kTouchId,
press1.time_stamp() + base::TimeDelta::FromMilliseconds(40));
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move1);
EXPECT_TRUE(delegate->pinch_begin());
EXPECT_EQ(gfx::Rect(141, 196, 65, 10).ToString(),
delegate->bounding_box().ToString());
delegate->Reset();
// The position doesn't move, but the radius changes.
TouchEvent move2(ui::ET_TOUCH_MOVED, gfx::Point(101, 201), kTouchId,
press2.time_stamp() + base::TimeDelta::FromMilliseconds(40));
move2.set_radius_x(50);
move2.set_radius_y(60);
root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&move2);
EXPECT_FALSE(delegate->tap());
EXPECT_FALSE(delegate->scroll_update());
EXPECT_FALSE(delegate->pinch_update());
delegate->Reset();
}
} // namespace test } // namespace test
} // namespace aura } // namespace aura
...@@ -675,12 +675,12 @@ void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point, ...@@ -675,12 +675,12 @@ void GestureSequence::AppendScrollGestureUpdate(const GesturePoint& point,
gfx::Point current_center = bounding_box_.CenterPoint(); gfx::Point current_center = bounding_box_.CenterPoint();
int dx = current_center.x() - bounding_box_last_center_.x(); int dx = current_center.x() - bounding_box_last_center_.x();
int dy = current_center.y() - bounding_box_last_center_.y(); int dy = current_center.y() - bounding_box_last_center_.y();
if (dx == 0 && dy == 0)
return;
if (scroll_type_ == ST_HORIZONTAL) if (scroll_type_ == ST_HORIZONTAL)
dy = 0; dy = 0;
else if (scroll_type_ == ST_VERTICAL) else if (scroll_type_ == ST_VERTICAL)
dx = 0; dx = 0;
if (dx == 0 && dy == 0)
return;
gestures->push_back(CreateGestureEvent( gestures->push_back(CreateGestureEvent(
GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy), GestureEventDetails(ui::ET_GESTURE_SCROLL_UPDATE, dx, dy),
...@@ -908,6 +908,22 @@ bool GestureSequence::PinchUpdate(const TouchEvent& event, ...@@ -908,6 +908,22 @@ bool GestureSequence::PinchUpdate(const TouchEvent& event,
const GesturePoint& point, Gestures* gestures) { const GesturePoint& point, Gestures* gestures) {
DCHECK(state_ == GS_PINCH); DCHECK(state_ == GS_PINCH);
// It is possible that the none of the touch-points changed their position,
// but their radii changed, and that caused the bounding box to also change.
// But in such cases, we do not want to either pinch or scroll.
// To avoid small jiggles, it is also necessary to make sure that at least one
// of the fingers moved enough before a pinch or scroll update is created.
bool did_scroll = false;
for (int i = 0; i < kMaxGesturePoints; ++i) {
if (!points_[i].in_use() || !points_[i].DidScroll(event, 2))
continue;
did_scroll = true;
break;
}
if (!did_scroll)
return false;
float distance = BoundingBoxDiagonal(bounding_box_); float distance = BoundingBoxDiagonal(bounding_box_);
if (abs(distance - pinch_distance_current_) >= if (abs(distance - pinch_distance_current_) >=
......
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