2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/devel-api/adaptor-framework/actor-accessible.h>
22 #include <dali/devel-api/adaptor-framework/window-devel.h>
24 namespace Dali::Accessibility
26 ActorAccessible::ActorAccessible(Actor actor)
31 std::string ActorAccessible::GetName() const
33 return Self().GetProperty<std::string>(Dali::Actor::Property::NAME);
36 std::string ActorAccessible::GetDescription() const
41 Accessible* ActorAccessible::GetParent()
45 auto data = GetBridgeData();
46 return data->mBridge->GetApplication();
49 return Get(Self().GetParent());
52 std::size_t ActorAccessible::GetChildCount() const
54 return static_cast<std::size_t>(Self().GetChildCount());
57 std::vector<Accessible*> ActorAccessible::GetChildren()
59 std::vector<Accessible*> tmp(GetChildCount());
60 for(auto i = 0u; i < tmp.size(); ++i)
62 tmp[i] = GetChildAtIndex(i);
68 Accessible* ActorAccessible::GetChildAtIndex(std::size_t index)
70 auto numberOfChildren = GetChildCount();
71 if(DALI_UNLIKELY(index >= numberOfChildren))
73 throw std::domain_error{"invalid index " + std::to_string(index) + " for object with " + std::to_string(numberOfChildren) + " children"};
76 return Get(Self().GetChildAt(static_cast<std::uint32_t>(index)));
79 std::size_t ActorAccessible::GetIndexInParent()
82 auto parent = self.GetParent();
84 if(DALI_UNLIKELY(!parent))
86 throw std::domain_error{"can't call GetIndexInParent on object without parent"};
89 auto size = static_cast<std::size_t>(parent.GetChildCount());
90 for(auto i = 0u; i < size; ++i)
92 if(parent.GetChildAt(i) == self)
98 throw std::domain_error{"actor is not a child of its parent"};
101 Dali::Actor ActorAccessible::GetInternalActor()
106 ComponentLayer ActorAccessible::GetLayer() const
108 return ComponentLayer::WINDOW;
111 std::int16_t ActorAccessible::GetMdiZOrder() const
116 double ActorAccessible::GetAlpha() const
121 bool ActorAccessible::IsScrollable() const
126 Dali::Rect<> ActorAccessible::GetExtents(CoordinateType type) const
128 Dali::Actor actor = Self();
129 Vector2 screenPosition = actor.GetProperty<Vector2>(Actor::Property::SCREEN_POSITION);
130 Vector3 size = actor.GetCurrentProperty<Vector3>(Actor::Property::SIZE) * actor.GetCurrentProperty<Vector3>(Actor::Property::WORLD_SCALE);
131 bool positionUsesAnchorPoint = actor.GetProperty<bool>(Actor::Property::POSITION_USES_ANCHOR_POINT);
132 Vector3 anchorPointOffSet = size * (positionUsesAnchorPoint ? actor.GetCurrentProperty<Vector3>(Actor::Property::ANCHOR_POINT) : AnchorPoint::TOP_LEFT);
133 Vector2 position = Vector2(screenPosition.x - anchorPointOffSet.x, screenPosition.y - anchorPointOffSet.y);
135 if(type == CoordinateType::WINDOW)
137 return {position.x, position.y, size.x, size.y};
139 else // CoordinateType::SCREEN
141 auto window = Dali::DevelWindow::Get(actor);
142 auto windowPosition = window.GetPosition();
143 return {position.x + windowPosition.GetX(), position.y + windowPosition.GetY(), size.x, size.y};
147 } // namespace Dali::Accessibility