Refactored more code into Actor::Relayouter
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.h
index 7bd7e4a..73a98aa 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_INTERNAL_ACTOR_H
 
 /*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 
 // INTERNAL INCLUDES
 #include <dali/devel-api/actors/actor-devel.h>
+#include <dali/devel-api/rendering/renderer-devel.h>
+#include <dali/internal/common/const-string.h>
 #include <dali/internal/common/internal-constants.h>
 #include <dali/internal/common/memory-pool-object-allocator.h>
 #include <dali/internal/event/actors/actor-declarations.h>
 #include <dali/internal/event/actors/actor-parent-impl.h>
 #include <dali/internal/event/actors/actor-parent.h>
+#include <dali/internal/event/actors/actor-renderer-container.h>
 #include <dali/internal/event/common/object-impl.h>
 #include <dali/internal/event/common/stage-def.h>
-#include <dali/internal/event/rendering/renderer-impl.h>
-#include <dali/internal/update/manager/update-manager.h>
 #include <dali/internal/update/nodes/node-declarations.h>
 #include <dali/public-api/actors/actor.h>
 #include <dali/public-api/common/dali-common.h>
@@ -57,9 +58,6 @@ class RenderTask;
 class Renderer;
 class Scene;
 
-using RendererContainer = std::vector<RendererPtr>;
-using RendererIter      = RendererContainer::iterator;
-
 class ActorDepthTreeNode;
 using DepthNodeMemoryPool = Dali::Internal::MemoryPoolObjectAllocator<ActorDepthTreeNode>;
 
@@ -127,16 +125,16 @@ public:
    * Retrieve the name of the actor.
    * @return The name.
    */
-  const std::string& GetName() const
+  std::string_view GetName() const
   {
-    return mName;
+    return mName.GetStringView();
   }
 
   /**
    * Set the name of the actor.
    * @param[in] name The new name.
    */
-  void SetName(const std::string& name);
+  void SetName(std::string_view name);
 
   /**
    * @copydoc Dali::Actor::GetId
@@ -169,7 +167,7 @@ public:
   bool IsRenderable() const
   {
     // inlined as this is called a lot in hit testing
-    return mRenderers && !mRenderers->empty();
+    return mRenderers && !mRenderers->IsEmpty();
   }
 
   /**
@@ -191,12 +189,17 @@ public:
   /**
    * @copydoc Dali::Internal::ActorParent::Add()
    */
-  void Add(Actor& child) override;
+  void Add(Actor& child, bool notify = true) override;
 
   /**
    * @copydoc Dali::Internal::ActorParent::Remove()
    */
-  void Remove(Actor& child) override;
+  void Remove(Actor& child, bool notify = true) override;
+
+  /**
+   * @copydoc Dali::DevelActor::SwitchParent()
+   */
+  void SwitchParent(Actor& newParent);
 
   /**
    * @copydoc Dali::Actor::Unparent
@@ -224,7 +227,7 @@ public:
   /**
    * @copydoc Dali::Internal::ActorParent::FindChildByName
    */
-  ActorPtr FindChildByName(const std::string& actorName) override;
+  ActorPtr FindChildByName(ConstString actorName) override;
 
   /**
    * @copydoc Dali::Internal::ActorParent::FindChildById
@@ -253,6 +256,23 @@ public:
   Rect<> CalculateScreenExtents() const;
 
   /**
+   * @copydoc DevelActor::SetNeedGesturePropagation.
+   */
+  void SetNeedGesturePropagation(bool propagation)
+  {
+    mNeedGesturePropagation = propagation;
+  }
+
+  /**
+   * Retrieve need gesture propagation value
+   * @return The actor's need gesture propagation value.
+   */
+  bool NeedGesturePropagation() const
+  {
+    return mNeedGesturePropagation;
+  }
+
+  /**
    * Sets the size of an actor.
    * This does not interfere with the actors scale factor.
    * @param [in] width  The new width.
@@ -369,6 +389,13 @@ public:
   const Vector3& GetCurrentAnchorPoint() const;
 
   /**
+   * If the position uses the anchor point, return the anchor point, otherwise
+   * return top left.
+   * @return The anchor point for positioning.
+   */
+  Vector3 GetAnchorPointForPosition() const;
+
+  /**
    * Sets the position of the Actor.
    * The coordinates are relative to the Actor's parent.
    * The Actor's z position will be set to 0.0f.
@@ -753,11 +780,20 @@ public:
    *
    * @return The depth used for hit-testing and renderer sorting
    */
