diff options
5 files changed, 96 insertions, 48 deletions
diff --git a/ui/events/gesture_detection/gesture_event_data_packet.cc b/ui/events/gesture_detection/gesture_event_data_packet.cc index 58d4e50..5fc9190 100644 --- a/ui/events/gesture_detection/gesture_event_data_packet.cc +++ b/ui/events/gesture_detection/gesture_event_data_packet.cc @@ -36,8 +36,12 @@ GestureEventDataPacket::GestureEventDataPacket() : gesture_count_(0), gesture_source_(UNDEFINED) {} GestureEventDataPacket::GestureEventDataPacket(base::TimeTicks timestamp, - GestureSource source) - : timestamp_(timestamp), gesture_count_(0), gesture_source_(source) { + GestureSource source, + gfx::PointF touch_location) + : timestamp_(timestamp), + gesture_count_(0), + touch_location_(touch_location), + gesture_source_(source) { DCHECK_NE(gesture_source_, UNDEFINED); } @@ -45,6 +49,7 @@ GestureEventDataPacket::GestureEventDataPacket( const GestureEventDataPacket& other) : timestamp_(other.timestamp_), gesture_count_(other.gesture_count_), + touch_location_(other.touch_location_), gesture_source_(other.gesture_source_) { std::copy(other.gestures_, other.gestures_ + other.gesture_count_, gestures_); } @@ -56,6 +61,7 @@ GestureEventDataPacket& GestureEventDataPacket::operator=( timestamp_ = other.timestamp_; gesture_count_ = other.gesture_count_; gesture_source_ = other.gesture_source_; + touch_location_ = other.touch_location_; std::copy(other.gestures_, other.gestures_ + other.gesture_count_, gestures_); return *this; } @@ -68,12 +74,15 @@ void GestureEventDataPacket::Push(const GestureEventData& gesture) { GestureEventDataPacket GestureEventDataPacket::FromTouch( const ui::MotionEvent& touch) { - return GestureEventDataPacket(touch.GetEventTime(), ToGestureSource(touch)); + return GestureEventDataPacket(touch.GetEventTime(), + ToGestureSource(touch), + gfx::PointF(touch.GetX(), touch.GetY())); } GestureEventDataPacket GestureEventDataPacket::FromTouchTimeout( const GestureEventData& gesture) { - GestureEventDataPacket packet(gesture.time, TOUCH_TIMEOUT); + GestureEventDataPacket packet( + gesture.time, TOUCH_TIMEOUT, gfx::PointF(gesture.x, gesture.y)); packet.Push(gesture); return packet; } diff --git a/ui/events/gesture_detection/gesture_event_data_packet.h b/ui/events/gesture_detection/gesture_event_data_packet.h index fee86f1..777b0d5 100644 --- a/ui/events/gesture_detection/gesture_event_data_packet.h +++ b/ui/events/gesture_detection/gesture_event_data_packet.h @@ -44,14 +44,18 @@ 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_; } private: - GestureEventDataPacket(base::TimeTicks timestamp, GestureSource source); + GestureEventDataPacket(base::TimeTicks timestamp, + GestureSource source, + gfx::PointF touch_location); enum { kMaxGesturesPerTouch = 5 }; base::TimeTicks timestamp_; GestureEventData gestures_[kMaxGesturesPerTouch]; size_t gesture_count_; + gfx::PointF touch_location_; GestureSource gesture_source_; }; diff --git a/ui/events/gesture_detection/touch_disposition_gesture_filter.cc b/ui/events/gesture_detection/touch_disposition_gesture_filter.cc index bfff780..a1b4543 100644 --- a/ui/events/gesture_detection/touch_disposition_gesture_filter.cc +++ b/ui/events/gesture_detection/touch_disposition_gesture_filter.cc @@ -17,15 +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 base::TimeTicks& timestamp, + const gfx::PointF& location) { GestureEventDetails details(type, 0, 0); return GestureEventData(type, motion_event_id, timestamp, - 0, - 0, + location.x(), + location.y(), 1, - gfx::RectF(0, 0, 0, 0), + gfx::RectF(location.x(), location.y(), 0, 0), details); } @@ -129,11 +130,14 @@ TouchDispositionGestureFilter::TouchDispositionGestureFilter( needs_tap_ending_event_(false), needs_show_press_event_(false), needs_fling_ending_event_(false), - needs_scroll_ending_event_(false) { + needs_scroll_ending_event_(false), + packet_being_sent_(NULL) { DCHECK(client_); } -TouchDispositionGestureFilter::~TouchDispositionGestureFilter() {} +TouchDispositionGestureFilter::~TouchDispositionGestureFilter() { + DCHECK(!packet_being_sent_); +} TouchDispositionGestureFilter::PacketResult TouchDispositionGestureFilter::OnGesturePacket( @@ -205,10 +209,12 @@ bool TouchDispositionGestureFilter::IsEmpty() const { void TouchDispositionGestureFilter::FilterAndSendPacket( const GestureEventDataPacket& packet) { + base::AutoReset<const GestureEventDataPacket*> packet_being_sent( + &packet_being_sent_, &packet); if (packet.gesture_source() == GestureEventDataPacket::TOUCH_SEQUENCE_START) { - CancelTapIfNecessary(packet.timestamp()); - EndScrollIfNecessary(packet.timestamp()); - CancelFlingIfNecessary(packet.timestamp()); + CancelTapIfNecessary(); + EndScrollIfNecessary(); + CancelFlingIfNecessary(); } for (size_t i = 0; i < packet.gesture_count(); ++i) { @@ -216,7 +222,7 @@ void TouchDispositionGestureFilter::FilterAndSendPacket( DCHECK(ET_GESTURE_TYPE_START <= gesture.type && gesture.type <= ET_GESTURE_TYPE_END); if (state_.Filter(gesture.type)) { - CancelTapIfNecessary(gesture.time); + CancelTapIfNecessary(); continue; } SendGesture(gesture); @@ -224,11 +230,11 @@ void TouchDispositionGestureFilter::FilterAndSendPacket( if (packet.gesture_source() == GestureEventDataPacket::TOUCH_SEQUENCE_CANCEL) { - EndScrollIfNecessary(packet.timestamp()); - CancelTapIfNecessary(packet.timestamp()); + EndScrollIfNecessary(); + CancelTapIfNecessary(); } else if (packet.gesture_source() == GestureEventDataPacket::TOUCH_SEQUENCE_END) { - EndScrollIfNecessary(packet.timestamp()); + EndScrollIfNecessary(); } } @@ -239,8 +245,8 @@ void TouchDispositionGestureFilter::SendGesture(const GestureEventData& event) { case ET_GESTURE_LONG_TAP: if (!needs_tap_ending_event_) return; - CancelTapIfNecessary(event.time); - CancelFlingIfNecessary(event.time); + CancelTapIfNecessary(); + CancelFlingIfNecessary(); break; case ET_GESTURE_TAP_DOWN: DCHECK(!needs_tap_ending_event_); @@ -254,7 +260,7 @@ void TouchDispositionGestureFilter::SendGesture(const GestureEventData& event) { needs_show_press_event_ = false; break; case ET_GESTURE_DOUBLE_TAP: - CancelTapIfNecessary(event.time); + CancelTapIfNecessary(); needs_show_press_event_ = false; break; case ET_GESTURE_TAP: @@ -271,9 +277,9 @@ void TouchDispositionGestureFilter::SendGesture(const GestureEventData& event) { needs_tap_ending_event_ = false; break; case ET_GESTURE_SCROLL_BEGIN: - CancelTapIfNecessary(event.time); - CancelFlingIfNecessary(event.time); - EndScrollIfNecessary(event.time); + CancelTapIfNecessary(); + CancelFlingIfNecessary(); + EndScrollIfNecessary(); ending_event_motion_event_id_ = event.motion_event_id; needs_scroll_ending_event_ = true; break; @@ -281,7 +287,7 @@ void TouchDispositionGestureFilter::SendGesture(const GestureEventData& event) { needs_scroll_ending_event_ = false; break; case ET_SCROLL_FLING_START: - CancelFlingIfNecessary(event.time); + CancelFlingIfNecessary(); ending_event_motion_event_id_ = event.motion_event_id; needs_fling_ending_event_ = true; needs_scroll_ending_event_ = false; @@ -295,33 +301,39 @@ void TouchDispositionGestureFilter::SendGesture(const GestureEventData& event) { client_->ForwardGestureEvent(event); } -void TouchDispositionGestureFilter::CancelTapIfNecessary( - const base::TimeTicks& timestamp) { - if (!needs_tap_ending_event_) +void TouchDispositionGestureFilter::CancelTapIfNecessary() { + DCHECK(packet_being_sent_); + if (!needs_tap_ending_event_ || !packet_being_sent_) return; - SendGesture(CreateGesture( - ET_GESTURE_TAP_CANCEL, ending_event_motion_event_id_, timestamp)); + SendGesture(CreateGesture(ET_GESTURE_TAP_CANCEL, + ending_event_motion_event_id_, + packet_being_sent_->timestamp(), + packet_being_sent_->touch_location())); DCHECK(!needs_tap_ending_event_); } -void TouchDispositionGestureFilter::CancelFlingIfNecessary( - const base::TimeTicks& timestamp) { - if (!needs_fling_ending_event_) +void TouchDispositionGestureFilter::CancelFlingIfNecessary() { + DCHECK(packet_being_sent_); + if (!needs_fling_ending_event_ || !packet_being_sent_) return; - SendGesture(CreateGesture( - ET_SCROLL_FLING_CANCEL, ending_event_motion_event_id_, timestamp)); + SendGesture(CreateGesture(ET_SCROLL_FLING_CANCEL, + ending_event_motion_event_id_, + packet_being_sent_->timestamp(), + packet_being_sent_->touch_location())); DCHECK(!needs_fling_ending_event_); } -void TouchDispositionGestureFilter::EndScrollIfNecessary( - const base::TimeTicks& timestamp) { - if (!needs_scroll_ending_event_) +void TouchDispositionGestureFilter::EndScrollIfNecessary() { + DCHECK(packet_being_sent_); + if (!needs_scroll_ending_event_ || !packet_being_sent_) return; - SendGesture(CreateGesture( - ET_GESTURE_SCROLL_END, ending_event_motion_event_id_, timestamp)); + SendGesture(CreateGesture(ET_GESTURE_SCROLL_END, + ending_event_motion_event_id_, + packet_being_sent_->timestamp(), + packet_being_sent_->touch_location())); DCHECK(!needs_scroll_ending_event_); } diff --git a/ui/events/gesture_detection/touch_disposition_gesture_filter.h b/ui/events/gesture_detection/touch_disposition_gesture_filter.h index fc49301..e3ffd2b 100644 --- a/ui/events/gesture_detection/touch_disposition_gesture_filter.h +++ b/ui/events/gesture_detection/touch_disposition_gesture_filter.h @@ -78,9 +78,9 @@ class GESTURE_DETECTION_EXPORT TouchDispositionGestureFilter { void FilterAndSendPacket(const GestureEventDataPacket& packet); void SendGesture(const GestureEventData& gesture); - void CancelTapIfNecessary(const base::TimeTicks& timestamp); - void CancelFlingIfNecessary(const base::TimeTicks& timestamp); - void EndScrollIfNecessary(const base::TimeTicks& timestamp); + void CancelTapIfNecessary(); + void CancelFlingIfNecessary(); + void EndScrollIfNecessary(); void PopGestureSequence(); GestureSequence& Head(); GestureSequence& Tail(); @@ -98,6 +98,8 @@ class GESTURE_DETECTION_EXPORT TouchDispositionGestureFilter { bool needs_show_press_event_; bool needs_fling_ending_event_; bool needs_scroll_ending_event_; + // Only valid in the scope of |FilterAndSendPacket()|. + const GestureEventDataPacket* packet_being_sent_; DISALLOW_COPY_AND_ASSIGN(TouchDispositionGestureFilter); }; diff --git a/ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc b/ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc index 6e78240..391c669 100644 --- a/ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc +++ b/ui/events/gesture_detection/touch_disposition_gesture_filter_unittest.cc @@ -32,6 +32,7 @@ class TouchDispositionGestureFilterTest ++sent_gesture_count_; last_sent_gesture_time_ = event.time; sent_gestures_.push_back(event.type); + last_sent_gesture_location_ = gfx::PointF(event.x, event.y); if (cancel_after_next_gesture_) { CancelTouchPoint(); SendTouchNotConsumedAck(); @@ -177,13 +178,22 @@ class TouchDispositionGestureFilterTest return sent_gestures; } + gfx::PointF LastSentGestureLocation() { + return last_sent_gesture_location_; + } + void SetCancelAfterNextGesture(bool cancel_after_next_gesture) { cancel_after_next_gesture_ = cancel_after_next_gesture; } - static GestureEventData CreateGesture(EventType type) { - return GestureEventData( - type, 0, base::TimeTicks(), 0, 0, 1, gfx::RectF(0, 0, 0, 0)); + GestureEventData CreateGesture(EventType type) { + return GestureEventData(type, + 0, + base::TimeTicks(), + touch_event_.GetX(0), + touch_event_.GetY(0), + 1, + gfx::RectF(0, 0, 0, 0)); } private: @@ -194,6 +204,7 @@ class TouchDispositionGestureFilterTest size_t sent_gesture_count_; base::TimeTicks last_sent_gesture_time_; GestureList sent_gestures_; + gfx::PointF last_sent_gesture_location_; }; TEST_F(TouchDispositionGestureFilterTest, BasicNoGestures) { @@ -569,6 +580,7 @@ TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnNewTouchSequence) { EXPECT_TRUE(GesturesMatch(Gestures(ET_SCROLL_FLING_CANCEL), GetAndResetSentGestures())); EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime()); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1)); ReleaseTouchPoint(); SendTouchNotConsumedAck(); EXPECT_FALSE(GesturesSent()); @@ -589,6 +601,7 @@ TEST_F(TouchDispositionGestureFilterTest, ScrollEndedOnTouchReleaseIfNoFling) { EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_SCROLL_END), GetAndResetSentGestures())); EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime()); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1)); } TEST_F(TouchDispositionGestureFilterTest, ScrollEndedOnNewTouchSequence) { @@ -604,11 +617,12 @@ TEST_F(TouchDispositionGestureFilterTest, ScrollEndedOnNewTouchSequence) { // A new touch sequence should end the outstanding scroll. ResetTouchPoints(); - PressTouchPoint(1, 1); + PressTouchPoint(2, 3); SendTouchConsumedAck(); EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_SCROLL_END), GetAndResetSentGestures())); EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime()); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(2, 3)); } TEST_F(TouchDispositionGestureFilterTest, FlingCancelledOnScrollBegin) { @@ -641,7 +655,7 @@ TEST_F(TouchDispositionGestureFilterTest, FlingNotCancelledIfGFCEventReceived) { PressTouchPoint(1, 1); SendTouchNotConsumedAck(); PushGesture(ET_SCROLL_FLING_START); - MoveTouchPoint(0, 1, 1); + MoveTouchPoint(0, 2, 3); SendTouchNotConsumedAck(); PushGesture(ET_SCROLL_FLING_CANCEL); ReleaseTouchPoint(); @@ -650,6 +664,7 @@ TEST_F(TouchDispositionGestureFilterTest, FlingNotCancelledIfGFCEventReceived) { ET_SCROLL_FLING_START, ET_SCROLL_FLING_CANCEL), GetAndResetSentGestures())); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(2, 3)); // A new touch sequence will not inject a ET_SCROLL_FLING_CANCEL, as the fling // has already been cancelled. @@ -689,6 +704,7 @@ TEST_F(TouchDispositionGestureFilterTest, TapCancelledWhenTouchConsumed) { SendTouchConsumedAck(); EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_TAP_CANCEL), GetAndResetSentGestures())); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(2, 2)); } TEST_F(TouchDispositionGestureFilterTest, @@ -888,6 +904,7 @@ TEST_F(TouchDispositionGestureFilterTest, TapAndScrollCancelledOnTouchCancel) { EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_TAP_CANCEL), GetAndResetSentGestures())); EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime()); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1)); PushGesture(ET_GESTURE_SCROLL_BEGIN); PressTouchPoint(1, 1); @@ -902,6 +919,7 @@ TEST_F(TouchDispositionGestureFilterTest, TapAndScrollCancelledOnTouchCancel) { EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_SCROLL_END), GetAndResetSentGestures())); EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime()); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1)); } TEST_F(TouchDispositionGestureFilterTest, @@ -928,6 +946,7 @@ TEST_F(TouchDispositionGestureFilterTest, SendTouchNotConsumedAck(); EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_END, ET_GESTURE_SCROLL_END), GetAndResetSentGestures())); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(2, 2)); PushGesture(ET_GESTURE_BEGIN); PushGesture(ET_GESTURE_SCROLL_BEGIN); @@ -950,6 +969,7 @@ TEST_F(TouchDispositionGestureFilterTest, TapCancelledOnTouchCancel) { EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_TAP_CANCEL), GetAndResetSentGestures())); EXPECT_EQ(CurrentTouchTime(), LastSentGestureTime()); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1)); } // Test that a GestureEvent whose dispatch causes a cancel event to be fired @@ -962,6 +982,7 @@ TEST_F(TouchDispositionGestureFilterTest, TestCancelMidGesture) { EXPECT_TRUE(GesturesMatch(Gestures(ET_GESTURE_TAP_DOWN, ET_GESTURE_TAP_CANCEL), GetAndResetSentGestures())); + EXPECT_EQ(LastSentGestureLocation(), gfx::PointF(1, 1)); } // Test that a MultiFingerSwipe event is dispatched when appropriate. |