Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-accessible.h
1 #ifndef DALI_INTERNAL_ACCESSIBILITY_BRIDGE_ACCESSIBLE_H
2 #define DALI_INTERNAL_ACCESSIBILITY_BRIDGE_ACCESSIBLE_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <array>
23 #include <string>
24 #include <unordered_map>
25 #include <vector>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/atspi-interfaces/accessible.h>
29 #include <dali/devel-api/atspi-interfaces/component.h>
30 #include <dali/internal/accessibility/bridge/bridge-base.h>
31
32 /**
33  * @brief The BridgeAccessible class is to correspond with Dali::Accessibility::Accessible.
34  */
35 class BridgeAccessible : public virtual BridgeBase
36 {
37 protected:
38   /**
39    * @brief Constructor.
40    */
41   BridgeAccessible();
42
43   /**
44    * @brief Registers Accessible functions to dbus interfaces.
45    */
46   void RegisterInterfaces();
47
48 public:
49   /**
50    * @brief Enumeration for NeighborSearchMode.
51    */
52   enum class NeighborSearchMode
53   {
54     NORMAL                          = 0, ///< Normal
55     RECURSE_FROM_ROOT               = 1, ///< Recurse from root
56     CONTINUE_AFTER_FAILED_RECURSION = 2, ///< Continue after failed recursion
57     RECURSE_TO_OUTSIDE              = 3, ///< Recurse to outside
58   };
59
60   using ReadingMaterialType = DBus::ValueOrError<
61     std::unordered_map<std::string, std::string>, // attributes
62     std::string,                                  // name
63     std::string,                                  // labeledByName
64     std::string,                                  // textIfceName
65     uint32_t,
66     Dali::Accessibility::States,
67     std::string,                      // localized name
68     int32_t,                          // child count
69     double,                           // current value
70     double,                           // minimum increment
71     double,                           // maximum value
72     double,                           // minimum value
73     std::string,                      // description
74     int32_t,                          // index in parent
75     bool,                             // isSelectedInParent
76     bool,                             // hasCheckBoxChild
77     int32_t,                          // listChildrenCount
78     int32_t,                          // firstSelectedChildIndex
79     Dali::Accessibility::Accessible*, // parent
80     Dali::Accessibility::States,      // parentStateSet
81     int32_t,                          // parentChildCount
82     uint32_t,                         // parentRole
83     int32_t,                          // selectedChildCount,
84     Dali::Accessibility::Accessible*  // describedByObject
85     >;
86
87   using Relation = std::tuple<uint32_t, std::vector<Dali::Accessibility::Address>>;
88
89   /**
90    * @copydoc Dali::Accessibility::Accessible::GetChildCount()
91    */
92   int GetChildCount();
93
94   /**
95    * @copydoc Dali::Accessibility::Accessible::GetChildAtIndex()
96    */
97   DBus::ValueOrError<Dali::Accessibility::Accessible*> GetChildAtIndex(int index);
98
99   /**
100    * @copydoc Dali::Accessibility::Accessible::GetParent()
101    */
102   Dali::Accessibility::Accessible* GetParent();
103
104   /**
105    * @copydoc Dali::Accessibility::Accessible::GetChildren()
106    */
107   DBus::ValueOrError<std::vector<Dali::Accessibility::Accessible*>> GetChildren();
108
109   /**
110    * @copydoc Dali::Accessibility::Accessible::GetName()
111    */
112   std::string GetName();
113
114   /**
115    * @copydoc Dali::Accessibility::Accessible::GetDescription()
116    */
117   std::string GetDescription();
118
119   /**
120    * @copydoc Dali::Accessibility::Accessible::GetRole()
121    */
122   DBus::ValueOrError<uint32_t> GetRole();
123
124   /**
125    * @copydoc Dali::Accessibility::Accessible::GetRoleName()
126    */
127   DBus::ValueOrError<std::string> GetRoleName();
128
129   /**
130    * @copydoc Dali::Accessibility::Accessible::GetLocalizedRoleName()
131    */
132   DBus::ValueOrError<std::string> GetLocalizedRoleName();
133
134   /**
135    * @copydoc Dali::Accessibility::Accessible::GetIndexInParent()
136    */
137   DBus::ValueOrError<int32_t> GetIndexInParent();
138
139   /**
140    * @copydoc Dali::Accessibility::Accessible::GetStates()
141    */
142   DBus::ValueOrError<std::array<uint32_t, 2>> GetStates();
143
144   /**
145    * @copydoc Dali::Accessibility::Accessible::GetAttributes()
146    */
147   DBus::ValueOrError<std::unordered_map<std::string, std::string>> GetAttributes();
148
149   /**
150    * @copydoc Dali::Accessibility::Accessible::GetInterfaces()
151    */
152   DBus::ValueOrError<std::vector<std::string>> GetInterfaces();
153
154   /**
155    * @brief Gets Accessible object on which surface lies the point with given coordinates.
156    *
157    * @param[in] x X coordinate of a point
158    * @param[in] y Y coordinate of a point
159    * @param[in] coordinateType The coordinate type
160    * @return The array containing the Accessible object, recursive status, and deputy Accessible
161    */
162   DBus::ValueOrError<Dali::Accessibility::Accessible*, uint8_t, Dali::Accessibility::Accessible*> GetNavigableAtPoint(int32_t x, int32_t y, uint32_t coordinateType);
163
164   /**
165    * @brief Gets Accessible object that, dependently to the given direction parameter,
166    * stands in navigation order immediately before/after the Accessible object being a target of this dbus call.
167    *
168    * The 'direction' parameter denotes if the neighbor object search is done forward or backward in UI elements navigation order.
169    * @param[in] rootPath The path of root Accessible object
170    * @param[in] direction 1 is forward, 0 is backward
171    * @param[in] searchMode BridgeAccessible::NeighborSearchMode enum
172    * @return The array containing the neighbor Accessible object and recursive status
173    */
174   DBus::ValueOrError<Dali::Accessibility::Accessible*, uint8_t> GetNeighbor(std::string rootPath, int32_t direction, int32_t searchMode);
175
176   /**
177    * @brief Gets the default label information.
178    *
179    * The "Default label" is a text that could be read by screen-reader immediately
180    * after the navigation context has changed (window activates, popup shows up, tab changes) and before first UI element is highlighted.
181    * @return The array containing the Accessible object being a source of default label text, its role, and its attributes
182    * @note This is a Tizen only feature not present in upstream ATSPI.
183    * Feature can be enabled/disabled for particular context root object by setting value of its accessibility attribute "default_label".
184    */
185   DBus::ValueOrError<Dali::Accessibility::Accessible*, uint32_t, std::unordered_map<std::string, std::string>> GetDefaultLabelInfo();
186
187   /**
188    * @brief Gets Reading material information of the self object.
189    * @return Reading material information
190    */
191   ReadingMaterialType GetReadingMaterial();
192
193   /**
194    * @copydoc Dali::Accessibility::Accessible::DoGesture()
195    */
196   DBus::ValueOrError<bool> DoGesture(Dali::Accessibility::Gesture type, int32_t startPositionX, int32_t startPositionY, int32_t endPositionX, int32_t endPositionY, Dali::Accessibility::GestureState state, uint32_t eventTime);
197
198   /**
199    * @copydoc Dali::Accessibility::Accessible::GetRelationSet()
200    */
201   DBus::ValueOrError<std::vector<Relation>> GetRelationSet();
202
203 private:
204   /**
205    * @brief Calculates Neighbor candidate object in root node.
206    *
207    * The DFS algorithm in the method is implemented in iterative way.
208    * @param root The accessible root object
209    * @param start The start node
210    * @param forward If forward is 1, then it navigates forward, otherwise backward.
211    * @param searchMode BridgeAccessible::NeighborSearchMode  enum
212    * @return The neighbor Accessible object
213    */
214   Dali::Accessibility::Accessible* CalculateNeighbor(Dali::Accessibility::Accessible* root, Dali::Accessibility::Accessible* start, unsigned char forward, NeighborSearchMode searchMode);
215
216   /**
217    * @brief Gets valid children accessible.
218    *
219    * @param[in] children Children accessible objects
220    * @param start The start node
221    * @return The valid children
222    */
223   std::vector<Dali::Accessibility::Component*> GetValidChildren(const std::vector<Dali::Accessibility::Accessible*>& children, Dali::Accessibility::Accessible* start);
224
225   /**
226    * @brief Sorts children accessible based on the coordinates from top-left to bottom-right.
227    *
228    * @param[in,out] children Children accessible objects
229    * @return The sorted children
230    */
231   void SortChildrenFromTopLeft(std::vector<Dali::Accessibility::Component*>& children);
232
233   /**
234    * @brief Gets the currently highlighted accessible.
235    *
236    * @return The highlighted accessible
237    * @remarks This is an experimental feature and might not be supported now.
238    */
239   Dali::Accessibility::Accessible* GetCurrentlyHighlighted();
240
241   /**
242    * @brief Finds the non defunct sibling of the node.
243    *
244    * @param[out] areAllChildrenVisited True if all children are visited
245    * @param[in] node The accessible object to find its non defunct sibling
246    * @param[in] start The start node
247    * @param[in] root The root node
248    * @param[in] forward If forward is 1, then it navigates forward, otherwise backward.
249    * @return The non defunct sibling accessible
250    *
251    * @note This function performs a Depth-First Search (DFS) on all children within the node.
252    */
253   Dali::Accessibility::Accessible* FindNonDefunctSibling(bool& areAllChildrenVisited, Dali::Accessibility::Accessible* node, Dali::Accessibility::Accessible* start, Dali::Accessibility::Accessible* root, unsigned char forward);
254
255   /**
256    * @brief Gets the next non defunct sibling.
257    *
258    * @param obj The accessible object to find its non defunct sibling
259    * @param start The start node
260    * @param forward If forward is 1, then it navigates forward, otherwise backward.
261    * @return The non defunct sibling accessible
262    */
263   Dali::Accessibility::Accessible* GetNextNonDefunctSibling(Dali::Accessibility::Accessible* obj, Dali::Accessibility::Accessible* start, unsigned char forward);
264
265   /**
266    * @brief Gets Component object in relation.
267    * @param obj The accessible object to find component in its address
268    * @param relationType Accessibility::RelationType enum
269    * @return The Component object
270    */
271   Dali::Accessibility::Component* GetObjectInRelation(Dali::Accessibility::Accessible* obj, Dali::Accessibility::RelationType relationType);
272
273   /**
274    * @brief Calculates and gets Component object that can be navigable at given coordinates.
275    *
276    * This method calculates which Component should be addressed if user hits certain point in a screen.
277    * @param root The root node
278    * @param point The coordinate of a point
279    * @param type This type says if the coordinates of a point refer to the device screen or current window.
280    * @param maxRecursionDepth The maximum recursion depth count
281    * @return The Component object
282    */
283   Dali::Accessibility::Component* CalculateNavigableAccessibleAtPoint(Dali::Accessibility::Accessible* root, Dali::Accessibility::Point point, Dali::Accessibility::CoordinateType type, unsigned int maxRecursionDepth);
284 };
285
286 #endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_ACCESSIBLE_H