-  uint32_t GetSortingDepth()
+  inline uint32_t GetSortingDepth()
   {
     return mSortedDepth;
   }
 
+  /**
+   * Set the actor's sorted depth. Used during recreation of depth tree
+   * @param[in] sortedDepth the new sorted depth
+   */
+  inline void SetSortingDepth(uint32_t sortedDepth)
+  {
+    mSortedDepth = sortedDepth;
+  }
+
 public:
   // Size negotiation virtual functions
 
@@ -1018,22 +1054,6 @@ public:
   float NegotiateFromParent(Dimension::Type dimension);
 
   /**
-   * Negotiate a dimension based on the size of the parent. Fitting inside.
-   *
-   * @param[in] dimension The dimension to negotiate on
-   * @return Return the negotiated size
-   */
-  float NegotiateFromParentFit(Dimension::Type dimension);
-
-  /**
-   * Negotiate a dimension based on the size of the parent. Flooding the whole space.
-   *
-   * @param[in] dimension The dimension to negotiate on
-   * @return Return the negotiated size
-   */
-  float NegotiateFromParentFlood(Dimension::Type dimension);
-
-  /**
    * @brief Negotiate a dimension based on the size of the children
    *
    * @param[in] dimension The dimension to negotiate on
@@ -1213,7 +1233,7 @@ public:
   void RemoveRenderer(uint32_t index);
 
   /**
-   * Set BlendEquation at each renderer that added on this Actor.
+   * @brief Set BlendEquation at each renderer that added on this Actor.
    */
   void SetBlendEquation(DevelBlendEquation::Type blendEquation);
 
@@ -1222,6 +1242,16 @@ public:
    */
   DevelBlendEquation::Type GetBlendEquation() const;
 
+  /**
+   * @brief Set this Actor is transparent or not without any affection on the child Actors.
+   */
+  void SetTransparent(bool transparent);
+
+  /**
+   * @brief Get this Actor is transparent or not.
+   */
+  bool IsTransparent() const;
+
 public:
   /**
    * Converts screen coordinates into the actor's coordinate system.
@@ -1307,6 +1337,40 @@ public:
   }
 
   /**
+   * @copydoc Dali::Actor::SetKeyboardFocusableChildren()
+   */
+  void SetKeyboardFocusableChildren(bool focusable)
+  {
+    mKeyboardFocusableChildren = focusable;
+  }
+
+  /**
+   * @copydoc Dali::Actor::AreChildrenKeyBoardFocusable()
+   */
+  bool AreChildrenKeyBoardFocusable() const
+  {
+    return mKeyboardFocusableChildren;
+  }
+
+  /**
+   * Set whether this view can focus by touch.
+   * @param[in] focusable focuable by touch.
+   */
+  void SetTouchFocusable(bool focusable)
+  {
+    mTouchFocusable = focusable;
+  }
+
+  /**
+   * This returns whether this actor can focus by touch.
+   * @return true if this actor can focus by touch.
+   */
+  bool IsTouchFocusable() const
+  {
+    return mTouchFocusable;
+  }
+
+  /**
    * Query whether the application or derived actor type requires intercept touch events.
    * @return True if intercept touch events are required.
    */
@@ -1362,21 +1426,21 @@ public:
   }
 
   /**
-   * Sets the touch area of an actor.
-   * @param [in] area The new area.
+   * Sets the touch area offset of an actor.
+   * @param [in] offset The new offset of area (left, right, bottom, top).
    */
-  void SetTouchArea(Vector2 area)
+  void SetTouchAreaOffset(Rect<int> offset)
   {
-    mTouchArea = area;
+    mTouchAreaOffset = offset;
   }
 
   /**
-   * Retrieve the Actor's touch area.
-   * @return The Actor's touch area.
+   * Retrieve the Actor's touch area offset.
+   * @return The Actor's touch area offset.
    */
-  const Vector2& GetTouchArea() const
+  const Rect<int>& GetTouchAreaOffset() const
   {
-    return mTouchArea;
+    return mTouchAreaOffset;
   }
 
   // Gestures
