[Tizen] Not execute the remove callback
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-processor.h
1 #ifndef DALI_INTERNAL_GESTURE_PROCESSOR_H
2 #define DALI_INTERNAL_GESTURE_PROCESSOR_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/common/object-impl.h>
23 #include <dali/internal/event/events/gesture-detector-impl.h>
24 #include <dali/internal/event/events/gesture-recognizer.h>
25 #include <dali/internal/event/events/hit-test-algorithm-impl.h>
26
27 namespace Dali
28 {
29 class Actor;
30
31 namespace Internal
32 {
33 /**
34  * Base class for the different Gesture Processors.
35  */
36 class GestureProcessor : public Object::Observer
37 {
38 public:
39   /**
40    * Process the touch event in the attached recognizer
41    * @param[in] scene Scene.
42    * @param[in] event Touch event to process
43    */
44   void ProcessTouch(Scene& scene, const Integration::TouchEvent& event);
45
46   /**
47    * Returns whether any GestureDetector requires a Core::Update
48    * @return true if update required
49    */
50   inline bool NeedsUpdate()
51   {
52     bool updateRequired = mNeedsUpdate;
53     mNeedsUpdate        = false;
54     return updateRequired;
55   }
56
57 protected:
58   // Construction & Destruction
59
60   /**
61    * Protected constructor.  Cannot create an instance of GestureProcessor
62    */
63   GestureProcessor(GestureType::Value type);
64
65   /**
66    * Virtual protected destructor.
67    */
68   ~GestureProcessor() override;
69
70   // Methods to be used by deriving classes
71
72   /**
73    * Given the hit actor, this walks up the actor tree to determine the actor that is connected to one (or several) gesture detectors.
74    *
75    * @param[in,out]  actor               The gestured actor. When this function returns, this is the actor that has been hit by the gesture.
76    * @param[out]     gestureDetectors    A container containing all the gesture detectors that have the hit actor attached and satisfy the functor parameters.
77    *
78    * @note Uses CheckGestureDetector() to check if a the current gesture matches the criteria the gesture detector requires.
79    * @pre gestureDetectors should be empty.
80    */
81   void GetGesturedActor(Actor*& actor, GestureDetectorContainer& gestureDetectors);
82
83   /**
84    * Calls the emission method in the deriving class for matching gesture-detectors with the hit-actor (or one of its parents).
85    *
86    * @param[in]  hitTestResults      The Hit Test Results.
87    *
88    * @note Uses the CheckGestureDetector() to check if the gesture matches the criteria of the given gesture detector
89    *       and EmitGestureSignal() to emit the signal.
90    * @pre Hit Testing should already be done.
91    */
92   void ProcessAndEmit(HitTestAlgorithm::Results& hitTestResults);
93
94   /**
95    * Hit test the screen coordinates, and place the results in hitTestResults.
96    * @param[in] scene Scene.
97    * @param[in] screenCoordinates The screen coordinates to test.
98    * @param[out] hitTestResults Structure to write results into.
99    * @return false if the system overlay was hit or no actor was hit.
100    */
101   virtual bool HitTest(Scene& scene, Vector2 screenCoordinates, HitTestAlgorithm::Results& hitTestResults);
102
103   /**
104    * Sets the mCurrentGesturedActor and connects to the required signals.
105    * @actor  actor  The actor so set.
106    */
107   void SetActor(Actor* actor);
108
109   /**
110    * Resets the set actor and disconnects any connected signals.
111    */
112   void ResetActor();
113
114   /**
115    * Returns the current gestured actor if it is on stage
116    *
117    * @return The current gestured actor
118    */
119   Actor* GetCurrentGesturedActor();
120
121 private:
122   // For derived classes to override
123
124   /**
125    * Called when the gestured actor is removed from the stage.
126    */
127   virtual void OnGesturedActorStageDisconnection() = 0;
128
129   /**
130    * Called by the ProcessAndEmit() & GetGesturedActor() methods to check if the provided
131    * gesture-detector meets the parameters of the current gesture.
132    *
133    * @param[in]  detector  The gesture detector to check.
134    * @param[in]  actor     The actor that has been gestured.
135    *
136    * @return true, if the detector meets the parameters, false otherwise.
137    */
138   virtual bool CheckGestureDetector(GestureDetector* detector, Actor* actor) = 0;
139
140   /**
141    * Called by the ProcessAndEmit() method when the gesture meets all applicable criteria and
142    * should be overridden by deriving classes to emit the gesture signal on gesture-detectors
143    * provided for the actor the gesture has occurred on.
144    *
145    * @param[in]  actor             The actor which has been gestured.
146    * @param[in]  gestureDetectors  The detectors that should emit the signal.
147    * @param[in]  actorCoordinates  The local actor coordinates where the gesture took place.
148    */
149   virtual void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) = 0;
150
151   // Undefined
152
153   GestureProcessor(const GestureProcessor&);
154   GestureProcessor& operator=(const GestureProcessor&);
155
156   // SceneObject overrides
157
158   /**
159    * This will never get called as we do not observe objects that have not been added to the scene.
160    * @param[in] object The object object.
161    * @see Object::Observer::SceneObjectAdded()
162    */
163   void SceneObjectAdded(Object& object) override
164   {
165   }
166
167   /**
168    * This will be called when the actor is removed from the stage, we should clear and stop
169    * observing it.
170    * @param[in] object The object object.
171    * @see Object::Observer::SceneObjectRemoved()
172    */
173   void SceneObjectRemoved(Object& object) override;
174
175   /**
176    * This will be called when the actor is destroyed. We should clear the actor.
177    * No need to stop observing as the object is being destroyed anyway.
178    * @see Object::Observer::ObjectDestroyed()
179    */
180   void ObjectDestroyed(Object& object) override;
181
182 protected:                                 //Data
183   GestureRecognizerPtr mGestureRecognizer; ///< The gesture recognizer
184   bool                 mNeedsUpdate;       ///< Indicates if any GestureDetector requires a Core::Update
185
186 private:                                             // Data
187   GestureType::Value mType;                          ///< Type of GestureProcessor
188   Actor*             mCurrentGesturedActor;          ///< The current actor that has been gestured.
189   Integration::Point mPoint;                         ///< The point of event touched.
190   uint32_t           mEventTime;                     ///< The time the event occurred.
191   bool               mGesturedActorDisconnected : 1; ///< Indicates whether the gestured actor has been disconnected from the scene
192 };
193
194 } // namespace Internal
195
196 } // namespace Dali
197
198 #endif // DALI_INTERNAL_GESTURE_PROCESSOR_H