Commit 5abdd03c authored by jdduke@chromium.org's avatar jdduke@chromium.org

[Android] Map raw touch coordinates to global gesture locations

With r277082, raw touch locations are now exposed to the gesture detector.
Plumb these raw locations into the generated gesture events, in turn populating
the WebGestureEvent.global{X,Y} properties.

BUG=383690

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278672 0039d316-1c4b-4281-b951-d872f2087c98
parent 11dee508
......@@ -238,6 +238,8 @@ WebGestureEvent CreateWebGestureEventFromGestureEventData(
WebGestureEvent gesture;
gesture.x = data.x;
gesture.y = data.y;
gesture.globalX = data.raw_x;
gesture.globalY = data.raw_y;
gesture.timeStampSeconds = (data.time - base::TimeTicks()).InSecondsF();
gesture.sourceDevice = blink::WebGestureDeviceTouchscreen;
......
......@@ -13,37 +13,38 @@ GestureEventData::GestureEventData(const GestureEventDetails& details,
base::TimeTicks time,
float x,
float y,
int touch_point_count,
float raw_x,
float raw_y,
size_t touch_point_count,
const gfx::RectF& bounding_box)
: details(details),
motion_event_id(motion_event_id),
time(time),
x(x),
y(y) {
y(y),
raw_x(raw_x),
raw_y(raw_y) {
DCHECK_GE(motion_event_id, 0);
DCHECK_NE(0, touch_point_count);
this->details.set_touch_points(touch_point_count);
DCHECK_NE(0U, touch_point_count);
this->details.set_touch_points(static_cast<int>(touch_point_count));
this->details.set_bounding_box(bounding_box);
}
GestureEventData::GestureEventData(EventType type,
int motion_event_id,
base::TimeTicks time,
float x,
float y,
int touch_point_count,
const gfx::RectF& bounding_box)
: details(GestureEventDetails(type, 0, 0)),
motion_event_id(motion_event_id),
time(time),
x(x),
y(y) {
DCHECK_GE(motion_event_id, 0);
details.set_touch_points(touch_point_count);
details.set_bounding_box(bounding_box);
const GestureEventData& other)
: details(type, 0, 0),
motion_event_id(other.motion_event_id),
time(other.time),
x(other.x),
y(other.y),
raw_x(other.raw_x),
raw_y(other.raw_y) {
details.set_touch_points(other.details.touch_points());
details.set_bounding_box(other.details.bounding_box_f());
}
GestureEventData::GestureEventData() : x(0), y(0) {
GestureEventData::GestureEventData()
: motion_event_id(0), x(0), y(0), raw_x(0), raw_y(0) {
}
} // namespace ui
......@@ -20,16 +20,11 @@ struct GESTURE_DETECTION_EXPORT GestureEventData {
base::TimeTicks time,
float x,
float y,
int touch_point_count,
const gfx::RectF& bounding_box);
GestureEventData(EventType type,
int motion_event_id,
base::TimeTicks time,
float x,
float y,
int touch_point_count,
float raw_x,
float raw_y,
size_t touch_point_count,
const gfx::RectF& bounding_box);
GestureEventData(EventType type, const GestureEventData&);
EventType type() const { return details.type(); }
......@@ -38,6 +33,8 @@ struct GESTURE_DETECTION_EXPORT GestureEventData {
base::TimeTicks time;
float x;
float y;
float raw_x;
float raw_y;
private:
friend class GestureEventDataPacket;
......
......@@ -33,14 +33,18 @@ GestureEventDataPacket::GestureSource ToGestureSource(
} // namespace
GestureEventDataPacket::GestureEventDataPacket()
: gesture_count_(0), gesture_source_(UNDEFINED) {}
: gesture_count_(0), gesture_source_(UNDEFINED) {
}
GestureEventDataPacket::GestureEventDataPacket(base::TimeTicks timestamp,
GestureSource source,
gfx::PointF touch_location)
GestureEventDataPacket::GestureEventDataPacket(
base::TimeTicks timestamp,
GestureSource source,
const gfx::PointF& touch_location,
const gfx::PointF& raw_touch_location)
: timestamp_(timestamp),
gesture_count_(0),
touch_location_(touch_location),
raw_touch_location_(raw_touch_location),
gesture_source_(source) {
DCHECK_NE(gesture_source_, UNDEFINED);
}
......@@ -50,11 +54,13 @@ GestureEventDataPacket::GestureEventDataPacket(
: timestamp_(other.timestamp_),
gesture_count_(other.gesture_count_),
touch_location_(other.touch_location_),
raw_touch_location_(other.raw_touch_location_),
gesture_source_(other.gesture_source_) {
std::copy(other.gestures_, other.gestures_ + other.gesture_count_, gestures_);
}
GestureEventDataPacket::~GestureEventDataPacket() {}
GestureEventDataPacket::~GestureEventDataPacket() {
}
GestureEventDataPacket& GestureEventDataPacket::operator=(
const GestureEventDataPacket& other) {
......@@ -62,6 +68,7 @@ GestureEventDataPacket& GestureEventDataPacket::operator=(
gesture_count_ = other.gesture_count_;
gesture_source_ = other.gesture_source_;
touch_location_ = other.touch_location_;
raw_touch_location_ = other.raw_touch_location_;
std::copy(other.gestures_, other.gestures_ + other.gesture_count_, gestures_);
return *this;
}
......@@ -76,13 +83,16 @@ GestureEventDataPacket GestureEventDataPacket::FromTouch(
const ui::MotionEvent& touch) {
return GestureEventDataPacket(touch.GetEventTime(),
ToGestureSource(touch),
gfx::PointF(touch.GetX(), touch.GetY()));
gfx::PointF(touch.GetX(), touch.GetY()),
gfx::PointF(touch.GetRawX(), touch.GetRawY()));
}
GestureEventDataPacket GestureEventDataPacket::FromTouchTimeout(
const GestureEventData& gesture) {
GestureEventDataPacket packet(
gesture.time, TOUCH_TIMEOUT, gfx::PointF(gesture.x, gesture.y));
GestureEventDataPacket packet(gesture.time,
TOUCH_TIMEOUT,
gfx::PointF(gesture.x, gesture.y),
gfx::PointF(gesture.raw_x, gesture.raw_y));
packet.Push(gesture);
return packet;
}
......
......@@ -44,18 +44,21 @@ class GESTURE_DETECTION_EXPORT GestureEventDataPacket {
const GestureEventData& gesture(size_t i) const { return gestures_[i]; }
size_t gesture_count() const { return gesture_count_; }
GestureSource gesture_source() const { return gesture_source_; }
gfx::PointF touch_location() const { return touch_location_; }
const gfx::PointF& touch_location() const { return touch_location_; }
const gfx::PointF& raw_touch_location() const { return raw_touch_location_; }
private:
GestureEventDataPacket(base::TimeTicks timestamp,
GestureSource source,
gfx::PointF touch_location);
const gfx::PointF& touch_location,
const gfx::PointF& raw_touch_location);
enum { kMaxGesturesPerTouch = 5 };
base::TimeTicks timestamp_;
GestureEventData gestures_[kMaxGesturesPerTouch];
size_t gesture_count_;
gfx::PointF touch_location_;
gfx::PointF raw_touch_location_;
GestureSource gesture_source_;
};
......
......@@ -47,6 +47,8 @@ GestureEventData CreateGesture(const GestureEventDetails& details,
base::TimeTicks time,
float x,
float y,
float raw_x,
float raw_y,
size_t touch_point_count,
const gfx::RectF& bounding_box) {
return GestureEventData(details,
......@@ -54,7 +56,9 @@ GestureEventData CreateGesture(const GestureEventDetails& details,
time,
x,
y,
static_cast<int>(touch_point_count),
raw_x,
raw_y,
touch_point_count,
bounding_box);
}
......@@ -63,37 +67,36 @@ GestureEventData CreateGesture(EventType type,
base::TimeTicks time,
float x,
float y,
float raw_x,
float raw_y,
size_t touch_point_count,
const gfx::RectF& bounding_box) {
return GestureEventData(type,
return GestureEventData(GestureEventDetails(type, 0, 0),
motion_event_id,
time,
x,
y,
static_cast<int>(touch_point_count),
raw_x,
raw_y,
touch_point_count,
bounding_box);
}
GestureEventData CreateGesture(const GestureEventDetails& details,
const MotionEvent& event) {
return CreateGesture(details,
event.GetId(),
event.GetEventTime(),
event.GetX(),
event.GetY(),
event.GetPointerCount(),
GetBoundingBox(event));
return GestureEventData(details,
event.GetId(),
event.GetEventTime(),
event.GetX(),
event.GetY(),
event.GetRawX(),
event.GetRawY(),
event.GetPointerCount(),
GetBoundingBox(event));
}
GestureEventData CreateGesture(EventType type,
const MotionEvent& event) {
return CreateGesture(type,
event.GetId(),
event.GetEventTime(),
event.GetX(),
event.GetY(),
event.GetPointerCount(),
GetBoundingBox(event));
GestureEventData CreateGesture(EventType type, const MotionEvent& event) {
return CreateGesture(GestureEventDetails(type, 0, 0), event);
}
GestureEventDetails CreateTapGestureDetails(EventType type) {
......@@ -154,13 +157,7 @@ class GestureProvider::ScaleGestureListenerImpl
const MotionEvent& e) OVERRIDE {
if (!pinch_event_sent_)
return;
provider_->Send(CreateGesture(ET_GESTURE_PINCH_END,
e.GetId(),
detector.GetEventTime(),
0,
0,
e.GetPointerCount(),
GetBoundingBox(e)));
provider_->Send(CreateGesture(ET_GESTURE_PINCH_END, e));
pinch_event_sent_ = false;
}
......@@ -175,6 +172,8 @@ class GestureProvider::ScaleGestureListenerImpl
detector.GetEventTime(),
detector.GetFocusX(),
detector.GetFocusY(),
detector.GetFocusX() + e.GetRawOffsetX(),
detector.GetFocusY() + e.GetRawOffsetY(),
e.GetPointerCount(),
GetBoundingBox(e)));
}
......@@ -206,6 +205,8 @@ class GestureProvider::ScaleGestureListenerImpl
detector.GetEventTime(),
detector.GetFocusX(),
detector.GetFocusY(),
detector.GetFocusX() + e.GetRawOffsetX(),
detector.GetFocusY() + e.GetRawOffsetY(),
e.GetPointerCount(),
GetBoundingBox(e)));
return true;
......@@ -345,19 +346,26 @@ class GestureProvider::GestureListenerImpl
e2.GetEventTime(),
e1.GetX(),
e1.GetY(),
e1.GetRawX(),
e1.GetRawY(),
e2.GetPointerCount(),
GetBoundingBox(e2)));
}
if (distance_x || distance_y) {
const gfx::RectF bounding_box = GetBoundingBox(e2);
const gfx::PointF center = bounding_box.CenterPoint();
const gfx::PointF raw_center =
center + gfx::Vector2dF(e2.GetRawOffsetX(), e2.GetRawOffsetY());
GestureEventDetails scroll_details(
ET_GESTURE_SCROLL_UPDATE, -distance_x, -distance_y);
provider_->Send(CreateGesture(scroll_details,
e2.GetId(),
e2.GetEventTime(),
bounding_box.CenterPoint().x(),
bounding_box.CenterPoint().y(),
center.x(),
center.y(),
raw_center.x(),
raw_center.y(),
e2.GetPointerCount(),
bounding_box));
}
......@@ -402,6 +410,8 @@ class GestureProvider::GestureListenerImpl
e2.GetEventTime(),
e1.GetX(),
e1.GetY(),
e1.GetRawX(),
e1.GetRawY(),
e2.GetPointerCount(),
GetBoundingBox(e2)));
return true;
......@@ -671,25 +681,13 @@ void GestureProvider::Send(GestureEventData gesture) {
case ET_GESTURE_SCROLL_END:
DCHECK(touch_scroll_in_progress_);
if (pinch_in_progress_)
Send(CreateGesture(ET_GESTURE_PINCH_END,
gesture.motion_event_id,
gesture.time,
gesture.x,
gesture.y,
gesture.details.touch_points(),
gesture.details.bounding_box()));
Send(GestureEventData(ET_GESTURE_PINCH_END, gesture));
touch_scroll_in_progress_ = false;
break;
case ET_GESTURE_PINCH_BEGIN:
DCHECK(!pinch_in_progress_);
if (!touch_scroll_in_progress_)
Send(CreateGesture(ET_GESTURE_SCROLL_BEGIN,
gesture.motion_event_id,
gesture.time,
gesture.x,
gesture.y,
gesture.details.touch_points(),
gesture.details.bounding_box()));
Send(GestureEventData(ET_GESTURE_SCROLL_BEGIN, gesture));
pinch_in_progress_ = true;
break;
case ET_GESTURE_PINCH_END:
......@@ -741,11 +739,14 @@ void GestureProvider::OnTouchEventHandlingBegin(const MotionEvent& event) {
break;
case MotionEvent::ACTION_POINTER_DOWN:
if (gesture_begin_end_types_enabled_) {
const int action_index = event.GetActionIndex();
Send(CreateGesture(ET_GESTURE_BEGIN,
event.GetId(),
event.GetEventTime(),
event.GetX(event.GetActionIndex()),
event.GetY(event.GetActionIndex()),
event.GetX(action_index),
event.GetY(action_index),
event.GetRawX(action_index),
event.GetRawY(action_index),
event.GetPointerCount(),
GetBoundingBox(event)));
}
......@@ -775,6 +776,8 @@ void GestureProvider::OnTouchEventHandlingEnd(const MotionEvent& event) {
event.GetEventTime(),
event.GetX(i),
event.GetY(i),
event.GetRawX(i),
event.GetRawY(i),
event.GetPointerCount() - i,
bounding_box));
}
......
......@@ -736,6 +736,8 @@ TEST_F(GestureProviderTest, DoubleTapDragZoomBasic) {
TEST_F(GestureProviderTest, ScrollUpdateValues) {
const float delta_x = 16;
const float delta_y = 84;
const float raw_offset_x = 17.3f;
const float raw_offset_y = 13.7f;
const base::TimeTicks event_time = TimeTicks::Now();
......@@ -755,6 +757,7 @@ TEST_F(GestureProviderTest, ScrollUpdateValues) {
MotionEvent::ACTION_MOVE,
kFakeCoordX - delta_x,
kFakeCoordY - delta_y);
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
// Make sure the reported gesture event has all the expected details.
......@@ -764,6 +767,8 @@ TEST_F(GestureProviderTest, ScrollUpdateValues) {
EXPECT_EQ(event_time + kOneMicrosecond * 2, gesture.time);
EXPECT_EQ(kFakeCoordX - delta_x, gesture.x);
EXPECT_EQ(kFakeCoordY - delta_y, gesture.y);
EXPECT_EQ(kFakeCoordX - delta_x + raw_offset_x, gesture.raw_x);
EXPECT_EQ(kFakeCoordY - delta_y + raw_offset_y, gesture.raw_y);
EXPECT_EQ(1, gesture.details.touch_points());
// No horizontal delta because of snapping.
......@@ -1416,6 +1421,8 @@ TEST_F(GestureProviderTest, FixedPageScaleDuringDoubleTapDragZoom) {
TEST_F(GestureProviderTest, PinchZoom) {
base::TimeTicks event_time = base::TimeTicks::Now();
const float touch_slop = GetTouchSlop();
const float raw_offset_x = 3.2f;
const float raw_offset_y = 4.3f;
int motion_event_id = 0;
gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
......@@ -1428,8 +1435,13 @@ TEST_F(GestureProviderTest, PinchZoom) {
MockMotionEvent event =
ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN);
event.SetId(++motion_event_id);
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
EXPECT_EQ(kFakeCoordX, GetMostRecentGestureEvent().x);
EXPECT_EQ(kFakeCoordY, GetMostRecentGestureEvent().y);
EXPECT_EQ(kFakeCoordX + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(kFakeCoordY + raw_offset_y, GetMostRecentGestureEvent().raw_y);
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(BoundsForSingleMockTouchAtLocation(kFakeCoordX, kFakeCoordY),
GetMostRecentGestureEvent().details.bounding_box());
......@@ -1444,6 +1456,7 @@ TEST_F(GestureProviderTest, PinchZoom) {
secondary_coord_x,
secondary_coord_y);
event.SetId(++motion_event_id);
event.SetRawOffset(raw_offset_x, raw_offset_y);
gesture_provider_->OnTouchEvent(event);
EXPECT_EQ(1U, GetReceivedGestureCount());
......@@ -1460,6 +1473,7 @@ TEST_F(GestureProviderTest, PinchZoom) {
secondary_coord_x,
secondary_coord_y);
event.SetId(++motion_event_id);
event.SetRawOffset(raw_offset_x, raw_offset_y);
// Toggling double-tap support should not take effect until the next sequence.
gesture_provider_->SetDoubleTapSupportForPageEnabled(false);
......@@ -1473,6 +1487,10 @@ TEST_F(GestureProviderTest, PinchZoom) {
EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2, GetReceivedGesture(3).x);
EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2, GetReceivedGesture(3).y);
EXPECT_EQ((kFakeCoordX + secondary_coord_x) / 2 + raw_offset_x,
GetReceivedGesture(3).raw_x);
EXPECT_EQ((kFakeCoordY + secondary_coord_y) / 2 + raw_offset_y,
GetReceivedGesture(3).raw_y);
EXPECT_EQ(
gfx::RectF(kFakeCoordX - kMockTouchRadius,
......@@ -1832,11 +1850,14 @@ TEST_F(GestureProviderTest, DoubleTapDragZoomCancelledOnSecondaryPointerDown) {
TEST_F(GestureProviderTest, GestureBeginAndEnd) {
EnableBeginEndTypes();
base::TimeTicks event_time = base::TimeTicks::Now();
const float raw_offset_x = 7.5f;
const float raw_offset_y = 5.7f;
EXPECT_EQ(0U, GetReceivedGestureCount());
MockMotionEvent event =
ObtainMotionEvent(event_time, MotionEvent::ACTION_DOWN, 1, 1);
event.pointer_count = 1;
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_BEGIN, GetReceivedGesture(0).type());
EXPECT_EQ(ET_GESTURE_TAP_DOWN, GetMostRecentGestureEventType());
......@@ -1844,6 +1865,8 @@ TEST_F(GestureProviderTest, GestureBeginAndEnd) {
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(1, GetMostRecentGestureEvent().x);
EXPECT_EQ(1, GetMostRecentGestureEvent().y);
EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
EXPECT_EQ(gfx::RectF(1 - kMockTouchRadius,
1 - kMockTouchRadius,
kMockTouchRadius * 2,
......@@ -1853,35 +1876,45 @@ TEST_F(GestureProviderTest, GestureBeginAndEnd) {
event = ObtainMotionEvent(
event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2);
event.pointer_count = 2;
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
EXPECT_EQ(3U, GetReceivedGestureCount());
EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(2, GetMostRecentGestureEvent().x);
EXPECT_EQ(2, GetMostRecentGestureEvent().y);
EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
event = ObtainMotionEvent(
event_time, MotionEvent::ACTION_POINTER_DOWN, 1, 1, 2, 2, 3, 3);
event.pointer_count = 3;
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
EXPECT_EQ(4U, GetReceivedGestureCount());
EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(3, GetMostRecentGestureEvent().x);
EXPECT_EQ(3, GetMostRecentGestureEvent().y);
EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
event = ObtainMotionEvent(
event_time, MotionEvent::ACTION_POINTER_UP, 1, 1, 2, 2, 3, 3);
event.pointer_count = 2;
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
EXPECT_EQ(5U, GetReceivedGestureCount());
EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(1, GetMostRecentGestureEvent().x);
EXPECT_EQ(1, GetMostRecentGestureEvent().y);
EXPECT_EQ(1 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(1 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
event = ObtainMotionEvent(
event_time, MotionEvent::ACTION_POINTER_DOWN, 2, 2, 3, 3, 4, 4);
event.SetRawOffset(raw_offset_x, raw_offset_y);
event.pointer_count = 3;
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_BEGIN, GetMostRecentGestureEventType());
......@@ -1889,36 +1922,47 @@ TEST_F(GestureProviderTest, GestureBeginAndEnd) {
EXPECT_EQ(3, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(4, GetMostRecentGestureEvent().x);
EXPECT_EQ(4, GetMostRecentGestureEvent().y);
EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
event = ObtainMotionEvent(
event_time, MotionEvent::ACTION_POINTER_UP, 2, 2, 3, 3, 4, 4);
event.pointer_count = 2;
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
EXPECT_EQ(7U, GetReceivedGestureCount());
EXPECT_EQ(2, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(2, GetMostRecentGestureEvent().x);
EXPECT_EQ(2, GetMostRecentGestureEvent().y);
EXPECT_EQ(2 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(2 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
event =
ObtainMotionEvent(event_time, MotionEvent::ACTION_POINTER_UP, 3, 3, 4, 4);
event.pointer_count = 1;
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
EXPECT_EQ(8U, GetReceivedGestureCount());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(3, GetMostRecentGestureEvent().x);
EXPECT_EQ(3, GetMostRecentGestureEvent().y);
EXPECT_EQ(3 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(3 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
event = ObtainMotionEvent(event_time, MotionEvent::ACTION_UP, 4, 4);
event.pointer_count = 1;
event.SetRawOffset(raw_offset_x, raw_offset_y);
EXPECT_TRUE(gesture_provider_->OnTouchEvent(event));
EXPECT_EQ(ET_GESTURE_END, GetMostRecentGestureEventType());
EXPECT_EQ(9U, GetReceivedGestureCount());
EXPECT_EQ(1, GetMostRecentGestureEvent().details.touch_points());
EXPECT_EQ(4, GetMostRecentGestureEvent().x);
EXPECT_EQ(4, GetMostRecentGestureEvent().y);
EXPECT_EQ(4 + raw_offset_x, GetMostRecentGestureEvent().raw_x);
EXPECT_EQ(4 + raw_offset_y, GetMostRecentGestureEvent().raw_y);
}
// Verify that gesture begin and gesture end events are dispatched correctly
......
......@@ -101,11 +101,11 @@ float MockMotionEvent::GetY(size_t pointer_index) const {
}
float MockMotionEvent::GetRawX(size_t pointer_index) const {
return GetX(pointer_index);
return GetX(pointer_index) + raw_offset.x();
}
float MockMotionEvent::GetRawY(size_t pointer_index) const {
return GetY(pointer_index);
return GetY(pointer_index) + raw_offset.y();
}
float MockMotionEvent::GetTouchMajor(size_t pointer_index) const {
......@@ -196,4 +196,9 @@ void MockMotionEvent::SetTouchMajor(float new_touch_major) {
touch_major = new_touch_major;
}
void MockMotionEvent::SetRawOffset(float raw_offset_x, float raw_offset_y) {
raw_offset.set_x(raw_offset_x);
raw_offset.set_y(raw_offset_y);
}
} // namespace ui
......@@ -72,10 +72,12 @@ struct MockMotionEvent : public MotionEvent {
void ReleasePoint();
void CancelPoint();
void SetTouchMajor(float new_touch_major);
void SetRawOffset(float raw_offset_x, float raw_offset_y);
MotionEvent::Action action;
size_t pointer_count;
gfx::PointF points[MAX_POINTERS];
gfx::Vector2dF raw_offset;
base::TimeTicks time;
float touch_major;
int id;
......
......@@ -62,6 +62,8 @@ class GESTURE_DETECTION_EXPORT MotionEvent {
float GetY() const { return GetY(0); }
float GetRawX() const { return GetRawX(0); }
float GetRawY() const { return GetRawY(0); }
float GetRawOffsetX() const { return GetRawX() - GetX(); }
float GetRawOffsetY() const { return GetRawY() - GetY(); }
float GetTouchMajor() const { return GetTouchMajor(0); }
float GetPressure() const { return GetPressure(0); }
};
......
......@@ -17,16 +17,16 @@ COMPILE_ASSERT(ET_GESTURE_TYPE_END - ET_GESTURE_TYPE_START < 32,
GestureEventData CreateGesture(EventType type,
int motion_event_id,
const base::TimeTicks& timestamp,
const gfx::PointF& location) {
GestureEventDetails details(type, 0, 0);
return GestureEventData(details,
const GestureEventDataPacket& packet) {
return GestureEventData(GestureEventDetails(type, 0, 0),
motion_event_id,
timestamp,
location.x(),
location.y(),
packet.timestamp(),
packet.touch_location().x(),
packet.touch_location().y(),
packet.raw_touch_location().x(),
packet.raw_touch_location().y(),
1,
gfx::RectF(location.x(), location.y(), 0, 0));
gfx::RectF(packet.touch_location(), gfx::SizeF()));
}
enum RequiredTouches {
......@@ -269,14 +269,7 @@ void TouchDispositionGestureFilter::SendGesture(const GestureEventData& event) {
case ET_GESTURE_TAP:
DCHECK(needs_tap_ending_event_);
if (needs_show_press_event_) {
GestureEventData show_press_event(ET_GESTURE_SHOW_PRESS,
event.motion_event_id,
event.time,
event.x,
event.y,
event.details.touch_points(),
event.details.bounding_box_f());
SendGesture(show_press_event);
SendGesture(GestureEventData(ET_GESTURE_SHOW_PRESS, event));
DCHECK(!needs_show_press_event_);
}
needs_tap_ending_event_ = false;
......@@ -317,8 +310,7 @@ void TouchDispositionGestureFilter::CancelTapIfNecessary() {
SendGesture(CreateGesture(ET_GESTURE_TAP_CANCEL,
ending_event_motion_event_id_,
packet_being_sent_->timestamp(),
packet_being_sent_->touch_location()));
*packet_being_sent_));
DCHECK(!needs_tap_ending_event_);
}
......@@ -329,8 +321,7 @@ void TouchDispositionGestureFilter::CancelFlingIfNecessary() {
SendGesture(CreateGesture(ET_SCROLL_FLING_CANCEL,
ending_event_motion_event_id_,
packet_being_sent_->timestamp(),
packet_being_sent_->touch_location()));
*packet_being_sent_));
DCHECK(!needs_fling_ending_event_);
}
......@@ -341,8 +332,7 @@ void TouchDispositionGestureFilter::EndScrollIfNecessary() {
SendGesture(CreateGesture(ET_GESTURE_SCROLL_END,
ending_event_motion_event_id_,
packet_being_sent_->timestamp(),
packet_being_sent_->touch_location()));
*packet_being_sent_));
DCHECK(!needs_scroll_ending_event_);
}
......
......@@ -33,6 +33,7 @@ class TouchDispositionGestureFilterTest
last_sent_gesture_time_ = event.time;
sent_gestures_.push_back(event.type());
last_sent_gesture_location_ = gfx::PointF(event.x, event.y);
last_sent_gesture_raw_location_ = gfx::PointF(event.raw_x, event.raw_y);
if (cancel_after_next_gesture_) {
CancelTouchPoint();
SendTouchNotConsumedAck();
......@@ -158,6 +159,10 @@ class TouchDispositionGestureFilterTest
SendTouchGestures();
}
void SetRawTouchOffset(const gfx::Vector2dF& raw_offset) {
touch_event_.SetRawOffset(raw_offset.x(), raw_offset.y());
}
void ResetTouchPoints() { touch_event_ = MockMotionEvent(); }
bool GesturesSent() const { return !sent_gestures_.empty(); }
......@@ -178,20 +183,26 @@ class TouchDispositionGestureFilterTest
return sent_gestures;
}
gfx::PointF LastSentGestureLocation() {
const gfx::PointF& LastSentGestureLocation() const {
return last_sent_gesture_location_;
}
const gfx::PointF& LastSentGestureRawLocation() const {
return last_sent_gesture_raw_location_;
}
void SetCancelAfterNextGesture(bool cancel_after_next_gesture) {
cancel_after_next_gesture_ = cancel_after_next_gesture;
}
GestureEventData CreateGesture(EventType type) {
return GestureEventData(type,
return GestureEventData(GestureEventDetails(type, 0, 0),
0,
base::TimeTicks(),
touch_event_.GetX(0),
touch_event_.GetY(0),
touch_event_.GetRawX(0),
touch_event_.GetRawY(0),
1,
gfx::RectF(0, 0, 0, 0));
}
......@@ -205,6 +216,7 @@ class TouchDispositionGestureFilterTest
base::TimeTicks last_sent_gesture_time_;
GestureList sent_gestures_;
gfx::PointF last_sent_gesture_location_;
gfx::PointF last_sent_gesture_raw_location_;
};
TEST_F(TouchDispositionGestureFilterTest, BasicNoGestures) {
......@@ -559,6 +571,8 @@ TEST_F(TouchDispositionGestureFilterTest, MultipleTouchSequences) {
}
TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnNewTouchSequence) {
const gfx::Vector2dF raw_offset(1.3f, 3.7f);
SetRawTouchOffset(raw_offset);
// Simulate a fling.
PushGesture(ET_GESTURE_TAP_DOWN);
PushGesture(ET_GESTURE_SCROLL_BEGIN);
......@@ -581,6 +595,7 @@ TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnNewTouchSequence) {
GetAndResetSentGestures()));
EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime());
EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1));
EXPECT_EQ(LastSentGestureRawLocation(), gfx::PointF(1, 1) + raw_offset);
ReleaseTouchPoint();
SendTouchNotConsumedAck();
EXPECT_FALSE(GesturesSent());
......@@ -889,6 +904,8 @@ TEST_F(TouchDispositionGestureFilterTest, ShowPressNotInsertedIfAlreadySent) {
}
TEST_F(TouchDispositionGestureFilterTest, TapAndScrollCancelledOnTouchCancel) {
const gfx::Vector2dF raw_offset(1.3f, 3.7f);
SetRawTouchOffset(raw_offset);
PushGesture(ET_GESTURE_TAP_DOWN);
PressTouchPoint(1, 1);
SendTouchNotConsumedAck();
......@@ -902,6 +919,7 @@ TEST_F(TouchDispositionGestureFilterTest, TapAndScrollCancelledOnTouchCancel) {
GetAndResetSentGestures()));
EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime());
EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1));
EXPECT_EQ(LastSentGestureRawLocation(), gfx::PointF(1, 1) + raw_offset);
PushGesture(ET_GESTURE_SCROLL_BEGIN);
PressTouchPoint(1, 1);
......@@ -917,6 +935,7 @@ TEST_F(TouchDispositionGestureFilterTest, TapAndScrollCancelledOnTouchCancel) {
GetAndResetSentGestures()));
EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime());
EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1));
EXPECT_EQ(LastSentGestureRawLocation(), gfx::PointF(1, 1) + raw_offset);
}
TEST_F(TouchDispositionGestureFilterTest,
......
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