Merge "Add a callback for navigation policy in web engine." into devel/master
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / actor-accessible.cpp
1 /*
2  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 // CLASS HEADER
19 #include <dali/devel-api/adaptor-framework/actor-accessible.h>
20
21 // INTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/window-devel.h>
23
24 namespace Dali::Accessibility
25 {
26 ActorAccessible::ActorAccessible(Actor actor)
27 : mSelf(actor)
28 {
29 }
30
31 std::string ActorAccessible::GetName() const
32 {
33   return Self().GetProperty<std::string>(Dali::Actor::Property::NAME);
34 }
35
36 std::string ActorAccessible::GetDescription() const
37 {
38   return {};
39 }
40
41 Accessible* ActorAccessible::GetParent()
42 {
43   if(IsOnRootLevel())
44   {
45     auto data = GetBridgeData();
46     return data->mBridge->GetApplication();
47   }
48
49   return Get(Self().GetParent());
50 }
51
52 std::size_t ActorAccessible::GetChildCount() const
53 {
54   return static_cast<std::size_t>(Self().GetChildCount());
55 }
56
57 std::vector<Accessible*> ActorAccessible::GetChildren()
58 {
59   std::vector<Accessible*> tmp(GetChildCount());
60   for(auto i = 0u; i < tmp.size(); ++i)
61   {
62     tmp[i] = GetChildAtIndex(i);
63   }
64
65   return tmp;
66 }
67
68 Accessible* ActorAccessible::GetChildAtIndex(std::size_t index)
69 {
70   auto numberOfChildren = GetChildCount();
71   if(DALI_UNLIKELY(index >= numberOfChildren))
72   {
73     throw std::domain_error{"invalid index " + std::to_string(index) + " for object with " + std::to_string(numberOfChildren) + " children"};
74   }
75
76   return Get(Self().GetChildAt(static_cast<std::uint32_t>(index)));
77 }
78
79 std::size_t ActorAccessible::GetIndexInParent()
80 {
81   auto self   = Self();
82   auto parent = self.GetParent();
83
84   if(DALI_UNLIKELY(!parent))
85   {
86     throw std::domain_error{"can't call GetIndexInParent on object without parent"};
87   }
88
89   auto size = static_cast<std::size_t>(parent.GetChildCount());
90   for(auto i = 0u; i < size; ++i)
91   {
92     if(parent.GetChildAt(i) == self)
93     {
94       return i;
95     }
96   }
97
98   throw std::domain_error{"actor is not a child of its parent"};
99 }
100
101 Dali::Actor ActorAccessible::GetInternalActor()
102 {
103   return Self();
104 }
105
106 ComponentLayer ActorAccessible::GetLayer() const
107 {
108   return ComponentLayer::WINDOW;
109 }
110
111 std::int16_t ActorAccessible::GetMdiZOrder() const
112 {
113   return 0;
114 }
115
116 double ActorAccessible::GetAlpha() const
117 {
118   return 0;
119 }
120
121 bool ActorAccessible::IsScrollable() const
122 {
123   return false;
124 }
125
126 Dali::Rect<> ActorAccessible::GetExtents(CoordinateType type) const
127 {
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);
134
135   if(type == CoordinateType::WINDOW)
136   {
137     return {position.x, position.y, size.x, size.y};
138   }
139   else // CoordinateType::SCREEN
140   {
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};
144   }
145 }
146
147 } // namespace Dali::Accessibility