a11y refactor: Remove mKnownObjects 99/316999/3
authorYoungsun Suh <youngsun.suh@samsung.com>
Mon, 23 Dec 2024 02:20:05 +0000 (11:20 +0900)
committerYoungsun Suh <youngsun.suh@samsung.com>
Fri, 3 Jan 2025 04:17:46 +0000 (13:17 +0900)
mKnownObjects is redundant as we already store accessbles in a map in bridge-impl.
Removig the data and update the path calculation logic.wq

Change-Id: I40899257ab293f2afe0bcdf9c3a7791dbc4e88bc

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

index cf57cf7aa18f35922b4c933cd956a67639457ca5..ee800a654b64b225ddaeb1bcf6f5323ae7e823a0 100644 (file)
@@ -78,10 +78,15 @@ struct DALI_ADAPTOR_API Bridge
   virtual void RemoveAccessible(uint32_t actorId) = 0;
 
   /**
-   * @brief Gets the accessible object associated with given actor from the brige.
+   * @brief Gets the accessible object associated with given actor from the bridge.
    */
   virtual std::shared_ptr<Accessible> GetAccessible(Actor actor) const = 0;
 
+  /**
+   * @brief Gets the accessible object associated with given path from the bridge.
+   */
+  virtual std::shared_ptr<Accessible> GetAccessible(const std::string& path) const = 0;
+
   /**
    * @brief Returns true if GetChildren should include hidden objects; false otherwise.
    */
