Update the bridge to own accessible objects 79/316879/2
authorYoungsun Suh <youngsun.suh@samsung.com>
Fri, 30 Aug 2024 02:24:45 +0000 (11:24 +0900)
committerYoungsun Suh <youngsun.suh@samsung.com>
Fri, 30 Aug 2024 05:44:02 +0000 (14:44 +0900)
Change-Id: I6a4311ed6d94f73af885e7963fa08d9f21aa4044

dali/devel-api/adaptor-framework/accessibility-bridge.h
dali/devel-api/adaptor-framework/accessibility.cpp
dali/devel-api/atspi-interfaces/accessible.h
dali/internal/accessibility/bridge/bridge-impl.cpp
dali/internal/accessibility/bridge/dummy/dummy-atspi.h
dali/internal/adaptor/common/application-impl.cpp

index a47f6b234411ef365183079d57a772b4f5b44c40..156108aeeb0ab221e15dadd8b33273ac400ed42f 100644 (file)
@@ -62,6 +62,21 @@ struct DALI_ADAPTOR_API Bridge
    */
   virtual ~Bridge() = default;
 
+  /**
+   * @brief Adds the accessible object associated with given actorId to the brige.
+   */
+  virtual void AddAccessible(uint32_t actorId, std::shared_ptr<Accessible> accessible) = 0;
+
+  /**
+   * @brief Removed the accessible object associated with given actorId from the brige.
+   */
+  virtual void RemoveAccessible(uint32_t actorId) = 0;
+
+  /**
+   * @brief Gets the accessible object associated with given actorId from the brige.
+   */
+  virtual std::shared_ptr<Accessible> GetAccessible(uint32_t actorId) const = 0;
+
   /**
    * @brief Gets bus name which bridge is initialized on.
    *
index 6caf3d86bf7699ebeb039043246337263ba54fb8..19a0c72eaaaf9787708d1e3692f37d0abde3941c 100644 (file)
@@ -352,6 +352,12 @@ class AdaptorAccessible : public ActorAccessible
 private:
   std::unique_ptr<TriggerEventInterface> mRenderNotification = nullptr;
 
+  void OffSceneCallback(Actor actor)
+  {
+    uint32_t actorId = actor.GetProperty<int>(Actor::Property::ID);
+    Bridge::GetCurrentBridge()->RemoveAccessible(actorId);
+  }
+
 protected:
   bool mRoot = false;
 
@@ -360,6 +366,7 @@ public:
   : ActorAccessible(actor),
     mRoot(isRoot)
   {
+    actor.OffSceneSignal().Connect(this, &AdaptorAccessible::OffSceneCallback);
   }
 
   bool GrabFocus() override
@@ -526,31 +533,15 @@ public:
   }
 }; // AdaptorAccessible
 
-using AdaptorAccessiblesType = std::unordered_map<const Dali::RefObject*, std::shared_ptr<AdaptorAccessible>>;
+using ConvertingResult = std::pair<std::shared_ptr<Accessible>, bool>;
 
-// Save RefObject from an Actor in Accessible::Get()
-AdaptorAccessiblesType& GetAdaptorAccessibles()
-{
-  static AdaptorAccessiblesType gAdaptorAccessibles;
-  return gAdaptorAccessibles;
-}
-
-std::function<std::shared_ptr<Accessible>(Dali::Actor)> convertingFunctor = [](Dali::Actor) -> std::shared_ptr<Accessible> {
-  return nullptr;
+std::function<ConvertingResult(Dali::Actor)> convertingFunctor = [](Dali::Actor) -> ConvertingResult {
+  return {nullptr, true};
 };
 
-ObjectRegistry objectRegistry;
 } // namespace
 
-void Accessible::SetObjectRegistry(ObjectRegistry registry)
-{
-  objectRegistry = registry;
-  objectRegistry.ObjectDestroyedSignal().Connect([](const Dali::RefObject* obj) {
-    GetAdaptorAccessibles().erase(obj);
-  });
-}
-
-void Accessible::RegisterExternalAccessibleGetter(std::function<std::shared_ptr<Accessible>(Dali::Actor)> functor)
+void Accessible::RegisterExternalAccessibleGetter(std::function<ConvertingResult(Dali::Actor)> functor)
 {
   convertingFunctor = functor;
 }
@@ -562,21 +553,32 @@ std::shared_ptr<Accessible> Accessible::GetOwningPtr(Dali::Actor actor)
     return nullptr;
   }
 
-  auto accessible = convertingFunctor(actor);
-  if(!accessible)
+  auto bridge = Bridge::GetCurrentBridge();
+
+  uint32_t actorId    = actor.GetProperty<int>(Actor::Property::ID);
+  auto     accessible = bridge->GetAccessible(actorId);
+  if(accessible)
   {
-    auto pair = GetAdaptorAccessibles().emplace(&actor.GetBaseObject(), nullptr);
-    if(pair.second)
+    return accessible;
+  }
+
+  auto result                = convertingFunctor(actor);
+  accessible                 = result.first;
+  const bool creationEnabled = result.second;
+  if(!accessible && creationEnabled)
+  {
+    bool                     isRoot = false;
+    Dali::Integration::Scene scene  = Dali::Integration::Scene::Get(actor);
+    if(scene)
     {
-      bool                     isRoot = false;
-      Dali::Integration::Scene scene  = Dali::Integration::Scene::Get(actor);
-      if(scene)
-      {
-        isRoot = (actor == scene.GetRootLayer());
-      }
-      pair.first->second.reset(new AdaptorAccessible(actor, isRoot));
+      isRoot = (actor == scene.GetRootLayer());
     }
-    accessible = pair.first->second;
+    accessible = std::make_shared<AdaptorAccessible>(actor, isRoot);
+  }
+
+  if(accessible)
+  {
+    bridge->AddAccessible(actorId, accessible);
   }
 
   return accessible;
index b163ea25b32e71df9df0f37a1466fe16ffd52ab4..3ff4dcdb4cf66b491d9dea86a1630a2e16c97f68 100644 (file)
@@ -456,18 +456,11 @@ public:
    */
   static void SetCurrentlyHighlightedActor(Dali::Actor actor);
 
