InheritedVisibilityChangedCallback with window Visibility 82/315182/9
authorSeungho Baek <sbsh.baek@samsung.com>
Fri, 26 Jul 2024 06:51:07 +0000 (15:51 +0900)
committerSeungho Baek <sbsh.baek@samsung.com>
Wed, 31 Jul 2024 09:06:34 +0000 (18:06 +0900)
Change-Id: I0b99cb7052380537ff8f0924af3855445d9041cd
Signed-off-by: Seungho Baek <sbsh.baek@samsung.com>
automated-tests/src/dali/utc-Dali-Actor.cpp
dali/integration-api/scene.cpp
dali/integration-api/scene.h
dali/internal/event/actors/actor-impl.cpp
dali/internal/event/actors/actor-impl.h
dali/internal/event/common/scene-impl.cpp
dali/internal/event/common/scene-impl.h

index 43facb57d5ed354da840852f1170f02db221d573..6cdcd5a0a8d2f5314cd14d7beda31f594134ffc8 100644 (file)
@@ -10181,6 +10181,65 @@ int utcDaliActorInheritedVisibilityChangeSignal4(void)
   END_TEST;
 }
 
+int utcDaliActorInheritedVisibilityChangeSignal5(void)
+{
+  TestApplication application;
+  tet_infoline("Check that the inherited visibility change signal is called when the scene visibility is changed");
+
+  Actor parentActor = Actor::New();
+  Actor actor       = Actor::New();
+
+  InheritedVisibilityChangedFunctorData data;
+  actor.InheritedVisibilityChangedSignal().Connect(&application, InheritedVisibilityChangedFunctor(data));
+
+  application.GetScene().Hide();
+
+  parentActor.Add(actor);
+  data.Check(false, TEST_LOCATION);
+
+  data.Reset();
+  application.GetScene().Add(parentActor);
+  data.Check(false, TEST_LOCATION);
+
+  data.Reset();
+  application.GetScene().Show();
+  data.Check(true, actor, true, TEST_LOCATION);
+
+  data.Reset();
+  actor.SetProperty(Actor::Property::VISIBLE, false);
+  data.Check(true, actor, false, TEST_LOCATION);
+
+  data.Reset();
+  actor.SetProperty(Actor::Property::VISIBLE, false);
+  data.Check(false, TEST_LOCATION);
+
+  data.Reset();
+  actor.SetProperty(Actor::Property::VISIBLE, true);
+  data.Check(true, actor, true, TEST_LOCATION);
+
+  data.Reset();
+  actor.SetProperty(Actor::Property::VISIBLE, true);
+  data.Check(false, TEST_LOCATION);
+
+  data.Reset();
+  application.GetScene().Hide();
+  data.Check(true, actor, false, TEST_LOCATION);
+
+  data.Reset();
+  actor.SetProperty(Actor::Property::VISIBLE, false);
+  data.Check(false, TEST_LOCATION);
+
+  data.Reset();
+  application.GetScene().Show();
+  data.Check(false, TEST_LOCATION);
+
+  data.Reset();
+  actor.SetProperty(Actor::Property::VISIBLE, true);
+  data.Check(true, actor, true, TEST_LOCATION);
+
+  END_TEST;
+}
+
 static void LayoutDirectionChanged(Actor actor, LayoutDirection::Type type)
 {
   gLayoutDirectionType = type;
index f572e404ec3f2e1581613afa3a12b35a79070506..3e550433b42c7ff26d7cc581dc3f9370192c2c70 100644 (file)
@@ -68,6 +68,21 @@ void Scene::Remove(Actor actor)
   GetImplementation(*this).Remove(GetImplementation(actor));
 }
 
