xref: /aosp_15_r20/external/libchrome-gestures/include/multitouch_mouse_interpreter.h (revision aed3e5085e770be5b69ce25295ecf6ddf906af95)
1*aed3e508SAndroid Build Coastguard Worker // Copyright 2013 The ChromiumOS Authors
2*aed3e508SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*aed3e508SAndroid Build Coastguard Worker // found in the LICENSE file.
4*aed3e508SAndroid Build Coastguard Worker 
5*aed3e508SAndroid Build Coastguard Worker #include <gtest/gtest.h>  // For FRIEND_TEST
6*aed3e508SAndroid Build Coastguard Worker 
7*aed3e508SAndroid Build Coastguard Worker #include "include/gestures.h"
8*aed3e508SAndroid Build Coastguard Worker #include "include/immediate_interpreter.h"
9*aed3e508SAndroid Build Coastguard Worker #include "include/interpreter.h"
10*aed3e508SAndroid Build Coastguard Worker #include "include/mouse_interpreter.h"
11*aed3e508SAndroid Build Coastguard Worker #include "include/prop_registry.h"
12*aed3e508SAndroid Build Coastguard Worker #include "include/tracer.h"
13*aed3e508SAndroid Build Coastguard Worker 
14*aed3e508SAndroid Build Coastguard Worker #ifndef GESTURES_MULTITOUCH_MOUSE_INTERPRETER_H_
15*aed3e508SAndroid Build Coastguard Worker #define GESTURES_MULTITOUCH_MOUSE_INTERPRETER_H_
16*aed3e508SAndroid Build Coastguard Worker 
17*aed3e508SAndroid Build Coastguard Worker namespace gestures {
18*aed3e508SAndroid Build Coastguard Worker 
19*aed3e508SAndroid Build Coastguard Worker class Origin {
20*aed3e508SAndroid Build Coastguard Worker   // Origin keeps track of the origins of certin events.
21*aed3e508SAndroid Build Coastguard Worker  public:
22*aed3e508SAndroid Build Coastguard Worker   void PushGesture(const Gesture& result);
23*aed3e508SAndroid Build Coastguard Worker 
24*aed3e508SAndroid Build Coastguard Worker   // Return the last time when the buttons go up
25*aed3e508SAndroid Build Coastguard Worker   stime_t ButtonGoingUp(int button) const;
26*aed3e508SAndroid Build Coastguard Worker 
27*aed3e508SAndroid Build Coastguard Worker  private:
28*aed3e508SAndroid Build Coastguard Worker   stime_t button_going_up_left_{0.0};
29*aed3e508SAndroid Build Coastguard Worker   stime_t button_going_up_middle_{0.0};
30*aed3e508SAndroid Build Coastguard Worker   stime_t button_going_up_right_{0.0};
31*aed3e508SAndroid Build Coastguard Worker };
32*aed3e508SAndroid Build Coastguard Worker 
33*aed3e508SAndroid Build Coastguard Worker class MultitouchMouseInterpreter : public MouseInterpreter {
34*aed3e508SAndroid Build Coastguard Worker   FRIEND_TEST(MultitouchMouseInterpreterTest, SimpleTest);
35*aed3e508SAndroid Build Coastguard Worker  public:
36*aed3e508SAndroid Build Coastguard Worker   MultitouchMouseInterpreter(PropRegistry* prop_reg, Tracer* tracer);
~MultitouchMouseInterpreter()37*aed3e508SAndroid Build Coastguard Worker   virtual ~MultitouchMouseInterpreter() {}
38*aed3e508SAndroid Build Coastguard Worker 
39*aed3e508SAndroid Build Coastguard Worker  protected:
40*aed3e508SAndroid Build Coastguard Worker   virtual void SyncInterpretImpl(HardwareState& hwstate, stime_t* timeout);
41*aed3e508SAndroid Build Coastguard Worker   virtual void Initialize(const HardwareProperties* hw_props,
42*aed3e508SAndroid Build Coastguard Worker                           Metrics* metrics, MetricsProperties* mprops,
43*aed3e508SAndroid Build Coastguard Worker                           GestureConsumer* consumer);
44*aed3e508SAndroid Build Coastguard Worker   virtual void ProduceGesture(const Gesture& gesture);
45*aed3e508SAndroid Build Coastguard Worker 
46*aed3e508SAndroid Build Coastguard Worker  private:
47*aed3e508SAndroid Build Coastguard Worker   void InterpretMultitouchEvent();
48*aed3e508SAndroid Build Coastguard Worker 
49*aed3e508SAndroid Build Coastguard Worker   // We keep this for finger tracking:
50*aed3e508SAndroid Build Coastguard Worker   HardwareStateBuffer state_buffer_;
51*aed3e508SAndroid Build Coastguard Worker   // We keep this for standard mouse tracking:
52*aed3e508SAndroid Build Coastguard Worker   HardwareState prev_state_;
53*aed3e508SAndroid Build Coastguard Worker   ScrollEventBuffer scroll_buffer_;
54*aed3e508SAndroid Build Coastguard Worker 
55*aed3e508SAndroid Build Coastguard Worker   FingerMap prev_gs_fingers_;
56*aed3e508SAndroid Build Coastguard Worker   FingerMap gs_fingers_;
57*aed3e508SAndroid Build Coastguard Worker 
58*aed3e508SAndroid Build Coastguard Worker   GestureType prev_gesture_type_;
59*aed3e508SAndroid Build Coastguard Worker   GestureType current_gesture_type_;
60*aed3e508SAndroid Build Coastguard Worker 
61*aed3e508SAndroid Build Coastguard Worker   // Set to true when scrolls happen. Set to false when a fling happens,
62*aed3e508SAndroid Build Coastguard Worker   // or when mouse starts moving.
63*aed3e508SAndroid Build Coastguard Worker   bool should_fling_;
64*aed3e508SAndroid Build Coastguard Worker 
65*aed3e508SAndroid Build Coastguard Worker   ScrollManager scroll_manager_;
66*aed3e508SAndroid Build Coastguard Worker   Gesture prev_result_;
67*aed3e508SAndroid Build Coastguard Worker   Origin origin_;
68*aed3e508SAndroid Build Coastguard Worker 
69*aed3e508SAndroid Build Coastguard Worker   // This keeps track of where fingers started. Usually this is their original
70*aed3e508SAndroid Build Coastguard Worker   // position, but if the mouse is moved, we reset the positions at that time.
71*aed3e508SAndroid Build Coastguard Worker   std::map<short, Vector2> start_position_;
72*aed3e508SAndroid Build Coastguard Worker 
73*aed3e508SAndroid Build Coastguard Worker   // These fingers have started moving and should cause gestures.
74*aed3e508SAndroid Build Coastguard Worker   std::set<short> moving_;
75*aed3e508SAndroid Build Coastguard Worker 
76*aed3e508SAndroid Build Coastguard Worker   // Depth of recent scroll event buffer used to compute click.
77*aed3e508SAndroid Build Coastguard Worker   IntProperty click_buffer_depth_;
78*aed3e508SAndroid Build Coastguard Worker   // Maximum distance for a click
79*aed3e508SAndroid Build Coastguard Worker   DoubleProperty click_max_distance_;
80*aed3e508SAndroid Build Coastguard Worker 
81*aed3e508SAndroid Build Coastguard Worker   // Lead time of a button going up versus a finger lifting off
82*aed3e508SAndroid Build Coastguard Worker   DoubleProperty click_left_button_going_up_lead_time_;
83*aed3e508SAndroid Build Coastguard Worker   DoubleProperty click_right_button_going_up_lead_time_;
84*aed3e508SAndroid Build Coastguard Worker 
85*aed3e508SAndroid Build Coastguard Worker   // Distance [mm] a finger must deviate from the start position to be
86*aed3e508SAndroid Build Coastguard Worker   // considered moving.
87*aed3e508SAndroid Build Coastguard Worker   DoubleProperty min_finger_move_distance_;
88*aed3e508SAndroid Build Coastguard Worker   // If there is relative motion at or above this magnitude [mm], start
89*aed3e508SAndroid Build Coastguard Worker   // positions are reset.
90*aed3e508SAndroid Build Coastguard Worker   DoubleProperty moving_min_rel_amount_;
91*aed3e508SAndroid Build Coastguard Worker };
92*aed3e508SAndroid Build Coastguard Worker 
93*aed3e508SAndroid Build Coastguard Worker }  // namespace gestures
94*aed3e508SAndroid Build Coastguard Worker 
95*aed3e508SAndroid Build Coastguard Worker #endif  // GESTURES_MULTITOUCH_MOUSE_INTERPRETER_H_
96