@@ -1528,31 +1592,6 @@ public:
    */
   DevelActor::ChildOrderChangedSignalType& ChildOrderChangedSignal();
 
-  /**
-   * Connects a callback function with the object's signals.
-   * @param[in] object The object providing the signal.
-   * @param[in] tracker Used to disconnect the signal.
-   * @param[in] signalName The signal to connect to.
-   * @param[in] functor A newly allocated FunctorDelegate.
-   * @return True if the signal was connected.
-   * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
-   */
-  static bool DoConnectSignal(BaseObject*                 object,
-                              ConnectionTrackerInterface* tracker,
-                              const std::string&          signalName,
-                              FunctorDelegate*            functor);
-
-  /**
-   * Performs actions as requested using the action name.
-   * @param[in] object The object on which to perform the action.
-   * @param[in] actionName The action to perform.
-   * @param[in] attributes The attributes with which to perfrom this action.
-   * @return true if the action was done.
-   */
-  static bool DoAction(BaseObject*          object,
-                       const std::string&   actionName,
-                       const Property::Map& attributes);
-
 public:
   // For Animation
 
@@ -1593,16 +1632,9 @@ protected:
   /**
    * Called on a child during Add() when the parent actor is connected to the Scene.
    * @param[in] parentDepth The depth of the parent in the hierarchy.
+   * @param[in] notify Emits notification if set to true.
    */
-  void ConnectToScene(uint32_t parentDepth);
-
-  /**
-   * Helper for ConnectToScene, to recursively connect a tree of actors.
-   * This is atomic i.e. not interrupted by user callbacks.
-   * @param[in]  depth The depth in the hierarchy of the actor
-   * @param[out] connectionList On return, the list of connected actors which require notification.
-   */
-  void RecursiveConnectToScene(ActorContainer& connectionList, uint32_t depth);
+  void ConnectToScene(uint32_t parentDepth, bool notify);
 
   /**
    * Connect the Node associated with this Actor to the scene-graph.
@@ -1611,20 +1643,15 @@ protected:
 
   /**
    * Helper for ConnectToScene, to notify a connected actor through the public API.
+   * @param[in] notify Emits notification if set to true.
    */
-  void NotifyStageConnection();
+  void NotifyStageConnection(bool notify);
 
   /**
    * Called on a child during Remove() when the actor was previously on the Stage.
+   * @param[in] notify Emits notification if set to true.
    */
-  void DisconnectFromStage();
-
-  /**
-   * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
-   * This is atomic i.e. not interrupted by user callbacks.
-   * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
-   */
-  void RecursiveDisconnectFromStage(ActorContainer& disconnectionList);
+  void DisconnectFromStage(bool notify);
 
   /**
    * Disconnect the Node associated with this Actor from the scene-graph.
@@ -1633,8 +1660,9 @@ protected:
 
   /**
    * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
+   * @param[in] notify Emits notification if set to true.
    */
-  void NotifyStageDisconnection();
+  void NotifyStageDisconnection(bool notify);
 
   /**
    * When the Actor is OnScene, checks whether the corresponding Node is connected to the scene graph.
@@ -1650,14 +1678,6 @@ public:
    */
   void RebuildDepthTree();
 
-protected:
-  /**
-   * Traverse the actor tree, inserting actors into the depth tree in sibling order.
-   * @param[in] sceneGraphNodeDepths A vector capturing the nodes and their depth index
-   * @param[in,out] depthIndex The current depth index (traversal index)
-   */
-  void DepthTraverseActorTree(OwnerPointer<SceneGraph::NodeDepths>& sceneGraphNodeDepths, int32_t& depthIndex);
-
 public:
   // Default property extensions from Object
 
@@ -1713,10 +1733,7 @@ public:
    * Retrieve the actor's node.
    * @return The node used by this actor
    */
-  const SceneGraph::Node& GetNode() const
-  {
-    return *static_cast<const SceneGraph::Node*>(mUpdateObject);
-  }
+  const SceneGraph::Node& GetNode() const;
 
   /**
    * @copydoc Dali::DevelActor::Raise()
@@ -1803,8 +1820,9 @@ private:
   /**
    * Set the actor's parent.
    * @param[in] parent The new parent.
+   * @param[in] notify Emits notification if set to true. Default is true.
    */
