Merge "Add TOUCH_FOCUSABLE property" into devel/master
[platform/core/uifw/dali-core.git] / dali / internal / event / events / tap-gesture / tap-gesture-impl.h
1 #ifndef DALI_INTERNAL_TAP_GESTURE_H
2 #define DALI_INTERNAL_TAP_GESTURE_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-impl.h>
23 #include <dali/public-api/events/tap-gesture.h>
24 #include <dali/public-api/math/vector2.h>
25 #include <dali/public-api/object/base-object.h>
26
27 namespace Dali
28 {
29 namespace Internal
30 {
31 class TapGesture;
32 using TapGesturePtr = IntrusivePtr<TapGesture>;
33
34 /**
35  * @copydoc Dali::TapGesture
36  */
37 class TapGesture final : public Gesture
38 {
39 public:
40   /**
41    * @brief Default constructor
42    */
43   TapGesture(GestureState state)
44   : Gesture(GestureType::TAP, state)
45   {
46   }
47
48   TapGesture(const TapGesture&) = delete;            ///< Deleted copy constructor
49   TapGesture(TapGesture&&)      = delete;            ///< Deleted move constructor
50   TapGesture& operator=(const TapGesture&) = delete; ///< Deleted copy assignment operator
51   TapGesture& operator=(TapGesture&&) = delete;      ///< Deleted move assignment operator
52
53   /**
54    * @brief The number of taps in this tap gesture.
55    * @param[in] numberOfTaps The number of taps to set.
56    */
57   inline void SetNumberOfTaps(uint32_t numberOfTaps)
58   {
59     mNumberOfTaps = numberOfTaps;
60   }
61
62   /**
63    * @copydoc Dali::TapGesture::GetNumberOfTaps()
64    */
65   inline uint32_t GetNumberOfTaps() const
66   {
67     return mNumberOfTaps;
68   }
69
70   /**
71    * @brief The number of touch points in this tap gesture, i.e. the number of fingers the user had on the screen to generate the tap gesture.
72    * @param[in] numberOfTouches The number of touch points in this tap gesture to set.
73    */
74   inline void SetNumberOfTouches(uint32_t numberOfTouches)
75   {
76     mNumberOfTouches = numberOfTouches;
77   }
78
79   /**
80    * @copydoc Dali::TapGesture::GetPointCount()
81    */
82   inline uint32_t GetNumberOfTouches() const
83   {
84     return mNumberOfTouches;
85   }
86
87   /**
88    * @brief This is the point, in screen coordinates, where the tap occurred.
89    * @param[in] screenPoint The point in screen coordinates to set.
90    */
91   inline void SetScreenPoint(const Vector2& screenPoint)
92   {
93     mScreenPoint = screenPoint;
94   }
95
96   /**
97    * @copydoc Dali::TapGesture::GetDeviceId()
98    */
99   inline const Vector2& GetScreenPoint() const
100   {
101     return mScreenPoint;
102   }
103
104   /**
105    * @brief This is the point, in local actor coordinates, where the tap occurred.
106    * @param[in] localPoint The point in local actor coordinates to set.
107    */
108   inline void SetLocalPoint(const Vector2& localPoint)
109   {
110     mLocalPoint = localPoint;
111   }
112
113   /**
114    * @copydoc Dali::TapGesture::GetGetState()
115    */
116   inline const Vector2& GetLocalPoint() const
117   {
118     return mLocalPoint;
119   }
120
121   /**
122    * @brief This is the value of which input was tapped.
123    * @param[in] source This is the value of which input was tapped to set.
124    */
125   inline void SetGestureSourceType(const GestureSourceType sourceType)
126   {
127     mGestureSourceType = sourceType;
128   }
129
130   /**
131    * @copydoc Dali::TapGesture::GetSourceType()
132    */
133   inline const GestureSourceType& GetSourceType() const
134   {
135     return mGestureSourceType;
136   }
137
138 private:
139   /**
140    * @brief Virtual destructor
141    *
142    * A reference counted object may only be deleted by calling Unreference()
143    */
144   ~TapGesture() override = default;
145
146 private:
147   Vector2           mScreenPoint;
148   Vector2           mLocalPoint;
149   uint32_t          mNumberOfTaps{1u};
150   uint32_t          mNumberOfTouches{1u};
151   GestureSourceType mGestureSourceType{GestureSourceType::INVALID};
152 };
153
154 } // namespace Internal
155
156 // Helpers for public-api forwarding methods
157
158 inline Internal::TapGesture& GetImplementation(Dali::TapGesture& tapGesture)
159 {
160   DALI_ASSERT_ALWAYS(tapGesture && "TapGesture handle is empty");
161
162   BaseObject& object = tapGesture.GetBaseObject();
163
164   return static_cast<Internal::TapGesture&>(object);
165 }
166
167 inline const Internal::TapGesture& GetImplementation(const Dali::TapGesture& tapGesture)
168 {
169   DALI_ASSERT_ALWAYS(tapGesture && "TapGesture handle is empty");
170
171   const BaseObject& object = tapGesture.GetBaseObject();
172
173   return static_cast<const Internal::TapGesture&>(object);
174 }
175
176 } // namespace Dali
177
178 #endif // DALI_INTERNAL_TAP_GESTURE_H