[dali_2.3.25] Merge branch 'devel/master'
[platform/core/uifw/dali-core.git] / dali / internal / event / events / long-press-gesture / long-press-gesture-processor.h
1 #ifndef DALI_INTERNAL_LONG_PRESS_GESTURE_EVENT_PROCESSOR_H
2 #define DALI_INTERNAL_LONG_PRESS_GESTURE_EVENT_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/events/gesture-processor.h>
23 #include <dali/internal/event/events/long-press-gesture/long-press-gesture-detector-impl.h>
24 #include <dali/internal/event/render-tasks/render-task-impl.h>
25
26 namespace Dali
27 {
28 namespace Internal
29 {
30 class Stage;
31 class Scene;
32
33 struct GestureEvent;
34 struct LongPressGestureEvent;
35
36 /**
37  * Long Press Gesture Event Processing:
38  *
39  * When we receive a long press gesture event, we do the following:
40  * - Find the actor that requires a long-press at the long press position.
41  * - Emit the gesture if the event satisfies the detector conditions.
42  */
43 class LongPressGestureProcessor : public GestureProcessor, public RecognizerObserver<LongPressGestureEvent>
44 {
45 public:
46   /**
47    * Create a long press gesture processor.
48    */
49   LongPressGestureProcessor();
50
51   /**
52    * Non-virtual destructor; LongPressGestureProcessor is not a base class
53    */
54   ~LongPressGestureProcessor() override;
55
56 public: // To be called by GestureEventProcessor
57   /**
58    * This method is called whenever a long press gesture event occurs.
59    * @param[in] scene The scene the long press gesture event occurs in.
60    * @param[in] longPressEvent The event that has occurred.
61    */
62   void Process(Scene& scene, const LongPressGestureEvent& longPressEvent) override;
63
64   /**
65    * Adds a gesture detector to this gesture processor.
66    * If this is the first gesture detector being added, then this method registers the required
67    * gesture with the adaptor.
68    * @param[in]  gestureDetector  The gesture detector being added.
69    * @param[in] scene The scene the long press gesture event occurs in.
70    */
71   void AddGestureDetector(LongPressGestureDetector* 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(LongPressGestureDetector* 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(LongPressGestureDetector* gestureDetector);
86
87   /**
88    * @brief This method sets the minimum holding time required to be recognized as a long press gesture
89    *
90    * @param[in] value The time value in milliseconds
91    */
92   void SetMinimumHoldingTime(uint32_t time);
93
94   /**
95    * @return The minimum holding time required to be recognized as a long press gesture in milliseconds
96    */
97   uint32_t GetMinimumHoldingTime() const;
98
99 private:
100   // Undefined
101   LongPressGestureProcessor(const LongPressGestureProcessor&);
102   LongPressGestureProcessor& operator=(const LongPressGestureProcessor& rhs);
103
104 private:
105   /**
106    * Iterates through our GestureDetectors and determines if we need to ask the adaptor to update
107    * its detection policy.  If it does, it sends the appropriate gesture update request to adaptor.
108    */
109   void UpdateDetection();
110
111   // GestureProcessor overrides
112
113   /**
114    * @copydoc GestureProcessor::OnGesturedActorStageDisconnection()
115    */
116   void OnGesturedActorStageDisconnection() override;
117
118   /**
119    * @copydoc GestureProcessor::CheckGestureDetector()
120    */
121   bool CheckGestureDetector(GestureDetector* detector, Actor* actor) override;
122
123   /**
124    * @copydoc GestureProcessor::EmitGestureSignal()
125    */
126   void EmitGestureSignal(Actor* actor, const GestureDetectorContainer& gestureDetectors, Vector2 actorCoordinates) override;
127
128 private:
129   LongPressGestureDetectorContainer mLongPressGestureDetectors;
130
131   GestureDetectorContainer mCurrentEmitters;
132   RenderTaskPtr            mCurrentRenderTask;
133
134   uint32_t mMinTouchesRequired;
135   uint32_t mMaxTouchesRequired;
136
137   const LongPressGestureEvent* mCurrentLongPressEvent; ///< Pointer to current longPressEvent, used when calling ProcessAndEmit()
138
139   uint32_t mMinimumHoldingTime;
140 };
141
142 } // namespace Internal
143
144 } // namespace Dali
145
146 #endif // DALI_INTERNAL_LONG_PRESS_GESTURE_EVENT_PROCESSOR_H