Revert "[Tizen] fix visual artifact of Transition"
[platform/core/uifw/dali-core.git] / dali / public-api / actors / custom-actor-impl.h
1 #ifndef DALI_CUSTOM_ACTOR_IMPL_H
2 #define DALI_CUSTOM_ACTOR_IMPL_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 // EXTERNAL INCLUDES
22 #include <cstdint> // uint32_t
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/actors/actor-enumerations.h>
26 #include <dali/public-api/math/compile-time-math.h>
27 #include <dali/public-api/object/property.h>
28 #include <dali/public-api/object/ref-object.h>
29
30 namespace Dali
31 {
32 /**
33  * @addtogroup dali_core_actors
34  * @{
35  */
36
37 namespace Internal DALI_INTERNAL
38 {
39 class CustomActor;
40 }
41
42 class Actor;
43 class Animation;
44 class CustomActor;
45 class CustomActorImpl;
46 class RelayoutContainer;
47 class KeyEvent;
48 class HoverEvent;
49 class WheelEvent;
50 struct Vector2;
51 struct Vector3;
52
53 /**
54  * @brief Pointer to Dali::CustomActorImpl object.
55  * @SINCE_1_0.0
56  */
57 using CustomActorImplPtr = IntrusivePtr<CustomActorImpl>;
58
59 /**
60  * @brief CustomActorImpl is an abstract base class for custom control implementations.
61  *
62  * This provides a series of pure virtual methods, which are called when actor-specific events occur.
63  * And CustomActorImpl is typically owned by a single CustomActor instance; see also CustomActor::CustomActor( CustomActorImpl &implementation ).
64  * @SINCE_1_0.0
65  */
66 class DALI_CORE_API CustomActorImpl : public Dali::RefObject
67 {
68 public:
69   class Extension; ///< Forward declare future extension interface
70
71 protected:
72   /**
73    * @brief Virtual destructor
74    * @SINCE_1_0.0
75    */
76   ~CustomActorImpl() override;
77
78 public:
79   /**
80    * @brief Used by derived CustomActorImpl instances, to access the public Actor interface.
81    *
82    * @SINCE_1_0.0
83    * @return A pointer to self, or an uninitialized pointer if the CustomActorImpl is not owned.
84    */
85   CustomActor Self() const;
86
87   /**
88    * @brief Called after the actor has been connected to the Scene.
89    *
90    * When an actor is connected, it will be directly or indirectly parented to the root Actor.
91    * @SINCE_1_9.24
92    * @param[in] depth The depth in the hierarchy for the actor
93    *
94    * @note The root Actor is provided automatically by the Scene, and is always considered to be connected.
95    * When the parent of a set of actors is connected to the scene, then all of the children
96    * will received this callback.
97    * For the following actor tree, the callback order will be A, B, D, E, C, and finally F.
98    *
99    * @code
100    *
101    *       A (parent)
102    *      / \
103    *     B   C
104    *    / \   \
105    *   D   E   F
106    *
107    * @endcode
108    */
109   virtual void OnSceneConnection(int32_t depth) = 0;
110
111   /**
112    * @brief Called after the actor has been disconnected from the Scene.
113    *
114    * If an actor is disconnected, it either has no parent or is parented to a disconnected actor.
115    *
116    * @SINCE_1_9.24
117    * @note When the parent of a set of actors is disconnected to the scene, then all of the children
118    * will received this callback, starting with the leaf actors.
119    * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
120    *
121    * @code
122    *
123    *       A (parent)
124    *      / \
125    *     B   C
126    *    / \   \
127    *   D   E   F
128    *
129    * @endcode
130    */
131   virtual void OnSceneDisconnection() = 0;
132
133   /**
134    * @brief Called after a child has been added to the owning actor.
135    *
136    * @SINCE_1_0.0
137    * @param[in] child The child which has been added
138    */
139   virtual void OnChildAdd(Actor& child) = 0;
140
141   /**
142    * @brief Called after the owning actor has attempted to remove a child (regardless of whether it succeeded or not).
143    *
144    * @SINCE_1_0.0
145    * @param[in] child The child being removed
146    */
147   virtual void OnChildRemove(Actor& child) = 0;
148
149   /**
150    * @brief Called when the owning actor property is set.
151    *
152    * @SINCE_1_0.0
153    * @param[in] index The Property index that was set
154    * @param[in] propertyValue The value to set
155    */
156   virtual void OnPropertySet(Property::Index index, const Property::Value& propertyValue);
157
158   /**
159    * @brief Called when the owning actor's size is set e.g. using Actor::SetSize().
160    *
161    * @SINCE_1_0.0
162    * @param[in] targetSize The target size. Note that this target size may not match the size returned via @ref Actor::GetTargetSize
163    */
164   virtual void OnSizeSet(const Vector3& targetSize) = 0;
165
166   /**
167    * @brief Called when the owning actor's size is animated e.g. using Animation::AnimateTo( Property( actor, Actor::Property::SIZE ), ... ).
168    *
169    * @SINCE_1_0.0
170    * @param[in] animation The object which is animating the owning actor
171    * @param[in] targetSize The target size. Note that this target size may not match the size returned via @ref Actor::GetTargetSize
172    */
173   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) = 0;
174
175   /**
176    * @brief Called after the size negotiation has been finished for this control.
177    *
178    * The control is expected to assign this given size to itself/its children.
179    *
180    * Should be overridden by derived classes if they need to layout
181    * actors differently after certain operations like add or remove
182    * actors, resize or after changing specific properties.
183    *
184    * @SINCE_1_0.0
185    * @param[in]      size       The allocated size
186    * @param[in,out]  container  The control should add actors to this container that it is not able
187    *                            to allocate a size for
188    * @note  As this function is called from inside the size negotiation algorithm, you cannot
189    * call RequestRelayout (the call would just be ignored).
190    */
191   virtual void OnRelayout(const Vector2& size, RelayoutContainer& container) = 0;
192
193   /**
194    * @brief Notification for deriving classes.
195    *
196    * @SINCE_1_0.0
197    * @param[in] policy The policy being set
198    * @param[in] dimension The dimension the policy is being set for
199    */
200   virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension) = 0;
201
202   /**
203    * @brief Returns the natural size of the actor.
204    *
205    * @SINCE_1_0.0
206    * @return The actor's natural size
207    */
208   virtual Vector3 GetNaturalSize() = 0;
209
210   /**
211    * @brief Calculates the size for a child.
212    *
213    * @SINCE_1_0.0
214    * @param[in] child The child actor to calculate the size for
215    * @param[in] dimension The dimension to calculate the size for. E.g. width or height
216    * @return Return the calculated size for the given dimension
217    */
218   virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension) = 0;
219
220   /**
221    * @brief This method is called during size negotiation when a height is required for a given width.
222    *
223    * Derived classes should override this if they wish to customize the height returned.
224    *
225    * @SINCE_1_0.0
226    * @param[in] width Width to use
227    * @return The height based on the width
228    */
229   virtual float GetHeightForWidth(float width) = 0;
230
231   /**
232    * @brief This method is called during size negotiation when a width is required for a given height.
233    *
234    * Derived classes should override this if they wish to customize the width returned.
235    *
236    * @SINCE_1_0.0
237    * @param[in] height Height to use
238    * @return The width based on the width
239    */
240   virtual float GetWidthForHeight(float height) = 0;
241
242   /**
243    * @brief Determines if this actor is dependent on its children for relayout.
244    *
245    * @SINCE_1_0.0
246    * @param[in] dimension The dimension(s) to check for
247    * @return Return if the actor is dependent on it's children
248    */
249   virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) = 0;
250
251   /**
252    * @brief Virtual method to notify deriving classes that relayout dependencies have been
253    * met and the size for this object is about to be calculated for the given dimension.
254    *
255    * @SINCE_1_0.0
256    * @param[in] dimension The dimension that is about to be calculated
257    */
258   virtual void OnCalculateRelayoutSize(Dimension::Type dimension) = 0;
259
260   /**
261    * @brief Virtual method to notify deriving classes that the size for a dimension
262    * has just been negotiated.
263    *
264    * @SINCE_1_0.0
265    * @param[in] size The new size for the given dimension
266    * @param[in] dimension The dimension that was just negotiated
267    */
268   virtual void OnLayoutNegotiated(float size, Dimension::Type dimension) = 0;
269
270   /**
271    * @brief Retrieves the extension for this control.
272    *
273    * @SINCE_1_0.0
274    * @return The extension if available, NULL otherwise
275    */
276   virtual Extension* GetExtension()
277   {
278     return nullptr;
279   }
280
281 protected: // For derived classes
282   /**
283    * @brief Enumeration for the constructor flags.
284    * @SINCE_1_0.0
285    */
286   enum ActorFlags
287   {
288     ACTOR_BEHAVIOUR_DEFAULT  = 0,      ///< Use to provide default behaviour (size negotiation is on, event callbacks are not called). @SINCE_1_2_10
289     DISABLE_SIZE_NEGOTIATION = 1 << 0, ///< True if control does not need size negotiation, i.e. it can be skipped in the algorithm @SINCE_1_0.0
290     NOT_IN_USE_1             = 1 << 1,
291     NOT_IN_USE_2             = 1 << 2,
292     NOT_IN_USE_3             = 1 << 3,
293
294     LAST_ACTOR_FLAG ///< Special marker for last actor flag @SINCE_1_0.0
295   };
296
297   static constexpr int32_t ACTOR_FLAG_COUNT = Log<LAST_ACTOR_FLAG - 1>::value + 1; ///< Value for deriving classes to continue on the flag enum
298
299   /**
300    * @brief Creates a CustomActorImpl.
301    * @SINCE_1_0.0
302    * @param[in] flags Bitfield of ActorFlags to define behaviour
303    */
304   CustomActorImpl(ActorFlags flags);
305
306   // Size negotiation helpers
307
308   /**
309    * @brief Requests a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene).
310    *
311    * This method can also be called from a derived class every time it needs a different size.
312    * At the end of event processing, the relayout process starts and
313    * all controls which requested Relayout will have their sizes (re)negotiated.
314    *
315    * @SINCE_1_0.0
316    * @note RelayoutRequest() can be called multiple times; the size negotiation is still
317    * only performed once, i.e. there is no need to keep track of this in the calling side.
318    */
319   void RelayoutRequest();
320
321   /**
322    * @brief Provides the Actor implementation of GetHeightForWidth.
323    * @SINCE_1_0.0
324    * @param[in] width Width to use
325    * @return The height based on the width
326    */
327   float GetHeightForWidthBase(float width);
328
329   /**
330    * @brief Provides the Actor implementation of GetWidthForHeight.
331    * @SINCE_1_0.0
332    * @param[in] height Height to use
333    * @return The width based on the height
334    */
335   float GetWidthForHeightBase(float height);
336
337   /**
338    * @brief Calculates the size for a child using the base actor object.
339    *
340    * @SINCE_1_0.0
341    * @param[in] child The child actor to calculate the size for
342    * @param[in] dimension The dimension to calculate the size for. E.g. width or height
343    * @return Return the calculated size for the given dimension. If more than one dimension is requested, just return the first one found
344    */
345   float CalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension);
346
347   /**
348    * @brief Determines if this actor is dependent on its children for relayout from the base class.
349    *
350    * @SINCE_1_0.0
351    * @param[in] dimension The dimension(s) to check for
352    * @return Return if the actor is dependent on it's children
353    */
354   bool RelayoutDependentOnChildrenBase(Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
355
356   /**
357    * @brief Set this CustomActor is transparent or not without any affection on the child Actors.
358    */
359   virtual void SetTransparent(bool transparent);
360
361   /**
362    * @brief Get this CustomActor is transparent or not.
363    */
364   virtual bool GetTransparent() const;
365
366 public: // Not intended for application developers
367   /**
368    * @brief Initializes a CustomActor.
369    * @SINCE_1_0.0
370    * @param[in] owner The owning object
371    * @pre The CustomActorImpl is not already owned.
372    * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
373    */
374   void Initialize(Internal::CustomActor& owner);
375
376   /**
377    * @brief Gets the owner.
378    *
379    * This method is needed when creating additional handle objects to existing objects.
380    * Owner is the Dali::Internal::CustomActor that owns the implementation of the custom actor
381    * inside core. Creation of a handle to Dali public API Actor requires this pointer.
382    * @SINCE_1_0.0
383    * @return A pointer to the Actor implementation that owns this custom actor implementation
384    */
385   Internal::CustomActor* GetOwner() const;
386
387   /**
388    * @brief Returns whether relayout is enabled.
389    * @SINCE_1_0.0
390    * @return Return true if relayout is enabled on the custom actor
391    * @note Called when ownership of the CustomActorImpl is passed to a CustomActor.
392    */
393   bool IsRelayoutEnabled() const;
394
395 private:
396   Internal::CustomActor* mOwner; ///< Internal owner of this custom actor implementation
397   ActorFlags             mFlags; ///< ActorFlags flags to determine behaviour
398 };
399
400 /**
401  * @}
402  */
403 } // namespace Dali
404
405 #endif // DALI_CUSTOM_ACTOR_IMPL_H