[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / controls / control / control-data-impl.cpp
index 548a4c9..e67be8e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2023 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2024 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.
@@ -617,58 +617,61 @@ const Control::Impl& Control::Impl::Get(const Internal::Control& internalControl
 
 void Control::Impl::CheckHighlightedObjectGeometry()
 {
-  auto accessible     = GetAccessibleObject();
-  auto lastPosition   = accessible->GetLastPosition();
-  auto accessibleRect = accessible->GetExtents(Dali::Accessibility::CoordinateType::WINDOW);
-  auto rect           = GetShowingGeometry(accessibleRect, accessible);
-
-  switch(mAccessibilityLastScreenRelativeMoveType)
+  auto accessible = GetAccessibleObject();
+  if(DALI_LIKELY(accessible))
   {
-    case Dali::Accessibility::ScreenRelativeMoveType::OUTSIDE:
-    {
-      if(IsShowingGeometryOnScreen(rect))
-      {
-        mAccessibilityLastScreenRelativeMoveType = Dali::Accessibility::ScreenRelativeMoveType::INSIDE;
-      }
-      break;
-    }
-    case Dali::Accessibility::ScreenRelativeMoveType::INSIDE:
+    auto lastPosition   = accessible->GetLastPosition();
+    auto accessibleRect = accessible->GetExtents(Dali::Accessibility::CoordinateType::WINDOW);
+    auto rect           = GetShowingGeometry(accessibleRect, accessible);
+
+    switch(mAccessibilityLastScreenRelativeMoveType)
     {
-      if(rect.width < 0 && !Dali::Equals(accessibleRect.x, lastPosition.x))
+      case Dali::Accessibility::ScreenRelativeMoveType::OUTSIDE:
       {
-        mAccessibilityLastScreenRelativeMoveType = (accessibleRect.x < lastPosition.x) ? Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_TOP_LEFT : Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_BOTTOM_RIGHT;
-      }
-      if(rect.height < 0 && !Dali::Equals(accessibleRect.y, lastPosition.y))
-      {
-        mAccessibilityLastScreenRelativeMoveType = (accessibleRect.y < lastPosition.y) ? Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_TOP_LEFT : Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_BOTTOM_RIGHT;
+        if(IsShowingGeometryOnScreen(rect))
+        {
+          mAccessibilityLastScreenRelativeMoveType = Dali::Accessibility::ScreenRelativeMoveType::INSIDE;
+        }
+        break;
       }
-      // notify AT-clients on outgoing moves only
-      if(mAccessibilityLastScreenRelativeMoveType != Dali::Accessibility::ScreenRelativeMoveType::INSIDE)
+      case Dali::Accessibility::ScreenRelativeMoveType::INSIDE:
       {
-        accessible->EmitMovedOutOfScreen(mAccessibilityLastScreenRelativeMoveType);
+        if(rect.width < 0 && !Dali::Equals(accessibleRect.x, lastPosition.x))
+        {
+          mAccessibilityLastScreenRelativeMoveType = (accessibleRect.x < lastPosition.x) ? Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_TOP_LEFT : Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_BOTTOM_RIGHT;
+        }
+        if(rect.height < 0 && !Dali::Equals(accessibleRect.y, lastPosition.y))
+        {
+          mAccessibilityLastScreenRelativeMoveType = (accessibleRect.y < lastPosition.y) ? Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_TOP_LEFT : Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_BOTTOM_RIGHT;
+        }
+        // notify AT-clients on outgoing moves only
+        if(mAccessibilityLastScreenRelativeMoveType != Dali::Accessibility::ScreenRelativeMoveType::INSIDE)
+        {
+          accessible->EmitMovedOutOfScreen(mAccessibilityLastScreenRelativeMoveType);
+        }
+        break;
       }
-      break;
-    }
-    case Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_TOP_LEFT:
-    case Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_BOTTOM_RIGHT:
-    {
-      if(IsShowingGeometryOnScreen(rect))
+      case Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_TOP_LEFT:
+      case Dali::Accessibility::ScreenRelativeMoveType::OUTGOING_BOTTOM_RIGHT:
       {
-        mAccessibilityLastScreenRelativeMoveType = Dali::Accessibility::ScreenRelativeMoveType::INSIDE;
+        if(IsShowingGeometryOnScreen(rect))
+        {
+          mAccessibilityLastScreenRelativeMoveType = Dali::Accessibility::ScreenRelativeMoveType::INSIDE;
+        }
+        else
+        {
+          mAccessibilityLastScreenRelativeMoveType = Dali::Accessibility::ScreenRelativeMoveType::OUTSIDE;
+        }
+        break;
       }
-      else
+      default:
       {
-        mAccessibilityLastScreenRelativeMoveType = Dali::Accessibility::ScreenRelativeMoveType::OUTSIDE;
+        break;
       }
-      break;
-    }
-    default:
-    {
-      break;
     }
-  }
 
-  accessible->SetLastPosition(Vector2(accessibleRect.x, accessibleRect.y));
+    accessible->SetLastPosition(Vector2(accessibleRect.x, accessibleRect.y));
+  }
 }
 
 void Control::Impl::RegisterAccessibilityPositionPropertyNotification()
@@ -693,6 +696,49 @@ void Control::Impl::UnregisterAccessibilityPositionPropertyNotification()
   mIsAccessibilityPositionPropertyNotificationSet = false;
 }
 
