#endif
#include <dali/devel-api/actors/actor-devel.h>
+#include <dali/devel-api/adaptor-framework/window-devel.h>
// INTERNAL INCLUDES
#include <dali-toolkit/devel-api/asset-manager/asset-manager.h>
#include <dali-toolkit/public-api/controls/image-view/image-view.h>
#include <dali-toolkit/public-api/focus-manager/keyboard-focus-manager.h>
-namespace Dali::Toolkit::DevelControl {
-
+namespace Dali::Toolkit::DevelControl
+{
+namespace
+{
static std::string GetLocaleText(std::string string, const char *domain = "dali-toolkit")
{
#ifdef DGETTEXT_ENABLED
#endif
}
+static Dali::Actor CreateHighlightIndicatorActor()
+{
+ std::string focusBorderImagePath(AssetManager::GetDaliImagePath());
+ focusBorderImagePath += "/keyboard_focus.9.png";
+
+ // Create the default if it hasn't been set and one that's shared by all the
+ // keyboard focusable actors
+ auto actor = Toolkit::ImageView::New(focusBorderImagePath);
+ actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+
+ DevelControl::AppendAccessibilityAttribute(actor, "highlight", std::string());
+ actor.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false);
+
+ return actor;
+}
+} // unnamed namespace
+
AccessibleImpl::AccessibleImpl(Dali::Actor self, Dali::Accessibility::Role role, bool modal)
-: self(self),
- modal(modal)
+: mSelf(self),
+ mIsModal(modal)
{
auto control = Dali::Toolkit::Control::DownCast(Self());
Internal::Control& internalControl = Toolkit::Internal::GetImplementation(control);
Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get(internalControl);
if(controlImpl.mAccessibilityRole == Dali::Accessibility::Role::UNKNOWN)
+ {
controlImpl.mAccessibilityRole = role;
+ }
Self().PropertySetSignal().Connect(&controlImpl, [this, &controlImpl](Dali::Handle& handle, Dali::Property::Index index, Dali::Property::Value value) {
if(this->Self() != Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor())
size_t AccessibleImpl::GetIndexInParent()
{
- auto s = Self();
- auto parent = s.GetParent();
+ auto self = Self();
+ auto parent = self.GetParent();
DALI_ASSERT_ALWAYS(parent && "can't call GetIndexInParent on object without parent");
+
auto count = parent.GetChildCount();
for(auto i = 0u; i < count; ++i)
{
- auto c = parent.GetChildAt(i);
- if(c == s)
+ auto child = parent.GetChildAt(i);
+ if(child == self)
+ {
return i;
+ }
}
DALI_ASSERT_ALWAYS(false && "object isn't child of it's parent");
return static_cast<size_t>(-1);
return GetLocaleText(GetRoleName());
}
+bool AccessibleImpl::IsShowing()
+{
+ Dali::Actor self = Self();
+ if(!self.GetProperty<bool>(Actor::Property::VISIBLE) || self.GetProperty<Vector4>(Actor::Property::WORLD_COLOR).a == 0 || self.GetProperty<bool>(Dali::DevelActor::Property::CULLED))
+ {
+ return false;
+ }
+
+ auto* child = this;
+ auto* parent = dynamic_cast<Toolkit::DevelControl::AccessibleImpl*>(child->GetParent());
+ if(!parent)
+ {
+ return true;
+ }
+
+ auto childExtent = child->GetExtents(Dali::Accessibility::CoordinateType::WINDOW);
+ while(parent)
+ {
+ auto control = Dali::Toolkit::Control::DownCast(parent->Self());
+ if(!control.GetProperty<bool>(Actor::Property::VISIBLE))
+ {
+ return false;
+ }
+ auto clipMode = control.GetProperty(Actor::Property::CLIPPING_MODE).Get<bool>();
+ auto parentExtent = parent->GetExtents(Dali::Accessibility::CoordinateType::WINDOW);
+ if ((clipMode != ClippingMode::DISABLED) && !parentExtent.Intersects(childExtent))
+ {
+ return false;
+ }
+ parent = dynamic_cast<Toolkit::DevelControl::AccessibleImpl*>(parent->GetParent());
+ }
+
+ return true;
+}
+
Dali::Accessibility::States AccessibleImpl::CalculateStates()
{
Dali::Actor self = Self();
- Dali::Accessibility::States s;
- s[Dali::Accessibility::State::FOCUSABLE] = self.GetProperty<bool>(Actor::Property::KEYBOARD_FOCUSABLE);
- s[Dali::Accessibility::State::FOCUSED] = Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() == self;
+ Dali::Accessibility::States state;
+ state[Dali::Accessibility::State::FOCUSABLE] = self.GetProperty<bool>(Actor::Property::KEYBOARD_FOCUSABLE);
+ state[Dali::Accessibility::State::FOCUSED] = Toolkit::KeyboardFocusManager::Get().GetCurrentFocusActor() == self;
+
if(self.GetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE).GetType() == Dali::Property::NONE)
- s[Dali::Accessibility::State::HIGHLIGHTABLE] = false;
+ {
+ state[Dali::Accessibility::State::HIGHLIGHTABLE] = false;
+ }
else
- s[Dali::Accessibility::State::HIGHLIGHTABLE] = self.GetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE).Get<bool>();
- s[Dali::Accessibility::State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self;
- s[Dali::Accessibility::State::ENABLED] = true;
- s[Dali::Accessibility::State::SENSITIVE] = true;
- s[Dali::Accessibility::State::VISIBLE] = true;
- if(modal)
{
- s[Dali::Accessibility::State::MODAL] = true;
+ state[Dali::Accessibility::State::HIGHLIGHTABLE] = self.GetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE).Get<bool>();
}
- s[Dali::Accessibility::State::SHOWING] = !self.GetProperty(Dali::DevelActor::Property::CULLED).Get<bool>() && self.GetCurrentProperty<bool>(Actor::Property::VISIBLE);
- s[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty(Dali::DevelActor::Property::CONNECTED_TO_SCENE).Get<bool>();
- return s;
+ state[Dali::Accessibility::State::HIGHLIGHTED] = GetCurrentlyHighlightedActor() == self;
+ state[Dali::Accessibility::State::ENABLED] = true;
+ state[Dali::Accessibility::State::SENSITIVE] = true;
+ state[Dali::Accessibility::State::VISIBLE] = self.GetProperty<bool>(Actor::Property::VISIBLE);
+
+ if(mIsModal)
+ {
+ state[Dali::Accessibility::State::MODAL] = true;
+ }
+ state[Dali::Accessibility::State::SHOWING] = IsShowing();
+ state[Dali::Accessibility::State::DEFUNCT] = !self.GetProperty(Dali::DevelActor::Property::CONNECTED_TO_SCENE).Get<bool>();
+ return state;
}
Dali::Accessibility::States AccessibleImpl::GetStates()
Dali::Accessibility::Attributes AccessibleImpl::GetAttributes()
{
- std::unordered_map<std::string, std::string> attribute_map;
- auto q = Dali::Toolkit::Control::DownCast(Self());
- auto w =
- q.GetProperty(Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES);
- auto z = w.GetMap();
+ std::unordered_map<std::string, std::string> attributeMap;
+ auto control = Dali::Toolkit::Control::DownCast(Self());
+ auto attribute = control.GetProperty(Dali::Toolkit::DevelControl::Property::ACCESSIBILITY_ATTRIBUTES);
+ auto map = attribute.GetMap();
- if(z)
+ if(map)
{
- auto map_size = z->Count();
+ auto mapSize = map->Count();
- for(unsigned int i = 0; i < map_size; i++)
+ for(unsigned int i = 0; i < mapSize; i++)
{
- auto map_key = z->GetKeyAt(i);
- if(map_key.type == Dali::Property::Key::STRING)
+ auto mapKey = map->GetKeyAt(i);
+ if(mapKey.type == Dali::Property::Key::STRING)
{
- std::string map_value;
- if(z->GetValue(i).Get(map_value))
+ std::string mapValue;
+ if(map->GetValue(i).Get(mapValue))
{
- attribute_map.emplace(std::move(map_key.stringKey),
- std::move(map_value));
+ attributeMap.emplace(std::move(mapKey.stringKey), std::move(mapValue));
}
}
}
}
- return attribute_map;
+ return attributeMap;
}
Dali::Accessibility::ComponentLayer AccessibleImpl::GetLayer()
return Dali::Accessibility::ComponentLayer::WINDOW;
}
-Dali::Rect<> AccessibleImpl::GetExtents(Dali::Accessibility::CoordType ctype)
+Dali::Rect<> AccessibleImpl::GetExtents(Dali::Accessibility::CoordinateType type)
{
Dali::Actor self = Self();
- Vector2 screenPosition =
- self.GetProperty(Dali::DevelActor::Property::SCREEN_POSITION)
- .Get<Vector2>();
+
+ Vector2 screenPosition = self.GetProperty(Dali::DevelActor::Property::SCREEN_POSITION).Get<Vector2>();
auto size = self.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * self.GetCurrentProperty<Vector3>(Actor::Property::WORLD_SCALE);
- bool positionUsesAnchorPoint =
- self.GetProperty(Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT)
- .Get<bool>();
- Vector3 anchorPointOffSet =
- size * (positionUsesAnchorPoint ? self.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT)
- : AnchorPoint::TOP_LEFT);
- Vector2 position = Vector2(screenPosition.x - anchorPointOffSet.x,
- screenPosition.y - anchorPointOffSet.y);
+ bool positionUsesAnchorPoint = self.GetProperty(Dali::DevelActor::Property::POSITION_USES_ANCHOR_POINT).Get<bool>();
+ Vector3 anchorPointOffSet = size * (positionUsesAnchorPoint ? self.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};
+ if(type == Dali::Accessibility::CoordinateType::WINDOW)
+ {
+ return {position.x, position.y, size.x, size.y};
+ }
+ else // Dali::Accessibility::CoordinateType::SCREEN
+ {
+ auto window = Dali::DevelWindow::Get(self);
+ auto windowPosition = window.GetPosition();
+ return {position.x + windowPosition.GetX(), position.y + windowPosition.GetY(), size.x, size.y};
+ }
}
int16_t AccessibleImpl::GetMdiZOrder()
return Toolkit::KeyboardFocusManager::Get().SetCurrentFocusActor(Self());
}
-static Dali::Actor CreateHighlightIndicatorActor()
-{
- std::string focusBorderImagePath(AssetManager::GetDaliImagePath());
- focusBorderImagePath += "/keyboard_focus.9.png";
- // Create the default if it hasn't been set and one that's shared by all the
- // keyboard focusable actors
- auto actor = Toolkit::ImageView::New(focusBorderImagePath);
- actor.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
- DevelControl::AppendAccessibilityAttribute(actor, "highlight", std::string());
- actor.SetProperty(Toolkit::DevelControl::Property::ACCESSIBILITY_HIGHLIGHTABLE, false);
-
- return actor;
-}
-
void AccessibleImpl::ScrollToSelf()
{
auto* child = this;
parent->ScrollToChild(child->Self());
}
- child = parent;
parent = dynamic_cast<Toolkit::DevelControl::AccessibleImpl*>(parent->GetParent());
}
}
+void AccessibleImpl::RegisterPositionPropertyNotification()
+{
+ auto control = Dali::Toolkit::Control::DownCast(Self());
+ Internal::Control& internalControl = Toolkit::Internal::GetImplementation(control);
+ Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get(internalControl);
+ controlImpl.RegisterAccessibilityPositionPropertyNotification();
+}
+
+void AccessibleImpl::UnregisterPositionPropertyNotification()
+{
+ auto control = Dali::Toolkit::Control::DownCast(Self());
+ Internal::Control& internalControl = Toolkit::Internal::GetImplementation(control);
+ Internal::Control::Impl& controlImpl = Internal::Control::Impl::Get(internalControl);
+ controlImpl.UnregisterAccessibilityPositionPropertyNotification();
+}
+
bool AccessibleImpl::GrabHighlight()
{
Dali::Actor self = Self();
- auto old = GetCurrentlyHighlightedActor();
+ auto oldHighlightedActor = GetCurrentlyHighlightedActor();
if(!Dali::Accessibility::IsUp())
+ {
return false;
- if(self == old)
+ }
+
+ if(self == oldHighlightedActor)
+ {
return true;
- if(old)
+ }
+
+ // Clear the old highlight.
+ if(oldHighlightedActor)
{
- auto c = dynamic_cast<Dali::Accessibility::Component*>(Internal::Control::Impl::GetAccessibilityObject(old));
- if(c)
- c->ClearHighlight();
+ auto oldHighlightObject = dynamic_cast<Dali::Accessibility::Component*>(Internal::Control::Impl::GetAccessibilityObject(oldHighlightedActor));
+ if(oldHighlightObject)
+ {
+ oldHighlightObject->ClearHighlight();
+ }
}
+
auto highlight = GetHighlightActor();
if(!highlight)
{
highlight = CreateHighlightIndicatorActor();
SetHighlightActor(highlight);
}
- highlight.SetProperty(Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER);
- highlight.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::CENTER);
+
+ highlight.SetProperty(Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT);
highlight.SetProperty(Actor::Property::POSITION_Z, 1.0f);
highlight.SetProperty(Actor::Property::POSITION, Vector2(0.0f, 0.0f));
+ // Need to set resize policy again, to update SIZE property which is set by
+ // AccessibleImpl_NUI. The highlight could move from AccessibleImpl_NUI to
+ // AccessibleImpl. In this case, highlight has incorrect size.
+ highlight.SetResizePolicy(ResizePolicy::FILL_TO_PARENT, Dimension::ALL_DIMENSIONS);
+
// Remember the highlight actor, so that when the default is changed with
// SetHighlightActor(), the currently displayed highlight can still be cleared.
- currentHighlightActor = highlight;
+ mCurrentHighlightActor = highlight;
ScrollToSelf();
self.Add(highlight);
SetCurrentlyHighlightedActor(self);
EmitHighlighted(true);
+ RegisterPositionPropertyNotification();
return true;
}
Dali::Actor self = Self();
if(!Dali::Accessibility::IsUp())
+ {
return false;
+ }
+
if(GetCurrentlyHighlightedActor() == self)
{
- self.Remove(currentHighlightActor.GetHandle());
- currentHighlightActor = {};
+ UnregisterPositionPropertyNotification();
+ self.Remove(mCurrentHighlightActor.GetHandle());
+ mCurrentHighlightActor = {};
SetCurrentlyHighlightedActor({});
EmitHighlighted(false);
return true;
std::string AccessibleImpl::GetActionName(size_t index)
{
- if(index >= GetActionCount()) return {};
+ if(index >= GetActionCount())
+ {
+ return {};
+ }
+
Dali::TypeInfo type;
Self().GetTypeInfo(type);
DALI_ASSERT_ALWAYS(type && "no TypeInfo object");
std::vector<Dali::Accessibility::Relation> ret;
- auto& v = controlImpl.mAccessibilityRelations;
- for(auto i = 0u; i < v.size(); ++i)
+ auto& relations = controlImpl.mAccessibilityRelations;
+ for(auto i = 0u; i < relations.size(); ++i)
{
- if(v[i].empty())
+ auto& relation = relations[i];
+
+ if(relation.empty())
+ {
continue;
+ }
- ret.emplace_back(Accessibility::Relation{static_cast<Accessibility::RelationType>(i), v[i]});
+ // Map every Accessible* to its Address
+ std::vector<Accessibility::Address> targets;
+ std::transform(relation.begin(), relation.end(), std::back_inserter(targets), [](auto* x) {
+ return x->GetAddress();
+ });
+
+ ret.emplace_back(Accessibility::Relation{static_cast<Accessibility::RelationType>(i), std::move(targets)});
}
return ret;
}
+Dali::Actor AccessibleImpl::GetInternalActor()
+{
+ return Dali::Actor{};
+}
+
bool AccessibleImpl::ScrollToChild(Actor child)
{
return false;
return Dali::Property::INVALID_INDEX;
}
+void AccessibleImpl::SetLastPosition(Vector2 position)
+{
+ mLastPosition = position;
+}
+
+Vector2 AccessibleImpl::GetLastPosition() const
+{
+ return mLastPosition;
+}
+
} // namespace Dali::Toolkit::DevelControl