1 #ifndef DALI_ADAPTOR_ATSPI_ACCESSIBLE_H
2 #define DALI_ADAPTOR_ATSPI_ACCESSIBLE_H
5 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
29 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
30 #include <dali/devel-api/adaptor-framework/accessibility.h>
32 namespace Dali::Accessibility
35 * @brief Basic interface implemented by all accessibility objects.
37 class DALI_ADAPTOR_API Accessible
40 virtual ~Accessible() noexcept;
43 * @brief Helper function for emiting active-descendant-changed event.
45 * @param[in] child The child of the object
47 void EmitActiveDescendantChanged(Accessible* child);
50 * @brief Helper function for emiting state-changed event.
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)
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.
60 void EmitStateChanged(State state, int newValue, int reserved = 0);
63 * @brief Helper function for emiting bounds-changed event.
65 * @param rect The rectangle for changed bounds
67 void EmitBoundsChanged(Rect<> rect);
70 * @brief Emits "showing" event.
71 * The method informs accessibility clients about "showing" state.
73 * @param[in] isShowing The flag pointing if object is showing
75 void EmitShowing(bool isShowing);
78 * @brief Emits "visible" event.
79 * The method informs accessibility clients about "visible" state.
81 * @param[in] isVisible The flag pointing if object is visible
83 void EmitVisible(bool isVisible);
86 * @brief Emits "highlighted" event.
87 * The method informs accessibility clients about "highlighted" state.
89 * @param[in] isHighlighted The flag pointing if object is highlighted
91 void EmitHighlighted(bool isHighlighted);
94 * @brief Emits "focused" event.
95 * The method informs accessibility clients about "focused" state.
97 * @param[in] isFocused The flag pointing if object is focused
99 void EmitFocused(bool isFocused);
102 * @brief Emits "text inserted" event.
104 * @param[in] position The cursor position
105 * @param[in] length The text length
106 * @param[in] content The inserted text
108 void EmitTextInserted(unsigned int position, unsigned int length, const std::string& content);
111 * @brief Emits "text deleted" event.
113 * @param[in] position The cursor position
114 * @param[in] length The text length
115 * @param[in] content The deleted text
117 void EmitTextDeleted(unsigned int position, unsigned int length, const std::string& content);
120 * @brief Emits "cursor moved" event.
122 * @param[in] cursorPosition The new cursor position
124 void EmitTextCursorMoved(unsigned int cursorPosition);
127 * @brief Emits "MoveOuted" event.
129 * @param[in] type moved out of screen type
131 void EmitMovedOutOfScreen(ScreenRelativeMoveType type);
134 * @brief Emits "org.a11y.atspi.Socket.Available" signal.
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();
142 * @brief Emits "highlighted" event.
144 * @param[in] event The enumerated window event
145 * @param[in] detail The additional parameter which interpretation depends on chosen event
147 void Emit(WindowEvent event, unsigned int detail = 0);
150 * @brief Emits property-changed event.
152 * @param[in] event Property changed event
154 void Emit(ObjectPropertyChangeEvent event);
157 * @brief Gets accessibility name.
159 * @return The string with name
161 virtual std::string GetName() const = 0;
164 * @brief Gets accessibility description.
166 * @return The string with description
168 virtual std::string GetDescription() const = 0;
171 * @brief Gets parent.
173 * @return The handler to accessibility object
175 virtual Accessible* GetParent() = 0;
178 * @brief Gets the number of children.
180 * @return The number of children
182 virtual std::size_t GetChildCount() const = 0;
185 * @brief Gets collection with all children.
187 * @return The collection of accessibility objects
189 virtual std::vector<Accessible*> GetChildren() = 0;
192 * @brief Gets child of the index.
194 * @return The child object
196 virtual Accessible* GetChildAtIndex(std::size_t index) = 0;
199 * @brief Gets index that current object has in its parent's children collection.
201 * @return The index of the current object
203 virtual std::size_t GetIndexInParent() = 0;
206 * @brief Gets accessibility role.
208 * @return Role enumeration
210 * @see Dali::Accessibility::Role
212 virtual Role GetRole() const = 0;
215 * @brief Gets name of accessibility role.
217 * @return The string with human readable role converted from enumeration
219 * @see Dali::Accessibility::Role
220 * @see Accessibility::Accessible::GetRole
222 virtual std::string GetRoleName() const;
225 * @brief Gets localized name of accessibility role.
227 * @return The string with human readable role translated according to current
230 * @see Dali::Accessibility::Role
231 * @see Accessibility::Accessible::GetRole
232 * @see Accessibility::Accessible::GetRoleName
234 * @note translation is not supported in this version
236 virtual std::string GetLocalizedRoleName() const;
239 * @brief Gets accessibility states.
241 * @return The collection of states
243 * @note States class is instatation of ArrayBitset template class
245 * @see Dali::Accessibility::State
246 * @see Dali::Accessibility::ArrayBitset
248 virtual States GetStates() = 0;
251 * @brief Gets accessibility attributes.
253 * Attributes are key-value string pairs which can be used to transfer arbitrary
254 * information from the application to a client such as a screen reader or an
255 * automation framework.
257 * Typically, attributes are used when the data does not fit any other category
258 * with a dedicated API (name, description, states etc.).
260 * @see Accessible::SetAttribute()
261 * @see Accessible::UnsetAttribute()
262 * @see Accessible::ClearAttributes()
263 * @see Accessible::UpdateAttributes()
265 * @return The map of attributes and their values
267 const Attributes& GetAttributes() const;
270 * @brief Sets an attribute
272 * The key will be created if necessary and the old attribute value (if any) will be replaced.
274 * @param[in] key Attribute key
275 * @param[in] value Attribute value
277 * @return True if the key was created, false otherwise (only value was updated)
279 bool SetAttribute(const std::string& key, const std::string& value);
282 * @brief Unsets an attribute
284 * The key-value pair is removed from the attribute collection.
286 * @param[in] key Attribute key
288 * @return True if there was such a key, false otherwise
290 bool UnsetAttribute(const std::string& key);
293 * @brief Unsets all attributes
295 * @see Accessible::UnsetAttribute()
297 void ClearAttributes();
300 * @brief Gets the reading info types
302 * @return Reading info types bitmask
303 * @see Accessible::SetReadingInfoTypes()
305 ReadingInfoTypes GetReadingInfoTypes() const;
308 * @brief Sets the reading info types
310 * The reading info types are individual pieces of information (name, role etc.)
311 * that can be read by the screen reader. This method can be used to enable and
312 * disable reading specific pieces.
314 * @param[in] types Reading info types bitmask
316 * @note The types will appear in GetAttributes() under the "reading_info_type" key.
317 * @see Accessible::GetAttributes()
319 void SetReadingInfoTypes(ReadingInfoTypes types);
322 * @brief Checks if this is hidden.
324 * @return True if this is hidden
326 * @note Hidden means not present in the AT-SPI tree.
328 virtual bool IsHidden() const;
331 * @brief Checks if this is proxy.
333 * @return True if this is proxy
335 virtual bool IsProxy() const;
338 * @brief Gets unique address on accessibility bus.
340 * @return The Address class containing address
342 * @see Dali::Accessibility::Address
344 virtual Address GetAddress() const;
347 * @brief Deputes an object to perform provided gesture.
349 * @param[in] gestureInfo The structure describing the gesture
351 * @return true on success, false otherwise
353 * @see Dali::Accessibility::GestureInfo
355 virtual bool DoGesture(const GestureInfo& gestureInfo) = 0;
358 * @brief Re-emits selected states of an Accessibility Object.
360 * @param[in] states The chosen states to re-emit
361 * @param[in] isRecursive If true, all children of the Accessibility object will also re-emit the states
363 void NotifyAccessibilityStateChange(Dali::Accessibility::States states, bool isRecursive);
366 * @brief Gets information about current object and all relations that connects
367 * it with other accessibility objects.
369 * @return The iterable collection of Relation objects
371 * @see Dali::Accessibility::Relation
373 virtual std::vector<Relation> GetRelationSet() = 0;
376 * @brief Gets the Actor associated with this Accessible (if there is one).
378 * @return The internal Actor
380 virtual Dali::Actor GetInternalActor() = 0;
383 * @brief Sets whether to listen for post render callback.
385 * @param[in] enabled If ture, registration post render callback, false otherwise
387 virtual void SetListenPostRender(bool enabled);
390 * @brief Gets all implemented interfaces.
392 * Override DoGetInterfaces() to customize the return value of this method.
394 * @return The collection of implemented interfaces
396 * @see DoGetInterfaces()
398 AtspiInterfaces GetInterfaces() const;
401 * @brief Gets all implemented interfaces.
403 * Converts all interfaces returned by GetInterfaces() to their DBus names
404 * using GetInterfaceName().
406 * @return The collection of names of implemented interfaces
408 * @see GetInterfaces()
409 * @see GetInterfaceName()
411 std::vector<std::string> GetInterfacesAsStrings() const;
414 * @brief Checks if object is on root level.
416 * @return Whether object is on root level or not
418 bool IsOnRootLevel() const
420 return mIsOnRootLevel;
424 * @brief Gets all suppressed events.
426 * @return All suppressed events
428 AtspiEvents GetSuppressedEvents() const
430 return mSuppressedEvents;
434 * @brief Gets all suppressed events.
436 * @return All suppressed events
438 AtspiEvents& GetSuppressedEvents()
440 return mSuppressedEvents;
445 Accessible(const Accessible&) = delete;
446 Accessible(Accessible&&) = delete;
447 Accessible& operator=(const Accessible&) = delete;
448 Accessible& operator=(Accessible&&) = delete;
449 std::shared_ptr<Bridge::Data> GetBridgeData() const;
452 * @brief Returns the collection of AT-SPI interfaces implemented by this Accessible.
454 * This method is called only once and its return value is cached. The default implementation
455 * uses dynamic_cast to determine which interfaces are implemented. Override this if you
456 * conceptually provide fewer interfaces than dynamic_cast can see.
458 * @return The collection of implemented interfaces
460 * @see GetInterfaces()
461 * @see GetInterfaceName()
463 virtual AtspiInterfaces DoGetInterfaces() const;
466 * @brief Updates the attribute collection
468 * This method, which is always called by GetAttributes(), can be overriden to
469 * provide lazily-calculated or dynamically-calculated (i.e. non-constant)
470 * attributes. When overriding, make sure to call the base class implementation
473 * @note The attribute collection is non-empty on entry
474 * @see Accessible::GetAttributes()
476 * @param[inout] attributes The attribute collection to update
478 virtual void UpdateAttributes(Attributes& attributes) const;
482 * @brief Gets the highlight actor.
484 * This method is to get the highlight itself.
485 * @return The highlight actor
487 static Dali::Actor GetHighlightActor();
490 * @brief Sets the highlight actor.
492 * This method is to set the highlight itself.
493 * @param[in] actor The highlight actor
495 static void SetHighlightActor(Dali::Actor actor);
498 * @brief Gets the currently highlighted actor.
500 * @return The current highlighted actor
502 static Dali::Actor GetCurrentlyHighlightedActor();
505 * @brief Sets currently highlighted actor.
507 * @param[in] actor The highlight actor
509 static void SetCurrentlyHighlightedActor(Dali::Actor actor);
512 * @brief Sets ObjectRegistry.
514 * @param[in] registry ObjectRegistry instance
516 static void SetObjectRegistry(ObjectRegistry registry);
519 * @brief The method registers functor resposible for converting Actor into Accessible.
520 * @param functor The returning Accessible handle from Actor object
522 static void RegisterExternalAccessibleGetter(std::function<Accessible*(Dali::Actor)> functor);
525 * @brief Acquires Accessible object from Actor object.
527 * @param[in] actor Actor object
529 * @return The handle to Accessible object
531 static Accessible* Get(Dali::Actor actor);
534 * @brief Obtains the DBus interface name for the specified AT-SPI interface.
536 * @param interface AT-SPI interface identifier (e.g. AtspiInterface::ACCESSIBLE)
537 * @return AT-SPI interface name (e.g. "org.a11y.atspi.Accessible")
539 static std::string GetInterfaceName(AtspiInterface interface);
542 * @brief Downcasts an Accessible pointer to an AT-SPI interface pointer.
544 * @tparam I Desired AT-SPI interface
546 * @param obj Object to cast.
548 * @return Pointer to an AT-SPI interface or null if the interface is not implemented.
550 template<AtspiInterface I>
551 static AtspiInterfaceType<I>* DownCast(Accessible* obj)
553 if(!obj || !obj->GetInterfaces()[I])
558 return dynamic_cast<AtspiInterfaceType<I>*>(obj);
564 mutable std::weak_ptr<Bridge::Data> mBridgeData;
565 mutable AtspiInterfaces mInterfaces;
566 mutable Attributes mAttributes;
567 ReadingInfoTypes mReadingInfoTypes = ~ReadingInfoTypes(); // all set
568 AtspiEvents mSuppressedEvents;
569 bool mIsOnRootLevel = false;
570 }; // Accessible class
575 struct AtspiInterfaceTypeHelper<AtspiInterface::ACCESSIBLE>
577 using Type = Accessible;
579 } // namespace Internal
581 } // namespace Dali::Accessibility
583 #endif // DALI_ADAPTOR_ATSPI_ACCESSIBLE_H