X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=dali-toolkit%2Fdevel-api%2Fcontrols%2Fcontrol-accessible.cpp;h=8788adea9bd07107ddcf76557daeab633e145ecd;hp=5ac6317771d25e1f8f6dbc59dcd07a1694b10626;hb=HEAD;hpb=56fe73b3b5a7482d10bb9c271f494b5a09c2c75f diff --git a/dali-toolkit/devel-api/controls/control-accessible.cpp b/dali-toolkit/devel-api/controls/control-accessible.cpp index 5ac6317..7e6981b 100644 --- a/dali-toolkit/devel-api/controls/control-accessible.cpp +++ b/dali-toolkit/devel-api/controls/control-accessible.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Samsung Electronics Co., Ltd. + * Copyright (c) 2024 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. @@ -25,10 +25,13 @@ #include #include +#include +#include // INTERNAL INCLUDES #include #include +#include #include #include #include @@ -38,7 +41,9 @@ namespace Dali::Toolkit::DevelControl { namespace { -static std::string GetLocaleText(std::string string, const char* domain = "dali-toolkit") +constexpr const char* ATTR_IMG_SRC_KEY = "imgSrc"; + +std::string GetLocaleText(std::string string, const char* domain = "dali-toolkit") { #ifdef DGETTEXT_ENABLED /*TODO: currently non-localized string is used as a key for translation lookup. In case the lookup key formatting is forced @@ -49,7 +54,7 @@ static std::string GetLocaleText(std::string string, const char* domain = "dali- #endif } -static Dali::Actor CreateHighlightIndicatorActor() +Dali::Actor CreateHighlightIndicatorActor() { std::string focusBorderImagePath(AssetManager::GetDaliImagePath()); focusBorderImagePath += "/keyboard_focus.9.png"; @@ -64,38 +69,50 @@ static Dali::Actor CreateHighlightIndicatorActor() return actor; } -} // unnamed namespace -ControlAccessible::ControlAccessible(Dali::Actor self) -: ActorAccessible(self) +std::string FetchImageSrcFromMap(const Dali::Property::Map& imageMap) { - auto control = Toolkit::Control::DownCast(self); - - Internal::Control& internalControl = Toolkit::Internal::GetImplementation(control); - Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get(internalControl); - - self.PropertySetSignal().Connect(&controlImpl, [this, &controlImpl](Dali::Handle& handle, Dali::Property::Index index, Dali::Property::Value value) { - if(this->Self() != Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor()) + auto urlVal = imageMap.Find(Toolkit::ImageVisual::Property::URL); + if(urlVal) + { + if(urlVal->GetType() == Dali::Property::STRING) { - return; + return urlVal->Get(); } - - if(index == DevelControl::Property::ACCESSIBILITY_NAME || (index == GetNamePropertyIndex() && controlImpl.mAccessibilityName.empty())) + else if(urlVal->GetType() == Dali::Property::ARRAY) { - if(controlImpl.mAccessibilityGetNameSignal.Empty()) + auto urlArray = urlVal->GetArray(); + if(urlArray && !urlArray->Empty()) { - Emit(Dali::Accessibility::ObjectPropertyChangeEvent::NAME); + // Returns first element if url is an array + return (*urlArray)[0].Get(); } } + } + return {}; +} - if(index == DevelControl::Property::ACCESSIBILITY_DESCRIPTION || (index == GetDescriptionPropertyIndex() && controlImpl.mAccessibilityDescription.empty())) - { - if(controlImpl.mAccessibilityGetDescriptionSignal.Empty()) - { - Emit(Dali::Accessibility::ObjectPropertyChangeEvent::DESCRIPTION); - } - } - }); +std::string FetchImageSrc(const Toolkit::ImageView& imageView) +{ + const auto imageUrl = imageView.GetProperty(Toolkit::ImageView::Property::IMAGE); + if(!imageUrl.empty()) + { + return imageUrl; + } + + const auto imageMap = imageView.GetProperty(Toolkit::ImageView::Property::IMAGE); + if(!imageMap.Empty()) + { + return FetchImageSrcFromMap(imageMap); + } + return {}; +} + +} // unnamed namespace + +ControlAccessible::ControlAccessible(Dali::Actor self) +: ActorAccessible(self) +{ } std::string ControlAccessible::GetName() const @@ -218,9 +235,9 @@ Dali::Accessibility::States ControlAccessible::CalculateStates() states[State::FOCUSABLE] = self.GetProperty(Actor::Property::KEYBOARD_FOCUSABLE); states[State::FOCUSED] = Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() == self; states[State::HIGHLIGHTABLE] = self.GetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE); - states[State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self; + states[State::HIGHLIGHTED] = IsHighlighted(); states[State::ENABLED] = true; - states[State::SENSITIVE] = true; + states[State::SENSITIVE] = (Dali::DevelActor::IsHittable(self) && Dali::DevelActor::GetTouchRequired(self)); states[State::VISIBLE] = self.GetProperty(Actor::Property::VISIBLE); states[State::SHOWING] = IsShowing(); states[State::DEFUNCT] = !self.GetProperty(Dali::DevelActor::Property::CONNECTED_TO_SCENE).Get(); @@ -235,36 +252,58 @@ Dali::Accessibility::States ControlAccessible::GetStates() Dali::Accessibility::Attributes ControlAccessible::GetAttributes() const { - std::unordered_map attributeMap; - auto control = Dali::Toolkit::Control::DownCast(Self()); - auto attribute = control.GetProperty(Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES); - auto map = attribute.GetMap(); + static const std::string automationIdKey = "automationId"; + static const std::string classKey = "class"; + + Accessibility::Attributes result; + Toolkit::Control control = Toolkit::Control::DownCast(Self()); + Dali::Property::Value property = control.GetProperty(DevelControl::Property::ACCESSIBILITY_ATTRIBUTES); + Dali::Property::Map* attributeMap = property.GetMap(); + std::size_t attributeCount = attributeMap ? attributeMap->Count() : 0U; - if(map) + for(std::size_t i = 0; i < attributeCount; i++) { - auto mapSize = map->Count(); + Dali::Property::Key mapKey = attributeMap->GetKeyAt(i); + std::string mapValue; - for(unsigned int i = 0; i < mapSize; i++) + if(mapKey.type == Dali::Property::Key::STRING && attributeMap->GetValue(i).Get(mapValue)) { - auto mapKey = map->GetKeyAt(i); - if(mapKey.type == Dali::Property::Key::STRING) - { - std::string mapValue; - if(map->GetValue(i).Get(mapValue)) - { - attributeMap.emplace(std::move(mapKey.stringKey), std::move(mapValue)); - } - } + result.emplace(std::move(mapKey.stringKey), std::move(mapValue)); } } - auto automationId = control.GetProperty(Dali::Toolkit::DevelControl::Property::AUTOMATION_ID); + auto automationId = control.GetProperty(DevelControl::Property::AUTOMATION_ID); if(!automationId.empty()) { - attributeMap.emplace("automationId", std::move(automationId)); + result.emplace(automationIdKey, std::move(automationId)); + } + + if(auto imageView = Toolkit::ImageView::DownCast(Self())) + { + auto imageSrc = FetchImageSrc(imageView); + if(!imageSrc.empty()) + { + result.emplace(ATTR_IMG_SRC_KEY, std::move(imageSrc)); + } + } + + // Add "class" if not present already + if(result.find(classKey) == result.end()) + { + Dali::TypeInfo typeInfo; + Self().GetTypeInfo(typeInfo); + if(typeInfo) + { + const std::string& typeName = typeInfo.GetName(); + + result.emplace(classKey, typeName); + + // Save the 'typeName' so we don't have to calculate it again + DevelControl::AppendAccessibilityAttribute(control, classKey, typeName); + } } - return attributeMap; + return result; } bool ControlAccessible::IsHidden() const @@ -314,6 +353,22 @@ void ControlAccessible::UnregisterPositionPropertyNotification() controlImpl.UnregisterAccessibilityPositionPropertyNotification(); } +void ControlAccessible::RegisterPropertySetSignal() +{ + auto control = Dali::Toolkit::Control::DownCast(Self()); + Internal::Control& internalControl = Toolkit::Internal::GetImplementation(control); + Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get(internalControl); + controlImpl.RegisterAccessibilityPropertySetSignal(); +} + +void ControlAccessible::UnregisterPropertySetSignal() +{ + auto control = Dali::Toolkit::Control::DownCast(Self()); + Internal::Control& internalControl = Toolkit::Internal::GetImplementation(control); + Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get(internalControl); + controlImpl.UnregisterAccessibilityPropertySetSignal(); +} + bool ControlAccessible::GrabHighlight() { Dali::Actor self = Self(); @@ -363,23 +418,23 @@ bool ControlAccessible::GrabHighlight() SetCurrentlyHighlightedActor(self); EmitHighlighted(true); RegisterPositionPropertyNotification(); + RegisterPropertySetSignal(); return true; } bool ControlAccessible::ClearHighlight() { - Dali::Actor self = Self(); - if(!Dali::Accessibility::IsUp()) { return false; } - if(GetCurrentlyHighlightedActor() == self) + if(IsHighlighted()) { + UnregisterPropertySetSignal(); UnregisterPositionPropertyNotification(); - self.Remove(mCurrentHighlightActor.GetHandle()); + Self().Remove(mCurrentHighlightActor.GetHandle()); mCurrentHighlightActor = {}; SetCurrentlyHighlightedActor({}); EmitHighlighted(false);