Add KEYBOARD_FOCUSABLE_CHILDREN property.
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.h
1 #ifndef DALI_INTERNAL_ACTOR_H
2 #define DALI_INTERNAL_ACTOR_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 <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/actors/actor-devel.h>
26 #include <dali/devel-api/rendering/renderer-devel.h>
27 #include <dali/internal/common/const-string.h>
28 #include <dali/internal/common/internal-constants.h>
29 #include <dali/internal/common/memory-pool-object-allocator.h>
30 #include <dali/internal/event/actors/actor-declarations.h>
31 #include <dali/internal/event/actors/actor-parent-impl.h>
32 #include <dali/internal/event/actors/actor-parent.h>
33 #include <dali/internal/event/common/object-impl.h>
34 #include <dali/internal/event/common/stage-def.h>
35 #include <dali/internal/update/nodes/node-declarations.h>
36 #include <dali/public-api/actors/actor.h>
37 #include <dali/public-api/common/dali-common.h>
38 #include <dali/public-api/common/vector-wrapper.h>
39 #include <dali/public-api/events/gesture.h>
40 #include <dali/public-api/math/viewport.h>
41 #include <dali/public-api/object/ref-object.h>
42 #include <dali/public-api/size-negotiation/relayout-container.h>
43
44 namespace Dali
45 {
46 class KeyEvent;
47 class TouchData;
48 class TouchEvent;
49 class WheelEvent;
50
51 namespace Internal
52 {
53 class Actor;
54 class ActorGestureData;
55 class Animation;
56 class RenderTask;
57 class Renderer;
58 class Scene;
59
60 using RendererPtr       = IntrusivePtr<Renderer>;
61 using RendererContainer = std::vector<RendererPtr>;
62 using RendererIter      = RendererContainer::iterator;
63
64 class ActorDepthTreeNode;
65 using DepthNodeMemoryPool = Dali::Internal::MemoryPoolObjectAllocator<ActorDepthTreeNode>;
66
67 /**
68  * Actor is the primary object with which Dali applications interact.
69  * UI controls can be built by combining multiple actors.
70  * Multi-Touch events are received through signals emitted by the actor tree.
71  *
72  * An Actor is a proxy for a Node in the scene graph.
73  * When an Actor is added to the Stage, it creates a node and connects it to the scene graph.
74  * The scene-graph can be updated in a separate thread, so the connection is done using an asynchronous message.
75  * When a tree of Actors is detached from the Stage, a message is sent to destroy the associated nodes.
76  */
77 class Actor : public Object, public ActorParent
78 {
79 public:
80   /**
81    * @brief Struct to hold an actor and a dimension
82    */
83   struct ActorDimensionPair
84   {
85     /**
86      * @brief Constructor
87      *
88      * @param[in] newActor The actor to assign
89      * @param[in] newDimension The dimension to assign
90      */
91     ActorDimensionPair(Actor* newActor, Dimension::Type newDimension)
92     : actor(newActor),
93       dimension(newDimension)
94     {
95     }
96
97     /**
98      * @brief Equality operator
99      *
100      * @param[in] lhs The left hand side argument
101      * @param[in] rhs The right hand side argument
102      */
103     bool operator==(const ActorDimensionPair& rhs)
104     {
105       return (actor == rhs.actor) && (dimension == rhs.dimension);
106     }
107
108     Actor*          actor;     ///< The actor to hold
109     Dimension::Type dimension; ///< The dimension to hold
110   };
111
112   using ActorDimensionStack = std::vector<ActorDimensionPair>;
113
114 public:
115   /**
116    * Create a new actor.
117    * @return A smart-pointer to the newly allocated Actor.
118    */
119   static ActorPtr New();
120
121   /**
122    * Helper to create node for derived classes who don't have their own node type
123    * @return pointer to newly created unique node
124    */
125   static const SceneGraph::Node* CreateNode();
126
127   /**
128    * Retrieve the name of the actor.
129    * @return The name.
130    */
131   std::string_view GetName() const
132   {
133     return mName.GetStringView();
134   }
135
136   /**
137    * Set the name of the actor.
138    * @param[in] name The new name.
139    */
140   void SetName(std::string_view name);
141
142   /**
143    * @copydoc Dali::Actor::GetId
144    */
145   uint32_t GetId() const;
146
147   // Containment
148
149   /**
150    * Query whether an actor is the root actor, which is owned by the Stage.
151    * @return True if the actor is a root actor.
152    */
153   bool IsRoot() const
154   {
155     return mIsRoot;
156   }
157
158   /**
159    * Query whether the actor is connected to the Scene.
160    */
161   bool OnScene() const
162   {
163     return mIsOnScene;
164   }
165
166   /**
167    * Query whether the actor has any renderers.
168    * @return True if the actor is renderable.
169    */
170   bool IsRenderable() const
171   {
172     // inlined as this is called a lot in hit testing
173     return mRenderers && !mRenderers->empty();
174   }
175
176   /**
177    * Query whether the actor is of class Dali::Layer
178    * @return True if the actor is a layer.
179    */
180   bool IsLayer() const
181   {
182     // inlined as this is called a lot in hit testing
183     return mIsLayer;
184   }
185
186   /**
187    * Gets the layer in which the actor is present
188    * @return The layer, which will be uninitialized if the actor is off-stage.
189    */
190   Dali::Layer GetLayer();
191
192   /**
193    * @copydoc Dali::Internal::ActorParent::Add()
194    */
195   void Add(Actor& child, bool notify = true) override;
196
197   /**
198    * @copydoc Dali::Internal::ActorParent::Remove()
199    */
200   void Remove(Actor& child, bool notify = true) override;
201
202   /**
203    * @copydoc Dali::DevelActor::SwitchParent()
204    */
205   void SwitchParent(Actor& newParent);
206
207   /**
208    * @copydoc Dali::Actor::Unparent
209    */
210   void Unparent();
211
212   /**
213    * @copydoc Dali::Internal::ActorParent::GetChildCount()
214    */
215   uint32_t GetChildCount() const override;
216
217   /**
218    * @copydoc Dali::Internal::ActorParent::GetChildAt
219    */
220   ActorPtr GetChildAt(uint32_t index) const override;
221
222   /**
223    * Retrieve a reference to Actor's children.
224    * @note Not for public use.
225    * @return A reference to the container of children.
226    * @note The internal container is lazily initialized so ensure you check the child count before using the value returned by this method.
227    */
228   ActorContainer& GetChildrenInternal();
229
230   /**
231    * @copydoc Dali::Internal::ActorParent::FindChildByName
232    */
233   ActorPtr FindChildByName(ConstString actorName) override;
234
235   /**
236    * @copydoc Dali::Internal::ActorParent::FindChildById
237    */
238   ActorPtr FindChildById(const uint32_t id) override;
239
240   /**
241    * @copydoc Dali::Internal::ActorParent::UnparentChildren
242    */
243   void UnparentChildren() override;
244
245   /**
246    * Retrieve the parent of an Actor.
247    * @return The parent actor, or NULL if the Actor does not have a parent.
248    */
249   Actor* GetParent() const
250   {
251     return static_cast<Actor*>(mParent);
252   }
253
254   /**
255    * Calculates screen position and size.
256    *
257    * @return pair of two values, position of top-left corner on screen and size respectively.
258    */
259   Rect<> CalculateScreenExtents() const;
260
261   /**
262    * @copydoc DevelActor::SetNeedGesturePropagation.
263    */
264   void SetNeedGesturePropagation(bool propagation);
265
266   /**
267    * Retrieve need gesture propagation value
268    * @return The actor's need gesture propagation value.
269    */
270   bool NeedGesturePropagation();
271
272   /**
273    * Sets the size of an actor.
274    * This does not interfere with the actors scale factor.
275    * @param [in] width  The new width.
276    * @param [in] height The new height.
277    */
278   void SetSize(float width, float height);
279
280   /**
281    * Sets the size of an actor.
282    * This does not interfere with the actors scale factor.
283    * @param [in] width The size of the actor along the x-axis.
284    * @param [in] height The size of the actor along the y-axis.
285    * @param [in] depth The size of the actor along the z-axis.
286    */
287   void SetSize(float width, float height, float depth);
288
289   /**
290    * Sets the size of an actor.
291    * This does not interfere with the actors scale factor.
292    * @param [in] size The new size.
293    */
294   void SetSize(const Vector2& size);
295
296   /**
297    * Sets the update size for an actor.
298    *
299    * @param[in] size The size to set.
300    */
301   void SetSizeInternal(const Vector2& size);
302
303   /**
304    * Sets the size of an actor.
305    * This does not interfere with the actors scale factor.
306    * @param [in] size The new size.
307    */
308   void SetSize(const Vector3& size);
309
310   /**
311    * Sets the update size for an actor.
312    *
313    * @param[in] size The size to set.
314    */
315   void SetSizeInternal(const Vector3& size);
316
317   /**
318    * Set the width component of the Actor's size.
319    * @param [in] width The new width component.
320    */
321   void SetWidth(float width);
322
323   /**
324    * Set the height component of the Actor's size.
325    * @param [in] height The new height component.
326    */
327   void SetHeight(float height);
328
329   /**
330    * Set the depth component of the Actor's size.
331    * @param [in] depth The new depth component.
332    */
333   void SetDepth(float depth);
334
335   /**
336    * Retrieve the Actor's size from event side.
337    * This size will be the size set or if animating then the target size.
338    * @return The Actor's size.
339    */
340   Vector3 GetTargetSize() const;
341
342   /**
343    * Retrieve the Actor's size from update side.
344    * This size will be the size set or animating but will be a frame behind.
345    * @return The Actor's size.
346    */
347   const Vector3& GetCurrentSize() const;
348
349   /**
350    * Return the natural size of the actor
351    *
352    * @return The actor's natural size
353    */
354   virtual Vector3 GetNaturalSize() const;
355
356   /**
357    * Set the origin of an actor, within its parent's area.
358    * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
359    * and (1.0, 1.0, 0.5) is the bottom-right corner.
360    * The default parent-origin is top-left (0.0, 0.0, 0.5).
361    * An actor position is the distance between this origin, and the actors anchor-point.
362    * @param [in] origin The new parent-origin.
363    */
364   void SetParentOrigin(const Vector3& origin);
365
366   /**
367    * Retrieve the parent-origin of an actor.
368    * @return The parent-origin.
369    */
370   const Vector3& GetCurrentParentOrigin() const;
371
372   /**
373    * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
374    * (0.0, 0.0, 0.5) is the top-left corner of the actor, and (1.0, 1.0, 0.5) is the bottom-right corner.
375    * The default anchor point is top-left (0.0, 0.0, 0.5).
376    * An actor position is the distance between its parent-origin, and this anchor-point.
377    * An actor's rotation is centered around its anchor-point.
378    * @param [in] anchorPoint The new anchor-point.
379    */
380   void SetAnchorPoint(const Vector3& anchorPoint);
381
382   /**
383    * Retrieve the anchor-point of an actor.
384    * @return The anchor-point.
385    */
386   const Vector3& GetCurrentAnchorPoint() const;
387
388   /**
389    * Sets the position of the Actor.
390    * The coordinates are relative to the Actor's parent.
391    * The Actor's z position will be set to 0.0f.
392    * @param [in] x The new x position
393    * @param [in] y The new y position
394    */
395   void SetPosition(float x, float y);
396
397   /**
398    * Sets the position of the Actor.
399    * The coordinates are relative to the Actor's parent.
400    * @param [in] x The new x position
401    * @param [in] y The new y position
402    * @param [in] z The new z position
403    */
404   void SetPosition(float x, float y, float z);
405
406   /**
407    * Sets the position of the Actor.
408    * The coordinates are relative to the Actor's parent.
409    * @param [in] position The new position.
410    */
411   void SetPosition(const Vector3& position);
412
413   /**
414    * Set the position of an actor along the X-axis.
415    * @param [in] x The new x position
416    */
417   void SetX(float x);
418
419   /**
420    * Set the position of an actor along the Y-axis.
421    * @param [in] y The new y position.
422    */
423   void SetY(float y);
424
425   /**
426    * Set the position of an actor along the Z-axis.
427    * @param [in] z The new z position
428    */
429   void SetZ(float z);
430
431   /**
432    * Translate an actor relative to its existing position.
433    * @param[in] distance The actor will move by this distance.
434    */
435   void TranslateBy(const Vector3& distance);
436
437   /**
438    * Retrieve the position of the Actor.
439    * The coordinates are relative to the Actor's parent.
440    * @return the Actor's position.
441    */
442   const Vector3& GetCurrentPosition() const;
443
444   /**
445    * Retrieve the target position of the Actor.
446    * The coordinates are relative to the Actor's parent.
447    * @return the Actor's position.
448    */
449   const Vector3& GetTargetPosition() const
450   {
451     return mTargetPosition;
452   }
453
454   /**
455    * @copydoc Dali::Actor::GetCurrentWorldPosition()
456    */
457   const Vector3& GetCurrentWorldPosition() const;
458
459   /**
460    * @copydoc Dali::Actor::SetInheritPosition()
461    */
462   void SetInheritPosition(bool inherit);
463
464   /**
465    * @copydoc Dali::Actor::IsPositionInherited()
466    */
467   bool IsPositionInherited() const
468   {
469     return mInheritPosition;
470   }
471
472   /**
473    * Sets the orientation of the Actor.
474    * @param [in] angleRadians The new orientation angle in radians.
475    * @param [in] axis The new axis of orientation.
476    */
477   void SetOrientation(const Radian& angleRadians, const Vector3& axis);
478
479   /**
480    * Sets the orientation of the Actor.
481    * @param [in] orientation The new orientation.
482    */
483   void SetOrientation(const Quaternion& orientation);
484
485   /**
486    * Rotate an actor around its existing rotation axis.
487    * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
488    * @param[in] axis The axis of the rotation to combine with the existing rotation.
489    */
490   void RotateBy(const Radian& angleRadians, const Vector3& axis);
491
492   /**
493    * Apply a relative rotation to an actor.
494    * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
495    */
496   void RotateBy(const Quaternion& relativeRotation);
497
498   /**
499    * Retreive the Actor's orientation.
500    * @return the orientation.
501    */
502   const Quaternion& GetCurrentOrientation() const;
503
504   /**
505    * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
506    * Switching this off means that using SetOrientation() sets the actor's world orientation.
507    * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
508    */
509   void SetInheritOrientation(bool inherit);
510
511   /**
512    * Returns whether the actor inherit's it's parent's orientation.
513    * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
514    */
515   bool IsOrientationInherited() const
516   {
517     return mInheritOrientation;
518   }
519
520   /**
521    * Sets the factor of the parents size used for the child actor.
522    * Note: Only used if ResizePolicy is ResizePolicy::SIZE_RELATIVE_TO_PARENT or ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT.
523    * @param[in] factor The vector to multiply the parents size by to get the childs size.
524    */
525   void SetSizeModeFactor(const Vector3& factor);
526
527   /**
528    * Gets the factor of the parents size used for the child actor.
529    * Note: Only used if ResizePolicy is ResizePolicy::SIZE_RELATIVE_TO_PARENT or ResizePolicy::SIZE_FIXED_OFFSET_FROM_PARENT.
530    * @return The vector being used to multiply the parents size by to get the childs size.
531    */
532   const Vector3& GetSizeModeFactor() const;
533
534   /**
535    * @copydoc Dali::Actor::GetCurrentWorldOrientation()
536    */
537   const Quaternion& GetCurrentWorldOrientation() const;
538
539   /**
540    * Sets a scale factor applied to an actor.
541    * @param [in] scale The scale factor applied on all axes.
542    */
543   void SetScale(float scale);
544
545   /**
546    * Sets a scale factor applied to an actor.
547    * @param [in] scaleX The scale factor applied along the x-axis.
548    * @param [in] scaleY The scale factor applied along the y-axis.
549    * @param [in] scaleZ The scale factor applied along the z-axis.
550    */
551   void SetScale(float scaleX, float scaleY, float scaleZ);
552
553   /**
554    * Sets a scale factor applied to an actor.
555    * @param [in] scale A vector representing the scale factor for each axis.
556    */
557   void SetScale(const Vector3& scale);
558
559   /**
560    * Set the x component of the scale factor.
561    * @param [in] x The new x value.
562    */
563   void SetScaleX(float x);
564
565   /**
566    * Set the y component of the scale factor.
567    * @param [in] y The new y value.
568    */
569   void SetScaleY(float y);
570
571   /**
572    * Set the z component of the scale factor.
573    * @param [in] z The new z value.
574    */
575   void SetScaleZ(float z);
576
577   /**
578    * Apply a relative scale to an actor.
579    * @param[in] relativeScale The scale to combine with the actors existing scale.
580    */
581   void ScaleBy(const Vector3& relativeScale);
582
583   /**
584    * Retrieve the scale factor applied to an actor.
585    * @return A vector representing the scale factor for each axis.
586    */
587   const Vector3& GetCurrentScale() const;
588
589   /**
590    * @copydoc Dali::Actor::GetCurrentWorldScale()
591    */
592   const Vector3& GetCurrentWorldScale() const;
593
594   /**
595    * @copydoc Dali::Actor::SetInheritScale()
596    */
597   void SetInheritScale(bool inherit);
598
599   /**
600    * @copydoc Dali::Actor::IsScaleInherited()
601    */
602   bool IsScaleInherited() const
603   {
604     return mInheritScale;
605   }
606
607   /**
608    * @copydoc Dali::Actor::GetCurrentWorldMatrix()
609    */
610   Matrix GetCurrentWorldMatrix() const;
611
612   // Visibility
613
614   /**
615    * Sets the visibility flag of an actor.
616    * @param[in] visible The new visibility flag.
617    */
618   void SetVisible(bool visible);
619
620   /**
621    * Retrieve the visibility flag of an actor.
622    * @return The visibility flag.
623    */
624   bool IsVisible() const;
625
626   /**
627    * Sets the opacity of an actor.
628    * @param [in] opacity The new opacity.
629    */
630   void SetOpacity(float opacity);
631
632   /**
633    * Retrieve the actor's opacity.
634    * @return The actor's opacity.
635    */
636   float GetCurrentOpacity() const;
637
638   /**
639    * Retrieve the actor's clipping mode.
640    * @return The actor's clipping mode (cached)
641    */
642   ClippingMode::Type GetClippingMode() const
643   {
644     return mClippingMode;
645   }
646
647   /**
648    * Sets whether an actor should emit touch or hover signals; see SignalTouch() and SignalHover().
649    * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
650    * the touch event signal will be emitted, and as soon as an application connects to the SignalHover(), the
651    * hover event signal will be emitted.
652    *
653    * If the application wishes to temporarily disable the touch or hover event signal emission, then they can do so by calling:
654    * @code
655    * actor.SetSensitive(false);
656    * @endcode
657    *
658    * Then, to re-enable the touch or hover event signal emission, the application should call:
659    * @code
660    * actor.SetSensitive(true);
661    * @endcode
662    *
663    * @see SignalTouch() and SignalHover().
664    * @note If an actor's sensitivity is set to false, then it's children will not emit a touch or hover event signal either.
665    * @param[in]  sensitive  true to enable emission of the touch or hover event signals, false otherwise.
666    */
667   void SetSensitive(bool sensitive)
668   {
669     mSensitive = sensitive;
670   }
671
672   /**
673    * Query whether an actor emits touch or hover event signals.
674    * @see SetSensitive(bool)
675    * @return true, if emission of touch or hover event signals is enabled, false otherwise.
676    */
677   bool IsSensitive() const
678   {
679     return mSensitive;
680   }
681
682   /**
683    * @copydoc Dali::Actor::SetDrawMode
684    */
685   void SetDrawMode(DrawMode::Type drawMode);
686
687   /**
688    * @copydoc Dali::Actor::GetDrawMode
689    */
690   DrawMode::Type GetDrawMode() const
691   {
692     return mDrawMode;
693   }
694
695   /**
696    * @copydoc Dali::Actor::IsOverlay
697    */
698   bool IsOverlay() const
699   {
700     return (DrawMode::OVERLAY_2D == mDrawMode);
701   }
702
703   /**
704    * Sets the actor's color.  The final color of actor depends on its color mode.
705    * This final color is applied to the drawable elements of an actor.
706    * @param [in] color The new color.
707    */
708   void SetColor(const Vector4& color);
709
710   /**
711    * Set the red component of the color.
712    * @param [in] red The new red component.
713    */
714   void SetColorRed(float red);
715
716   /**
717    * Set the green component of the color.
718    * @param [in] green The new green component.
719    */
720   void SetColorGreen(float green);
721
722   /**
723    * Set the blue component of the scale factor.
724    * @param [in] blue The new blue value.
725    */
726   void SetColorBlue(float blue);
727
728   /**
729    * Retrieve the actor's color.
730    * @return The color.
731    */
732   const Vector4& GetCurrentColor() const;
733
734   /**
735    * Sets the actor's color mode.
736    * Color mode specifies whether Actor uses its own color or inherits its parent color
737    * @param [in] colorMode to use.
738    */
739   void SetColorMode(ColorMode colorMode);
740
741   /**
742    * Returns the actor's color mode.
743    * @return currently used colorMode.
744    */
745   ColorMode GetColorMode() const
746   {
747     return mColorMode;
748   }
749
750   /**
751    * @copydoc Dali::Actor::GetCurrentWorldColor()
752    */
753   const Vector4& GetCurrentWorldColor() const;
754
755   /**
756    * @copydoc Dali::Actor::GetHierarchyDepth()
757    */
758   inline int32_t GetHierarchyDepth() const
759   {
760     if(mIsOnScene)
761     {
762       return mDepth;
763     }
764
765     return -1;
766   }
767
768   /**
769    * Get the actor's sorting depth
770    *
771    * @return The depth used for hit-testing and renderer sorting
772    */
773   uint32_t GetSortingDepth()
774   {
775     return mSortedDepth;
776   }
777
778 public:
779   // Size negotiation virtual functions
780
781   /**
782    * @brief Called after the size negotiation has been finished for this control.
783    *
784    * The control is expected to assign this given size to itself/its children.
785    *
786    * Should be overridden by derived classes if they need to layout
787    * actors differently after certain operations like add or remove
788    * actors, resize or after changing specific properties.
789    *
790    * Note! As this function is called from inside the size negotiation algorithm, you cannot
791    * call RequestRelayout (the call would just be ignored)
792    *
793    * @param[in]      size       The allocated size.
794    * @param[in,out]  container  The control should add actors to this container that it is not able
795    *                            to allocate a size for.
796    */
797   virtual void OnRelayout(const Vector2& size, RelayoutContainer& container)
798   {
799   }
800
801   /**
802    * @brief Notification for deriving classes when the resize policy is set
803    *
804    * @param[in] policy The policy being set
805    * @param[in] dimension The dimension the policy is being set for
806    */
807   virtual void OnSetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension)
808   {
809   }
810
811   /**
812    * @brief Virtual method to notify deriving classes that relayout dependencies have been
813    * met and the size for this object is about to be calculated for the given dimension
814    *
815    * @param dimension The dimension that is about to be calculated
816    */
817   virtual void OnCalculateRelayoutSize(Dimension::Type dimension)
818   {
819   }
820
821   /**
822    * @brief Virtual method to notify deriving classes that the size for a dimension
823    * has just been negotiated
824    *
825    * @param[in] size The new size for the given dimension
826    * @param[in] dimension The dimension that was just negotiated
827    */
828   virtual void OnLayoutNegotiated(float size, Dimension::Type dimension)
829   {
830   }
831
832   /**
833    * @brief Determine if this actor is dependent on it's children for relayout
834    *
835    * @param dimension The dimension(s) to check for
836    * @return Return if the actor is dependent on it's children
837    */
838   virtual bool RelayoutDependentOnChildren(Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
839
840   /**
841    * @brief Determine if this actor is dependent on it's children for relayout.
842    *
843    * Called from deriving classes
844    *
845    * @param dimension The dimension(s) to check for
846    * @return Return if the actor is dependent on it's children
847    */
848   virtual bool RelayoutDependentOnChildrenBase(Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
849
850   /**
851    * @brief Calculate the size for a child
852    *
853    * @param[in] child The child actor to calculate the size for
854    * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
855    * @return Return the calculated size for the given dimension
856    */
857   virtual float CalculateChildSize(const Dali::Actor& child, Dimension::Type dimension);
858
859   /**
860    * @brief This method is called during size negotiation when a height is required for a given width.
861    *
862    * Derived classes should override this if they wish to customize the height returned.
863    *
864    * @param width to use.
865    * @return the height based on the width.
866    */
867   virtual float GetHeightForWidth(float width);
868
869   /**
870    * @brief This method is called during size negotiation when a width is required for a given height.
871    *
872    * Derived classes should override this if they wish to customize the width returned.
873    *
874    * @param height to use.
875    * @return the width based on the width.
876    */
877   virtual float GetWidthForHeight(float height);
878
879 public:
880   // Size negotiation
881
882   /**
883    * @brief Called by the RelayoutController to negotiate the size of an actor.
884    *
885    * The size allocated by the the algorithm is passed in which the
886    * actor must adhere to.  A container is passed in as well which
887    * the actor should populate with actors it has not / or does not
888    * need to handle in its size negotiation.
889    *
890    * @param[in]      size       The allocated size.
891    * @param[in,out]  container  The container that holds actors that are fed back into the
892    *                            RelayoutController algorithm.
893    */
894   void NegotiateSize(const Vector2& size, RelayoutContainer& container);
895
896   /**
897    * @brief Set whether size negotiation should use the assigned size of the actor
898    * during relayout for the given dimension(s)
899    *
900    * @param[in] use Whether the assigned size of the actor should be used
901    * @param[in] dimension The dimension(s) to set. Can be a bitfield of multiple dimensions
902    */
903   void SetUseAssignedSize(bool use, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
904
905   /**
906    * @brief Returns whether size negotiation should use the assigned size of the actor
907    * during relayout for a single dimension
908    *
909    * @param[in] dimension The dimension to get
910    * @return Return whether the assigned size of the actor should be used. If more than one dimension is requested, just return the first one found
911    */
912   bool GetUseAssignedSize(Dimension::Type dimension) const;
913
914   /**
915    * @copydoc Dali::Actor::SetResizePolicy()
916    */
917   void SetResizePolicy(ResizePolicy::Type policy, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
918
919   /**
920    * @copydoc Dali::Actor::GetResizePolicy()
921    */
922   ResizePolicy::Type GetResizePolicy(Dimension::Type dimension) const;
923
924   /**
925    * @copydoc Dali::Actor::SetSizeScalePolicy()
926    */
927   void SetSizeScalePolicy(SizeScalePolicy::Type policy);
928
929   /**
930    * @copydoc Dali::Actor::GetSizeScalePolicy()
931    */
932   SizeScalePolicy::Type GetSizeScalePolicy() const;
933
934   /**
935    * @copydoc Dali::Actor::SetDimensionDependency()
936    */
937   void SetDimensionDependency(Dimension::Type dimension, Dimension::Type dependency);
938
939   /**
940    * @copydoc Dali::Actor::GetDimensionDependency()
941    */
942   Dimension::Type GetDimensionDependency(Dimension::Type dimension) const;
943
944   /**
945    * @brief Set the size negotiation relayout enabled on this actor
946    *
947    * @param[in] relayoutEnabled Boolean to enable or disable relayout
948    */
949   void SetRelayoutEnabled(bool relayoutEnabled);
950
951   /**
952    * @brief Return if relayout is enabled
953    *
954    * @return Return if relayout is enabled or not for this actor
955    */
956   bool IsRelayoutEnabled() const;
957
958   /**
959    * @brief Mark an actor as having it's layout dirty
960    *
961    * @param dirty Whether to mark actor as dirty or not
962    * @param dimension The dimension(s) to mark as dirty
963    */
964   void SetLayoutDirty(bool dirty, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
965
966   /**
967    * @brief Return if any of an actor's dimensions are marked as dirty
968    *
969    * @param dimension The dimension(s) to check
970    * @return Return if any of the requested dimensions are dirty
971    */
972   bool IsLayoutDirty(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) const;
973
974   /**
975    * @brief Returns if relayout is enabled and the actor is not dirty
976    *
977    * @return Return if it is possible to relayout the actor
978    */
979   bool RelayoutPossible(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) const;
980
981   /**
982    * @brief Returns if relayout is enabled and the actor is dirty
983    *
984    * @return Return if it is required to relayout the actor
985    */
986   bool RelayoutRequired(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) const;
987
988   /**
989    * @brief Request a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene)
990    *
991    * This method is automatically called from OnSceneConnection(), OnChildAdd(),
992    * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and SetMaximumSize().
993    *
994    * This method can also be called from a derived class every time it needs a different size.
995    * At the end of event processing, the relayout process starts and
996    * all controls which requested Relayout will have their sizes (re)negotiated.
997    *
998    * @note RelayoutRequest() can be called multiple times; the size negotiation is still
999    * only performed once, i.e. there is no need to keep track of this in the calling side.
1000    */
1001   void RelayoutRequest(Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
1002
1003   /**
1004    * @brief Determine if this actor is dependent on it's parent for relayout
1005    *
1006    * @param dimension The dimension(s) to check for
1007    * @return Return if the actor is dependent on it's parent
1008    */
1009   bool RelayoutDependentOnParent(Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
1010
1011   /**
1012    * @brief Determine if this actor has another dimension depedent on the specified one
1013    *
1014    * @param dimension The dimension to check for
1015    * @param dependentDimension The dimension to check for dependency with
1016    * @return Return if the actor is dependent on this dimension
1017    */
1018   bool RelayoutDependentOnDimension(Dimension::Type dimension, Dimension::Type dependentDimension);
1019
1020   /**
1021    * @brief Calculate the size of a dimension
1022    *
1023    * @param[in] dimension The dimension to calculate the size for
1024    * @param[in] maximumSize The upper bounds on the size
1025    * @return Return the calculated size for the dimension
1026    */
1027   float CalculateSize(Dimension::Type dimension, const Vector2& maximumSize);
1028
1029   /**
1030    * Negotiate a dimension based on the size of the parent
1031    *
1032    * @param[in] dimension The dimension to negotiate on
1033    * @return Return the negotiated size
1034    */
1035   float NegotiateFromParent(Dimension::Type dimension);
1036
1037   /**
1038    * Negotiate a dimension based on the size of the parent. Fitting inside.
1039    *
1040    * @param[in] dimension The dimension to negotiate on
1041    * @return Return the negotiated size
1042    */
1043   float NegotiateFromParentFit(Dimension::Type dimension);
1044
1045   /**
1046    * Negotiate a dimension based on the size of the parent. Flooding the whole space.
1047    *
1048    * @param[in] dimension The dimension to negotiate on
1049    * @return Return the negotiated size
1050    */
1051   float NegotiateFromParentFlood(Dimension::Type dimension);
1052
1053   /**
1054    * @brief Negotiate a dimension based on the size of the children
1055    *
1056    * @param[in] dimension The dimension to negotiate on
1057    * @return Return the negotiated size
1058    */
1059   float NegotiateFromChildren(Dimension::Type dimension);
1060
1061   /**
1062    * Set the negotiated dimension value for the given dimension(s)
1063    *
1064    * @param negotiatedDimension The value to set
1065    * @param dimension The dimension(s) to set the value for
1066    */
1067   void SetNegotiatedDimension(float negotiatedDimension, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
1068
1069   /**
1070    * Return the value of negotiated dimension for the given dimension
1071    *
1072    * @param dimension The dimension to retrieve
1073    * @return Return the value of the negotiated dimension
1074    */
1075   float GetNegotiatedDimension(Dimension::Type dimension) const;
1076
1077   /**
1078    * @brief Set the padding for a dimension
1079    *
1080    * @param[in] padding Padding for the dimension. X = start (e.g. left, bottom), y = end (e.g. right, top)
1081    * @param[in] dimension The dimension to set
1082    */
1083   void SetPadding(const Vector2& padding, Dimension::Type dimension);
1084
1085   /**
1086    * Return the value of padding for the given dimension
1087    *
1088    * @param dimension The dimension to retrieve
1089    * @return Return the value of padding for the dimension
1090    */
1091   Vector2 GetPadding(Dimension::Type dimension) const;
1092
1093   /**
1094    * Return the actor size for a given dimension
1095    *
1096    * @param[in] dimension The dimension to retrieve the size for
1097    * @return Return the size for the given dimension
1098    */
1099   float GetSize(Dimension::Type dimension) const;
1100
1101   /**
1102    * Return the natural size of the actor for a given dimension
1103    *
1104    * @param[in] dimension The dimension to retrieve the size for
1105    * @return Return the natural size for the given dimension
1106    */
1107   float GetNaturalSize(Dimension::Type dimension) const;
1108
1109   /**
1110    * @brief Return the amount of size allocated for relayout
1111    *
1112    * May include padding
1113    *
1114    * @param[in] dimension The dimension to retrieve
1115    * @return Return the size
1116    */
1117   float GetRelayoutSize(Dimension::Type dimension) const;
1118
1119   /**
1120    * @brief If the size has been negotiated return that else return normal size
1121    *
1122    * @param[in] dimension The dimension to retrieve
1123    * @return Return the size
1124    */
1125   float GetLatestSize(Dimension::Type dimension) const;
1126
1127   /**
1128    * Apply the negotiated size to the actor
1129    *
1130    * @param[in] container The container to fill with actors that require further relayout
1131    */
1132   void SetNegotiatedSize(RelayoutContainer& container);
1133
1134   /**
1135    * @brief Flag the actor as having it's layout dimension negotiated.
1136    *
1137    * @param[in] negotiated The status of the flag to set.
1138    * @param[in] dimension The dimension to set the flag for
1139    */
1140   void SetLayoutNegotiated(bool negotiated, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
1141
1142   /**
1143    * @brief Test whether the layout dimension for this actor has been negotiated or not.
1144    *
1145    * @param[in] dimension The dimension to determine the value of the flag for
1146    * @return Return if the layout dimension is negotiated or not.
1147    */
1148   bool IsLayoutNegotiated(Dimension::Type dimension = Dimension::ALL_DIMENSIONS) const;
1149
1150   /**
1151    * @brief provides the Actor implementation of GetHeightForWidth
1152    * @param width to use.
1153    * @return the height based on the width.
1154    */
1155   float GetHeightForWidthBase(float width);
1156
1157   /**
1158    * @brief provides the Actor implementation of GetWidthForHeight
1159    * @param height to use.
1160    * @return the width based on the height.
1161    */
1162   float GetWidthForHeightBase(float height);
1163
1164   /**
1165    * @brief Calculate the size for a child
1166    *
1167    * @param[in] child The child actor to calculate the size for
1168    * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
1169    * @return Return the calculated size for the given dimension
1170    */
1171   float CalculateChildSizeBase(const Dali::Actor& child, Dimension::Type dimension);
1172
1173   /**
1174    * @brief Set the preferred size for size negotiation
1175    *
1176    * @param[in] size The preferred size to set
1177    */
1178   void SetPreferredSize(const Vector2& size);
1179
1180   /**
1181    * @brief Return the preferred size used for size negotiation
1182    *
1183    * @return Return the preferred size
1184    */
1185   Vector2 GetPreferredSize() const;
1186
1187   /**
1188    * @copydoc Dali::Actor::SetMinimumSize
1189    */
1190   void SetMinimumSize(float size, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
1191
1192   /**
1193    * @copydoc Dali::Actor::GetMinimumSize
1194    */
1195   float GetMinimumSize(Dimension::Type dimension) const;
1196
1197   /**
1198    * @copydoc Dali::Actor::SetMaximumSize
1199    */
1200   void SetMaximumSize(float size, Dimension::Type dimension = Dimension::ALL_DIMENSIONS);
1201
1202   /**
1203    * @copydoc Dali::Actor::GetMaximumSize
1204    */
1205   float GetMaximumSize(Dimension::Type dimension) const;
1206
1207   /**
1208    * @copydoc Dali::Actor::AddRenderer()
1209    */
1210   uint32_t AddRenderer(Renderer& renderer);
1211
1212   /**
1213    * @copydoc Dali::Actor::GetRendererCount()
1214    */
1215   uint32_t GetRendererCount() const;
1216
1217   /**
1218    * @copydoc Dali::Actor::GetRendererAt()
1219    */
1220   RendererPtr GetRendererAt(uint32_t index);
1221
1222   /**
1223    * @copydoc Dali::Actor::RemoveRenderer()
1224    */
1225   void RemoveRenderer(Renderer& renderer);
1226
1227   /**
1228    * @copydoc Dali::Actor::RemoveRenderer()
1229    */
1230   void RemoveRenderer(uint32_t index);
1231
1232   /**
1233    * @brief Set BlendEquation at each renderer that added on this Actor.
1234    */
1235   void SetBlendEquation(DevelBlendEquation::Type blendEquation);
1236
1237   /**
1238    * @brief Get Blend Equation that applied to this Actor
1239    */
1240   DevelBlendEquation::Type GetBlendEquation() const;
1241
1242   /**
1243    * @brief Set this Actor is transparent or not without any affection on the child Actors.
1244    */
1245   void SetTransparent(bool transparent);
1246
1247   /**
1248    * @brief Get this Actor is transparent or not.
1249    */
1250   bool IsTransparent() const;
1251
1252 public:
1253   /**
1254    * Converts screen coordinates into the actor's coordinate system.
1255    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1256    * @param[out] localX On return, the X-coordinate relative to the actor.
1257    * @param[out] localY On return, the Y-coordinate relative to the actor.
1258    * @param[in] screenX The screen X-coordinate.
1259    * @param[in] screenY The screen Y-coordinate.
1260    * @return True if the conversion succeeded.
1261    */
1262   bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
1263
1264   /**
1265    * Converts screen coordinates into the actor's coordinate system.
1266    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1267    * @param[in] renderTask The render-task used to display the actor.
1268    * @param[out] localX On return, the X-coordinate relative to the actor.
1269    * @param[out] localY On return, the Y-coordinate relative to the actor.
1270    * @param[in] screenX The screen X-coordinate.
1271    * @param[in] screenY The screen Y-coordinate.
1272    * @return True if the conversion succeeded.
1273    */
1274   bool ScreenToLocal(const RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const;
1275
1276   /**
1277    * Converts from the actor's coordinate system to screen coordinates.
1278    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1279    * @param[in] viewMatrix The view-matrix
1280    * @param[in] projectionMatrix The projection-matrix
1281    * @param[in] viewport The view-port
1282    * @param[out] localX On return, the X-coordinate relative to the actor.
1283    * @param[out] localY On return, the Y-coordinate relative to the actor.
1284    * @param[in] screenX The screen X-coordinate.
1285    * @param[in] screenY The screen Y-coordinate.
1286    * @return True if the conversion succeeded.
1287    */
1288   bool ScreenToLocal(const Matrix&   viewMatrix,
1289                      const Matrix&   projectionMatrix,
1290                      const Viewport& viewport,
1291                      float&          localX,
1292                      float&          localY,
1293                      float           screenX,
1294                      float           screenY) const;
1295
1296   /**
1297    * Sets whether the actor should receive a notification when touch or hover motion events leave
1298    * the boundary of the actor.
1299    *
1300    * @note By default, this is set to false as most actors do not require this.
1301    * @note Need to connect to the SignalTouch or SignalHover to actually receive this event.
1302    *
1303    * @param[in]  required  Should be set to true if a Leave event is required
1304    */
1305   void SetLeaveRequired(bool required)
1306   {
1307     mLeaveRequired = required;
1308   }
1309
1310   /**
1311    * This returns whether the actor requires touch or hover events whenever touch or hover motion events leave
1312    * the boundary of the actor.
1313    * @return true if a Leave event is required, false otherwise.
1314    */
1315   bool GetLeaveRequired() const
1316   {
1317     return mLeaveRequired;
1318   }
1319
1320   /**
1321    * @copydoc Dali::Actor::SetKeyboardFocusable()
1322    */
1323   void SetKeyboardFocusable(bool focusable)
1324   {
1325     mKeyboardFocusable = focusable;
1326   }
1327
1328   /**
1329    * @copydoc Dali::Actor::IsKeyboardFocusable()
1330    */
1331   bool IsKeyboardFocusable() const
1332   {
1333     return mKeyboardFocusable;
1334   }
1335
1336   /**
1337    * @copydoc Dali::Actor::SetKeyboardFocusableChildren()
1338    */
1339   void SetKeyboardFocusableChildren(bool focusable)
1340   {
1341     mKeyboardFocusableChildren = focusable;
1342   }
1343
1344   /**
1345    * @copydoc Dali::Actor::AreChildrenKeyBoardFocusable()
1346    */
1347   bool AreChildrenKeyBoardFocusable() const
1348   {
1349     return mKeyboardFocusableChildren;
1350   }
1351
1352   /**
1353    * Set whether this view can focus by touch.
1354    * @param[in] focusable focuable by touch.
1355    */
1356   void SetTouchFocusable(bool focusable)
1357   {
1358     mTouchFocusable = focusable;
1359   }
1360
1361   /**
1362    * This returns whether this actor can focus by touch.
1363    * @return true if this actor can focus by touch.
1364    */
1365   bool IsTouchFocusable() const
1366   {
1367     return mTouchFocusable;
1368   }
1369
1370   /**
1371    * Query whether the application or derived actor type requires intercept touch events.
1372    * @return True if intercept touch events are required.
1373    */
1374   bool GetInterceptTouchRequired() const
1375   {
1376     return !mInterceptTouchedSignal.Empty();
1377   }
1378
1379   /**
1380    * Query whether the application or derived actor type requires touch events.
1381    * @return True if touch events are required.
1382    */
1383   bool GetTouchRequired() const
1384   {
1385     return !mTouchedSignal.Empty();
1386   }
1387
1388   /**
1389    * Query whether the application or derived actor type requires hover events.
1390    * @return True if hover events are required.
1391    */
1392   bool GetHoverRequired() const
1393   {
1394     return !mHoveredSignal.Empty();
1395   }
1396
1397   /**
1398    * Query whether the application or derived actor type requires wheel events.
1399    * @return True if wheel events are required.
1400    */
1401   bool GetWheelEventRequired() const
1402   {
1403     return !mWheelEventSignal.Empty();
1404   }
1405
1406   /**
1407    * Query whether the actor is actually hittable.  This method checks whether the actor is
1408    * sensitive, has the visibility flag set to true and is not fully transparent.
1409    * @return true, if it can be hit, false otherwise.
1410    */
1411   bool IsHittable() const
1412   {
1413     return IsSensitive() && IsVisible() && (GetCurrentWorldColor().a > FULLY_TRANSPARENT) && IsNodeConnected();
1414   }
1415
1416   /**
1417    * Query whether the actor captures all touch after it starts even if touch leaves its boundary.
1418    * @return true, if it captures all touch after start
1419    */
1420   bool CapturesAllTouchAfterStart() const
1421   {
1422     return mCaptureAllTouchAfterStart;
1423   }
1424
1425   /**
1426    * Sets the touch area offset of an actor.
1427    * @param [in] offset The new offset of area (left, right, bottom, top).
1428    */
1429   void SetTouchAreaOffset(Rect<int> offset)
1430   {
1431     mTouchAreaOffset = offset;
1432   }
1433
1434   /**
1435    * Retrieve the Actor's touch area offset.
1436    * @return The Actor's touch area offset.
1437    */
1438   const Rect<int>& GetTouchAreaOffset() const
1439   {
1440     return mTouchAreaOffset;
1441   }
1442
1443   // Gestures
1444
1445   /**
1446    * Retrieve the gesture data associated with this actor. The first call to this method will
1447    * allocate space for the ActorGestureData so this should only be called if an actor really does
1448    * require gestures.
1449    * @return Reference to the ActorGestureData for this actor.
1450    * @note Once the gesture-data is created for an actor it is likely that gestures are required
1451    * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
1452    */
1453   ActorGestureData& GetGestureData();
1454
1455   /**
1456    * Queries whether the actor requires the gesture type.
1457    * @param[in] type The gesture type.
1458    * @return True if the gesture is required, false otherwise.
1459    */
1460   bool IsGestureRequired(GestureType::Value type) const;
1461
1462   // Signals
1463
1464   /**
1465    * Used by the EventProcessor to emit intercept touch event signals.
1466    * @param[in] touch The touch data.
1467    * @return True if the event was intercepted.
1468    */
1469   bool EmitInterceptTouchEventSignal(const Dali::TouchEvent& touch);
1470
1471   /**
1472    * Used by the EventProcessor to emit touch event signals.
1473    * @param[in] touch The touch data.
1474    * @return True if the event was consumed.
1475    */
1476   bool EmitTouchEventSignal(const Dali::TouchEvent& touch);
1477
1478   /**
1479    * Used by the EventProcessor to emit hover event signals.
1480    * @param[in] event The hover event.
1481    * @return True if the event was consumed.
1482    */
1483   bool EmitHoverEventSignal(const Dali::HoverEvent& event);
1484
1485   /**
1486    * Used by the EventProcessor to emit wheel event signals.
1487    * @param[in] event The wheel event.
1488    * @return True if the event was consumed.
1489    */
1490   bool EmitWheelEventSignal(const Dali::WheelEvent& event);
1491
1492   /**
1493    * @brief Emits the visibility change signal for this actor and all its children.
1494    * @param[in] visible Whether the actor has become visible or not.
1495    * @param[in] type Whether the actor's visible property has changed or a parent's.
1496    */
1497   void EmitVisibilityChangedSignal(bool visible, DevelActor::VisibilityChange::Type type);
1498
1499   /**
1500    * @brief Emits the layout direction change signal for this actor and all its children.
1501    * @param[in] type Whether the actor's layout direction property has changed or a parent's.
1502    */
1503   void EmitLayoutDirectionChangedSignal(LayoutDirection::Type type);
1504
1505   /**
1506    * @copydoc DevelActor::InterceptTouchedSignal()
1507    */
1508   Dali::Actor::TouchEventSignalType& InterceptTouchedSignal()
1509   {
1510     return mInterceptTouchedSignal;
1511   }
1512
1513   /**
1514    * @copydoc Dali::Actor::TouchedSignal()
1515    */
1516   Dali::Actor::TouchEventSignalType& TouchedSignal()
1517   {
1518     return mTouchedSignal;
1519   }
1520
1521   /**
1522    * @copydoc Dali::Actor::HoveredSignal()
1523    */
1524   Dali::Actor::HoverSignalType& HoveredSignal()
1525   {
1526     return mHoveredSignal;
1527   }
1528
1529   /**
1530    * @copydoc Dali::Actor::WheelEventSignal()
1531    */
1532   Dali::Actor::WheelEventSignalType& WheelEventSignal()
1533   {
1534     return mWheelEventSignal;
1535   }
1536
1537   /**
1538    * @copydoc Dali::Actor::OnSceneSignal()
1539    */
1540   Dali::Actor::OnSceneSignalType& OnSceneSignal()
1541   {
1542     return mOnSceneSignal;
1543   }
1544
1545   /**
1546    * @copydoc Dali::Actor::OffSceneSignal()
1547    */
1548   Dali::Actor::OffSceneSignalType& OffSceneSignal()
1549   {
1550     return mOffSceneSignal;
1551   }
1552
1553   /**
1554    * @copydoc Dali::Actor::OnRelayoutSignal()
1555    */
1556   Dali::Actor::OnRelayoutSignalType& OnRelayoutSignal()
1557   {
1558     return mOnRelayoutSignal;
1559   }
1560
1561   /**
1562    * @copydoc DevelActor::VisibilityChangedSignal
1563    */
1564   DevelActor::VisibilityChangedSignalType& VisibilityChangedSignal()
1565   {
1566     return mVisibilityChangedSignal;
1567   }
1568
1569   /**
1570    * @copydoc LayoutDirectionChangedSignal
1571    */
1572   Dali::Actor::LayoutDirectionChangedSignalType& LayoutDirectionChangedSignal()
1573   {
1574     return mLayoutDirectionChangedSignal;
1575   }
1576
1577   /**
1578    * @copydoc DevelActor::ChildAddedSignal
1579    */
1580   DevelActor::ChildChangedSignalType& ChildAddedSignal();
1581
1582   /**
1583    * @copydoc DevelActor::ChildRemovedSignal
1584    */
1585   DevelActor::ChildChangedSignalType& ChildRemovedSignal();
1586
1587   /**
1588    * @copydoc DevelActor::ChildOrderChangedSignal
1589    */
1590   DevelActor::ChildOrderChangedSignalType& ChildOrderChangedSignal();
1591
1592   /**
1593    * Connects a callback function with the object's signals.
1594    * @param[in] object The object providing the signal.
1595    * @param[in] tracker Used to disconnect the signal.
1596    * @param[in] signalName The signal to connect to.
1597    * @param[in] functor A newly allocated FunctorDelegate.
1598    * @return True if the signal was connected.
1599    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
1600    */
1601   static bool DoConnectSignal(BaseObject*                 object,
1602                               ConnectionTrackerInterface* tracker,
1603                               const std::string&          signalName,
1604                               FunctorDelegate*            functor);
1605
1606   /**
1607    * Performs actions as requested using the action name.
1608    * @param[in] object The object on which to perform the action.
1609    * @param[in] actionName The action to perform.
1610    * @param[in] attributes The attributes with which to perfrom this action.
1611    * @return true if the action was done.
1612    */
1613   static bool DoAction(BaseObject*          object,
1614                        const std::string&   actionName,
1615                        const Property::Map& attributes);
1616
1617 public:
1618   // For Animation
1619
1620   /**
1621    * For use in derived classes.
1622    * This should only be called by Animation, when the actor is resized using Animation::Resize().
1623    */
1624   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize)
1625   {
1626   }
1627
1628 protected:
1629   enum DerivedType
1630   {
1631     BASIC,
1632     LAYER,
1633     ROOT_LAYER
1634   };
1635
1636   /**
1637    * Protected Constructor.  See Actor::New().
1638    * The second-phase construction Initialize() member should be called immediately after this.
1639    * @param[in] derivedType The derived type of actor (if any).
1640    * @param[in] reference to the node
1641    */
1642   Actor(DerivedType derivedType, const SceneGraph::Node& node);
1643
1644   /**
1645    * Second-phase constructor. Must be called immediately after creating a new Actor;
1646    */
1647   void Initialize(void);
1648
1649   /**
1650    * A reference counted object may only be deleted by calling Unreference()
1651    */
1652   ~Actor() override;
1653
1654   /**
1655    * Called on a child during Add() when the parent actor is connected to the Scene.
1656    * @param[in] parentDepth The depth of the parent in the hierarchy.
1657    * @param[in] notify Emits notification if set to true.
1658    */
1659   void ConnectToScene(uint32_t parentDepth, bool notify);
1660
1661   /**
1662    * Helper for ConnectToScene, to recursively connect a tree of actors.
1663    * This is atomic i.e. not interrupted by user callbacks.
1664    * @param[in]  depth The depth in the hierarchy of the actor
1665    * @param[out] connectionList On return, the list of connected actors which require notification.
1666    */
1667   void RecursiveConnectToScene(ActorContainer& connectionList, uint32_t depth);
1668
1669   /**
1670    * Connect the Node associated with this Actor to the scene-graph.
1671    */
1672   void ConnectToSceneGraph();
1673
1674   /**
1675    * Helper for ConnectToScene, to notify a connected actor through the public API.
1676    * @param[in] notify Emits notification if set to true.
1677    */
1678   void NotifyStageConnection(bool notify);
1679
1680   /**
1681    * Called on a child during Remove() when the actor was previously on the Stage.
1682    * @param[in] notify Emits notification if set to true.
1683    */
1684   void DisconnectFromStage(bool notify);
1685
1686   /**
1687    * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1688    * This is atomic i.e. not interrupted by user callbacks.
1689    * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1690    */
1691   void RecursiveDisconnectFromStage(ActorContainer& disconnectionList);
1692
1693   /**
1694    * Disconnect the Node associated with this Actor from the scene-graph.
1695    */
1696   void DisconnectFromSceneGraph();
1697
1698   /**
1699    * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1700    * @param[in] notify Emits notification if set to true.
1701    */
1702   void NotifyStageDisconnection(bool notify);
1703
1704   /**
1705    * When the Actor is OnScene, checks whether the corresponding Node is connected to the scene graph.
1706    * @return True if the Actor is OnScene & has a Node connected to the scene graph.
1707    */
1708   bool IsNodeConnected() const;
1709
1710 public:
1711   /**
1712    * Trigger a rebuild of the actor depth tree from this root
1713    * If a Layer3D is encountered, then this doesn't descend any further.
1714    * The mSortedDepth of each actor is set appropriately.
1715    */
1716   void RebuildDepthTree();
1717
1718 protected:
1719   /**
1720    * Traverse the actor tree, inserting actors into the depth tree in sibling order.
1721    * @param[in] sceneGraphNodeDepths A vector capturing the nodes and their depth index
1722    * @param[in,out] depthIndex The current depth index (traversal index)
1723    */
1724   void DepthTraverseActorTree(OwnerPointer<SceneGraph::NodeDepths>& sceneGraphNodeDepths, int32_t& depthIndex);
1725
1726 public:
1727   // Default property extensions from Object
1728
1729   /**
1730    * @copydoc Dali::Internal::Object::SetDefaultProperty()
1731    */
1732   void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
1733
1734   /**
1735    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
1736    */
1737   void SetSceneGraphProperty(Property::Index index, const PropertyMetadata& entry, const Property::Value& value) override;
1738
1739   /**
1740    * @copydoc Dali::Internal::Object::GetDefaultProperty()
1741    */
1742   Property::Value GetDefaultProperty(Property::Index index) const override;
1743
1744   /**
1745    * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
1746    */
1747   Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
1748
1749   /**
1750    * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
1751    */
1752   void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
1753
1754   /**
1755    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
1756    */
1757   const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
1758
1759   /**
1760    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
1761    */
1762   const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
1763
1764   /**
1765    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
1766    */
1767   int32_t GetPropertyComponentIndex(Property::Index index) const override;
1768
1769   /**
1770    * @copydoc Dali::Internal::Object::IsAnimationPossible()
1771    */
1772   bool IsAnimationPossible() const override
1773   {
1774     return OnScene();
1775   }
1776
1777   /**
1778    * Retrieve the actor's node.
1779    * @return The node used by this actor
1780    */
1781   const SceneGraph::Node& GetNode() const;
1782
1783   /**
1784    * @copydoc Dali::DevelActor::Raise()
1785    */
1786   void Raise();
1787
1788   /**
1789    * @copydoc Dali::DevelActor::Lower()
1790    */
1791   void Lower();
1792
1793   /**
1794    * @copydoc Dali::DevelActor::RaiseToTop()
1795    */
1796   void RaiseToTop();
1797
1798   /**
1799    * @copydoc Dali::DevelActor::LowerToBottom()
1800    */
1801   void LowerToBottom();
1802
1803   /**
1804    * @copydoc Dali::DevelActor::RaiseAbove()
1805    */
1806   void RaiseAbove(Internal::Actor& target);
1807
1808   /**
1809    * @copydoc Dali::DevelActor::LowerBelow()
1810    */
1811   void LowerBelow(Internal::Actor& target);
1812
1813 public:
1814   /**
1815    * Sets the scene which this actor is added to.
1816    * @param[in] scene The scene
1817    */
1818   void SetScene(Scene& scene)
1819   {
1820     mScene = &scene;
1821   }
1822
1823   /**
1824    * Gets the scene which this actor is added to.
1825    * @return The scene
1826    */
1827   Scene& GetScene() const
1828   {
1829     return *mScene;
1830   }
1831
1832   LayoutDirection::Type GetLayoutDirection() const
1833   {
1834     return mLayoutDirection;
1835   }
1836
1837 private:
1838   struct SendMessage
1839   {
1840     enum Type
1841     {
1842       FALSE = 0,
1843       TRUE  = 1,
1844     };
1845   };
1846
1847   struct AnimatedSizeFlag
1848   {
1849     enum Type
1850     {
1851       CLEAR  = 0,
1852       WIDTH  = 1,
1853       HEIGHT = 2,
1854       DEPTH  = 4
1855     };
1856   };
1857
1858   struct Relayouter;
1859
1860   // Remove default constructor and copy constructor
1861   Actor()             = delete;
1862   Actor(const Actor&) = delete;
1863   Actor& operator=(const Actor& rhs) = delete;
1864
1865   /**
1866    * Set the actor's parent.
1867    * @param[in] parent The new parent.
1868    * @param[in] notify Emits notification if set to true. Default is true.
1869    */
1870   void SetParent(ActorParent* parent, bool notify = true);
1871
1872   /**
1873    * For use in derived classes, called after Initialize()
1874    */
1875   virtual void OnInitialize()
1876   {
1877   }
1878
1879   /**
1880    * For use in internal derived classes.
1881    * This is called during ConnectToScene(), after the actor has finished adding its node to the scene-graph.
1882    * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1883    */
1884   virtual void OnSceneConnectionInternal()
1885   {
1886   }
1887
1888   /**
1889    * For use in internal derived classes.
1890    * This is called during DisconnectFromStage(), before the actor removes its node from the scene-graph.
1891    * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1892    */
1893   virtual void OnSceneDisconnectionInternal()
1894   {
1895   }
1896
1897   /**
1898    * For use in external (CustomActor) derived classes.
1899    * This is called after the atomic ConnectToScene() traversal has been completed.
1900    */
1901   virtual void OnSceneConnectionExternal(int depth)
1902   {
1903   }
1904
1905   /**
1906    * For use in external (CustomActor) derived classes.
1907    * This is called after the atomic DisconnectFromStage() traversal has been completed.
1908    */
1909   virtual void OnSceneDisconnectionExternal()
1910   {
1911   }
1912
1913   /**
1914    * For use in derived classes; this is called after Add() has added a child.
1915    * @param[in] child The child that was added.
1916    */
1917   virtual void OnChildAdd(Actor& child)
1918   {
1919   }
1920
1921   /**
1922    * For use in derived classes; this is called after Remove() has attempted to remove a child( regardless of whether it succeeded or not ).
1923    * @param[in] child The child that was removed.
1924    */
1925   virtual void OnChildRemove(Actor& child)
1926   {
1927   }
1928
1929   /**
1930    * For use in derived classes.
1931    * This is called after SizeSet() has been called.
1932    */
1933   virtual void OnSizeSet(const Vector3& targetSize)
1934   {
1935   }
1936
1937   /**
1938    * @brief Retrieves the cached event side value of a default property.
1939    * @param[in]  index  The index of the property
1940    * @param[out] value  Is set with the cached value of the property if found.
1941    * @return True if value set, false otherwise.
1942    */
1943   bool GetCachedPropertyValue(Property::Index index, Property::Value& value) const;
1944
1945   /**
1946    * @brief Retrieves the current value of a default property from the scene-graph.
1947    * @param[in]  index  The index of the property
1948    * @param[out] value  Is set with the current scene-graph value of the property
1949    * @return True if value set, false otherwise.
1950    */
1951   bool GetCurrentPropertyValue(Property::Index index, Property::Value& value) const;
1952
1953   /**
1954    * @brief Ensure the relayouter is allocated
1955    */
1956   Relayouter& EnsureRelayouter();
1957
1958   /**
1959    * @brief Apply the size set policy to the input size
1960    *
1961    * @param[in] size The size to apply the policy to
1962    * @return Return the adjusted size
1963    */
1964   Vector2 ApplySizeSetPolicy(const Vector2& size);
1965
1966   /**
1967    * Retrieve the parent object of an Actor.
1968    * @return The parent object, or NULL if the Actor does not have a parent.
1969    */
1970   Object* GetParentObject() const override
1971   {
1972     return static_cast<Actor*>(mParent);
1973   }
1974
1975   /**
1976    * @brief Get the current position of the actor in screen coordinates.
1977    *
1978    * @return Returns the screen position of actor
1979    */
1980   const Vector2 GetCurrentScreenPosition() const;
1981
1982   /**
1983    * Sets the visibility flag of an actor.
1984    * @param[in] visible The new visibility flag.
1985    * @param[in] sendMessage Whether to send a message to the update thread or not.
1986    */
1987   void SetVisibleInternal(bool visible, SendMessage::Type sendMessage);
1988
1989   /**
1990    * @copydoc ActorParent::SetSiblingOrderOfChild
1991    */
1992   void SetSiblingOrderOfChild(Actor& child, uint32_t order) override;
1993
1994   /**
1995    * @copydoc ActorParent::GetSiblingOrderOfChild
1996    */
1997   uint32_t GetSiblingOrderOfChild(const Actor& child) const override;
1998
1999   /**
2000    * @copydoc ActorParent::RaiseChild
2001    */
2002   void RaiseChild(Actor& child) override;
2003
2004   /**
2005    * @copydoc ActorParent::LowerChild
2006    */
2007   void LowerChild(Actor& child) override;
2008
2009   /**
2010    * @copydoc ActorParent::RaiseChildToTop
2011    */
2012   void RaiseChildToTop(Actor& child) override;
2013
2014   /**
2015    * @copydoc ActorParent::LowerChildToBottom
2016    */
2017   void LowerChildToBottom(Actor& child) override;
2018
2019   /**
2020    * @copydoc ActorParent::RaiseChildAbove
2021    */
2022   void RaiseChildAbove(Actor& child, Actor& target) override;
2023
2024   /**
2025    * @copydoc ActorParent::LowerChildBelow()
2026    */
2027   void LowerChildBelow(Actor& child, Actor& target) override;
2028
2029   /**
2030    * Set whether a child actor inherits it's parent's layout direction. Default is to inherit.
2031    * @param[in] inherit - true if the actor should inherit layout direction, false otherwise.
2032    */
2033   void SetInheritLayoutDirection(bool inherit);
2034
2035   /**
2036    * Returns whether the actor inherits it's parent's layout direction.
2037    * @return true if the actor inherits it's parent's layout direction, false otherwise.
2038    */
2039   bool IsLayoutDirectionInherited() const
2040   {
2041     return mInheritLayoutDirection;
2042   }
2043
2044   /**
2045    * @brief Propagates layout direction recursively.
2046    * @param[in] direction New layout direction.
2047    */
2048   void InheritLayoutDirectionRecursively(Dali::LayoutDirection::Type direction, bool set = false);
2049
2050   /**
2051    * @brief Sets the update size hint of an actor.
2052    * @param [in] updateSizeHint The update size hint.
2053    */
2054   void SetUpdateSizeHint(const Vector2& updateSizeHint);
2055
2056   /**
2057    * @brief Recursively emits the visibility-changed-signal on the actor tree.
2058    *
2059    * @param[in] visible The new visibility of the actor
2060    * @param[in] type Whether the actor's visible property has changed or a parent's
2061    */
2062   void EmitVisibilityChangedSignalRecursively(bool                               visible,
2063                                               DevelActor::VisibilityChange::Type type);
2064
2065 protected:
2066   ActorParentImpl    mParentImpl;   ///< Implementation of ActorParent;
2067   ActorParent*       mParent;       ///< Each actor (except the root) can have one parent
2068   Scene*             mScene;        ///< The scene the actor is added to
2069   RendererContainer* mRenderers;    ///< Renderer container
2070   Vector3*           mParentOrigin; ///< NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
2071   Vector3*           mAnchorPoint;  ///< NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
2072   Relayouter*        mRelayoutData; ///< Struct to hold optional collection of relayout variables
2073   ActorGestureData*  mGestureData;  ///< Optional Gesture data. Only created when actor requires gestures
2074
2075   // Signals
2076   Dali::Actor::TouchEventSignalType             mInterceptTouchedSignal;
2077   Dali::Actor::TouchEventSignalType             mTouchedSignal;
2078   Dali::Actor::HoverSignalType                  mHoveredSignal;
2079   Dali::Actor::WheelEventSignalType             mWheelEventSignal;
2080   Dali::Actor::OnSceneSignalType                mOnSceneSignal;
2081   Dali::Actor::OffSceneSignalType               mOffSceneSignal;
2082   Dali::Actor::OnRelayoutSignalType             mOnRelayoutSignal;
2083   DevelActor::VisibilityChangedSignalType       mVisibilityChangedSignal;
2084   Dali::Actor::LayoutDirectionChangedSignalType mLayoutDirectionChangedSignal;
2085
2086   Quaternion mTargetOrientation; ///< Event-side storage for orientation
2087   Vector4    mTargetColor;       ///< Event-side storage for color
2088   Vector3    mTargetSize;        ///< Event-side storage for size (not a pointer as most actors will have a size)
2089   Vector3    mTargetPosition;    ///< Event-side storage for position (not a pointer as most actors will have a position)
2090   Vector3    mTargetScale;       ///< Event-side storage for scale
2091   Vector3    mAnimatedSize;      ///< Event-side storage for size animation
2092   Rect<int>  mTouchAreaOffset;   ///< touch area offset (left, right, bottom, top)
2093
2094   ConstString mName;            ///< Name of the actor
2095   uint32_t    mSortedDepth;     ///< The sorted depth index. A combination of tree traversal and sibling order.
2096   int16_t     mDepth;           ///< The depth in the hierarchy of the actor. Only 32,767 levels of depth are supported
2097   uint16_t    mUseAnimatedSize; ///< Whether the size is animated.
2098
2099   const bool               mIsRoot : 1;                    ///< Flag to identify the root actor
2100   const bool               mIsLayer : 1;                   ///< Flag to identify that this is a layer
2101   bool                     mIsOnScene : 1;                 ///< Flag to identify whether the actor is on-scene
2102   bool                     mSensitive : 1;                 ///< Whether the actor emits touch event signals
2103   bool                     mLeaveRequired : 1;             ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
2104   bool                     mKeyboardFocusable : 1;         ///< Whether the actor should be focusable by keyboard navigation
2105   bool                     mKeyboardFocusableChildren : 1; ///< Whether the children of this actor can be focusable by keyboard navigation.
2106   bool                     mTouchFocusable : 1;            ///< Whether the actor should be focusable by touch
2107   bool                     mOnSceneSignalled : 1;          ///< Set to true before OnSceneConnection signal is emitted, and false before OnSceneDisconnection
2108   bool                     mInsideOnSizeSet : 1;           ///< Whether we are inside OnSizeSet
2109   bool                     mInheritPosition : 1;           ///< Cached: Whether the parent's position should be inherited.
2110   bool                     mInheritOrientation : 1;        ///< Cached: Whether the parent's orientation should be inherited.
2111   bool                     mInheritScale : 1;              ///< Cached: Whether the parent's scale should be inherited.
2112   bool                     mPositionUsesAnchorPoint : 1;   ///< Cached: Whether the position uses the anchor point or not.
2113   bool                     mVisible : 1;                   ///< Cached: Whether the actor is visible or not.
2114   bool                     mInheritLayoutDirection : 1;    ///< Whether the actor inherits the layout direction from parent.
2115   bool                     mCaptureAllTouchAfterStart : 1; ///< Whether the actor should capture all touch after touch starts even if the motion moves outside of the actor area.
2116   bool                     mIsBlendEquationSet : 1;        ///< Flag to identify whether the Blend equation is set
2117   bool                     mNeedGesturePropagation : 1;    ///< Whether the parent listens for gesture events or not
2118   LayoutDirection::Type    mLayoutDirection : 2;           ///< Layout direction, Left to Right or Right to Left.
2119   DrawMode::Type           mDrawMode : 3;                  ///< Cached: How the actor and its children should be drawn
2120   ColorMode                mColorMode : 3;                 ///< Cached: Determines whether mWorldColor is inherited
2121   ClippingMode::Type       mClippingMode : 3;              ///< Cached: Determines which clipping mode (if any) to use.
2122   DevelBlendEquation::Type mBlendEquation : 16;            ///< Cached: Determines which blend equation will be used to render renderers.
2123
2124 private:
2125   static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)
2126
2127   struct PropertyHandler;
2128   struct SiblingHandler;
2129
2130   friend class ActorParentImpl; // Allow impl to call private methods on actor
2131 };
2132
2133 } // namespace Internal
2134
2135 // Helpers for public-api forwarding methods
2136
2137 inline Internal::Actor& GetImplementation(Dali::Actor& actor)
2138 {
2139   DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
2140
2141   BaseObject& handle = actor.GetBaseObject();
2142
2143   return static_cast<Internal::Actor&>(handle);
2144 }
2145
2146 inline const Internal::Actor& GetImplementation(const Dali::Actor& actor)
2147 {
2148   DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
2149
2150   const BaseObject& handle = actor.GetBaseObject();
2151
2152   return static_cast<const Internal::Actor&>(handle);
2153 }
2154
2155 } // namespace Dali
2156
2157 #endif // DALI_INTERNAL_ACTOR_H