1 // Copyright 2012 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <memory> 6 #include <set> 7 #include <gtest/gtest.h> // for FRIEND_TEST 8 9 #include "include/filter_interpreter.h" 10 #include "include/finger_metrics.h" 11 #include "include/gestures.h" 12 #include "include/prop_registry.h" 13 #include "include/tracer.h" 14 15 #ifndef GESTURES_FLING_STOP_FILTER_INTERPRETER_H_ 16 #define GESTURES_FLING_STOP_FILTER_INTERPRETER_H_ 17 18 namespace gestures { 19 20 // This interpreter generates the fling-stop messages when new fingers 21 // arrive on the pad. 22 23 class FlingStopFilterInterpreter : public FilterInterpreter { 24 FRIEND_TEST(FlingStopFilterInterpreterTest, SimpleTest); 25 FRIEND_TEST(FlingStopFilterInterpreterTest, FlingGestureTest); 26 FRIEND_TEST(FlingStopFilterInterpreterTest, FlingStopMultimouseMoveTest); 27 public: 28 // Takes ownership of |next|: 29 FlingStopFilterInterpreter(PropRegistry* prop_reg, 30 Interpreter* next, 31 Tracer* tracer, 32 GestureInterpreterDeviceClass devclass); ~FlingStopFilterInterpreter()33 virtual ~FlingStopFilterInterpreter() {} 34 35 protected: 36 virtual void SyncInterpretImpl(HardwareState& hwstate, stime_t* timeout); 37 38 virtual void HandleTimerImpl(stime_t now, stime_t* timeout); 39 40 virtual void ConsumeGesture(const Gesture& gesture); 41 42 private: 43 // May override an outgoing gesture with a fling stop gesture. 44 bool NeedsExtraTime(const HardwareState& hwstate) const; 45 bool FlingStopNeeded(const Gesture& gesture) const; 46 void UpdateFlingStopDeadline(const HardwareState& hwstate); 47 48 // Has the deadline has already been extended once 49 bool already_extended_; 50 51 // Which tracking id's were on the pad at the last fling 52 std::set<short> fingers_present_for_last_fling_; 53 54 // tracking id's of the last hardware state 55 std::set<short> fingers_of_last_hwstate_; 56 57 // touch_cnt from previously input HardwareState. 58 short prev_touch_cnt_; 59 // timestamp from previous input HardwareState. 60 stime_t prev_timestamp_; 61 62 // Most recent gesture type consumed and produced. 63 GestureType prev_gesture_type_; 64 // Whether a fling stop has been sent since the last gesture. 65 bool fling_stop_already_sent_; 66 67 // When we should send fling-stop, or NO_DEADLINE if not set. 68 stime_t fling_stop_deadline_; 69 70 // Device class (e.g. touchpad, mouse). 71 GestureInterpreterDeviceClass devclass_; 72 73 // How long to wait when new fingers arrive (and possibly scroll), before 74 // halting fling 75 DoubleProperty fling_stop_timeout_; 76 // How much extra time to add if it looks likely to be the start of a scroll 77 DoubleProperty fling_stop_extra_delay_; 78 }; 79 80 } // namespace gestures 81 82 #endif // GESTURES_FLING_STOP_FILTER_INTERPRETER_H_ 83