80a6865099bb42597dd35fd95c4cb758a532f39b
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / accessibility-manager / accessibility-manager-impl.cpp
1 /*
2  * Copyright (c) 2020 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 "accessibility-manager-impl.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali/devel-api/adaptor-framework/accessibility.h>
23 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
24
25 // INTERNAL INCLUDES
26 #include <dali-toolkit/public-api/controls/control.h>
27 #include <dali-toolkit/public-api/controls/control-impl.h>
28 #include <dali-toolkit/devel-api/controls/control-devel.h>
29
30 namespace Dali
31 {
32
33 namespace Toolkit
34 {
35
36 namespace Internal
37 {
38
39 AccessibilityManager::AccessibilityManager()
40 {
41   mFocusOrder.push_back( {} ); // zero has a special meaning
42 }
43
44 AccessibilityManager::~AccessibilityManager()
45 {
46 }
47
48 void AccessibilityManager::SetAccessibilityAttribute(Actor actor, Toolkit::AccessibilityManager::AccessibilityAttribute type, const std::string& text)
49 {
50   switch ( type )
51   {
52   case Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL:
53     actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_NAME, text );
54     break;
55
56   case Toolkit::AccessibilityManager::ACCESSIBILITY_HINT:
57     actor.SetProperty( Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION, text );
58     break;
59
60   case Toolkit::AccessibilityManager::ACCESSIBILITY_TRAIT:
61   case Toolkit::AccessibilityManager::ACCESSIBILITY_VALUE:
62   default:
63     break;
64   }
65 }
66
67 std::string AccessibilityManager::GetAccessibilityAttribute(Actor actor, Toolkit::AccessibilityManager::AccessibilityAttribute type) const
68 {
69   switch ( type )
70   {
71   case Toolkit::AccessibilityManager::ACCESSIBILITY_LABEL:
72     return actor.GetProperty< std::string >( Toolkit::DevelControl::Property::ACCESSIBILITY_NAME );
73
74   case Toolkit::AccessibilityManager::ACCESSIBILITY_HINT:
75     return actor.GetProperty< std::string >( Toolkit::DevelControl::Property::ACCESSIBILITY_DESCRIPTION );
76
77   case Toolkit::AccessibilityManager::ACCESSIBILITY_TRAIT:
78   case Toolkit::AccessibilityManager::ACCESSIBILITY_VALUE:
79   default:
80     return "";
81   }
82 }
83
84 void AccessibilityManager::SetFocusOrder(Actor actor, const unsigned int order)
85 {
86   if (order == 0)
87     return;
88
89   if (order >= mFocusOrder.size())
90     mFocusOrder.resize(order + 1);
91
92   auto it = mFocusOrder.begin() + order;
93   mFocusOrder.insert(it, actor);
94
95   if (order > 0)
96   {
97     Actor prev = mFocusOrder[order - 1];
98     DevelControl::AppendAccessibilityRelation( prev, actor, Accessibility::RelationType::FLOWS_TO );
99     DevelControl::AppendAccessibilityRelation( actor, prev, Accessibility::RelationType::FLOWS_FROM );
100   }
101
102   if (order + 1 < mFocusOrder.size())
103   {
104     Actor next = mFocusOrder[order + 1];
105     DevelControl::AppendAccessibilityRelation( actor, next, Accessibility::RelationType::FLOWS_TO );
106     DevelControl::AppendAccessibilityRelation( next, actor, Accessibility::RelationType::FLOWS_FROM );
107   }
108 }
109
110 unsigned int AccessibilityManager::GetFocusOrder(Actor actor) const
111 {
112   for (auto it = mFocusOrder.begin(); it != mFocusOrder.end(); ++it)
113   {
114     if (actor == *it)
115       return it - mFocusOrder.begin();
116   }
117
118   return 0;
119 }
120
121 unsigned int AccessibilityManager::GenerateNewFocusOrder() const
122 {
123   return static_cast<unsigned>(mFocusOrder.size());
124 }
125
126 Actor AccessibilityManager::GetActorByFocusOrder(const unsigned int order)
127 {
128   Actor actor;
129
130   if (order > 0 && order < mFocusOrder.size())
131     actor = mFocusOrder[order];
132
133   return actor;
134 }
135
136 bool AccessibilityManager::SetCurrentFocusActor(Actor actor)
137 {
138   Dali::Accessibility::Accessible::SetCurrentlyHighlightedActor(actor);
139
140   return true;
141 }
142
143 Actor AccessibilityManager::GetCurrentFocusActor()
144 {
145   return Dali::Accessibility::Accessible::GetCurrentlyHighlightedActor();
146 }
147
148 Actor AccessibilityManager::GetCurrentFocusGroup()
149 {
150   return GetFocusGroup(GetCurrentFocusActor());
151 }
152
153 unsigned int AccessibilityManager::GetCurrentFocusOrder()
154 {
155   auto actor = GetCurrentFocusActor();
156   unsigned order = 0;
157
158   if (actor)
159     order = GetFocusOrder( actor );
160
161   return order;
162 }
163
164 bool AccessibilityManager::MoveFocusForward()
165 {
166   unsigned current = GetCurrentFocusOrder();
167
168   if (current + 1 < mFocusOrder.size())
169     return SetCurrentFocusActor(mFocusOrder[current + 1]);
170
171   return false;
172 }
173
174 bool AccessibilityManager::MoveFocusBackward()
175 {
176   unsigned current = GetCurrentFocusOrder();
177
178   if (current > 1) // zero has a special meaning
179     return SetCurrentFocusActor(mFocusOrder[current - 1]);
180
181   return false;
182 }
183
184 void AccessibilityManager::ClearFocus()
185 {
186   auto actor = GetCurrentFocusActor();
187   Toolkit::DevelControl::ClearAccessibilityHighlight( actor );
188 }
189
190 void AccessibilityManager::Reset()
191 {
192   ClearFocus();
193
194   for (std::size_t i = 2; i < mFocusOrder.size(); ++i)
195   {
196     Actor prev = mFocusOrder[i - 1];
197     Actor next = mFocusOrder[i];
198
199     DevelControl::RemoveAccessibilityRelation( prev, next, Accessibility::RelationType::FLOWS_TO );
200     DevelControl::RemoveAccessibilityRelation( next, prev, Accessibility::RelationType::FLOWS_FROM );
201   }
202
203   mFocusOrder.clear();
204   mFocusOrder.push_back( {} );
205 }
206
207 void AccessibilityManager::SetFocusGroup(Actor actor, bool isFocusGroup)
208 {
209 }
210
211 bool AccessibilityManager::IsFocusGroup(Actor actor) const
212 {
213   return false;
214 }
215
216 Actor AccessibilityManager::GetFocusGroup(Actor actor)
217 {
218   return {};
219 }
220
221 Vector2 AccessibilityManager::GetReadPosition() const
222 {
223   return {};
224 }
225
226 void AccessibilityManager::SetGroupMode(bool enabled)
227 {
228 }
229
230 bool AccessibilityManager::GetGroupMode() const
231 {
232   return false;
233 }
234
235 void AccessibilityManager::SetWrapMode(bool wrapped)
236 {
237 }
238
239 bool AccessibilityManager::GetWrapMode() const
240 {
241   return true;
242 }
243
244 void AccessibilityManager::SetFocusIndicatorActor(Actor indicator)
245 {
246   Dali::Accessibility::Accessible::SetHighlightActor( indicator );
247 }
248
249 Actor AccessibilityManager::GetFocusIndicatorActor()
250 {
251   return Dali::Accessibility::Accessible::GetHighlightActor();
252 }
253
254 Toolkit::AccessibilityManager::FocusChangedSignalType& AccessibilityManager::FocusChangedSignal()
255 {
256   return mFocusChangedSignal;
257 }
258
259 Toolkit::AccessibilityManager::FocusOvershotSignalType& AccessibilityManager::FocusOvershotSignal()
260 {
261   return mFocusOvershotSignal;
262 }
263
264 Toolkit::AccessibilityManager::FocusedActorActivatedSignalType& AccessibilityManager::FocusedActorActivatedSignal()
265 {
266   return mFocusedActorActivatedSignal;
267 }
268
269 } // namespace Internal
270
271 } // namespace Toolkit
272
273 } // namespace Dali