Commit 647665c4 authored by lanwei's avatar lanwei Committed by Commit bot

changing bounding box for show press and tap gesture

The bounding boxes of show press and tap gesture are the same right now,
which are based on the touch start location and the largest radius seen
before the show press gesture is sent.

BUG=403747

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

Cr-Commit-Position: refs/heads/master@{#293807}
parent 1ebcd949
...@@ -257,6 +257,14 @@ class GestureProviderTest : public testing::Test, public GestureProviderClient { ...@@ -257,6 +257,14 @@ class GestureProviderTest : public testing::Test, public GestureProviderClient {
SetUpWithConfig(config); SetUpWithConfig(config);
} }
void SetShowPressAndLongPressTimeout(base::TimeDelta showpress_timeout,
base::TimeDelta longpress_timeout) {
GestureProvider::Config config = GetDefaultConfig();
config.gesture_detector_config.showpress_timeout = showpress_timeout;
config.gesture_detector_config.longpress_timeout = longpress_timeout;
SetUpWithConfig(config);
}
bool HasDownEvent() const { return gesture_provider_->current_down_event(); } bool HasDownEvent() const { return gesture_provider_->current_down_event(); }
protected: protected:
...@@ -2398,8 +2406,8 @@ TEST_F(GestureProviderTest, NoMinOrMaxGestureBoundsLengthWithStylusOrMouse) { ...@@ -2398,8 +2406,8 @@ TEST_F(GestureProviderTest, NoMinOrMaxGestureBoundsLengthWithStylusOrMouse) {
EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType()); EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
EXPECT_EQ(MotionEvent::TOOL_TYPE_STYLUS, EXPECT_EQ(MotionEvent::TOOL_TYPE_STYLUS,
GetMostRecentGestureEvent().primary_tool_type); GetMostRecentGestureEvent().primary_tool_type);
EXPECT_EQ(1.f, GetMostRecentGestureEvent().details.bounding_box_f().width()); EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().width());
EXPECT_EQ(1.f, GetMostRecentGestureEvent().details.bounding_box_f().height()); EXPECT_EQ(0, GetMostRecentGestureEvent().details.bounding_box_f().height());
event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN); event = ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
event.SetTouchMajor(2.f * kMaxGestureBoundsLength); event.SetTouchMajor(2.f * kMaxGestureBoundsLength);
...@@ -2427,4 +2435,47 @@ TEST_F(GestureProviderTest, NoMinOrMaxGestureBoundsLengthWithStylusOrMouse) { ...@@ -2427,4 +2435,47 @@ TEST_F(GestureProviderTest, NoMinOrMaxGestureBoundsLengthWithStylusOrMouse) {
GetMostRecentGestureEvent().details.bounding_box_f().height()); GetMostRecentGestureEvent().details.bounding_box_f().height());
} }
// Test the bounding box for show press and tap gestures.
TEST_F(GestureProviderTest, BoundingBoxForShowPressAndTapGesture) {
base::TimeTicks event_time = base::TimeTicks::Now();
gesture_provider_->SetDoubleTapSupportForPlatformEnabled(false);
base::TimeDelta showpress_timeout = kOneMicrosecond;
base::TimeDelta longpress_timeout = kOneSecond;
SetShowPressAndLongPressTimeout(showpress_timeout, longpress_timeout);
MockMotionEvent event =
ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 10, 10);
event.SetTouchMajor(10);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(gfx::RectF(5, 5, 10, 10),
GetMostRecentGestureEvent().details.bounding_box());
event = ObtainMotionEvent(
event_time + kOneMicrosecond, MotionEvent::ACTION_MOVE, 11, 9);
event.SetTouchMajor(20);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
event = ObtainMotionEvent(
event_time + kOneMicrosecond, MotionEvent::ACTION_MOVE, 8, 11);
event.SetTouchMajor(10);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
RunTasksAndWait(showpress_timeout + kOneMicrosecond);
EXPECT_EQ(ET_GESTURE_SHOW_PRESS, GetMostRecentGestureEventType());
EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
GetMostRecentGestureEvent().details.bounding_box());
event =
ObtainMotionEvent(event_time + kOneMicrosecond, MotionEvent::ACTION_UP);
event.SetTouchMajor(30);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_TAP, GetMostRecentGestureEventType());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.tap_count());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(gfx::RectF(0, 0, 20, 20),
GetMostRecentGestureEvent().details.bounding_box());
}
} // namespace ui } // namespace ui
...@@ -36,6 +36,8 @@ class TouchDispositionGestureFilterTest ...@@ -36,6 +36,8 @@ class TouchDispositionGestureFilterTest
sent_gestures_.push_back(event.type()); sent_gestures_.push_back(event.type());
last_sent_gesture_location_ = gfx::PointF(event.x, event.y); last_sent_gesture_location_ = gfx::PointF(event.x, event.y);
last_sent_gesture_raw_location_ = gfx::PointF(event.raw_x, event.raw_y); last_sent_gesture_raw_location_ = gfx::PointF(event.raw_x, event.raw_y);
if (event.type() == ET_GESTURE_SHOW_PRESS)
show_press_bounding_box_ = event.details.bounding_box();
if (cancel_after_next_gesture_) { if (cancel_after_next_gesture_) {
cancel_after_next_gesture_ = false; cancel_after_next_gesture_ = false;
CancelTouchPoint(); CancelTouchPoint();
...@@ -141,6 +143,10 @@ class TouchDispositionGestureFilterTest ...@@ -141,6 +143,10 @@ class TouchDispositionGestureFilterTest
pending_gesture_packet_.Push(CreateGesture(type)); pending_gesture_packet_.Push(CreateGesture(type));
} }
void PushGesture(EventType type, float x, float y, float diameter) {
pending_gesture_packet_.Push(CreateGesture(type, x, y, diameter));
}
void PressTouchPoint(int x, int y) { void PressTouchPoint(int x, int y) {
touch_event_.PressPoint(x, y); touch_event_.PressPoint(x, y);
touch_event_.SetRawOffset(raw_offset_.x(), raw_offset_.y()); touch_event_.SetRawOffset(raw_offset_.x(), raw_offset_.y());
...@@ -195,21 +201,33 @@ class TouchDispositionGestureFilterTest ...@@ -195,21 +201,33 @@ class TouchDispositionGestureFilterTest
return last_sent_gesture_raw_location_; return last_sent_gesture_raw_location_;
} }
const gfx::RectF& ShowPressBoundingBox() const {
return show_press_bounding_box_;
}
void SetCancelAfterNextGesture(bool cancel_after_next_gesture) { void SetCancelAfterNextGesture(bool cancel_after_next_gesture) {
cancel_after_next_gesture_ = cancel_after_next_gesture; cancel_after_next_gesture_ = cancel_after_next_gesture;
} }
GestureEventData CreateGesture(EventType type) { GestureEventData CreateGesture(EventType type) {
return GestureEventData(GestureEventDetails(type, 0, 0), return CreateGesture(type, 0, 0, 0);
0, }
MotionEvent::TOOL_TYPE_FINGER,
base::TimeTicks(), GestureEventData CreateGesture(EventType type,
touch_event_.GetX(0), float x,
touch_event_.GetY(0), float y,
touch_event_.GetRawX(0), float diameter) {
touch_event_.GetRawY(0), return GestureEventData(
1, GestureEventDetails(type, 0, 0),
gfx::RectF(0, 0, 0, 0)); 0,
MotionEvent::TOOL_TYPE_FINGER,
base::TimeTicks(),
touch_event_.GetX(0),
touch_event_.GetY(0),
touch_event_.GetRawX(0),
touch_event_.GetRawY(0),
1,
gfx::RectF(x - diameter / 2, y - diameter / 2, diameter, diameter));
} }
private: private:
...@@ -223,6 +241,7 @@ class TouchDispositionGestureFilterTest ...@@ -223,6 +241,7 @@ class TouchDispositionGestureFilterTest
gfx::Vector2dF raw_offset_; gfx::Vector2dF raw_offset_;
gfx::PointF last_sent_gesture_location_; gfx::PointF last_sent_gesture_location_;
gfx::PointF last_sent_gesture_raw_location_; gfx::PointF last_sent_gesture_raw_location_;
gfx::RectF show_press_bounding_box_;
}; };
TEST_F(TouchDispositionGestureFilterTest, BasicNoGestures) { TEST_F(TouchDispositionGestureFilterTest, BasicNoGestures) {
...@@ -1067,4 +1086,19 @@ TEST_F(TouchDispositionGestureFilterTest, TapCancelOnSecondFingerDown) { ...@@ -1067,4 +1086,19 @@ TEST_F(TouchDispositionGestureFilterTest, TapCancelOnSecondFingerDown) {
GetAndResetSentGestures())); GetAndResetSentGestures()));
} }
TEST_F(TouchDispositionGestureFilterTest, ShowPressBoundingBox) {
PushGesture(ET_GESTURE_TAP_DOWN, 9, 9, 8);
PressTouchPoint(9, 9);
SendTouchNotConsumedAck();
EXPECT_TRUE(
GesturesMatch(Gestures(ET_GESTURE_TAP_DOWN), GetAndResetSentGestures()));
PushGesture(ET_GESTURE_TAP, 10, 10, 10);
ReleaseTouchPoint();
SendTouchNotConsumedAck();
EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_SHOW_PRESS, ET_GESTURE_TAP),
GetAndResetSentGestures()));
EXPECT_EQ(gfx::RectF(5, 5, 10, 10), ShowPressBoundingBox());
}
} // 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