From d03ac920db0e79bebd3cd6d20943dd5791eb253a Mon Sep 17 00:00:00 2001 From: Youngsun Suh Date: Fri, 14 Jun 2024 16:01:44 +0900 Subject: [PATCH] Use shared_ptr for Accessible object Change-Id: I83e50c800587fa413d235d15952cbf2dec8bdfe7 --- .../devel-api/controls/control-devel.cpp | 8 ++--- .../buttons/check-box-button-impl.cpp | 2 +- .../controls/buttons/push-button-impl.cpp | 2 +- .../controls/buttons/radio-button-impl.cpp | 2 +- .../controls/buttons/toggle-button-impl.cpp | 2 +- .../controls/control/control-data-impl.cpp | 35 +++++++++---------- .../controls/control/control-data-impl.h | 4 +-- .../internal/controls/popup/popup-impl.cpp | 2 +- .../public-api/controls/control-impl.cpp | 6 ++-- .../public-api/controls/control-impl.h | 2 +- 10 files changed, 31 insertions(+), 34 deletions(-) diff --git a/dali-toolkit/devel-api/controls/control-devel.cpp b/dali-toolkit/devel-api/controls/control-devel.cpp index 1de25f46de..93c3d713e2 100644 --- a/dali-toolkit/devel-api/controls/control-devel.cpp +++ b/dali-toolkit/devel-api/controls/control-devel.cpp @@ -256,7 +256,7 @@ Dali::Accessibility::ReadingInfoTypes GetAccessibilityReadingInfoType(Toolkit::C bool ClearAccessibilityHighlight(Toolkit::Control control) { - auto* controlAccessible = GetControlImplementation(control).GetAccessibleObject(); + auto controlAccessible = GetControlImplementation(control).GetAccessibleObject(); if(DALI_LIKELY(controlAccessible)) { return controlAccessible->ClearHighlight(); @@ -266,7 +266,7 @@ bool ClearAccessibilityHighlight(Toolkit::Control control) bool GrabAccessibilityHighlight(Toolkit::Control control) { - auto* controlAccessible = GetControlImplementation(control).GetAccessibleObject(); + auto controlAccessible = GetControlImplementation(control).GetAccessibleObject(); if(DALI_LIKELY(controlAccessible)) { return controlAccessible->GrabHighlight(); @@ -276,7 +276,7 @@ bool GrabAccessibilityHighlight(Toolkit::Control control) Dali::Accessibility::States GetAccessibilityStates(Toolkit::Control control) { - auto* controlAccessible = GetControlImplementation(control).GetAccessibleObject(); + auto controlAccessible = GetControlImplementation(control).GetAccessibleObject(); if(DALI_LIKELY(controlAccessible)) { return controlAccessible->GetStates(); @@ -286,7 +286,7 @@ Dali::Accessibility::States GetAccessibilityStates(Toolkit::Control control) void NotifyAccessibilityStateChange(Toolkit::Control control, Dali::Accessibility::States states, bool recurse) { - auto* controlAccessible = GetControlImplementation(control).GetAccessibleObject(); + auto controlAccessible = GetControlImplementation(control).GetAccessibleObject(); if(DALI_LIKELY(controlAccessible)) { controlAccessible->NotifyAccessibilityStateChange(std::move(states), recurse); diff --git a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp index b000325755..a7783716b9 100644 --- a/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/check-box-button-impl.cpp @@ -101,7 +101,7 @@ void CheckBoxButton::OnStateChange(State newState) // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used if(newState == SELECTED_STATE || newState == UNSELECTED_STATE) { - auto* accessible = GetAccessibleObject(); + auto accessible = GetAccessibleObject(); if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) { accessible->EmitStateChanged(Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0); diff --git a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp index 70e7261514..4e26fad394 100644 --- a/dali-toolkit/internal/controls/buttons/push-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/push-button-impl.cpp @@ -209,7 +209,7 @@ void PushButton::OnStateChange(State newState) // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used if(newState == SELECTED_STATE || newState == UNSELECTED_STATE) { - auto* accessible = GetAccessibleObject(); + auto accessible = GetAccessibleObject(); if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) { accessible->EmitStateChanged(Dali::Accessibility::State::PRESSED, newState == SELECTED_STATE ? 1 : 0, 0); diff --git a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp index d352f2b8c2..3241ea07b5 100644 --- a/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/radio-button-impl.cpp @@ -109,7 +109,7 @@ void RadioButton::OnStateChange(State newState) // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used if(newState == SELECTED_STATE || newState == UNSELECTED_STATE) { - auto* accessible = GetAccessibleObject(); + auto accessible = GetAccessibleObject(); if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) { accessible->EmitStateChanged(Dali::Accessibility::State::CHECKED, newState == SELECTED_STATE ? 1 : 0, 0); diff --git a/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp b/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp index 5dd9b877e4..d292b0ec2f 100644 --- a/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp +++ b/dali-toolkit/internal/controls/buttons/toggle-button-impl.cpp @@ -414,7 +414,7 @@ void ToggleButton::OnStateChange(State newState) // TODO: replace it with OnPropertySet hook once Button::Property::SELECTED will be consistently used if(newState == SELECTED_STATE || newState == UNSELECTED_STATE) { - auto* accessible = GetAccessibleObject(); + auto accessible = GetAccessibleObject(); if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) { accessible->EmitStateChanged(Dali::Accessibility::State::CHECKED, mCurrentToggleIndex ? 1 : 0, 0); diff --git a/dali-toolkit/internal/controls/control/control-data-impl.cpp b/dali-toolkit/internal/controls/control/control-data-impl.cpp index a67cd3473e..efb0dee96c 100644 --- a/dali-toolkit/internal/controls/control/control-data-impl.cpp +++ b/dali-toolkit/internal/controls/control/control-data-impl.cpp @@ -497,19 +497,6 @@ static bool IsShowingGeometryOnScreen(Dali::Rect<> rect) return rect.width > 0 && rect.height > 0; } -Dali::Accessibility::Accessible* ExternalAccessibleGetter(Dali::Actor actor) -{ - auto control = Toolkit::Control::DownCast(actor); - if(!control) - { - return nullptr; - } - - auto& controlImpl = Toolkit::Internal::GetImplementation(control); - - return controlImpl.GetAccessibleObject(); -} - } // unnamed namespace // clang-format off @@ -580,7 +567,17 @@ Control::Impl::Impl(Control& controlImpl) mDispatchKeyEvents(true), mProcessorRegistered(false) { - Dali::Accessibility::Accessible::RegisterExternalAccessibleGetter(&ExternalAccessibleGetter); + Accessibility::Accessible::RegisterExternalAccessibleGetter([](Dali::Actor actor) -> std::shared_ptr { + auto control = Toolkit::Control::DownCast(actor); + if(!control) + { + return nullptr; + } + + auto& controlImpl = Toolkit::Internal::GetImplementation(control); + + return controlImpl.GetAccessibleObject(); + }); } Control::Impl::~Impl() @@ -632,7 +629,7 @@ void Control::Impl::CheckHighlightedObjectGeometry() { auto lastPosition = accessible->GetLastPosition(); auto accessibleRect = accessible->GetExtents(Dali::Accessibility::CoordinateType::WINDOW); - auto rect = GetShowingGeometry(accessibleRect, accessible); + auto rect = GetShowingGeometry(accessibleRect, accessible.get()); switch(mAccessibilityLastScreenRelativeMoveType) { @@ -728,7 +725,7 @@ void Control::Impl::UnregisterAccessibilityPropertySetSignal() void Control::Impl::OnAccessibilityPropertySet(Dali::Handle& handle, Dali::Property::Index index, const Dali::Property::Value& value) { - auto* accessible = GetAccessibleObject(); + auto accessible = GetAccessibleObject(); if(DALI_LIKELY(accessible)) { if(mAccessibilityGetNameSignal.Empty()) @@ -1530,7 +1527,7 @@ void Control::Impl::SetProperty(BaseObject* object, Property::Index index, const { controlImpl.mImpl->mAccessibilityHidden = hidden; - auto* accessible = controlImpl.GetAccessibleObject(); + auto accessible = controlImpl.GetAccessibleObject(); if(DALI_LIKELY(accessible)) { auto* parent = dynamic_cast(accessible->GetParent()); @@ -2293,14 +2290,14 @@ bool Control::Impl::OnIdleCallback() return mIdleCallbackRegistered; } -Toolkit::DevelControl::ControlAccessible* Control::Impl::GetAccessibleObject() +std::shared_ptr Control::Impl::GetAccessibleObject() { if(mAccessibleCreatable && !mAccessibleObject) { mAccessibleObject.reset(mControlImpl.CreateAccessibleObject()); } - return mAccessibleObject.get(); + return mAccessibleObject; } bool Control::Impl::IsAccessibleCreated() const diff --git a/dali-toolkit/internal/controls/control/control-data-impl.h b/dali-toolkit/internal/controls/control/control-data-impl.h index fff6769068..6320864dc9 100644 --- a/dali-toolkit/internal/controls/control/control-data-impl.h +++ b/dali-toolkit/internal/controls/control/control-data-impl.h @@ -456,7 +456,7 @@ public: /** * @copydoc Dali::Toolkit::Internal::Control::GetAccessibleObject() */ - Toolkit::DevelControl::ControlAccessible* GetAccessibleObject(); + std::shared_ptr GetAccessibleObject(); /** * @copydoc Dali::Toolkit::DevelControl::IsAccessibleCreated() @@ -636,7 +636,7 @@ public: Dali::Accessibility::Role mAccessibilityRole = Dali::Accessibility::Role::UNKNOWN; std::map> mAccessibilityRelations; - std::unique_ptr mAccessibleObject; + std::shared_ptr mAccessibleObject; // Gesture Detection PinchGestureDetector mPinchGestureDetector; diff --git a/dali-toolkit/internal/controls/popup/popup-impl.cpp b/dali-toolkit/internal/controls/popup/popup-impl.cpp index 9c9a1f2691..31959657b6 100644 --- a/dali-toolkit/internal/controls/popup/popup-impl.cpp +++ b/dali-toolkit/internal/controls/popup/popup-impl.cpp @@ -729,7 +729,7 @@ void Popup::SetDisplayState(Toolkit::Popup::DisplayState displayState) // Convert the bool state to the actual display state to use. mDisplayState = display ? Toolkit::Popup::SHOWING : Toolkit::Popup::HIDING; - auto* accessible = Dali::Accessibility::Accessible::Get(Self()); + auto accessible = Dali::Accessibility::Accessible::GetOwningPtr(Self()); if(display) { diff --git a/dali-toolkit/public-api/controls/control-impl.cpp b/dali-toolkit/public-api/controls/control-impl.cpp index a1f1828112..e4357109e6 100644 --- a/dali-toolkit/public-api/controls/control-impl.cpp +++ b/dali-toolkit/public-api/controls/control-impl.cpp @@ -199,7 +199,7 @@ void Control::SetResourceReady() controlDataImpl.ResourceReady(); } -Toolkit::DevelControl::ControlAccessible* Control::GetAccessibleObject() +std::shared_ptr Control::GetAccessibleObject() { return mImpl->GetAccessibleObject(); } @@ -525,7 +525,7 @@ void Control::EmitKeyInputFocusSignal(bool focusGained) auto parent = accessible->GetParent(); if(parent && !accessible->GetStates()[Dali::Accessibility::State::MANAGES_DESCENDANTS]) { - parent->EmitActiveDescendantChanged(accessible); + parent->EmitActiveDescendantChanged(accessible.get()); } } } @@ -608,7 +608,7 @@ void Control::OnPropertySet(Property::Index index, const Property::Value& proper } case Actor::Property::VISIBLE: { - auto* accessible = GetAccessibleObject(); + auto accessible = GetAccessibleObject(); if(DALI_LIKELY(accessible) && accessible->IsHighlighted()) { accessible->EmitVisible(Self().GetProperty(Actor::Property::VISIBLE)); diff --git a/dali-toolkit/public-api/controls/control-impl.h b/dali-toolkit/public-api/controls/control-impl.h index 4fe078121d..76991aa0a0 100644 --- a/dali-toolkit/public-api/controls/control-impl.h +++ b/dali-toolkit/public-api/controls/control-impl.h @@ -140,7 +140,7 @@ public: * * @see CreateAccessibleObject() */ - Toolkit::DevelControl::ControlAccessible* GetAccessibleObject(); + std::shared_ptr GetAccessibleObject(); // Gesture Detection -- 2.34.1