Merge "(A11y) Connect PropertySet signal only if highlighed" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / control-accessible.cpp
index 85b3c6a..c4ad881 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2023 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.
@@ -38,14 +38,14 @@ namespace Dali::Toolkit::DevelControl
 {
 namespace
 {
-static std::string GetLocaleText(std::string string, const char *domain = "dali-toolkit")
+static std::string GetLocaleText(std::string string, const chardomain = "dali-toolkit")
 {
 #ifdef DGETTEXT_ENABLED
-    /*TODO: currently non-localized string is used as a key for translation lookup. In case the lookup key formatting is forced
+  /*TODO: currently non-localized string is used as a key for translation lookup. In case the lookup key formatting is forced
           consider calling utility function for converting non-localized string into well-formatted key before lookup. */
-    return dgettext(domain, string.c_str());
+  return dgettext(domain, string.c_str());
 #else
-    return string;
+  return string;
 #endif
 }
 
@@ -69,33 +69,6 @@ static Dali::Actor CreateHighlightIndicatorActor()
 ControlAccessible::ControlAccessible(Dali::Actor self)
 : ActorAccessible(self)
 {
-  auto control = Toolkit::Control::DownCast(self);
-
-  Internal::Control&       internalControl = Toolkit::Internal::GetImplementation(control);
-  Internal::Control::Impl& controlImpl     = Internal::Control::Impl::Get(internalControl);
-
-  self.PropertySetSignal().Connect(&controlImpl, [this, &controlImpl](Dali::Handle& handle, Dali::Property::Index index, Dali::Property::Value value) {
-    if(this->Self() != Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
-    {
-      return;
-    }
-
-    if(index == DevelControl::Property::ACCESSIBILITY_NAME || (index == GetNamePropertyIndex() && controlImpl.mAccessibilityName.empty()))
-    {
-      if(controlImpl.mAccessibilityGetNameSignal.Empty())
-      {
-        Emit(Dali::Accessibility::ObjectPropertyChangeEvent::NAME);
-      }
-    }
-
-    if(index == DevelControl::Property::ACCESSIBILITY_DESCRIPTION || (index == GetDescriptionPropertyIndex() && controlImpl.mAccessibilityDescription.empty()))
-    {
-      if(controlImpl.mAccessibilityGetDescriptionSignal.Empty())
-      {
-        Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION);
-      }
-    }
-  });
 }
 
 std::string ControlAccessible::GetName() const
@@ -104,7 +77,7 @@ std::string ControlAccessible::GetName() const
 
   Internal::Control&       internalControl = Toolkit::Internal::GetImplementation(control);
   Internal::Control::Impl& controlImpl     = Internal::Control::Impl::Get(internalControl);
-  std::string name;
+  std::string              name;
 
   if(!controlImpl.mAccessibilityGetNameSignal.Empty())
   {
@@ -142,7 +115,7 @@ std::string ControlAccessible::GetDescription() const
 
   Internal::Control&       internalControl = Toolkit::Internal::GetImplementation(control);
   Internal::Control::Impl& controlImpl     = Internal::Control::Impl::Get(internalControl);
-  std::string description;
+  std::string              description;
 
   if(!controlImpl.mAccessibilityGetDescriptionSignal.Empty())
   {
@@ -183,7 +156,7 @@ std::string ControlAccessible::GetLocalizedRoleName() const
 bool ControlAccessible::IsShowing()
 {
   Dali::Actor self = Self();
-  if(!self.GetProperty<bool>(Actor::Property::VISIBLE) || self.GetProperty<Vector4>(Actor::Property::WORLD_COLOR).a == 0 || self.GetProperty<bool>(Dali::DevelActor::Property::CULLED))
+  if(!self.GetProperty<bool>(Actor::Property::VISIBLE) || Dali::EqualsZero(self.GetProperty<Vector4>(Actor::Property::WORLD_COLOR).a) || self.GetProperty<bool>(Dali::DevelActor::Property::CULLED))
   {
     return false;
   }
@@ -195,20 +168,13 @@ bool ControlAccessible::IsShowing()
     return true;
   }
 
-  auto childExtent = child->GetExtents(Dali::Accessibility::CoordinateType::WINDOW);
   while(parent)
   {
-    auto control      = Dali::Toolkit::Control::DownCast(parent->Self());
+    auto control = Dali::Toolkit::Control::DownCast(parent->Self());
     if(!control.GetProperty<bool>(Actor::Property::VISIBLE))
     {
       return false;
     }
-    auto clipMode     = control.GetProperty(Actor::Property::CLIPPING_MODE).Get<bool>();
-    auto parentExtent = parent->GetExtents(Dali::Accessibility::CoordinateType::WINDOW);
-    if ((clipMode != ClippingMode::DISABLED) && !parentExtent.Intersects(childExtent))
-    {
-      return false;
-    }
     parent = dynamic_cast<Toolkit::DevelControl::ControlAccessible*>(parent->GetParent());
   }
 
@@ -219,7 +185,7 @@ Dali::Accessibility::States ControlAccessible::CalculateStates()
 {
   using Dali::Accessibility::State;
 
-  Dali::Actor self = Self();
+  Dali::Actor                 self = Self();
   Dali::Accessibility::States states;
 
   states[State::FOCUSABLE]     = self.GetProperty<bool>(Actor::Property::KEYBOARD_FOCUSABLE);
@@ -227,7 +193,7 @@ Dali::Accessibility::States ControlAccessible::CalculateStates()
   states[State::HIGHLIGHTABLE] = self.GetProperty<bool>(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE);
   states[State::HIGHLIGHTED]   = GetCurrentlyHighlightedActor() == self;
   states[State::ENABLED]       = true;
-  states[State::SENSITIVE]     = true;
+  states[State::SENSITIVE]     = (Dali::DevelActor::IsHittable(self) && Dali::DevelActor::GetTouchRequired(self));
   states[State::VISIBLE]       = self.GetProperty<bool>(Actor::Property::VISIBLE);
   states[State::SHOWING]       = IsShowing();
   states[State::DEFUNCT]       = !self.GetProperty(Dali::DevelActor::Property::CONNECTED_TO_SCENE).Get<bool>();
@@ -243,9 +209,9 @@ Dali::Accessibility::States ControlAccessible::GetStates()
 Dali::Accessibility::Attributes ControlAccessible::GetAttributes() const
 {
   std::unordered_map<std::string, std::string> attributeMap;
-  auto control = Dali::Toolkit::Control::DownCast(Self());
-  auto attribute = control.GetProperty(Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES);
-  auto map = attribute.GetMap();
+  auto                                         control   = Dali::Toolkit::Control::DownCast(Self());
+  auto                                         attribute = control.GetProperty(Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES);
+  auto                                         map       = attribute.GetMap();
 
   if(map)
   {
@@ -265,6 +231,12 @@ Dali::Accessibility::Attributes ControlAccessible::GetAttributes() const
     }
   }
 
+  auto automationId = control.GetProperty<std::string>(Dali::Toolkit::DevelControl::Property::AUTOMATION_ID);
+  if(!automationId.empty())
+  {
+    attributeMap.emplace("automationId", std::move(automationId));
+  }
+
   return attributeMap;
 }
 
@@ -285,12 +257,12 @@ bool ControlAccessible::GrabFocus()
 
 void ControlAccessible::ScrollToSelf()
 {
-  auto* child = this;
+  auto* child  = this;
   auto* parent = dynamic_cast<Toolkit::DevelControl::ControlAccessible*>(child->GetParent());
 
-  while (parent)
+  while(parent)
   {
-    if (parent->IsScrollable())
+    if(parent->IsScrollable())
     {
       parent->ScrollToChild(child->Self());
     }
@@ -315,10 +287,26 @@ void ControlAccessible::UnregisterPositionPropertyNotification()
   controlImpl.UnregisterAccessibilityPositionPropertyNotification();
 }
 
+void ControlAccessible::RegisterPropertySetSignal()
+{
+  auto                     control         = Dali::Toolkit::Control::DownCast(Self());
+  Internal::Control&       internalControl = Toolkit::Internal::GetImplementation(control);
+  Internal::Control::Impl& controlImpl     = Internal::Control::Impl::Get(internalControl);
+  controlImpl.RegisterAccessibilityPropertySetSignal();
+}
+
+void ControlAccessible::UnregisterPropertySetSignal()
+{
+  auto                     control         = Dali::Toolkit::Control::DownCast(Self());
+  Internal::Control&       internalControl = Toolkit::Internal::GetImplementation(control);
+  Internal::Control::Impl& controlImpl     = Internal::Control::Impl::Get(internalControl);
+  controlImpl.UnregisterAccessibilityPropertySetSignal();
+}
+
 bool ControlAccessible::GrabHighlight()
 {
-  Dali::Actor self = Self();
-  auto oldHighlightedActor = GetCurrentlyHighlightedActor();
+  Dali::Actor self                = Self();
+  auto        oldHighlightedActor = GetCurrentlyHighlightedActor();
 
   if(!Dali::Accessibility::IsUp())
   {
@@ -364,6 +352,7 @@ bool ControlAccessible::GrabHighlight()
   SetCurrentlyHighlightedActor(self);
   EmitHighlighted(true);
   RegisterPositionPropertyNotification();
+  RegisterPropertySetSignal();
 
   return true;
 }
@@ -379,6 +368,7 @@ bool ControlAccessible::ClearHighlight()
 
   if(GetCurrentlyHighlightedActor() == self)
   {
+    UnregisterPropertySetSignal();
     UnregisterPositionPropertyNotification();
     self.Remove(mCurrentHighlightActor.GetHandle());
     mCurrentHighlightActor = {};