+void Control::Impl::RegisterAccessibilityPropertySetSignal()
+{
+  if(mIsAccessibilityPropertySetSignalRegistered)
+  {
+    return;
+  }
+  mControlImpl.Self().PropertySetSignal().Connect(this, &Control::Impl::OnAccessibilityPropertySet);
+  mIsAccessibilityPropertySetSignalRegistered = true;
+}
+
+void Control::Impl::UnregisterAccessibilityPropertySetSignal()
+{
+  if(!mIsAccessibilityPropertySetSignalRegistered)
+  {
+    return;
+  }
+  mControlImpl.Self().PropertySetSignal().Disconnect(this, &Control::Impl::OnAccessibilityPropertySet);
+  mIsAccessibilityPropertySetSignalRegistered = false;
+}
+
+void Control::Impl::OnAccessibilityPropertySet(Dali::Handle& handle, Dali::Property::Index index, const Dali::Property::Value& value)
+{
+  auto* accessible = GetAccessibleObject();
+  if(DALI_LIKELY(accessible))
+  {
+    if(mAccessibilityGetNameSignal.Empty())
+    {
+      if(index == DevelControl::Property::ACCESSIBILITY_NAME || (mAccessibilityName.empty() && index == accessible->GetNamePropertyIndex()))
+      {
+        accessible->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::NAME);
+      }
+    }
+
+    if(mAccessibilityGetDescriptionSignal.Empty())
+    {
+      if(index == DevelControl::Property::ACCESSIBILITY_DESCRIPTION || (mAccessibilityDescription.empty() && index == accessible->GetDescriptionPropertyIndex()))
+      {
+        accessible->Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
+      }
+    }
+  }
+}
+
 // Gesture Detection Methods
 void Control::Impl::PinchDetected(Actor actor, const PinchGesture& pinch)
 {
@@ -1467,10 +1513,13 @@ void Control::Impl::SetProperty(BaseObject* object, Property::Index index, const
           controlImpl.mImpl->mAccessibilityHidden = hidden;
 
           auto* accessible = controlImpl.GetAccessibleObject();
-          auto* parent     = dynamic_cast<Dali::Accessibility::ActorAccessible*>(accessible->GetParent());
-          if(parent)
+          if(DALI_LIKELY(accessible))
           {
-            parent->OnChildrenChanged();
+            auto* parent = dynamic_cast<Dali::Accessibility::ActorAccessible*>(accessible->GetParent());
+            if(parent)
+            {
+              parent->OnChildrenChanged();
+            }
           }
         }
         break;
@@ -2116,7 +2165,7 @@ Dali::Property Control::Impl::GetVisualProperty(Dali::Property::Index index, Dal
   if(visual)
   {
     Internal::Visual::Base& visualImpl = Toolkit::GetImplementation(visual);
-    return visualImpl.GetPropertyObject(visualPropertyKey);
+    return visualImpl.GetPropertyObject(std::move(visualPropertyKey));
   }
 
   Handle handle;
@@ -2192,7 +2241,12 @@ void Control::Impl::EmitResourceReadySignal()
       {
         // The callback manager takes the ownership of the callback object.
         mIdleCallback = MakeCallback(this, &Control::Impl::OnIdleCallback);
-        Adaptor::Get().AddIdle(mIdleCallback, true);
+        if(DALI_UNLIKELY(!Adaptor::Get().AddIdle(mIdleCallback, true)))
+        {
+          DALI_LOG_ERROR("Fail to add idle callback for control resource ready. Skip this callback.\n");
+          mIdleCallback           = nullptr;
+          mIdleCallbackRegistered = false;
+        }
       }
     }
   }
@@ -2223,7 +2277,7 @@ bool Control::Impl::OnIdleCallback()
 
 Toolkit::DevelControl::ControlAccessible* Control::Impl::GetAccessibleObject()
 {
-  if(!mAccessibleObject)
+  if(mAccessibleCreatable && !mAccessibleObject)
   {
     mAccessibleObject.reset(mControlImpl.CreateAccessibleObject());
   }
@@ -2231,6 +2285,21 @@ Toolkit::DevelControl::ControlAccessible* Control::Impl::GetAccessibleObject()
   return mAccessibleObject.get();
 }
 
+bool Control::Impl::IsAccessibleCreated() const
+{
+  return !!mAccessibleObject;
+}
+
+void Control::Impl::EnableCreateAccessible(bool enable)
+{
+  mAccessibleCreatable = enable;
+}
+
+bool Control::Impl::IsCreateAccessibleEnabled() const
+{
+  return mAccessibleCreatable;
+}
+
 } // namespace Internal
 
 } // namespace Toolkit