@@ -585,7 +590,6 @@ struct DALI_ADAPTOR_API Bridge
 protected:
   struct Data
   {
-    std::unordered_set<const Accessible*> mKnownObjects;
     std::string                           mBusName;
     Bridge*                               mBridge = nullptr;
     Actor                                 mHighlightActor;
index ae00f95bc2d349bdd54bee01d5a0177dda264fd7..74f5823a5eec0af0d032c9df0d0776dbc24ef137 100644 (file)
@@ -38,7 +38,7 @@ namespace Dali::Accessibility
 class DALI_ADAPTOR_API Accessible
 {
 public:
-  virtual ~Accessible() noexcept;
+  virtual ~Accessible() noexcept = default;
 
   /**
    * @brief Gets accessibility name.
@@ -284,7 +284,7 @@ public:
   std::string DumpTree(DumpDetailLevel detailLevel);
 
 protected:
-  Accessible();
+  Accessible()                          = default;
   Accessible(const Accessible&)         = delete;
   Accessible(Accessible&&)              = delete;
   Accessible&                   operator=(const Accessible&) = delete;
index c03173f88961ad0d984fd515d299327d180ef261..7eff029f948480d765ec3cd5e67fc11e1d3ffd9e 100644 (file)
@@ -250,19 +250,6 @@ std::string DumpJson(Accessible* node, Accessible::DumpDetailLevel detailLevel,
 
 } // anonymous namespace
 
-Accessible::Accessible()
-{
-}
-
-Accessible::~Accessible() noexcept
-{
-  auto handle = mBridgeData.lock();
-  if(handle)
-  {
-    handle->mKnownObjects.erase(this);
-  }
-}
-
 std::shared_ptr<Bridge::Data> Accessible::GetBridgeData() const
 {
   auto handle = mBridgeData.lock();
@@ -285,9 +272,14 @@ Address Accessible::GetAddress() const
       handle->mBridge->RegisterOnBridge(this);
     }
   }
-  std::ostringstream tmp;
-  tmp << this;
-  return {handle ? handle->mBusName : "", tmp.str()};
+  std::string path;
+  auto        actor = GetInternalActor();
+  if(actor)
+  {
+    uint32_t actorId = actor.GetProperty<int>(Dali::Actor::Property::ID);
+    path             = std::to_string(actorId);
+  }
+  return {handle ? handle->mBusName : "", path};
 }
 
 void Bridge::RegisterOnBridge(const Accessible* object)
@@ -296,7 +288,6 @@ void Bridge::RegisterOnBridge(const Accessible* object)
   if(!object->mBridgeData.lock())
   {
     assert(mData);
-    mData->mKnownObjects.insert(object);
     object->mBridgeData = mData;
   }
 }
index 44342b26a8dee01c3906a7b081aef0f08804ca76..d15a0e88ca4c273ca34cc79de1f545ccbeefc249 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
@@ -332,20 +332,13 @@ Accessible* BridgeBase::Find(const std::string& path) const
     return &mApplication;
   }
 
-  void*              accessible;
-  std::istringstream tmp{path};
-  if(!(tmp >> accessible))
-  {
-    throw std::domain_error{"invalid path '" + path + "'"};
-  }
-
-  auto it = mData->mKnownObjects.find(static_cast<Accessible*>(accessible));
-  if(it == mData->mKnownObjects.end() || (!mApplication.mShouldIncludeHidden && (*it)->IsHidden()))
+  auto accessible = GetAccessible(path);
+  if(!accessible || (!mApplication.mShouldIncludeHidden && accessible->IsHidden()))
   {
     throw std::domain_error{"unknown object '" + path + "'"};
   }
 
-  return static_cast<Accessible*>(accessible);
+  return accessible.get();
 }
 
 Accessible* BridgeBase::Find(const Address& ptr) const
index 4bab31bc2ae2121cf7de2181fa5838ea4c2a5b82..632cc143574078b030e6c2705a3f6157c6165a4b 100644 (file)
@@ -121,6 +121,29 @@ public:
     return iter != mAccessibles.end() ? iter->second : nullptr;
   }
 
+  /**
+   * @copydoc Dali::Accessibility::Bridge::GetAccessible()
+   */
+  std::shared_ptr<Accessible> GetAccessible(const std::string& path) const override
+  {
+    try
+    {
+      uint32_t actorId = static_cast<uint32_t>(std::stoi(path));
+      auto     iter    = mAccessibles.find(actorId);
+      return iter != mAccessibles.end() ? iter->second : nullptr;
+    }
+    catch(const std::invalid_argument& ia)
+    {
+      // Handle invalid argument (e.g., non-numeric characters in the string)
+      throw std::runtime_error("Invalid argument: string is not a valid integer");
+    }
+    catch(const std::out_of_range& oor)
+    {
+      // Handle out of range (e.g., the number is too large for uint32_t)
+      throw std::runtime_error("Out of range: number is too large for uint32_t");
+    }
+  }
+
   /**
    * @copydoc Dali::Accessibility::Bridge::ShouldIncludeHidden()
    */
@@ -661,7 +684,7 @@ public:
   void SwitchBridge()
   {
     //If DBusClient is not ready, don't remove initialize timer.
-    if (mInitializeTimer && mInitializeTimer.IsRunning()) return;
+    if(mInitializeTimer && mInitializeTimer.IsRunning()) return;
 
     bool isScreenReaderEnabled = mIsScreenReaderEnabled && !mIsScreenReaderSuppressed;
 
index 8bfbb77c218d6d92be7d36044ece68e2f4343eeb..51cc9666676177251ed7e6f5b5ebc3e2ca191a38 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2024 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2025 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.
 
 namespace Dali
 {
-Accessibility::Accessible::Accessible()
-{
-}
-
-Accessibility::Accessible::~Accessible() noexcept
-{
-}
-
 std::vector<Accessibility::Accessible*> Accessibility::Accessible::GetChildren()
 {
   return {};
index 8b8e2c7c720f0d3a3cf0183b7f81e95e422bd89a..deb02b13dc7eff09057a51ef140de29f14fa00a2 100644 (file)
@@ -246,7 +246,12 @@ struct DummyBridge : Dali::Accessibility::Bridge
   std::shared_ptr<Accessible> GetAccessible(Actor actor) const override
   {
     return nullptr;
-  };
+  }
+
+  std::shared_ptr<Accessible> GetAccessible(const std::string& path) const override
+  {
+    return nullptr;
+  }
 
   bool ShouldIncludeHidden() const override
   {