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