Revert "[Tizen] Not execute the remove callback"
[platform/core/uifw/dali-core.git] / dali / internal / event / events / actor-gesture-data.cpp
1 /*
2  * Copyright (c) 2021 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/actor-gesture-data.h>
20
21 namespace Dali
22 {
23 namespace Internal
24 {
25 ActorGestureData::ActorGestureData()
26 : gesturesRequired(GestureType::Value(0)),
27   panDetectors(nullptr),
28   pinchDetectors(nullptr),
29   longPressDetectors(nullptr),
30   tapDetectors(nullptr),
31   rotationDetectors(nullptr)
32 {
33 }
34
35 ActorGestureData::~ActorGestureData()
36 {
37   delete panDetectors;
38   delete pinchDetectors;
39   delete longPressDetectors;
40   delete tapDetectors;
41   delete rotationDetectors;
42 }
43
44 void ActorGestureData::AddGestureDetector(GestureDetector& detector)
45 {
46   const GestureType::Value type(detector.GetType());
47
48   GestureDetectorContainer*& containerPtr(GetContainerPtr(type));
49   if(nullptr == containerPtr)
50   {
51     containerPtr = new GestureDetectorContainer;
52   }
53   containerPtr->push_back(&detector);
54
55   gesturesRequired = GestureType::Value(gesturesRequired | type);
56 }
57
58 void ActorGestureData::RemoveGestureDetector(GestureDetector& detector)
59 {
60   const GestureType::Value type(detector.GetType());
61
62   GestureDetectorContainer*& containerPtr(GetContainerPtr(type));
63   DALI_ASSERT_DEBUG(containerPtr && "Container had not been created");
64
65   GestureDetectorContainer&          container(*containerPtr);
66   GestureDetectorContainer::iterator match(std::remove(container.begin(), container.end(), &detector));
67   DALI_ASSERT_DEBUG(match != container.end() && "Actor does not have the detector");
68   container.erase(match, container.end());
69
70   if(container.empty())
71   {
72     gesturesRequired = GestureType::Value(gesturesRequired & ~type);
73     delete containerPtr;
74     containerPtr = nullptr;
75   }
76 }
77
78 GestureDetectorContainer& ActorGestureData::GetGestureDetectorContainer(GestureType::Value type)
79 {
80   return *GetContainerPtr(type);
81 }
82
83 GestureDetectorContainer*& ActorGestureData::GetContainerPtr(GestureType::Value type)
84 {
85   switch(type)
86   {
87     case GestureType::PAN:
88     {
89       return panDetectors;
90     }
91
92     case GestureType::PINCH:
93     {
94       return pinchDetectors;
95     }
96
97     case GestureType::LONG_PRESS:
98     {
99       return longPressDetectors;
100     }
101
102     case GestureType::TAP:
103     {
104       return tapDetectors;
105     }
106
107     case GestureType::ROTATION:
108     {
109       return rotationDetectors;
110     }
111   }
112
113   DALI_ASSERT_DEBUG(!"Invalid Type");
114   static GestureDetectorContainer* invalidType(nullptr);
115   return invalidType;
116 }
117
118 } // namespace Internal
119
120 } // namespace Dali