• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  public:
26   // Takes ownership of |next|:
27   FlingStopFilterInterpreter(PropRegistry* prop_reg,
28                              Interpreter* next,
29                              Tracer* tracer,
30                              GestureInterpreterDeviceClass devclass);
~FlingStopFilterInterpreter()31   virtual ~FlingStopFilterInterpreter() {}
32 
33  protected:
34   virtual void SyncInterpretImpl(HardwareState* hwstate, stime_t* timeout);
35 
36   virtual void HandleTimerImpl(stime_t now, stime_t* timeout);
37 
38   virtual void ConsumeGesture(const Gesture& gesture);
39 
40  private:
41   // May override an outgoing gesture with a fling stop gesture.
42   bool NeedsExtraTime(const HardwareState& hwstate) const;
43   bool FlingStopNeeded(const Gesture& gesture) const;
44   void UpdateFlingStopDeadline(const HardwareState& hwstate);
45 
46   // Has the deadline has already been extended once
47   bool already_extended_;
48 
49   // Which tracking id's were on the pad at the last fling
50   std::set<short> fingers_present_for_last_fling_;
51 
52   // tracking id's of the last hardware state
53   std::set<short> fingers_of_last_hwstate_;
54 
55   // touch_cnt from previously input HardwareState.
56   short prev_touch_cnt_;
57   // timestamp from previous input HardwareState.
58   stime_t prev_timestamp_;
59 
60   // Most recent gesture type consumed and produced.
61   GestureType prev_gesture_type_;
62   // Whether a fling stop has been sent since the last gesture.
63   bool fling_stop_already_sent_;
64 
65   // When we should send fling-stop, or NO_DEADLINE if not set.
66   stime_t fling_stop_deadline_;
67 
68   // Device class (e.g. touchpad, mouse).
69   GestureInterpreterDeviceClass devclass_;
70 
71   // How long to wait when new fingers arrive (and possibly scroll), before
72   // halting fling
73   DoubleProperty fling_stop_timeout_;
74   // How much extra time to add if it looks likely to be the start of a scroll
75   DoubleProperty fling_stop_extra_delay_;
76 };
77 
78 }  // namespace gestures
79 
80 #endif  // GESTURES_FLING_STOP_FILTER_INTERPRETER_H_
81