Revert "[Tizen] Not execute the remove callback"
[platform/core/uifw/dali-core.git] / dali / internal / event / events / gesture-event-processor.cpp
1 /*
2  * Copyright (c) 2023 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/internal/event/events/gesture-event-processor.h>
20
21 #if defined(DEBUG_ENABLED)
22 #include <sstream>
23 #endif
24
25 // INTERNAL INCLUDES
26 #include <dali/integration-api/debug.h>
27 #include <dali/integration-api/render-controller.h>
28 #include <dali/internal/event/common/stage-impl.h>
29 #include <dali/internal/event/events/pan-gesture/pan-gesture-impl.h>
30 #include <dali/internal/event/events/pinch-gesture/pinch-gesture-detector-impl.h>
31 #include <dali/internal/update/gestures/scene-graph-pan-gesture.h>
32
33 namespace Dali
34 {
35 namespace Internal
36 {
37 GestureEventProcessor::GestureEventProcessor(SceneGraph::UpdateManager& updateManager, Integration::RenderController& renderController)
38 : mLongPressGestureProcessor(),
39   mPanGestureProcessor(updateManager),
40   mPinchGestureProcessor(),
41   mTapGestureProcessor(),
42   mRotationGestureProcessor(),
43   mRenderController(renderController),
44   envOptionMinimumPanDistance(-1),
45   envOptionMinimumPanEvents(-1)
46 {
47 }
48
49 GestureEventProcessor::~GestureEventProcessor() = default;
50
51 void GestureEventProcessor::ProcessTouchEvent(Scene& scene, const Integration::TouchEvent& event)
52 {
53   mLongPressGestureProcessor.ProcessTouch(scene, event);
54   mPanGestureProcessor.ProcessTouch(scene, event);
55   mPinchGestureProcessor.ProcessTouch(scene, event);
56   mTapGestureProcessor.ProcessTouch(scene, event);
57   mRotationGestureProcessor.ProcessTouch(scene, event);
58 }
59
60 void GestureEventProcessor::AddGestureDetector(GestureDetector* gestureDetector, Scene& scene)
61 {
62   switch(gestureDetector->GetType())
63   {
64     case GestureType::LONG_PRESS:
65     {
66       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
67       mLongPressGestureProcessor.AddGestureDetector(longPress, scene);
68       break;
69     }
70
71     case GestureType::PAN:
72     {
73       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
74       mPanGestureProcessor.AddGestureDetector(pan, scene, envOptionMinimumPanDistance, envOptionMinimumPanEvents);
75       break;
76     }
77
78     case GestureType::PINCH:
79     {
80       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
81       mPinchGestureProcessor.AddGestureDetector(pinch, scene);
82       break;
83     }
84
85     case GestureType::TAP:
86     {
87       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
88       mTapGestureProcessor.AddGestureDetector(tap, scene);
89       break;
90     }
91
92     case GestureType::ROTATION:
93     {
94       RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
95       mRotationGestureProcessor.AddGestureDetector(rotation, scene);
96       break;
97     }
98   }
99 }
100
101 void GestureEventProcessor::RemoveGestureDetector(GestureDetector* gestureDetector)
102 {
103   switch(gestureDetector->GetType())
104   {
105     case GestureType::LONG_PRESS:
106     {
107       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
108       mLongPressGestureProcessor.RemoveGestureDetector(longPress);
109       break;
110     }
111
112     case GestureType::PAN:
113     {
114       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
115       mPanGestureProcessor.RemoveGestureDetector(pan);
116       break;
117     }
118
119     case GestureType::PINCH:
120     {
121       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
122       mPinchGestureProcessor.RemoveGestureDetector(pinch);
123       break;
124     }
125
126     case GestureType::TAP:
127     {
128       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
129       mTapGestureProcessor.RemoveGestureDetector(tap);
130       break;
131     }
132
133     case GestureType::ROTATION:
134     {
135       RotationGestureDetector* rotation = static_cast<RotationGestureDetector*>(gestureDetector);
136       mRotationGestureProcessor.RemoveGestureDetector(rotation);
137       break;
138     }
139   }
140 }
141
142 void GestureEventProcessor::GestureDetectorUpdated(GestureDetector* gestureDetector)
143 {
144   switch(gestureDetector->GetType())
145   {
146     case GestureType::LONG_PRESS:
147     {
148       LongPressGestureDetector* longPress = static_cast<LongPressGestureDetector*>(gestureDetector);
149       mLongPressGestureProcessor.GestureDetectorUpdated(longPress);
150       break;
151     }
152
153     case GestureType::PAN:
154     {
155       PanGestureDetector* pan = static_cast<PanGestureDetector*>(gestureDetector);
156       mPanGestureProcessor.GestureDetectorUpdated(pan);
157       break;
158     }
159
160     case GestureType::PINCH:
161     {
162       PinchGestureDetector* pinch = static_cast<PinchGestureDetector*>(gestureDetector);
163       mPinchGestureProcessor.GestureDetectorUpdated(pinch);
164       break;
165     }
166
167     case GestureType::TAP:
168     {
169       TapGestureDetector* tap = static_cast<TapGestureDetector*>(gestureDetector);
170       mTapGestureProcessor.GestureDetectorUpdated(tap);
171       break;
172     }
173
174     case GestureType::ROTATION:
175     {
176       // Nothing to do
177       break;
178     }
179   }
180 }
181
182 void GestureEventProcessor::SetGestureProperties(const Dali::Gesture& gesture)
183 {
184   DALI_ASSERT_DEBUG(gesture.GetType() == GestureType::PAN && "Only PanGesture has a scene object\n");
185
186   const Dali::PanGesture& pan = static_cast<const Dali::PanGesture&>(gesture);
187   if(mPanGestureProcessor.SetPanGestureProperties(pan))
188   {
189     // We may not be updating so we need to ask the render controller for an update.
190     mRenderController.RequestUpdate();
191   }
192 }
193
194 bool GestureEventProcessor::NeedsUpdate()
195 {
196   bool updateRequired = false;
197
198   updateRequired |= mLongPressGestureProcessor.NeedsUpdate();
199   updateRequired |= mPanGestureProcessor.NeedsUpdate();
200   updateRequired |= mPinchGestureProcessor.NeedsUpdate();
201   updateRequired |= mTapGestureProcessor.NeedsUpdate();
202   updateRequired |= mRotationGestureProcessor.NeedsUpdate();
203
204   return updateRequired;
205 }
206
207 void GestureEventProcessor::EnablePanGestureProfiling()
208 {
209   mPanGestureProcessor.EnableProfiling();
210 }
211
212 void GestureEventProcessor::SetPanGesturePredictionMode(int mode)
213 {
214   mPanGestureProcessor.SetPredictionMode(mode);
215 }
216
217 void GestureEventProcessor::SetPanGesturePredictionAmount(uint32_t amount)
218 {
219   mPanGestureProcessor.SetPredictionAmount(amount);
220 }
221
222 void GestureEventProcessor::SetPanGestureMaximumPredictionAmount(uint32_t amount)
223 {
224   mPanGestureProcessor.SetMaximumPredictionAmount(amount);
225 }
226
227 void GestureEventProcessor::SetPanGestureMinimumPredictionAmount(uint32_t amount)
228 {
229   mPanGestureProcessor.SetMinimumPredictionAmount(amount);
230 }
231
232 void GestureEventProcessor::SetPanGesturePredictionAmountAdjustment(uint32_t amount)
233 {
234   mPanGestureProcessor.SetPredictionAmountAdjustment(amount);
235 }
236
237 void GestureEventProcessor::SetPanGestureSmoothingMode(int32_t mode)
238 {
239   mPanGestureProcessor.SetSmoothingMode(mode);
240 }
241
242 void GestureEventProcessor::SetPanGestureSmoothingAmount(float amount)
243 {
244   mPanGestureProcessor.SetSmoothingAmount(amount);
245 }
246
247 void GestureEventProcessor::SetPanGestureUseActualTimes(bool value)
248 {
249   mPanGestureProcessor.SetUseActualTimes(value);
250 }
251
252 void GestureEventProcessor::SetPanGestureInterpolationTimeRange(int32_t value)
253 {
254   mPanGestureProcessor.SetInterpolationTimeRange(value);
255 }
256
257 void GestureEventProcessor::SetPanGestureScalarOnlyPredictionEnabled(bool value)
258 {
259   mPanGestureProcessor.SetScalarOnlyPredictionEnabled(value);
260 }
261
262 void GestureEventProcessor::SetPanGestureTwoPointPredictionEnabled(bool value)
263 {
264   mPanGestureProcessor.SetTwoPointPredictionEnabled(value);
265 }
266
267 void GestureEventProcessor::SetPanGestureTwoPointInterpolatePastTime(int value)
268 {
269   mPanGestureProcessor.SetTwoPointInterpolatePastTime(value);
270 }
271
272 void GestureEventProcessor::SetPanGestureTwoPointVelocityBias(float value)
273 {
274   mPanGestureProcessor.SetTwoPointVelocityBias(value);
275 }
276
277 void GestureEventProcessor::SetPanGestureTwoPointAccelerationBias(float value)
278 {
279   mPanGestureProcessor.SetTwoPointAccelerationBias(value);
280 }
281
282 void GestureEventProcessor::SetPanGestureMultitapSmoothingRange(int32_t value)
283 {
284   mPanGestureProcessor.SetMultitapSmoothingRange(value);
285 }
286
287 void GestureEventProcessor::SetPanGestureMinimumDistance(int32_t value)
288 {
289   envOptionMinimumPanDistance = value;
290 }
291
292 void GestureEventProcessor::SetPanGestureMinimumPanEvents(int32_t value)
293 {
294   envOptionMinimumPanEvents = value;
295 }
296
297 void GestureEventProcessor::SetPinchGestureMinimumDistance(float value)
298 {
299   mPinchGestureProcessor.SetMinimumPinchDistance(value);
300 }
301
302 void GestureEventProcessor::SetPinchGestureMinimumTouchEvents(uint32_t value)
303 {
304   mPinchGestureProcessor.SetMinimumTouchEvents(value);
305 }
306
307 void GestureEventProcessor::SetPinchGestureMinimumTouchEventsAfterStart(uint32_t value)
308 {
309   mPinchGestureProcessor.SetMinimumTouchEventsAfterStart(value);
310 }
311
312 void GestureEventProcessor::SetRotationGestureMinimumTouchEvents(uint32_t value)
313 {
314   mRotationGestureProcessor.SetMinimumTouchEvents(value);
315 }
316
317 void GestureEventProcessor::SetRotationGestureMinimumTouchEventsAfterStart(uint32_t value)
318 {
319   mRotationGestureProcessor.SetMinimumTouchEventsAfterStart(value);
320 }
321
322 void GestureEventProcessor::SetLongPressMinimumHoldingTime(uint32_t value)
323 {
324   mLongPressGestureProcessor.SetMinimumHoldingTime(value);
325 }
326
327 uint32_t GestureEventProcessor::GetLongPressMinimumHoldingTime() const
328 {
329   return mLongPressGestureProcessor.GetMinimumHoldingTime();
330 }
331
332 const PanGestureProcessor& GestureEventProcessor::GetPanGestureProcessor()
333 {
334   return mPanGestureProcessor;
335 }
336
337 void GestureEventProcessor::SetTapMaximumAllowedTime(uint32_t time)
338 {
339   mTapGestureProcessor.SetMaximumAllowedTime(time);
340 }
341
342 void GestureEventProcessor::SetTapRecognizerTime(uint32_t time)
343 {
344   mTapGestureProcessor.SetRecognizerTime(time);
345 }
346
347 } // namespace Internal
348
349 } // namespace Dali