-  void SetParent(ActorParent* parent);
+  void SetParent(ActorParent* parent, bool notify = true);
 
   /**
    * For use in derived classes, called after Initialize()
@@ -1979,26 +1997,11 @@ private:
   }
 
   /**
-   * @brief Propagates layout direction recursively.
-   * @param[in] direction New layout direction.
-   */
-  void InheritLayoutDirectionRecursively(Dali::LayoutDirection::Type direction, bool set = false);
-
-  /**
    * @brief Sets the update size hint of an actor.
    * @param [in] updateSizeHint The update size hint.
    */
   void SetUpdateSizeHint(const Vector2& updateSizeHint);
 
-  /**
-   * @brief Recursively emits the visibility-changed-signal on the actor tree.
-   *
-   * @param[in] visible The new visibility of the actor
-   * @param[in] type Whether the actor's visible property has changed or a parent's
-   */
-  void EmitVisibilityChangedSignalRecursively(bool                               visible,
-                                              DevelActor::VisibilityChange::Type type);
-
 protected:
   ActorParentImpl    mParentImpl;   ///< Implementation of ActorParent;
   ActorParent*       mParent;       ///< Each actor (except the root) can have one parent
@@ -2026,9 +2029,9 @@ protected:
   Vector3    mTargetPosition;    ///< Event-side storage for position (not a pointer as most actors will have a position)
   Vector3    mTargetScale;       ///< Event-side storage for scale
   Vector3    mAnimatedSize;      ///< Event-side storage for size animation
-  Vector2    mTouchArea;         ///< touch area
+  Rect<int>  mTouchAreaOffset;   ///< touch area offset (left, right, bottom, top)
 
-  std::string mName;            ///< Name of the actor
+  ConstString mName;            ///< Name of the actor
   uint32_t    mSortedDepth;     ///< The sorted depth index. A combination of tree traversal and sibling order.
   int16_t     mDepth;           ///< The depth in the hierarchy of the actor. Only 32,767 levels of depth are supported
   uint16_t    mUseAnimatedSize; ///< Whether the size is animated.
@@ -2039,6 +2042,8 @@ protected:
   bool                     mSensitive : 1;                 ///< Whether the actor emits touch event signals
   bool                     mLeaveRequired : 1;             ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
   bool                     mKeyboardFocusable : 1;         ///< Whether the actor should be focusable by keyboard navigation
+  bool                     mKeyboardFocusableChildren : 1; ///< Whether the children of this actor can be focusable by keyboard navigation.
+  bool                     mTouchFocusable : 1;            ///< Whether the actor should be focusable by touch
   bool                     mOnSceneSignalled : 1;          ///< Set to true before OnSceneConnection signal is emitted, and false before OnSceneDisconnection
   bool                     mInsideOnSizeSet : 1;           ///< Whether we are inside OnSizeSet
   bool                     mInheritPosition : 1;           ///< Cached: Whether the parent's position should be inherited.
@@ -2048,12 +2053,13 @@ protected:
   bool                     mVisible : 1;                   ///< Cached: Whether the actor is visible or not.
   bool                     mInheritLayoutDirection : 1;    ///< Whether the actor inherits the layout direction from parent.
   bool                     mCaptureAllTouchAfterStart : 1; ///< Whether the actor should capture all touch after touch starts even if the motion moves outside of the actor area.
+  bool                     mIsBlendEquationSet : 1;        ///< Flag to identify whether the Blend equation is set
+  bool                     mNeedGesturePropagation : 1;    ///< Whether the parent listens for gesture events or not
   LayoutDirection::Type    mLayoutDirection : 2;           ///< Layout direction, Left to Right or Right to Left.
   DrawMode::Type           mDrawMode : 3;                  ///< Cached: How the actor and its children should be drawn
   ColorMode                mColorMode : 3;                 ///< Cached: Determines whether mWorldColor is inherited
   ClippingMode::Type       mClippingMode : 3;              ///< Cached: Determines which clipping mode (if any) to use.
   DevelBlendEquation::Type mBlendEquation : 16;            ///< Cached: Determines which blend equation will be used to render renderers.
-  bool                     mIsBlendEquationSet : 1;        ///< Flag to identify whether the Blend equation is set
 
 private:
   static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)