-  /**
-   * @brief Sets ObjectRegistry.
-   *
-   * @param[in] registry ObjectRegistry instance
-   */
-  static void SetObjectRegistry(ObjectRegistry registry);
-
   /**
    * @brief The method registers functor resposible for converting Actor into Accessible.
    * @param functor The returning Accessible handle from Actor object
    */
-  static void RegisterExternalAccessibleGetter(std::function<std::shared_ptr<Accessible>(Dali::Actor)> functor);
+  static void RegisterExternalAccessibleGetter(std::function<std::pair<std::shared_ptr<Accessible>, bool>(Dali::Actor)> functor);
 
   /**
    * @brief Acquires Accessible object from Actor object.
index 6e18a472eb873f8534c7540cd0f68783354df767..698afac16733a84e259caa9883bcffa6d46def75 100644 (file)
@@ -90,10 +90,27 @@ class BridgeImpl : public virtual BridgeBase,
   Dali::Timer                                                   mReadScreenReaderEnabledTimer;
   Dali::Timer                                                   mForceUpTimer;
   std::string                                                   mPreferredBusName;
+  std::map<uint32_t, std::shared_ptr<Accessible>>               mAccessibles; // Actor.ID to Accessible map
 
 public:
   BridgeImpl() = default;
 
+  void AddAccessible(uint32_t actorId, std::shared_ptr<Accessible> accessible) override
+  {
+    mAccessibles[actorId] = std::move(accessible);
+  }
+
+  void RemoveAccessible(uint32_t actorId) override
+  {
+    mAccessibles.erase(actorId);
+  }
+
+  std::shared_ptr<Accessible> GetAccessible(uint32_t actorId) const override
+  {
+    auto iter = mAccessibles.find(actorId);
+    return iter != mAccessibles.end() ? iter->second : nullptr;
+  }
+
   /**
    * @copydoc Dali::Accessibility::Bridge::EmitKeyEvent()
    */
index 8353a4d4b934423189e3969c48168f518616a8a0..063d4dc11cfdff6a297090f109819e5b6eaf2bcc 100644 (file)
@@ -237,6 +237,15 @@ struct DummyBridge : Dali::Accessibility::Bridge
   void SetPreferredBusName(std::string_view preferredBusName) override
   {
   }
+
+  void AddAccessible(uint32_t actorId, std::shared_ptr<Accessible> accessible) override{};
+
+  void RemoveAccessible(uint32_t actorId) override{};
+
+  std::shared_ptr<Accessible> GetAccessible(uint32_t actorId) const override
+  {
+    return nullptr;
+  };
 };
 
 } // namespace Dali::Accessibility
index 519e6a45729c7e9724d78d017e37fb340169755c..41c8f646e2b6901bad6c9c80949e316a1e0d3139 100644 (file)
@@ -387,7 +387,6 @@ void Application::OnInit()
   DALI_TRACE_BEGIN(gTraceFilter, "DALI_APP_ADAPTOR_START");
   mAdaptor->Start();
   DALI_TRACE_END(gTraceFilter, "DALI_APP_ADAPTOR_START");
-  Accessibility::Accessible::SetObjectRegistry(mAdaptor->GetObjectRegistry());
 
   if(!mStylesheet.empty())
   {