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 "ScrollStarted" event.
145 void EmitScrollStarted();
148 * @brief Emits "ScrollFinished" event.
151 void EmitScrollFinished();
154 * @brief Emits "highlighted" event.
156 * @param[in] event The enumerated window event
157 * @param[in] detail The additional parameter which interpretation depends on chosen event
159 void Emit(WindowEvent event, unsigned int detail = 0);
162 * @brief Emits property-changed event.
164 * @param[in] event Property changed event
166 void Emit(ObjectPropertyChangeEvent event);
169 * @brief Gets accessibility name.
171 * @return The string with name
173 virtual std::string GetName() const = 0;
176 * @brief Gets accessibility description.
178 * @return The string with description
180 virtual std::string GetDescription() const = 0;
183 * @brief Gets parent.
185 * @return The handler to accessibility object
187 virtual Accessible* GetParent() = 0;
190 * @brief Gets the number of children.
192 * @return The number of children
194 virtual std::size_t GetChildCount() const = 0;
197 * @brief Gets collection with all children.
199 * @return The collection of accessibility objects
201 virtual std::vector<Accessible*> GetChildren() = 0;
204 * @brief Gets child of the index.
206 * @return The child object
208 virtual Accessible* GetChildAtIndex(std::size_t index) = 0;
211 * @brief Gets index that current object has in its parent's children collection.
213 * @return The index of the current object
215 virtual std::size_t GetIndexInParent() = 0;
218 * @brief Gets accessibility role.
220 * @return Role enumeration
222 * @see Dali::Accessibility::Role
224 virtual Role GetRole() const = 0;
227 * @brief Gets name of accessibility role.
229 * @return The string with human readable role converted from enumeration
231 * @see Dali::Accessibility::Role
232 * @see Accessibility::Accessible::GetRole
234 virtual std::string GetRoleName() const;
237 * @brief Gets localized name of accessibility role.
239 * @return The string with human readable role translated according to current
242 * @see Dali::Accessibility::Role
243 * @see Accessibility::Accessible::GetRole
244 * @see Accessibility::Accessible::GetRoleName
246 * @note translation is not supported in this version
248 virtual std::string GetLocalizedRoleName() const;
251 * @brief Gets accessibility states.
253 * @return The collection of states
255 * @note States class is instatation of ArrayBitset template class
257 * @see Dali::Accessibility::State
258 * @see Dali::Accessibility::ArrayBitset
260 virtual States GetStates() = 0;
263 * @brief Gets accessibility attributes.
265 * @return The map of attributes and their values
267 virtual Attributes GetAttributes() const = 0;
270 * @brief Checks if this is hidden.
272 * @return True if this is hidden
274 * @note Hidden means not present in the AT-SPI tree.
276 virtual bool IsHidden() const;
279 * @brief Checks if this is proxy.
281 * @return True if this is proxy
283 virtual bool IsProxy() const;
286 * @brief Gets unique address on accessibility bus.
288 * @return The Address class containing address
290 * @see Dali::Accessibility::Address
292 virtual Address GetAddress() const;
295 * @brief Deputes an object to perform provided gesture.
297 * @param[in] gestureInfo The structure describing the gesture
299 * @return true on success, false otherwise
301 * @see Dali::Accessibility::GestureInfo
303 virtual bool DoGesture(const GestureInfo& gestureInfo) = 0;
306 * @brief Re-emits selected states of an Accessibility Object.
308 * @param[in] states The chosen states to re-emit
309 * @param[in] isRecursive If true, all children of the Accessibility object will also re-emit the states
311 void NotifyAccessibilityStateChange(Dali::Accessibility::States states, bool isRecursive);
314 * @brief Gets information about current object and all relations that connects
315 * it with other accessibility objects.
317 * @return The iterable collection of Relation objects
319 * @see Dali::Accessibility::Relation
321 virtual std::vector<Relation> GetRelationSet() = 0;
324 * @brief Gets the Actor associated with this Accessible (if there is one).
326 * @return The internal Actor
328 virtual Dali::Actor GetInternalActor() = 0;
331 * @brief Sets whether to listen for post render callback.
333 * @param[in] enabled If ture, registration post render callback, false otherwise
335 virtual void SetListenPostRender(bool enabled);
338 * @brief Gets all implemented interfaces.
340 * Override DoGetInterfaces() to customize the return value of this method.
342 * @return The collection of implemented interfaces
344 * @see DoGetInterfaces()
346 AtspiInterfaces GetInterfaces() const;
349 * @brief Gets all implemented interfaces.
351 * Converts all interfaces returned by GetInterfaces() to their DBus names
352 * using GetInterfaceName().
354 * @return The collection of names of implemented interfaces
356 * @see GetInterfaces()
357 * @see GetInterfaceName()
359 std::vector<std::string> GetInterfacesAsStrings() const;
362 * @brief Checks if object is on root level.
364 * @return Whether object is on root level or not
366 bool IsOnRootLevel() const
368 return mIsOnRootLevel;
372 * @brief Gets all suppressed events.
374 * @return All suppressed events
376 AtspiEvents GetSuppressedEvents() const
378 return mSuppressedEvents;
382 * @brief Gets all suppressed events.
384 * @return All suppressed events
386 AtspiEvents& GetSuppressedEvents()
388 return mSuppressedEvents;
393 Accessible(const Accessible&) = delete;
394 Accessible(Accessible&&) = delete;
395 Accessible& operator=(const Accessible&) = delete;
396 Accessible& operator=(Accessible&&) = delete;
397 std::shared_ptr<Bridge::Data> GetBridgeData() const;
400 * @brief Returns the collection of AT-SPI interfaces implemented by this Accessible.
402 * This method is called only once and its return value is cached. The default implementation
403 * uses dynamic_cast to determine which interfaces are implemented. Override this if you
404 * conceptually provide fewer interfaces than dynamic_cast can see.
406 * @return The collection of implemented interfaces
408 * @see GetInterfaces()
409 * @see GetInterfaceName()
411 virtual AtspiInterfaces DoGetInterfaces() const;
415 * @brief Gets the highlight actor.
417 * This method is to get the highlight itself.
418 * @return The highlight actor
420 static Dali::Actor GetHighlightActor();
423 * @brief Sets the highlight actor.
425 * This method is to set the highlight itself.
426 * @param[in] actor The highlight actor
428 static void SetHighlightActor(Dali::Actor actor);
431 * @brief Gets the currently highlighted actor.
433 * @return The current highlighted actor
435 static Dali::Actor GetCurrentlyHighlightedActor();
438 * @brief Sets currently highlighted actor.
440 * @param[in] actor The highlight actor
442 static void SetCurrentlyHighlightedActor(Dali::Actor actor);
445 * @brief Sets ObjectRegistry.
447 * @param[in] registry ObjectRegistry instance
449 static void SetObjectRegistry(ObjectRegistry registry);
452 * @brief The method registers functor resposible for converting Actor into Accessible.
453 * @param functor The returning Accessible handle from Actor object
455 static void RegisterExternalAccessibleGetter(std::function<Accessible*(Dali::Actor)> functor);
458 * @brief Acquires Accessible object from Actor object.
460 * @param[in] actor Actor object
462 * @return The handle to Accessible object
464 static Accessible* Get(Dali::Actor actor);
467 * @brief Obtains the DBus interface name for the specified AT-SPI interface.
469 * @param interface AT-SPI interface identifier (e.g. AtspiInterface::ACCESSIBLE)
470 * @return AT-SPI interface name (e.g. "org.a11y.atspi.Accessible")
472 static std::string GetInterfaceName(AtspiInterface interface);
475 * @brief Downcasts an Accessible pointer to an AT-SPI interface pointer.
477 * @tparam I Desired AT-SPI interface
479 * @param obj Object to cast.
481 * @return Pointer to an AT-SPI interface or null if the interface is not implemented.
483 template<AtspiInterface I>
484 static AtspiInterfaceType<I>* DownCast(Accessible* obj)
486 if(!obj || !obj->GetInterfaces()[I])
491 return dynamic_cast<AtspiInterfaceType<I>*>(obj);
497 mutable std::weak_ptr<Bridge::Data> mBridgeData;
498 mutable AtspiInterfaces mInterfaces;
499 AtspiEvents mSuppressedEvents;
500 bool mIsOnRootLevel = false;
502 }; // Accessible class
507 struct AtspiInterfaceTypeHelper<AtspiInterface::ACCESSIBLE>
509 using Type = Accessible;
511 } // namespace Internal
513 } // namespace Dali::Accessibility
515 #endif // DALI_ADAPTOR_ATSPI_ACCESSIBLE_H