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