Add ReceiveAllTapEvents(bool)
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-detector-impl.h
1 #ifndef DALI_INTERNAL_TAP_GESTURE_DETECTOR_H
2 #define DALI_INTERNAL_TAP_GESTURE_DETECTOR_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 // INTERNAL INCLUDES
22 #include <dali/internal/event/events/gesture-detector-impl.h>
23 #include <dali/public-api/events/tap-gesture-detector.h>
24 #include <dali/public-api/events/tap-gesture.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class TapGestureDetector;
31
32 using TapGestureDetectorPtr       = IntrusivePtr<TapGestureDetector>;
33 using TapGestureDetectorContainer = DerivedGestureDetectorContainer<TapGestureDetector>::type;
34
35 /**
36  * @copydoc Dali::TapGestureDetector
37  */
38 class TapGestureDetector : public GestureDetector
39 {
40 public: // Creation
41   /**
42    * Create a new gesture detector.
43    * @return A smart-pointer to the newly allocated detector.
44    */
45   static TapGestureDetectorPtr New();
46
47   /**
48    * Create a new gesture detector with the specified parameters.
49    * @param[in]  tapsRequired     The number of taps required.
50    * @return A smart-pointer to the newly allocated detector.
51    */
52   static TapGestureDetectorPtr New(unsigned int tapsRequired);
53
54   /**
55    * Construct a new GestureDetector.
56    */
57   TapGestureDetector();
58
59   /**
60    * Construct a new GestureDetector with the specified parameters.
61    * @param[in]  tapsRequired     The number of taps required.
62    */
63   TapGestureDetector(unsigned int tapsRequired);
64
65 public:
66   /**
67    * @copydoc Dali::TapGestureDetector::SetTouchesRequired(unsigned int)
68    */
69   void SetTouchesRequired(unsigned int touches);
70
71   /**
72    * @copydoc Dali::TapGestureDetector::SetMinimumTapsRequired()
73    */
74   void SetMinimumTapsRequired(unsigned int minTaps);
75
76   /**
77    * @copydoc Dali::TapGestureDetector::SetMaximumTapsRequired()
78    */
79   void SetMaximumTapsRequired(unsigned int maxTaps);
80
81   /**
82    * @copydoc Dali::TapGestureDetector::GetMinimumTapsRequired()
83    */
84   unsigned int GetMinimumTapsRequired() const;
85
86   /**
87    * @copydoc Dali::TapGestureDetector::SetMaximumTapsRequired()
88    */
89   unsigned int GetMaximumTapsRequired() const;
90
91   /**
92    * @copydoc Dali::TapGestureDetector::GetTouchesRequired()
93    */
94   unsigned int GetTouchesRequired() const;
95
96   /**
97    * @copydoc Dali::TapGestureDetector::ReceiveAllTapEvents()
98    */
99   void ReceiveAllTapEvents(bool receive);
100
101 public:
102   /**
103    * Called by the TapGestureProcessor when a tap gesture event occurs within the bounds of our
104    * attached actor.
105    * @param[in]  tappedActor  The tapped actor.
106    * @param[in]  tap          The tap gesture.
107    */
108   void EmitTapGestureSignal(Dali::Actor tappedActor, const Dali::TapGesture& tap);
109
110 public: // Signals
111   /**
112    * @copydoc Dali::TapGestureDetector::DetectedSignal()
113    */
114   Dali::TapGestureDetector::DetectedSignalType& DetectedSignal()
115   {
116     return mDetectedSignal;
117   }
118
119   /**
120    * Connects a callback function with the object's signals.
121    * @param[in] object The object providing the signal.
122    * @param[in] tracker Used to disconnect the signal.
123    * @param[in] signalName The signal to connect to.
124    * @param[in] functor A newly allocated FunctorDelegate.
125    * @return True if the signal was connected.
126    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
127    */
128   static bool DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor);
129
130 protected:
131   /**
132    * A reference counted object may only be deleted by calling Unreference()
133    */
134   ~TapGestureDetector() override;
135
136 private:
137   // Undefined
138   TapGestureDetector(const TapGestureDetector&);
139   TapGestureDetector& operator=(const TapGestureDetector& rhs);
140
141   /**
142    * Timer Callback
143    * @return will return false; one-shot timer.
144    */
145   bool TimerCallback();
146
147 private: // GestureDetector overrides
148   /**
149    * @copydoc Dali::Internal::GestureDetector::OnActorAttach(Actor&)
150    */
151   void OnActorAttach(Actor& actor) override;
152
153   /**
154    * @copydoc Dali::Internal::GestureDetector::OnActorDetach(Actor&)
155    */
156   void OnActorDetach(Actor& actor) override;
157
158   /**
159    * @copydoc Dali::Internal::GestureDetector::OnActorDestroyed(Object&)
160    */
161   void OnActorDestroyed(Object& object) override;
162
163 private:
164   Dali::TapGestureDetector::DetectedSignalType mDetectedSignal;
165
166   unsigned int     mMinimumTapsRequired;
167   unsigned int     mMaximumTapsRequired;
168   unsigned int     mTouchesRequired;
169   uint32_t         mTimerId;
170   Dali::Actor      mTappedActor;
171   Dali::TapGesture mTap;
172   bool             mReceiveAllTapEvents;
173 };
174
175 } // namespace Internal
176
177 // Helpers for public-api forwarding methods
178
179 inline Internal::TapGestureDetector& GetImplementation(Dali::TapGestureDetector& detector)
180 {
181   DALI_ASSERT_ALWAYS(detector && "TapGestureDetector handle is empty");
182
183   BaseObject& handle = detector.GetBaseObject();
184
185   return static_cast<Internal::TapGestureDetector&>(handle);
186 }
187
188 inline const Internal::TapGestureDetector& GetImplementation(const Dali::TapGestureDetector& detector)
189 {
190   DALI_ASSERT_ALWAYS(detector && "TapGestureDetector handle is empty");
191
192   const BaseObject& handle = detector.GetBaseObject();
193
194   return static_cast<const Internal::TapGestureDetector&>(handle);
195 }
196
197 } // namespace Dali
198
199 #endif // DALI_INTERNAL_TAP_GESTURE_DETECTOR_H