726d77ee0060084a0b7aa895845ac70371a3762a
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-processor.h
1 #ifndef DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H
3
4 /*
5  * Copyright (c) 2023 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 // INTERNAL INCLUDES
22 #include <dali/internal/event/events/actor-observer.h>
23 #include <dali/internal/event/events/gesture-processor.h>
24 #include <dali/internal/event/events/tap-gesture/tap-gesture-detector-impl.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class Scene;
31 class Stage;
32 class Actor;
33
34 struct GestureEvent;
35 struct TapGestureEvent;
36
37 /**
38  * Tap Gesture Event Processing:
39  *
40  * When we receive a tap gesture event, we do the following:
41  * - Find the actor that requires a tap where the tap occurred.
42  * - Emit the gesture if the tap gesture event satisfies the detector conditions.
43  */
44 class TapGestureProcessor : public GestureProcessor, public RecognizerObserver<TapGestureEvent>
45 {
46 public:
47   /**
48    * Create a tap gesture processor.
49    */
50   TapGestureProcessor();
51
52   /**
53    * Non-virtual destructor; TapGestureProcessor is not a base class
54    */
55   ~TapGestureProcessor() override;
56
57 public: // To be called by GestureEventProcessor
58   /**
59    * This method is called whenever a tap gesture event occurs.
60    * @param[in] scene The scene the tap gesture event occurs in.
61    * @param[in] tapEvent The event that has occurred.
62    */
63   void Process(Scene& scene, const TapGestureEvent& event) override;
64
65   /**
66    * Adds a gesture detector to this gesture processor.
67    * If this is the first gesture detector being added, then this method registers the required
68    * gesture with the adaptor.
69    * @param[in]  gestureDetector  The gesture detector being added.
70    */
71   void AddGestureDetector(TapGestureDetector* gestureDetector, Scene& scene);
72
73   /**
74    * Removes the specified gesture detector from this gesture processor.  If, after removing this
75    * gesture detector, there are no more gesture detectors registered, then this method unregisters
76    * the gesture from the adaptor.
77    * @param[in]  gestureDetector  The gesture detector being removed.
78    */
79   void RemoveGestureDetector(TapGestureDetector* gestureDetector);
80
81   /**
82    * This method updates the gesture detection parameters.
83    * @param[in]  gestureDetector  The gesture detector that has been updated.
84    */
85   void GestureDetectorUpdated(TapGestureDetector* gestureDetector);
86
87   /**
88    * @brief This method sets the maximum allowed time required to be recognized as a multi tap gesture (millisecond)
89    *
90    * @param[in] time The time value in milliseconds
91    */
92   void SetMaximumAllowedTime(uint32_t time);
93
94   /**
95    * @brief This method sets the recognizer time required to be recognized as a tap gesture (millisecond)
96    *
97    * This time is from touch down to touch up to recognize the tap gesture.
98    *
99    * @param[in] time The time value in milliseconds
100    */
101   void SetRecognizerTime(uint32_t time);
102
103 private:
104   // Undefined
105   TapGestureProcessor(const TapGestureProcessor&);
106   TapGestureProcessor& operator=(const TapGestureProcessor& rhs);
107
108 private:
109   /**
110    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
111    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
112    */
113   void UpdateDetection();
114
115   // GestureProcessor overrides
116
117   /**
118    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
119    */
120   void OnGesturedActorStageDisconnection() override
121   { /* Nothing to do */
122   }
123
124   /**
125    * @copydoc GestureProcessor::CheckGestureDetector()
126    */
127   bool CheckGestureDetector(GestureDetector* detector, Actor* actor) override;
128
129   /**
130    * @copydoc GestureProcessor::EmitGestureSignal()
131    */
132   void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) override;
133
134 private:
135   TapGestureDetectorContainer mTapGestureDetectors;
136
137   unsigned int mMinTapsRequired;
138   unsigned int mMaxTapsRequired;
139   unsigned int mMinTouchesRequired;
140   unsigned int mMaxTouchesRequired;
141
142   ActorObserver          mCurrentTapActor;   ///< Observer for the current gesture actor
143   const TapGestureEvent* mCurrentTapEvent;   ///< Pointer to current TapEvent, used when calling ProcessAndEmit()
144   bool                   mPossibleProcessed; ///< Indication of whether we've processed a touch down for this gestuee
145
146   uint32_t mMaximumAllowedTime; ///< The maximum allowed time required to be recognized as a multi tap gesture (millisecond)
147   uint32_t mRecognizerTime;     ///< The recognizer time required to be recognized as a tap gesture (millisecond)
148 };
149
150 } // namespace Internal
151
152 } // namespace Dali
153
154 #endif // DALI_INTERNAL_TAP_GESTURE_EVENT_PROCESSOR_H