[Tizen][AT-SPI] Add Value::GetValueText()
[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) 2023 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   /**
49    * @brief Returns the Accessible object of the currently executed DBus method call.
50    *
51    * @return The Accessible object
52    */
53   Dali::Accessibility::Accessible* FindSelf() const;
54
55 public:
56   /**
57    * @brief Enumeration for NeighborSearchMode.
58    */
59   enum class NeighborSearchMode
60   {
61     NORMAL                          = 0, ///< Normal
62     RECURSE_FROM_ROOT               = 1, ///< Recurse from root
63     CONTINUE_AFTER_FAILED_RECURSION = 2, ///< Continue after failed recursion
64     RECURSE_TO_OUTSIDE              = 3, ///< Recurse to outside
65   };
66
67   using ReadingMaterialType = DBus::ValueOrError<
68     std::unordered_map<std::string, std::string>, // attributes
69     std::string,                                  // name
70     std::string,                                  // labeledByName
71     std::string,                                  // textIfceName
72     uint32_t,
73     Dali::Accessibility::States,
74     std::string,                      // localized name
75     int32_t,                          // child count
76     double,                           // current value
77     std::string,                      // formatted current value
78     double,                           // minimum increment
79     double,                           // maximum value
80     double,                           // minimum value
81     std::string,                      // description
82     int32_t,                          // index in parent
83     bool,                             // isSelectedInParent
84     bool,                             // hasCheckBoxChild
85     int32_t,                          // listChildrenCount
86     int32_t,                          // firstSelectedChildIndex
87     Dali::Accessibility::Accessible*, // parent
88     Dali::Accessibility::States,      // parentStateSet
89     int32_t,                          // parentChildCount
90     uint32_t,                         // parentRole
91     int32_t,                          // selectedChildCount,
92     Dali::Accessibility::Accessible*  // describedByObject
93     >;
94
95   using Relation = std::tuple<uint32_t, std::vector<Dali::Accessibility::Accessible*>>;
96
97   /**
98    * @copydoc Dali::Accessibility::Accessible::GetChildCount()
99    */
100   int GetChildCount();
101
102   /**
103    * @copydoc Dali::Accessibility::Accessible::GetChildAtIndex()
104    */
105   DBus::ValueOrError<Dali::Accessibility::Accessible*> GetChildAtIndex(int index);
106
107   /**
108    * @copydoc Dali::Accessibility::Accessible::GetParent()
109    */
110   Dali::Accessibility::Accessible* GetParent();
111
112   /**
113    * @copydoc Dali::Accessibility::Accessible::GetChildren()
114    */
115   DBus::ValueOrError<std::vector<Dali::Accessibility::Accessible*>> GetChildren();
116
117   /**
118    * @copydoc Dali::Accessibility::Accessible::GetName()
119    */
120   std::string GetName();
121
122   /**
123    * @copydoc Dali::Accessibility::Accessible::GetDescription()
124    */
125   std::string GetDescription();
126
127   /**
128    * @copydoc Dali::Accessibility::Accessible::GetRole()
129    */
130   DBus::ValueOrError<uint32_t> GetRole();
131
132   /**
133    * @copydoc Dali::Accessibility::Accessible::GetRoleName()
134    */
135   DBus::ValueOrError<std::string> GetRoleName();
136
137   /**
138    * @copydoc Dali::Accessibility::Accessible::GetLocalizedRoleName()
139    */
140   DBus::ValueOrError<std::string> GetLocalizedRoleName();
141
142   /**
143    * @copydoc Dali::Accessibility::Accessible::GetIndexInParent()
144    */
145   DBus::ValueOrError<int32_t> GetIndexInParent();
146
147   /**
148    * @copydoc Dali::Accessibility::Accessible::GetStates()
149    */
150   DBus::ValueOrError<std::array<uint32_t, 2>> GetStates();
151
152   /**
153    * @copydoc Dali::Accessibility::Accessible::GetAttributes()
154    */
155   DBus::ValueOrError<std::unordered_map<std::string, std::string>> GetAttributes();
156
157   /**
158    * @copydoc Dali::Accessibility::Accessible::GetInterfacesAsStrings()
159    */
160   DBus::ValueOrError<std::vector<std::string>> GetInterfacesAsStrings();
161
162   /**
163    * @brief Gets Accessible object on which surface lies the point with given coordinates.
164    *
165    * @param[in] x X coordinate of a point
166    * @param[in] y Y coordinate of a point
167    * @param[in] coordinateType The coordinate type
168    * @return The array containing the Accessible object, recursive status, and deputy Accessible
169    */
170   DBus::ValueOrError<Dali::Accessibility::Accessible*, uint8_t, Dali::Accessibility::Accessible*> GetNavigableAtPoint(int32_t x, int32_t y, uint32_t coordinateType);
171
172   /**
173    * @brief Gets Accessible object that, dependently to the given direction parameter,
174    * stands in navigation order immediately before/after the Accessible object being a target of this dbus call.
175    *
176    * The 'direction' parameter denotes if the neighbor object search is done forward or backward in UI elements navigation order.
177    * @param[in] rootPath The path of root Accessible object
178    * @param[in] direction 1 is forward, 0 is backward
179    * @param[in] searchMode BridgeAccessible::NeighborSearchMode enum
180    * @return The array containing the neighbor Accessible object and recursive status
181    */
182   DBus::ValueOrError<Dali::Accessibility::Accessible*, uint8_t> GetNeighbor(std::string rootPath, int32_t direction, int32_t searchMode);
183
184   /**
185    * @brief Gets the default label information.
186    *
187    * The "Default label" is a text that could be read by screen-reader immediately
188    * after the navigation context has changed (window activates, popup shows up, tab changes) and before first UI element is highlighted.
189    * @return The array containing the Accessible object being a source of default label text, its role, and its attributes
190    * @note This is a Tizen only feature not present in upstream ATSPI.
191    * Feature can be enabled/disabled for particular context root object by setting value of its accessibility attribute "default_label".
192    */
193   DBus::ValueOrError<Dali::Accessibility::Accessible*, uint32_t, std::unordered_map<std::string, std::string>> GetDefaultLabelInfo();
194
195   /**
196    * @brief Gets Reading material information of the self object.
197    * @return Reading material information
198    */
199   ReadingMaterialType GetReadingMaterial();
200
201   /**
202    * @copydoc Dali::Accessibility::Accessible::DoGesture()
203    */
204   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);
205
206   /**
207    * @copydoc Dali::Accessibility::Accessible::GetRelationSet()
208    */
209   DBus::ValueOrError<std::vector<Relation>> GetRelationSet();
210
211   /**
212    * @copydoc Dali::Accessibility::Accessible::SetListenPostRender()
213    */
214   DBus::ValueOrError<void> SetListenPostRender(bool enabled);
215
216 private:
217   /**
218    * @brief Calculates Neighbor candidate object in root node.
219    *
220    * The DFS algorithm in the method is implemented in iterative way.
221    * @param root The accessible root object
222    * @param start The start node
223    * @param forward If forward is 1, then it navigates forward, otherwise backward.
224    * @param searchMode BridgeAccessible::NeighborSearchMode  enum
225    * @return The neighbor Accessible object
226    */
227   Dali::Accessibility::Accessible* CalculateNeighbor(Dali::Accessibility::Accessible* root, Dali::Accessibility::Accessible* start, unsigned char forward, NeighborSearchMode searchMode);
228
229   /**
230    * @brief Gets valid children accessible.
231    *
232    * @param[in] children Children accessible objects
233    * @param start The start node
234    * @return The valid children
235    */
236   std::vector<Dali::Accessibility::Component*> GetValidChildren(const std::vector<Dali::Accessibility::Accessible*>& children, Dali::Accessibility::Accessible* start);
237
238   /**
239    * @brief Sorts children accessible based on the coordinates from top-left to bottom-right.
240    *
241    * @param[in,out] children Children accessible objects
242    * @return The sorted children
243    */
244   void SortChildrenFromTopLeft(std::vector<Dali::Accessibility::Component*>& children);
245
246   /**
247    * @brief Gets the currently highlighted accessible.
248    *
249    * @return The highlighted accessible
250    * @remarks This is an experimental feature and might not be supported now.
251    */
252   Dali::Accessibility::Accessible* GetCurrentlyHighlighted();
253
254   /**
255    * @brief Finds the non defunct sibling of the node.
256    *
257    * @param[out] areAllChildrenVisited True if all children are visited
258    * @param[in] node The accessible object to find its non defunct sibling
259    * @param[in] start The start node
260    * @param[in] root The root node
261    * @param[in] forward If forward is 1, then it navigates forward, otherwise backward.
262    * @return The non defunct sibling accessible
263    *
264    * @note This function performs a Depth-First Search (DFS) on all children within the node.
265    */
266   Dali::Accessibility::Accessible* FindNonDefunctSibling(bool& areAllChildrenVisited, Dali::Accessibility::Accessible* node, Dali::Accessibility::Accessible* start, Dali::Accessibility::Accessible* root, unsigned char forward);
267
268   /**
269    * @brief Gets the next non defunct sibling.
270    *
271    * @param obj The accessible object to find its non defunct sibling
272    * @param start The start node
273    * @param forward If forward is 1, then it navigates forward, otherwise backward.
274    * @return The non defunct sibling accessible
275    */
276   Dali::Accessibility::Accessible* GetNextNonDefunctSibling(Dali::Accessibility::Accessible* obj, Dali::Accessibility::Accessible* start, unsigned char forward);
277
278   /**
279    * @brief Gets Component object in relation.
280    * @param obj The accessible object to find component in its address
281    * @param relationType Accessibility::RelationType enum
282    * @return The Component object
283    */
284   Dali::Accessibility::Component* GetObjectInRelation(Dali::Accessibility::Accessible* obj, Dali::Accessibility::RelationType relationType);
285
286   /**
287    * @brief Calculates and gets Component object that can be navigable at given coordinates.
288    *
289    * This method calculates which Component should be addressed if user hits certain point in a screen.
290    * @param root The root node
291    * @param point The coordinate of a point
292    * @param type This type says if the coordinates of a point refer to the device screen or current window.
293    * @param maxRecursionDepth The maximum recursion depth count
294    * @return The Component object
295    */
296   Dali::Accessibility::Component* CalculateNavigableAccessibleAtPoint(Dali::Accessibility::Accessible* root, Dali::Accessibility::Point point, Dali::Accessibility::CoordinateType type, unsigned int maxRecursionDepth);
297 };
298
299 #endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_ACCESSIBLE_H