+void Scene::Show()
+{
+  GetImplementation(*this).Show();
+}
+
+void Scene::Hide()
+{
+  GetImplementation(*this).Hide();
+}
+
+bool Scene::IsVisible() const
+{
+  return GetImplementation(*this).IsVisible();
+}
+
 Size Scene::GetSize() const
 {
   return GetImplementation(*this).GetSize();
index e6ef8cee4887bcec3cb8b7384596fc73d6c72e1b..cf1861e834ce84c5f3c127098389880e9610d38f 100644 (file)
@@ -166,6 +166,25 @@ public:
    */
   void Remove(Actor actor);
 
+  /**
+   * @brief Shows the scene if it is hidden.
+   * @SINCE_2_3.35
+   */
+  void Show();
+
+  /**
+   * @brief Hides the scene if it is showing.
+   * @SINCE_2_3.35
+   */
+  void Hide();
+
+  /**
+   * @brief Returns whether the window is visible or not.
+   * @SINCE_2_3.35
+   * @return True if the window is visible, false otherwise.
+   */
+  bool IsVisible() const;
+
   /**
    * @brief Returns the size of the Scene in pixels as a Vector.
    *
index 5e1e60408b1fce5e7e21a09b79e25e391a223853..d139c7a62f2aebac30f09a8a0b72775a6bc3ac36 100644 (file)
@@ -1411,6 +1411,17 @@ void Actor::RebuildDepthTree()
   DALI_LOG_TIMER_END(depthTimer, gLogFilter, Debug::Concise, "Depth tree traversal time: ");
 }
 
+void Actor::EmitInheritedVisibilityChangedSignalRecursively(bool visible)
+{
+  ActorContainer inheritedVisibilityChangedList;
+  mParentImpl.InheritVisibilityRecursively(inheritedVisibilityChangedList);
+  // Notify applications about the newly connected actors.
+  for(const auto& actor : inheritedVisibilityChangedList)
+  {
+    actor->EmitInheritedVisibilityChangedSignal(visible);
+  }
+}
+
 void Actor::SetDefaultProperty(Property::Index index, const Property::Value& property)
 {
   PropertyHandler::SetDefaultProperty(*this, index, property);
@@ -1544,7 +1555,8 @@ void Actor::SetParent(ActorParent* parent, bool notify)
       ConnectToScene(parentActor->GetHierarchyDepth(), parentActor->GetLayer3DParentCount(), notify);
 
       Actor* actor         = this;
-      emitInheritedVisible = true;
+      // OnScene should be checked, this actor can be removed during OnSceneConnection.
+      emitInheritedVisible = OnScene() && mScene->IsVisible();
       while(emitInheritedVisible && actor)
       {
         emitInheritedVisible &= actor->GetProperty(Dali::Actor::Property::VISIBLE).Get<bool>();
@@ -1563,7 +1575,7 @@ void Actor::SetParent(ActorParent* parent, bool notify)
        OnScene())
     {
       Actor* actor         = this;
-      emitInheritedVisible = true;
+      emitInheritedVisible = mScene->IsVisible();
       while(emitInheritedVisible && actor)
       {
         emitInheritedVisible &= actor->GetProperty(Dali::Actor::Property::VISIBLE).Get<bool>();
@@ -1759,7 +1771,7 @@ void Actor::SetVisibleInternal(bool visible, SendMessage::Type sendMessage)
     }
 
     Actor* actor                = this->GetParent();
-    bool   emitInheritedVisible = OnScene();
+    bool   emitInheritedVisible = OnScene() && mScene->IsVisible();
     while(emitInheritedVisible && actor)
     {
       emitInheritedVisible &= actor->GetProperty(Dali::Actor::Property::VISIBLE).Get<bool>();
@@ -1777,17 +1789,6 @@ void Actor::SetVisibleInternal(bool visible, SendMessage::Type sendMessage)
   }
 }
 
-void Actor::EmitInheritedVisibilityChangedSignalRecursively(bool visible)
-{
-  ActorContainer inheritedVisibilityChangedList;
-  mParentImpl.InheritVisibilityRecursively(inheritedVisibilityChangedList);
-  // Notify applications about the newly connected actors.
-  for(const auto& actor : inheritedVisibilityChangedList)
-  {
-    actor->EmitInheritedVisibilityChangedSignal(visible);
-  }
-}
-
 void Actor::SetSiblingOrderOfChild(Actor& child, uint32_t order)
 {
   mParentImpl.SetSiblingOrderOfChild(child, order);
index 30381ab8fe540a974d419f92a8e3e55696562ff7..f8905951888e20c5e130c5c906da987115919ad2 100644 (file)
@@ -1649,6 +1649,13 @@ public:
    */
   void RebuildDepthTree();
 
+  /**
+   * Emits the visibility flag of an actor.
+   * @param[in] visible The new visibility flag.
+   * @param[in] sendMessage Whether to send a message to the update thread or not.
+   */
+  void EmitInheritedVisibilityChangedSignalRecursively(bool visible);
+
 public:
   // Default property extensions from Object
 
@@ -1886,13 +1893,6 @@ private:
    */
   void SetVisibleInternal(bool visible, SendMessage::Type sendMessage);
 
-  /**
-   * Emits the visibility flag of an actor.
-   * @param[in] visible The new visibility flag.
-   * @param[in] sendMessage Whether to send a message to the update thread or not.
-   */
-  void EmitInheritedVisibilityChangedSignalRecursively(bool visible);
-
   /**
    * @copydoc ActorParent::SetSiblingOrderOfChild
    */
index 25cd4e6347aad463587fd7b5d4de8409ca2ac7c7..a1fc549c1a30b23430d0357a226cc956f4e37b8e 100644 (file)
@@ -59,6 +59,7 @@ Scene::Scene()
   mDepthTreeDirty(false),
   mPartialUpdateEnabled(true),
   mGeometryHittest(false),
+  mIsVisible(true),
   mEventProcessor(*this, ThreadLocalStorage::GetInternal()->GetGestureEventProcessor()),
   mSurfaceOrientation(0),
   mScreenOrientation(0),
@@ -156,6 +157,29 @@ void Scene::Remove(Actor& actor)
   mRootLayer->Remove(actor);
 }
 
+void Scene::Show()
+{
+  if(!mIsVisible)
+  {
+    mIsVisible = true;
+    mRootLayer->EmitInheritedVisibilityChangedSignalRecursively(true);
+  }
+}
+
+void Scene::Hide()
+{
+  if(mIsVisible)
+  {
+    mIsVisible = false;
+    mRootLayer->EmitInheritedVisibilityChangedSignalRecursively(false);
+  }
+}
+
+bool Scene::IsVisible() const
+{
+  return mIsVisible;
+}
+
 Size Scene::GetSize() const
 {
   return mSize;
index 72d84348e165da5228dd97e64ea99a3a6801ab0b..6fed884e6d7c364ab5e00d06cc9bea1159a179a8 100644 (file)
@@ -79,6 +79,21 @@ public:
    */
   void Remove(Actor& actor);
 
+  /**
+   * @copydoc Dali::Integration::Scene::Show
+   */
+  void Show();
+
+  /**
+   * @copydoc Dali::Integration::Scene::Hide
+   */
+  void Hide();
+
+  /**
+   * @copydoc Dali::Integration::Scene::IsVisible
+   */
+  bool IsVisible() const;
+
   /**
    * @copydoc Dali::Integration::Scene::GetSize
    */
@@ -449,6 +464,7 @@ private:
   bool mDepthTreeDirty : 1;       ///< True if the depth tree needs recalculating
   bool mPartialUpdateEnabled : 1; ///< True if the partial update is enabled
   bool mGeometryHittest : 1;      ///< True if the geometry hittest is enabled
+  bool mIsVisible : 1;            ///< True if this Scene is visible
 
   EventProcessor mEventProcessor;