diff options
-rw-r--r-- | include/fling_stop_filter_interpreter.h | 2 | ||||
-rw-r--r-- | src/fling_stop_filter_interpreter.cc | 40 | ||||
-rw-r--r-- | src/fling_stop_filter_interpreter_unittest.cc | 44 |
3 files changed, 76 insertions, 10 deletions
diff --git a/include/fling_stop_filter_interpreter.h b/include/fling_stop_filter_interpreter.h index 62c5ae0..577cebd 100644 --- a/include/fling_stop_filter_interpreter.h +++ b/include/fling_stop_filter_interpreter.h @@ -22,6 +22,8 @@ namespace gestures { class FlingStopFilterInterpreter : public FilterInterpreter { FRIEND_TEST(FlingStopFilterInterpreterTest, SimpleTest); + FRIEND_TEST(FlingStopFilterInterpreterTest, FlingGestureTest); + FRIEND_TEST(FlingStopFilterInterpreterTest, FlingStopMultimouseMoveTest); public: // Takes ownership of |next|: FlingStopFilterInterpreter(PropRegistry* prop_reg, diff --git a/src/fling_stop_filter_interpreter.cc b/src/fling_stop_filter_interpreter.cc index 2ce44f6..5cf3c78 100644 --- a/src/fling_stop_filter_interpreter.cc +++ b/src/fling_stop_filter_interpreter.cc @@ -25,6 +25,9 @@ FlingStopFilterInterpreter::FlingStopFilterInterpreter( void FlingStopFilterInterpreter::SyncInterpretImpl(HardwareState& hwstate, stime_t* timeout) { + const char name[] = "FlingStopFilterInterpreter::SyncInterpretImpl"; + LogHardwareStatePre(name, hwstate); + fingers_of_last_hwstate_.clear(); for (int i = 0; i < hwstate.finger_cnt; i++) fingers_of_last_hwstate_.insert(hwstate.fingers[i].tracking_id); @@ -37,15 +40,19 @@ void FlingStopFilterInterpreter::SyncInterpretImpl(HardwareState& hwstate, } if (hwstate.timestamp > fling_stop_deadline_) { // sub in a fling before processing other interpreters - ProduceGesture(Gesture(kGestureFling, prev_timestamp_, - hwstate.timestamp, 0.0, 0.0, - GESTURES_FLING_TAP_DOWN)); + auto fling_tap_down = Gesture(kGestureFling, prev_timestamp_, + hwstate.timestamp, 0.0, 0.0, + GESTURES_FLING_TAP_DOWN); + LogGestureProduce(name, fling_tap_down); + ProduceGesture(fling_tap_down); + fling_stop_already_sent_ = true; fling_stop_deadline_ = NO_DEADLINE; } } stime_t next_timeout = NO_DEADLINE; + LogHardwareStatePost(name, hwstate); next_->SyncInterpret(hwstate, &next_timeout); *timeout = SetNextDeadlineAndReturnTimeoutVal(hwstate.timestamp, @@ -62,7 +69,6 @@ bool FlingStopFilterInterpreter::NeedsExtraTime( num_new_fingers++; } } - return (num_new_fingers >= 2); } @@ -80,6 +86,9 @@ bool FlingStopFilterInterpreter::FlingStopNeeded(const Gesture& gesture) const { } void FlingStopFilterInterpreter::ConsumeGesture(const Gesture& gesture) { + const char name[] = "FlingStopFilterInterpreter::ConsumeGesture"; + LogGestureConsume(name, gesture); + if (gesture.type == kGestureTypeFling) { fingers_present_for_last_fling_ = fingers_of_last_hwstate_; already_extended_ = false; @@ -87,11 +96,15 @@ void FlingStopFilterInterpreter::ConsumeGesture(const Gesture& gesture) { if (FlingStopNeeded(gesture)) { // sub in a fling before a new gesture - ProduceGesture(Gesture(kGestureFling, gesture.start_time, - gesture.start_time, 0.0, 0.0, - GESTURES_FLING_TAP_DOWN)); + auto fling_tap_down = Gesture(kGestureFling, gesture.start_time, + gesture.start_time, 0.0, 0.0, + GESTURES_FLING_TAP_DOWN); + LogGestureProduce(name, fling_tap_down); + ProduceGesture(fling_tap_down); } + LogGestureProduce(name, gesture); ProduceGesture(gesture); + fling_stop_deadline_ = NO_DEADLINE; prev_gesture_type_ = gesture.type; fling_stop_already_sent_ = false; @@ -117,6 +130,9 @@ void FlingStopFilterInterpreter::UpdateFlingStopDeadline( void FlingStopFilterInterpreter::HandleTimerImpl(stime_t now, stime_t* timeout) { + const char name[] = "FlingStopFilterInterpreter::HandleTimerImpl"; + LogHandleTimerPre(name, now, timeout); + stime_t next_timeout; if (ShouldCallNextTimer(fling_stop_deadline_)) { if (next_timer_deadline_ > now) { @@ -133,9 +149,12 @@ void FlingStopFilterInterpreter::HandleTimerImpl(stime_t now, return; } fling_stop_deadline_ = NO_DEADLINE; - ProduceGesture(Gesture(kGestureFling, prev_timestamp_, - now, 0.0, 0.0, - GESTURES_FLING_TAP_DOWN)); + auto fling_tap_down = Gesture(kGestureFling, prev_timestamp_, + now, 0.0, 0.0, + GESTURES_FLING_TAP_DOWN); + LogGestureProduce(name, fling_tap_down); + ProduceGesture(fling_tap_down); + fling_stop_already_sent_ = true; next_timeout = next_timer_deadline_ == NO_DEADLINE || next_timer_deadline_ <= now @@ -144,6 +163,7 @@ void FlingStopFilterInterpreter::HandleTimerImpl(stime_t now, } *timeout = SetNextDeadlineAndReturnTimeoutVal(now, fling_stop_deadline_, next_timeout); + LogHandleTimerPost(name, now, timeout); } } // namespace gestures diff --git a/src/fling_stop_filter_interpreter_unittest.cc b/src/fling_stop_filter_interpreter_unittest.cc index 6410d2f..8637cf9 100644 --- a/src/fling_stop_filter_interpreter_unittest.cc +++ b/src/fling_stop_filter_interpreter_unittest.cc @@ -142,4 +142,48 @@ TEST(FlingStopFilterInterpreterTest, SimpleTest) { } } +TEST(FlingStopFilterInterpreterTest, FlingGestureTest) { + FlingStopFilterInterpreterTestInterpreter* base_interpreter = + new FlingStopFilterInterpreterTestInterpreter; + FlingStopFilterInterpreter interpreter(nullptr, base_interpreter, nullptr, + GESTURES_DEVCLASS_TOUCHPAD); + + Gesture fling(kGestureFling, 0.0, 1.0, 0.0, 0.0, GESTURES_FLING_TAP_DOWN); + Gesture swipelift(kGestureSwipeLift, 1.0, 2.0); + Gesture swipe4flift(kGestureFourFingerSwipeLift, 1.0, 2.0); + Gesture move(kGestureMove, 1.0, 2.0, 3.0, 4.0); + + interpreter.fling_stop_already_sent_ = true; + interpreter.ConsumeGesture(fling); + interpreter.ConsumeGesture(fling); + EXPECT_EQ(interpreter.prev_gesture_type_, kGestureTypeFling); + interpreter.ConsumeGesture(swipelift); + EXPECT_EQ(interpreter.prev_gesture_type_, kGestureTypeSwipeLift); + interpreter.ConsumeGesture(swipe4flift); + EXPECT_EQ(interpreter.prev_gesture_type_, kGestureTypeFourFingerSwipeLift); + + interpreter.fling_stop_already_sent_ = false; + interpreter.ConsumeGesture(fling); + interpreter.ConsumeGesture(fling); + EXPECT_EQ(interpreter.prev_gesture_type_, kGestureTypeFling); + interpreter.ConsumeGesture(swipelift); + EXPECT_EQ(interpreter.prev_gesture_type_, kGestureTypeSwipeLift); + interpreter.ConsumeGesture(swipe4flift); + EXPECT_EQ(interpreter.prev_gesture_type_, kGestureTypeFourFingerSwipeLift); + + interpreter.ConsumeGesture(move); + EXPECT_EQ(interpreter.prev_gesture_type_, kGestureTypeMove); +} + +TEST(FlingStopFilterInterpreterTest, FlingStopMultimouseMoveTest) { + FlingStopFilterInterpreterTestInterpreter* base_interpreter = + new FlingStopFilterInterpreterTestInterpreter; + FlingStopFilterInterpreter interpreter(nullptr, base_interpreter, nullptr, + GESTURES_DEVCLASS_MULTITOUCH_MOUSE); + + Gesture move(kGestureMove, 1.0, 2.0, 3.0, 4.0); + interpreter.ConsumeGesture(move); + EXPECT_EQ(interpreter.prev_gesture_type_, kGestureTypeMove); +} + } // namespace gestures |