Revert "Revert "Update the bridge to own accessible objects"" 33/317333/1
authorYoungsun Suh <youngsun.suh@samsung.com>
Mon, 9 Sep 2024 02:24:25 +0000 (11:24 +0900)
committerYoungsun Suh <youngsun.suh@samsung.com>
Mon, 9 Sep 2024 05:29:44 +0000 (14:29 +0900)
This reverts commit d7334f5f25d69f3231b9ee64d39d02561452afb7.

Change-Id: Idb61242ede92cf6062ed86e37ab636e3e308987b

automated-tests/src/dali-toolkit-internal/utc-Dali-Accessibility-Controls-BridgeUp.cpp
automated-tests/src/dali-toolkit/dali-toolkit-test-utils/toolkit-test-application.cpp
dali-toolkit/internal/controls/control/control-data-impl.cpp
dali-toolkit/internal/controls/control/control-data-impl.h

index 75046c5b08c8d8adb6fe151a2a8d5eccb0986a18..4aa5a7e0458f45647b4a3d6e66f7cb1d74d2f209 100644 (file)
@@ -1945,5 +1945,43 @@ int UtcDaliEmitAccessibilityStateChanged(void)
   DALI_TEST_CHECK(Dali::Accessibility::TestStateChangedResult("showing", 1));
   DALI_TEST_CHECK(Accessibility::Bridge::GetCurrentBridge()->GetDefaultLabel(rootAccessible) != buttonAccessible);
 
+  Dali::Accessibility::TestEnableSC(false);
+
+  END_TEST;
+}
+
+int UtcDaliGetAcessibleTestWithSceneConnection(void)
+{
+  ToolkitTestApplication application;
+
+  Dali::Accessibility::TestEnableSC(true);
+
+  auto layer = Layer::New();
+
+  auto control = Control::New();
+
+  std::weak_ptr<Accessibility::Accessible> layerAccessible   = Accessibility::Accessible::GetOwningPtr(layer);   // AdaptorAccessible
+  std::weak_ptr<Accessibility::Accessible> controlAccessible = Accessibility::Accessible::GetOwningPtr(control); // ControlAccessible
+  DALI_TEST_CHECK(layerAccessible.lock());
+  DALI_TEST_CHECK(controlAccessible.lock());
+
+  // Test Getting already added accessible from the map
+  DALI_TEST_CHECK(!layerAccessible.expired());
+  DALI_TEST_CHECK(!controlAccessible.expired());
+  DALI_TEST_CHECK(Accessibility::Accessible::Get(layer) == layerAccessible.lock().get());
+  DALI_TEST_CHECK(Accessibility::Accessible::Get(control) == controlAccessible.lock().get());
+
+  // Test ControlAccessible Removal
+  control.Reset();
+  DALI_TEST_CHECK(controlAccessible.expired());
+  DALI_TEST_CHECK(Accessibility::Accessible::Get(control) == nullptr);
+
+  // Test AdaptorAccessible Removal
+  layer.Reset();
+  DALI_TEST_CHECK(layerAccessible.expired());
+  DALI_TEST_CHECK(Accessibility::Accessible::Get(layer) == nullptr);
+
+  Dali::Accessibility::TestEnableSC(false);
+
   END_TEST;
 }
index ce66dae3358b27517b4f0b5483bc57b6b1b7cf52..48091cd4d1a6e5d1c9078effa9c45b5504596625 100644 (file)
@@ -54,7 +54,6 @@ ToolkitTestApplication::ToolkitTestApplication(size_t surfaceWidth, size_t surfa
 
   // Core needs to be initialized next before we start the adaptor
   InitializeCore();
-  Accessibility::Accessible::SetObjectRegistry(mCore->GetObjectRegistry());
 
   // This will also emit the window created signals
   AdaptorImpl::GetImpl(*mAdaptor).Start(mMainWindow);
index 985ed9d55777334196d6aaecde443923c3449dc1..9ded0d25b658ea0423535ceb942db9a1ac7532a2 100644 (file)
@@ -643,16 +643,20 @@ Control::Impl::Impl(Control& controlImpl)
   mDispatchKeyEvents(true),
   mProcessorRegistered(false)
 {
-  Accessibility::Accessible::RegisterExternalAccessibleGetter([](Dali::Actor actor) -> std::shared_ptr<Accessibility::Accessible> {
+  Accessibility::Accessible::RegisterExternalAccessibleGetter([](Dali::Actor actor) -> std::pair<std::shared_ptr<Accessibility::Accessible>, bool> {
     auto control = Toolkit::Control::DownCast(actor);
     if(!control)
     {
-      return nullptr;
+      return {nullptr, true};
     }
 
     auto& controlImpl = Toolkit::Internal::GetImplementation(control);
+    if(controlImpl.mImpl->IsCreateAccessibleEnabled())
+    {
+      return {std::shared_ptr<DevelControl::ControlAccessible>(controlImpl.CreateAccessibleObject()), true};
+    }
 
-    return controlImpl.GetAccessibleObject();
+    return {nullptr, false};
   });
   mAccessibilityProps.states[DevelControl::AccessibilityState::ENABLED] = true;
 }
@@ -2442,17 +2446,12 @@ bool Control::Impl::OnIdleCallback()
 
 std::shared_ptr<Toolkit::DevelControl::ControlAccessible> Control::Impl::GetAccessibleObject()
 {
-  if(mAccessibleCreatable && !mAccessibleObject)
-  {
-    mAccessibleObject.reset(mControlImpl.CreateAccessibleObject());
-  }
-
-  return mAccessibleObject;
+  return std::dynamic_pointer_cast<DevelControl::ControlAccessible>(Accessibility::Accessible::GetOwningPtr(mControlImpl.Self()));
 }
 
 bool Control::Impl::IsAccessibleCreated() const
 {
-  return !!mAccessibleObject;
+  return !!Accessibility::Bridge::GetCurrentBridge()->GetAccessible(mControlImpl.Self());
 }
 
 void Control::Impl::EnableCreateAccessible(bool enable)
index 93e25447ed9b642e9739b9c93aba62bd8fb77fb5..71c6d3c69c357c9b762ee308beb821cbdb22a30d 100644 (file)
@@ -703,8 +703,6 @@ private:
   bool                                        mIsAccessibilityPropertySetSignalRegistered{false};
   Dali::PropertyNotification                  mAccessibilityPositionNotification;
   Dali::Accessibility::ScreenRelativeMoveType mAccessibilityLastScreenRelativeMoveType{Accessibility::ScreenRelativeMoveType::OUTSIDE};
-
-  std::shared_ptr<Toolkit::DevelControl::ControlAccessible> mAccessibleObject;
 };
 
 } // namespace Internal