1. Revert "Sets the tap gesture timer to 330ms."
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-recognizer.h
1 #ifndef DALI_INTERNAL_EVENT_EVENTS_TAP_GESTURE_RECOGNIZER_H
2 #define DALI_INTERNAL_EVENT_EVENTS_TAP_GESTURE_RECOGNIZER_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <dali/integration-api/events/point.h>
23 #include <dali/public-api/common/vector-wrapper.h>
24 #include <cstdint>
25
26 // INTERNAL INCLUDES
27 #include <dali/internal/event/events/gesture-recognizer.h>
28 #include <dali/internal/event/events/tap-gesture/tap-gesture-event.h>
29
30 namespace Dali
31 {
32 namespace Integration
33 {
34 struct TouchEvent;
35 }
36
37 namespace Internal
38 {
39 struct TapGestureRequest;
40
41 /**
42  * When given a set of touch events, this detector attempts to determine if a tap gesture has taken place.
43  */
44 class TapGestureRecognizer : public GestureRecognizer
45 {
46 public:
47   using Observer = RecognizerObserver<TapGestureEvent>;
48
49   /**
50    * Constructor
51    * @param[in] coreEventInterface Used to send events to Core.
52    * @param[in]  screenSize  The size of the screen.
53    * @param[in]  request     The tap gesture request.
54    */
55   TapGestureRecognizer(Observer& observer, Vector2 screenSize, const TapGestureRequest& request);
56
57   /**
58    * Virtual destructor.
59    */
60   ~TapGestureRecognizer() override;
61
62 public:
63   /**
64    * @copydoc Dali::Internal::GestureDetector::SendEvent(const Integration::TouchEvent&)
65    */
66   void SendEvent(const Integration::TouchEvent& event) override;
67
68   /**
69    * @copydoc Dali::Internal::GestureDetector::Update(const Integration::GestureRequest&)
70    */
71   void Update(const GestureRequest& request) override;
72
73 private:
74   /**
75    * Checks if registered taps are within required bounds and emits tap gesture if they are.
76    *
77    * @param[in] state current state of incomplete gesture
78    * @param[in] time time of this latest touch event
79    */
80   void EmitGesture(GestureState state, uint32_t time);
81
82   /**
83    * Initialises tap gesture detector for next tap sequence
84    *
85    * @param[in] event registered touch event
86    * @param[in] point position touch event occurred
87    */
88   void SetupForTouchDown(const Integration::TouchEvent& event, const Integration::Point& point);
89
90   /**
91    * Emit a touch down event for hit testing
92    *
93    * @param[in] event registered touch event
94    */
95   void EmitPossibleState(const Integration::TouchEvent& event);
96
97   /**
98    * Force a touch event sequence to be treated as a single tap
99    *
100    * @param[in] time time of this latest touch event
101    * @param[in] point position touch event occurred
102     */
103   void EmitSingleTap(uint32_t time, const Integration::Point& point);
104
105   /**
106    * Emit a tap event
107    *
108    * @param[in] time time of this latest touch event
109    * @param[in] event registered touch event
110    */
111   void EmitTap(uint32_t time, TapGestureEvent& event);
112
113   /**
114    * Send the event for processing
115    *
116    * @param[in] tap event for processing
117    */
118   void ProcessEvent(TapGestureEvent& event);
119
120 private:
121   // Reference to the gesture processor for this recognizer
122   Observer& mObserver;
123
124   /**
125    * Internal state machine.
126    */
127   enum State
128   {
129     CLEAR,      ///< No gesture detected.
130     TOUCHED,    ///< User is touching the screen.
131     REGISTERED, ///< At least one tap has been registered.
132     FAILED,     ///< Gesture has failed.
133   };
134
135   State mState; ///< Current state of the detector.
136
137   int mMinimumTapsRequired; ///< Minimum number of taps required.
138   int mMaximumTapsRequired; ///< Maximum number of taps required.
139   int mTapsRegistered;      ///< In current detection, the number of taps registered.
140
141   Vector2  mTouchPosition; ///< The initial touch down position.
142   uint32_t mTouchTime;     ///< The initial touch down time.
143   uint32_t mLastTapTime;   ///< Time last tap gesture was registered
144
145   GestureSourceType mGestureSourceType; /// < Gesture input source type value.
146 };
147
148 } // namespace Internal
149
150 } // namespace Dali
151
152 #endif // DALI_INTERNAL_EVENT_EVENTS_TAP_GESTURE_RECOGNIZER_H