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 43facb5..6cdcd5a 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 f572e40..3e55043 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 e6ef8ce..cf1861e 100644 (file)
@@ -167,6 +167,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.
    *
    * The x component will be the width of the Scene in pixels.
index 5e1e604..d139c7a 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 30381ab..f890595 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
 
@@ -1887,13 +1894,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
    */
   void SetSiblingOrderOfChild(Actor& child, uint32_t order) override;
index 25cd4e6..a1fc549 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 72d8434..6fed884 100644 (file)
@@ -80,6 +80,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
    */
   Size GetSize() const;
@@ -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;