Add trace log for touch, wheel and gesture
[platform/core/uifw/dali-core.git] / dali / internal / event / events / long-press-gesture / long-press-gesture-detector-impl.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 "long-press-gesture-detector-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <cstring> // for strcmp
23
24 // INTERNAL INCLUDES
25
26 #include <dali/internal/event/events/gesture-event-processor.h>
27 #include <dali/public-api/object/type-registry.h>
28
29 namespace Dali
30 {
31 namespace Internal
32 {
33 namespace
34 {
35 // Signals
36
37 const char* const SIGNAL_LONG_PRESS_DETECTED = "longPressDetected";
38
39 BaseHandle Create()
40 {
41   return Dali::LongPressGestureDetector::New();
42 }
43
44 TypeRegistration mType(typeid(Dali::LongPressGestureDetector), typeid(Dali::GestureDetector), Create);
45
46 SignalConnectorType signalConnector1(mType, SIGNAL_LONG_PRESS_DETECTED, &LongPressGestureDetector::DoConnectSignal);
47
48 } // namespace
49
50 namespace
51 {
52 const unsigned int DEFAULT_TOUCHES_REQUIRED = 1;
53 } // unnamed namespace
54
55 LongPressGestureDetectorPtr LongPressGestureDetector::New()
56 {
57   return new LongPressGestureDetector;
58 }
59
60 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int touchesRequired)
61 {
62   return new LongPressGestureDetector(touchesRequired, touchesRequired);
63 }
64
65 LongPressGestureDetectorPtr LongPressGestureDetector::New(unsigned int minTouches, unsigned int maxTouches)
66 {
67   return new LongPressGestureDetector(minTouches, maxTouches);
68 }
69
70 LongPressGestureDetector::LongPressGestureDetector()
71 : GestureDetector(GestureType::LONG_PRESS),
72   mMinimumTouchesRequired(DEFAULT_TOUCHES_REQUIRED),
73   mMaximumTouchesRequired(DEFAULT_TOUCHES_REQUIRED)
74 {
75 }
76
77 LongPressGestureDetector::LongPressGestureDetector(unsigned int minTouches, unsigned int maxTouches)
78 : GestureDetector(GestureType::LONG_PRESS),
79   mMinimumTouchesRequired(minTouches),
80   mMaximumTouchesRequired(maxTouches)
81 {
82 }
83
84 LongPressGestureDetector::~LongPressGestureDetector() = default;
85
86 void LongPressGestureDetector::SetTouchesRequired(unsigned int touches)
87 {
88   DALI_ASSERT_ALWAYS(touches > 0 && "Can only set a positive number of required touches");
89
90   if(mMinimumTouchesRequired != touches || mMaximumTouchesRequired != touches)
91   {
92     mMinimumTouchesRequired = mMaximumTouchesRequired = touches;
93
94     if(!mAttachedActors.empty())
95     {
96       mGestureEventProcessor.GestureDetectorUpdated(this);
97     }
98   }
99 }
100
101 void LongPressGestureDetector::SetTouchesRequired(unsigned int minTouches, unsigned int maxTouches)
102 {
103   DALI_ASSERT_ALWAYS(minTouches > 0 && "Can only set a positive number of minimum touches");
104   DALI_ASSERT_ALWAYS(maxTouches > 0 && "Can only set a positive number of minimum touches");
105   DALI_ASSERT_ALWAYS(minTouches <= maxTouches && "Number of minimum touches must be less than maximum");
106
107   if(mMinimumTouchesRequired != minTouches || mMaximumTouchesRequired != maxTouches)
108   {
109     mMinimumTouchesRequired = minTouches;
110     mMaximumTouchesRequired = maxTouches;
111
112     if(!mAttachedActors.empty())
113     {
114       mGestureEventProcessor.GestureDetectorUpdated(this);
115     }
116   }
117 }
118
119 unsigned int LongPressGestureDetector::GetMinimumTouchesRequired() const
120 {
121   return mMinimumTouchesRequired;
122 }
123
124 unsigned int LongPressGestureDetector::GetMaximumTouchesRequired() const
125 {
126   return mMaximumTouchesRequired;
127 }
128
129 void LongPressGestureDetector::EmitLongPressGestureSignal(Dali::Actor pressedActor, const Dali::LongPressGesture& longPress)
130 {
131   // Guard against destruction during signal emission
132   Dali::LongPressGestureDetector handle(this);
133
134   mDetectedSignal.Emit(pressedActor, longPress);
135 }
136
137 bool LongPressGestureDetector::DoConnectSignal(BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor)
138 {
139   bool                      connected(true);
140   LongPressGestureDetector* gesture = static_cast<LongPressGestureDetector*>(object); // TypeRegistry guarantees that this is the correct type.
141
142   if(0 == strcmp(signalName.c_str(), SIGNAL_LONG_PRESS_DETECTED))
143   {
144     gesture->DetectedSignal().Connect(tracker, functor);
145   }
146   else
147   {
148     // signalName does not match any signal
149     connected = false;
150   }
151
152   return connected;
153 }
154
155 void LongPressGestureDetector::OnActorAttach(Actor& actor)
156 {
157   // Do nothing
158 }
159
160 void LongPressGestureDetector::OnActorDetach(Actor& actor)
161 {
162   // Do nothing
163 }
164
165 void LongPressGestureDetector::OnActorDestroyed(Object& object)
166 {
167   // Do nothing
168 }
169
170 uint32_t LongPressGestureDetector::GetMinimumHoldingTime() const
171 {
172   return mGestureEventProcessor.GetLongPressMinimumHoldingTime();
173 }
174
175 } // namespace Internal
176
177 } // namespace Dali