[ATSPI] Check parents to define SHOWING state
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / accessible-impl.cpp
index c42cb8a..1cf9a26 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include <dali/devel-api/actors/actor-devel.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
@@ -35,7 +36,8 @@
 
 namespace Dali::Toolkit::DevelControl
 {
-
+namespace
+{
 static std::string GetLocaleText(std::string string, const char *domain = "dali-toolkit")
 {
 #ifdef DGETTEXT_ENABLED
@@ -47,6 +49,23 @@ static std::string GetLocaleText(std::string string, const char *domain = "dali-
 #endif
 }
 
+static Dali::Actor CreateHighlightIndicatorActor()
+{
+  std::string focusBorderImagePath(AssetManager::GetDaliImagePath());
+  focusBorderImagePath += "/keyboard_focus.9.png";
+
+  // Create the default if it hasn't been set and one that's shared by all the
+  // keyboard focusable actors
+  auto actor = Toolkit::ImageView::New(focusBorderImagePath);
+  actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+
+  DevelControl::AppendAccessibilityAttribute(actor, "highlight", std::string());
+  actor.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false);
+
+  return actor;
+}
+} // unnamed namespace
+
 AccessibleImpl::AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal)
 : mSelf(self),
   mIsModal(modal)
@@ -199,6 +218,41 @@ std::string AccessibleImpl::GetLocalizedRoleName()
   return GetLocaleText(GetRoleName());
 }
 
+bool AccessibleImpl::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))
+  {
+    return false;
+  }
+
+  auto* child  = this;
+  auto* parent = dynamic_cast<Toolkit::DevelControl::AccessibleImpl*>(child->GetParent());
+  if(!parent)
+  {
+    return true;
+  }
+
+  auto childExtent = child->GetExtents(Dali::Accessibility::CoordinateType::WINDOW);
+  while(parent)
+  {
+    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::AccessibleImpl*>(parent->GetParent());
+  }
+
+  return true;
+}
+
 Dali::Accessibility::States AccessibleImpl::CalculateStates()
 {
   Dali::Actor self = Self();
@@ -218,14 +272,13 @@ Dali::Accessibility::States AccessibleImpl::CalculateStates()
   state[Dali::Accessibility::State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self;
   state[Dali::Accessibility::State::ENABLED]     = true;
   state[Dali::Accessibility::State::SENSITIVE]   = true;
-  state[Dali::Accessibility::State::VISIBLE]     = true;
+  state[Dali::Accessibility::State::VISIBLE]     = self.GetProperty<bool>(Actor::Property::VISIBLE);
 
   if(mIsModal)
   {
     state[Dali::Accessibility::State::MODAL] = true;
   }
-  state[Dali::Accessibility::State::SHOWING] = !self.GetProperty(Dali::DevelActor::Property::CULLED).Get<bool>() && self.GetCurrentProperty<bool>(Actor::Property::VISIBLE);
-
+  state[Dali::Accessibility::State::SHOWING] = IsShowing();
   state[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty(Dali::DevelActor::Property::CONNECTED_TO_SCENE).Get<bool>();
   return state;
 }
@@ -278,7 +331,16 @@ Dali::Rect<> AccessibleImpl::GetExtents(Dali::Accessibility::CoordinateType type
   Vector3 anchorPointOffSet = size * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
   Vector2 position = Vector2((screenPosition.x - anchorPointOffSet.x), (screenPosition.y - anchorPointOffSet.y));
 
-  return {position.x, position.y, size.x, size.y};
+  if(type == Dali::Accessibility::CoordinateType::WINDOW)
+  {
+    return {position.x, position.y, size.x, size.y};
+  }
+  else // Dali::Accessibility::CoordinateType::SCREEN
+  {
+    auto window = Dali::DevelWindow::Get(self);
+    auto windowPosition = window.GetPosition();
+    return {position.x + windowPosition.GetX(), position.y + windowPosition.GetY(), size.x, size.y};
+  }
 }
 
 int16_t AccessibleImpl::GetMdiZOrder()
@@ -295,22 +357,6 @@ bool AccessibleImpl::GrabFocus()
   return Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor(Self());
 }
 
-static Dali::Actor CreateHighlightIndicatorActor()
-{
-  std::string focusBorderImagePath(AssetManager::GetDaliImagePath());
-  focusBorderImagePath += "/keyboard_focus.9.png";
-
-  // Create the default if it hasn't been set and one that's shared by all the
-  // keyboard focusable actors
-  auto actor = Toolkit::ImageView::New(focusBorderImagePath);
-  actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
-
-  DevelControl::AppendAccessibilityAttribute(actor, "highlight", std::string());
-  actor.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false);
-
-  return actor;
-}
-
 void AccessibleImpl::ScrollToSelf()
 {
   auto* child = this;
@@ -323,11 +369,26 @@ void AccessibleImpl::ScrollToSelf()
       parent->ScrollToChild(child->Self());
     }
 
