#include <dali/public-api/object/object-registry.h>
#include <dali/public-api/object/type-info.h>
#include <dali/public-api/object/type-registry-helper.h>
+#include <dali/public-api/object/weak-handle.h>
// INTERNAL INCLUDES
-#include <dali/public-api/dali-adaptor-common.h>
#include <dali/devel-api/adaptor-framework/accessibility-impl.h>
#include <dali/internal/adaptor/common/adaptor-impl.h>
+#include <dali/public-api/dali-adaptor-common.h>
using namespace Dali::Accessibility;
using namespace Dali;
std::string Accessible::GetRoleName()
{
- switch( GetRole() )
+ switch(GetRole())
{
case Role::INVALID:
{
void Accessible::SetCurrentlyHighlightedActor(Dali::Actor actor)
{
- if (IsUp())
+ if(IsUp())
{
Bridge::GetCurrentBridge()->data->currentlyHighlightedActor = actor;
}
void Accessible::SetHighlightActor(Dali::Actor actor)
{
- if (IsUp())
+ if(IsUp())
{
Bridge::GetCurrentBridge()->data->highlightActor = actor;
}
void Bridge::ForceDown()
{
auto highlighted = Accessible::GetCurrentlyHighlightedActor();
- if( highlighted )
+ if(highlighted)
{
- auto p = dynamic_cast< Component* >( Accessible::Get( highlighted ) );
- if( p )
+ auto p = dynamic_cast<Component*>(Accessible::Get(highlighted));
+ if(p)
{
p->ClearHighlight();
}
data = {};
}
-void Bridge::SetIsOnRootLevel( Accessible* o )
+void Bridge::SetIsOnRootLevel(Accessible* o)
{
o->isOnRootLevel = true;
}
{
class NonControlAccessible : public virtual Accessible, public virtual Collection, public virtual Component
{
-public:
- Dali::Actor actor;
- bool root = false;
+protected:
+ Dali::WeakHandle<Dali::Actor> self;
+ bool root = false;
+
+ Dali::Actor Self()
+ {
+ auto handle = self.GetHandle();
+
+ // NonControlAccessible is deleted on ObjectDestroyedSignal
+ // for the respective actor (see `nonControlAccessibles`).
+ DALI_ASSERT_ALWAYS(handle);
- NonControlAccessible( Dali::Actor actor, bool root ) : actor( actor ), root( root )
+ return handle;
+ }
+
+public:
+ NonControlAccessible(Dali::Actor actor, bool root)
+ : self(actor),
+ root(root)
{
}
- Dali::Rect<> GetExtents( Dali::Accessibility::CoordType ctype ) override
+ Dali::Rect<> GetExtents(Dali::Accessibility::CoordType ctype) override
{
- Vector2 screenPosition = actor.GetProperty( Actor::Property::SCREEN_POSITION ).Get< Vector2 >();
- Vector3 size = actor.GetCurrentProperty< Vector3 >( Actor::Property::SIZE ) * actor.GetCurrentProperty< Vector3 >( Actor::Property::WORLD_SCALE );
- bool positionUsesAnchorPoint = actor.GetProperty( Actor::Property::POSITION_USES_ANCHOR_POINT ).Get< bool >();
- Vector3 anchorPointOffSet = size * ( positionUsesAnchorPoint ? actor.GetCurrentProperty< Vector3 >( Actor::Property::ANCHOR_POINT ) : AnchorPoint::TOP_LEFT );
- Vector2 position = Vector2( screenPosition.x - anchorPointOffSet.x, screenPosition.y - anchorPointOffSet.y );
+ Dali::Actor actor = Self();
+ Vector2 screenPosition = actor.GetProperty(Actor::Property::SCREEN_POSITION).Get<Vector2>();
+ Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_SCALE);
+ bool positionUsesAnchorPoint = actor.GetProperty(Actor::Property::POSITION_USES_ANCHOR_POINT).Get<bool>();
+ Vector3 anchorPointOffSet = size * (positionUsesAnchorPoint ? actor.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 };
+ return {position.x, position.y, size.x, size.y};
}
Dali::Accessibility::ComponentLayer GetLayer() override
{
}
std::string GetName() override
{
- return actor.GetProperty< std::string >( Dali::Actor::Property::NAME );
+ return Self().GetProperty<std::string>(Dali::Actor::Property::NAME);
}
std::string GetDescription() override
{
}
Accessible* GetParent() override
{
- if( GetIsOnRootLevel() )
+ if(GetIsOnRootLevel())
{
auto b = GetBridgeData();
return b->bridge->GetApplication();
}
- return Get( actor.GetParent() );
+ return Get(Self().GetParent());
}
size_t GetChildCount() override
{
- return static_cast< size_t >( actor.GetChildCount() );
+ return static_cast<size_t>(Self().GetChildCount());
}
- Accessible* GetChildAtIndex( size_t index ) override
+ Accessible* GetChildAtIndex(size_t index) override
{
- auto s = static_cast< size_t >( actor.GetChildCount() );
- if( index >= s )
+ auto s = static_cast<size_t>(Self().GetChildCount());
+ if(index >= s)
{
- throw std::domain_error{"invalid index " + std::to_string( index ) + " for object with " + std::to_string( s ) + " children"};
+ throw std::domain_error{"invalid index " + std::to_string(index) + " for object with " + std::to_string(s) + " children"};
}
- return Get( actor.GetChildAt( static_cast< unsigned int >( index ) ) );
+ return Get(Self().GetChildAt(static_cast<unsigned int>(index)));
}
size_t GetIndexInParent() override
{
- auto parent = actor.GetParent();
- if( !parent )
+ auto parent = Self().GetParent();
+ if(!parent)
{
return 0;
}
- auto size = static_cast< size_t >( parent.GetChildCount() );
- for( auto i = 0u; i < size; ++i )
+ auto size = static_cast<size_t>(parent.GetChildCount());
+ for(auto i = 0u; i < size; ++i)
{
- if( parent.GetChildAt( i ) == actor )
+ if(parent.GetChildAt(i) == Self())
{
return i;
}
States GetStates() override
{
States s;
- if( root )
+ if(root)
{
- s[State::ENABLED] = true;
+ s[State::ENABLED] = true;
s[State::SENSITIVE] = true;
- s[State::SHOWING] = true;
- s[State::VISIBLE] = true;
- s[State::ACTIVE] = true;
+ s[State::SHOWING] = true;
+ s[State::VISIBLE] = true;
+ s[State::ACTIVE] = true;
}
else
{
- auto t = GetParent()->GetStates();
+ auto t = GetParent()->GetStates();
s[State::SHOWING] = t[State::SHOWING];
s[State::VISIBLE] = t[State::VISIBLE];
}
Attributes GetAttributes() override
{
Dali::TypeInfo type;
- actor.GetTypeInfo( type );
- return { {"t", type.GetName()}, };
+ Self().GetTypeInfo(type);
+ return {
+ {"t", type.GetName()},
+ };
}
- bool DoGesture(const GestureInfo &gestureInfo) override
+ bool DoGesture(const GestureInfo& gestureInfo) override
{
return false;
}
}
};
-using NonControlAccessiblesType = std::unordered_map< const Dali::RefObject*, std::unique_ptr< NonControlAccessible > >;
+using NonControlAccessiblesType = std::unordered_map<const Dali::RefObject*, std::unique_ptr<NonControlAccessible> >;
NonControlAccessiblesType nonControlAccessibles;
-std::function< Accessible*( Dali::Actor ) > convertingFunctor = []( Dali::Actor ) -> Accessible*
-{
+std::function<Accessible*(Dali::Actor)> convertingFunctor = [](Dali::Actor) -> Accessible* {
return nullptr;
};
objectRegistry = registry;
}
-void Accessible::RegisterControlAccessibilityGetter( std::function< Accessible*( Dali::Actor ) > functor )
+void Accessible::RegisterControlAccessibilityGetter(std::function<Accessible*(Dali::Actor)> functor)
{
convertingFunctor = functor;
}
-Accessible* Accessible::Get( Dali::Actor actor, bool root )
+Accessible* Accessible::Get(Dali::Actor actor, bool root)
{
- if( !actor )
+ if(!actor)
{
return nullptr;
}
- auto accessible = convertingFunctor( actor );
- if( !accessible )
+ auto accessible = convertingFunctor(actor);
+ if(!accessible)
{
- if( nonControlAccessibles.empty() && objectRegistry )
+ if(nonControlAccessibles.empty() && objectRegistry)
{
- objectRegistry.ObjectDestroyedSignal().Connect( []( const Dali::RefObject* obj )
- {
- nonControlAccessibles.erase( obj );
- }
- );
+ objectRegistry.ObjectDestroyedSignal().Connect([](const Dali::RefObject* obj) {
+ nonControlAccessibles.erase(obj);
+ });
}
- auto it = nonControlAccessibles.emplace( &actor.GetBaseObject(), nullptr );
- if( it.second )
+ auto it = nonControlAccessibles.emplace(&actor.GetBaseObject(), nullptr);
+ if(it.second)
{
- it.first->second.reset( new NonControlAccessible( actor, root ) );
+ it.first->second.reset(new NonControlAccessible(actor, root));
}
accessible = it.first->second.get();
}