[ATSPI] Introduce SetListenPostRender interface
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / atspi-interfaces / accessible.h
1 #ifndef DALI_ADAPTOR_ATSPI_ACCESSIBLE_H
2 #define DALI_ADAPTOR_ATSPI_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 // EXTERNAL INCLUDES
21 #include <dali/public-api/actors/actor.h>
22 #include <dali/public-api/math/rect.h>
23 #include <dali/public-api/object/object-registry.h>
24 #include <cstdint>
25 #include <string>
26 #include <vector>
27
28 // INTERNAL INCLUDES
29 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
30 #include <dali/devel-api/adaptor-framework/accessibility.h>
31
32 namespace Dali::Accessibility
33 {
34 /**
35  * @brief Basic interface implemented by all accessibility objects.
36  */
37 class DALI_ADAPTOR_API Accessible
38 {
39 public:
40   virtual ~Accessible() noexcept;
41
42   /**
43    * @brief Helper function for emiting active-descendant-changed event.
44    *
45    * @param[in] child The child of the object
46    */
47   void EmitActiveDescendantChanged(Accessible* child);
48
49   /**
50    * @brief Helper function for emiting state-changed event.
51    *
52    * @param[in] state The accessibility state (SHOWING, HIGHLIGHTED, etc)
53    * @param[in] newValue Whether the state value is changed to new value or not.
54    * @param[in] reserved Reserved. (TODO : Currently, this argument is not implemented in dali)
55    *
56    * @note The second argument determines which value is depending on State.
57    * For instance, if the state is PRESSED, newValue means isPressed or isSelected.
58    * If the state is SHOWING, newValue means isShowing.
59    */
60   void EmitStateChanged(State state, int newValue, int reserved = 0);
61
62   /**
63    * @brief Helper function for emiting bounds-changed event.
64    *
65    * @param rect The rectangle for changed bounds
66    */
67   void EmitBoundsChanged(Rect<> rect);
68
69   /**
70    * @brief Emits "showing" event.
71    * The method informs accessibility clients about "showing" state.
72    *
73    * @param[in] isShowing The flag pointing if object is showing
74    */
75   void EmitShowing(bool isShowing);
76
77   /**
78    * @brief Emits "visible" event.
79    * The method informs accessibility clients about "visible" state.
80    *
81    * @param[in] isVisible The flag pointing if object is visible
82    */
83   void EmitVisible(bool isVisible);
84
85   /**
86    * @brief Emits "highlighted" event.
87    * The method informs accessibility clients about "highlighted" state.
88    *
89    * @param[in] isHighlighted The flag pointing if object is highlighted
90    */
91   void EmitHighlighted(bool isHighlighted);
92
93   /**
94    * @brief Emits "focused" event.
95    * The method informs accessibility clients about "focused" state.
96    *
97    * @param[in] isFocused The flag pointing if object is focused
98    */
99   void EmitFocused(bool isFocused);
100
101   /**
102    * @brief Emits "text inserted" event.
103    *
104    * @param[in] position The cursor position
105    * @param[in] length The text length
106    * @param[in] content The inserted text
107    */
108   void EmitTextInserted(unsigned int position, unsigned int length, const std::string& content);
109
110   /**
111    * @brief Emits "text deleted" event.
112    *
113    * @param[in] position The cursor position
114    * @param[in] length The text length
115    * @param[in] content The deleted text
116    */
117   void EmitTextDeleted(unsigned int position, unsigned int length, const std::string& content);
118
119   /**
120    * @brief Emits "cursor moved" event.
121    *
122    * @param[in] cursorPosition The new cursor position
123    */
124   void EmitTextCursorMoved(unsigned int cursorPosition);
125
126   /**
127    * @brief Emits "MoveOuted" event.
128    *
129    * @param[in] type moved out of screen type
130    */
131   void EmitMovedOutOfScreen(ScreenRelativeMoveType type);
132
133   /**
134    * @brief Emits "org.a11y.atspi.Socket.Available" signal.
135    */
136   // This belongs to Dali::Accessibility::Socket. However, all Emit*() helpers
137   // are here in Accessible, regardless of what interface they belong to (perhaps
138   // to spare a dynamic_cast if used like this: Accessible::Get()->Emit*(...)).
139   void EmitSocketAvailable();
140
141   /**
142    * @brief Emits "highlighted" event.
143    *
144    * @param[in] event The enumerated window event
145    * @param[in] detail The additional parameter which interpretation depends on chosen event
146    */
147   void Emit(WindowEvent event, unsigned int detail = 0);
148
149   /**
150    * @brief Emits property-changed event.
151    *
152    * @param[in] event Property changed event
153    **/
154   void Emit(ObjectPropertyChangeEvent event);
155
156   /**
157    * @brief Gets accessibility name.
158    *
159    * @return The string with name
160    */
161   virtual std::string GetName() const = 0;
162
163   /**
164    * @brief Gets accessibility description.
165    *
166    * @return The string with description
167    */
168   virtual std::string GetDescription() const = 0;
169
170   /**
171    * @brief Gets parent.
172    *
173    * @return The handler to accessibility object
174    */
175   virtual Accessible* GetParent() = 0;
176
177   /**
178    * @brief Gets the number of children.
179    *
180    * @return The number of children
181    */
182   virtual std::size_t GetChildCount() const = 0;
183
184   /**
185    * @brief Gets collection with all children.
186    *
187    * @return The collection of accessibility objects
188    */
189   virtual std::vector<Accessible*> GetChildren() = 0;
190
191   /**
192    * @brief Gets child of the index.
193    *
194    * @return The child object
195    */
196   virtual Accessible* GetChildAtIndex(std::size_t index) = 0;
197
198   /**
199    * @brief Gets index that current object has in its parent's children collection.
200    *
201    * @return The index of the current object
202    */
203   virtual std::size_t GetIndexInParent() = 0;
204
205   /**
206    * @brief Gets accessibility role.
207    *
208    * @return Role enumeration
209    *
210    * @see Dali::Accessibility::Role
211    */
212   virtual Role GetRole() const = 0;
213
214   /**
215    * @brief Gets name of accessibility role.
216    *
217    * @return The string with human readable role converted from enumeration
218    *
219    * @see Dali::Accessibility::Role
220    * @see Accessibility::Accessible::GetRole
221    */
222   virtual std::string GetRoleName() const;
223
224   /**
225    * @brief Gets localized name of accessibility role.
226    *
227    * @return The string with human readable role translated according to current
228    * translation domain
229    *
230    * @see Dali::Accessibility::Role
231    * @see Accessibility::Accessible::GetRole
232    * @see Accessibility::Accessible::GetRoleName
233    *
234    * @note translation is not supported in this version
235    */
236   virtual std::string GetLocalizedRoleName() const;
237
238   /**
239    * @brief Gets accessibility states.
240    *
241    * @return The collection of states
242    *
243    * @note States class is instatation of ArrayBitset template class
244    *
245    * @see Dali::Accessibility::State
246    * @see Dali::Accessibility::ArrayBitset
247    */
248   virtual States GetStates() = 0;
249
250   /**
251    * @brief Gets accessibility attributes.
252    *
253    * @return The map of attributes and their values
254    */
255   virtual Attributes GetAttributes() const = 0;
256
257   /**
258    * @brief Checks if this is hidden.
259    *
260    * @return True if this is hidden
261    *
262    * @note Hidden means not present in the AT-SPI tree.
263    */
264   virtual bool IsHidden() const;
265
266   /**
267    * @brief Checks if this is proxy.
268    *
269    * @return True if this is proxy
270    */
271   virtual bool IsProxy() const;
272
273   /**
274    * @brief Gets unique address on accessibility bus.
275    *
276    * @return The Address class containing address
277    *
278    * @see Dali::Accessibility::Address
279    */
280   virtual Address GetAddress() const;
281
282   /**
283    * @brief Deputes an object to perform provided gesture.
284    *
285    * @param[in] gestureInfo The structure describing the gesture
286    *
287    * @return true on success, false otherwise
288    *
289    * @see Dali::Accessibility::GestureInfo
290    */
291   virtual bool DoGesture(const GestureInfo& gestureInfo) = 0;
292
293   /**
294    * @brief Re-emits selected states of an Accessibility Object.
295    *
296    * @param[in] states The chosen states to re-emit
297    * @param[in] isRecursive If true, all children of the Accessibility object will also re-emit the states
298    */
299   void NotifyAccessibilityStateChange(Dali::Accessibility::States states, bool isRecursive);
300
301   /**
302    * @brief Gets information about current object and all relations that connects
303    * it with other accessibility objects.
304    *
305    * @return The iterable collection of Relation objects
306    *
307    * @see Dali::Accessibility::Relation
308    */
309   virtual std::vector<Relation> GetRelationSet() = 0;
310
311   /**
312    * @brief Gets the Actor associated with this Accessible (if there is one).
313    *
314    * @return The internal Actor
315    */
316   virtual Dali::Actor GetInternalActor() = 0;
317
318   /**
319    * @brief Sets whether to listen for post render callback.
320    *
321    * @param[in] enabled If ture, registration post render callback, false otherwise
322    */
323   virtual void SetListenPostRender(bool enabled);
324
325   /**
326    * @brief Gets all implemented interfaces.
327    *
328    * Override DoGetInterfaces() to customize the return value of this method.
329    *
330    * @return The collection of implemented interfaces
331    *
332    * @see DoGetInterfaces()
333    */
334   AtspiInterfaces GetInterfaces() const;
335
336   /**
337    * @brief Gets all implemented interfaces.
338    *
339    * Converts all interfaces returned by GetInterfaces() to their DBus names
340    * using GetInterfaceName().
341    *
342    * @return The collection of names of implemented interfaces
343    *
344    * @see GetInterfaces()
345    * @see GetInterfaceName()
346    */
347   std::vector<std::string> GetInterfacesAsStrings() const;
348
349   /**
350    * @brief Checks if object is on root level.
351    *
352    * @return Whether object is on root level or not
353    */
354   bool IsOnRootLevel() const
355   {
356     return mIsOnRootLevel;
357   }
358
359   /**
360    * @brief Gets all suppressed events.
361    *
362    * @return All suppressed events
363    */
364   AtspiEvents GetSuppressedEvents() const
365   {
366     return mSuppressedEvents;
367   }
368
369   /**
370    * @brief Gets all suppressed events.
371    *
372    * @return All suppressed events
373    */
374   AtspiEvents& GetSuppressedEvents()
375   {
376     return mSuppressedEvents;
377   }
378
379 protected:
380   Accessible();
381   Accessible(const Accessible&)         = delete;
382   Accessible(Accessible&&)              = delete;
383   Accessible&                   operator=(const Accessible&) = delete;
384   Accessible&                   operator=(Accessible&&) = delete;
385   std::shared_ptr<Bridge::Data> GetBridgeData() const;
386
387   /**
388    * @brief Returns the collection of AT-SPI interfaces implemented by this Accessible.
389    *
390    * This method is called only once and its return value is cached. The default implementation
391    * uses dynamic_cast to determine which interfaces are implemented. Override this if you
392    * conceptually provide fewer interfaces than dynamic_cast can see.
393    *
394    * @return The collection of implemented interfaces
395    *
396    * @see GetInterfaces()
397    * @see GetInterfaceName()
398    */
399   virtual AtspiInterfaces DoGetInterfaces() const;
400
401 public:
402   /**
403    * @brief Gets the highlight actor.
404    *
405    * This method is to get the highlight itself.
406    * @return The highlight actor
407    */
408   static Dali::Actor GetHighlightActor();
409
410   /**
411    * @brief Sets the highlight actor.
412    *
413    * This method is to set the highlight itself.
414    * @param[in] actor The highlight actor
415    */
416   static void SetHighlightActor(Dali::Actor actor);
417
418   /**
419    * @brief Gets the currently highlighted actor.
420    *
421    * @return The current highlighted actor
422    */
423   static Dali::Actor GetCurrentlyHighlightedActor();
424
425   /**
426    * @brief Sets currently highlighted actor.
427    *
428    * @param[in] actor The highlight actor
429    */
430   static void SetCurrentlyHighlightedActor(Dali::Actor actor);
431
432   /**
433    * @brief Sets ObjectRegistry.
434    *
435    * @param[in] registry ObjectRegistry instance
436    */
437   static void SetObjectRegistry(ObjectRegistry registry);
438
439   /**
440    * @brief The method registers functor resposible for converting Actor into Accessible.
441    * @param functor The returning Accessible handle from Actor object
442    */
443   static void RegisterExternalAccessibleGetter(std::function<Accessible*(Dali::Actor)> functor);
444
445   /**
446    * @brief Acquires Accessible object from Actor object.
447    *
448    * @param[in] actor Actor object
449    *
450    * @return The handle to Accessible object
451    */
452   static Accessible* Get(Dali::Actor actor);
453
454   /**
455    * @brief Obtains the DBus interface name for the specified AT-SPI interface.
456    *
457    * @param interface AT-SPI interface identifier (e.g. AtspiInterface::ACCESSIBLE)
458    * @return AT-SPI interface name (e.g. "org.a11y.atspi.Accessible")
459    */
460   static std::string GetInterfaceName(AtspiInterface interface);
461
462   /**
463    * @brief Downcasts an Accessible pointer to an AT-SPI interface pointer.
464    *
465    * @tparam I Desired AT-SPI interface
466    *
467    * @param obj Object to cast.
468    *
469    * @return Pointer to an AT-SPI interface or null if the interface is not implemented.
470    */
471   template<AtspiInterface I>
472   static AtspiInterfaceType<I>* DownCast(Accessible* obj)
473   {
474     if(!obj || !obj->GetInterfaces()[I])
475     {
476       return nullptr;
477     }
478
479     return dynamic_cast<AtspiInterfaceType<I>*>(obj);
480   }
481
482 private:
483   friend class Bridge;
484
485   mutable std::weak_ptr<Bridge::Data> mBridgeData;
486   mutable AtspiInterfaces             mInterfaces;
487   AtspiEvents                         mSuppressedEvents;
488   bool                                mIsOnRootLevel = false;
489
490 }; // Accessible class
491
492 namespace Internal
493 {
494 template<>
495 struct AtspiInterfaceTypeHelper<AtspiInterface::ACCESSIBLE>
496 {
497   using Type = Accessible;
498 };
499 } // namespace Internal
500
501 } // namespace Dali::Accessibility
502
503 #endif // DALI_ADAPTOR_ATSPI_ACCESSIBLE_H