-    child = parent;
     parent = dynamic_cast<Toolkit::DevelControl::AccessibleImpl*>(parent->GetParent());
   }
 }
 
+void AccessibleImpl::RegisterPositionPropertyNotification()
+{
+  auto                     control         = Dali::Toolkit::Control::DownCast(Self());
+  Internal::Control&       internalControl = Toolkit::Internal::GetImplementation(control);
+  Internal::Control::Impl& controlImpl     = Internal::Control::Impl::Get(internalControl);
+  controlImpl.RegisterAccessibilityPositionPropertyNotification();
+}
+
+void AccessibleImpl::UnregisterPositionPropertyNotification()
+{
+  auto                     control         = Dali::Toolkit::Control::DownCast(Self());
+  Internal::Control&       internalControl = Toolkit::Internal::GetImplementation(control);
+  Internal::Control::Impl& controlImpl     = Internal::Control::Impl::Get(internalControl);
+  controlImpl.UnregisterAccessibilityPositionPropertyNotification();
+}
+
 bool AccessibleImpl::GrabHighlight()
 {
   Dali::Actor self = Self();
@@ -360,11 +421,15 @@ bool AccessibleImpl::GrabHighlight()
     SetHighlightActor(highlight);
   }
 
-  highlight.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
-  highlight.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+  highlight.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
   highlight.SetProperty(Actor::Property::POSITION_Z, 1.0f);
   highlight.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
 
+  // Need to set resize policy again, to update SIZE property which is set by
+  // AccessibleImpl_NUI. The highlight could move from AccessibleImpl_NUI to
+  // AccessibleImpl. In this case, highlight has incorrect size.
+  highlight.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+
   // Remember the highlight actor, so that when the default is changed with
   // SetHighlightActor(), the currently displayed highlight can still be cleared.
   mCurrentHighlightActor = highlight;
@@ -372,6 +437,7 @@ bool AccessibleImpl::GrabHighlight()
   self.Add(highlight);
   SetCurrentlyHighlightedActor(self);
   EmitHighlighted(true);
+  RegisterPositionPropertyNotification();
 
   return true;
 }
@@ -387,6 +453,7 @@ bool AccessibleImpl::ClearHighlight()
 
   if(GetCurrentlyHighlightedActor() == self)
   {
+    UnregisterPositionPropertyNotification();
     self.Remove(mCurrentHighlightActor.GetHandle());
     mCurrentHighlightActor = {};
     SetCurrentlyHighlightedActor({});
@@ -480,6 +547,11 @@ std::vector<Dali::Accessibility::Relation> AccessibleImpl::GetRelationSet()
   return ret;
 }
 
+Dali::Actor AccessibleImpl::GetInternalActor()
+{
+  return Dali::Actor{};
+}
+
 bool AccessibleImpl::ScrollToChild(Actor child)
 {
   return false;
@@ -495,4 +567,14 @@ Dali::Property::Index AccessibleImpl::GetDescriptionPropertyIndex()
   return Dali::Property::INVALID_INDEX;
 }
 
+void AccessibleImpl::SetLastPosition(Vector2 position)
+{
+  mLastPosition = position;
+}
+
+Vector2 AccessibleImpl::GetLastPosition() const
+{
+  return mLastPosition;
+}
+
 } // namespace Dali::Toolkit::DevelControl