1 #ifndef DALI_ADAPTOR_ATSPI_ACCESSIBLE_H
2 #define DALI_ADAPTOR_ATSPI_ACCESSIBLE_H
5 * Copyright (c) 2021 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.h>
30 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
32 namespace Dali::Accessibility
35 * @brief Basic interface implemented by all accessibility objects.
37 class DALI_ADAPTOR_API Accessible
40 virtual ~Accessible() noexcept;
42 using utf8_t = unsigned char;
45 * @brief Calculates and finds word boundaries in given utf8 text.
47 * @param[in] string The source text to find
48 * @param[in] length The length of text to find
49 * @param[in] language The language to use
50 * @param[out] breaks The word boundaries in given text
52 * @note Word boundaries are returned as non-zero values in table breaks, which must be of size at least length.
54 static void FindWordSeparationsUtf8(const utf8_t* string, std::size_t length, const char* language, char* breaks);
57 * @brief Calculates and finds line boundaries in given utf8 text.
59 * @param[in] string The source text to find
60 * @param[in] length The length of text to find
61 * @param[in] language The language to use
62 * @param[out] breaks The line boundaries in given text
64 * @note Line boundaries are returned as non-zero values in table breaks, which must be of size at least length.
66 static void FindLineSeparationsUtf8(const utf8_t* string, std::size_t length, const char* language, char* breaks);
69 * @brief Helper function for emiting active-descendant-changed event.
71 * @param[in] obj The accessible object
72 * @param[in] child The child of the object
74 void EmitActiveDescendantChanged(Accessible* obj, Accessible* child);
77 * @brief Helper function for emiting state-changed event.
79 * @param[in] state The accessibility state (SHOWING, HIGHLIGHTED, etc)
80 * @param[in] newValue Whether the state value is changed to new value or not.
81 * @param[in] reserved Reserved. (TODO : Currently, this argument is not implemented in dali)
83 * @note The second argument determines which value is depending on State.
84 * For instance, if the state is PRESSED, newValue means isPressed or isSelected.
85 * If the state is SHOWING, newValue means isShowing.
87 void EmitStateChanged(State state, int newValue, int reserved = 0);
90 * @brief Helper function for emiting bounds-changed event.
92 * @param rect The rectangle for changed bounds
94 void EmitBoundsChanged(Rect<> rect);
97 * @brief Emits "showing" event.
98 * The method informs accessibility clients about "showing" state.
100 * @param[in] isShowing The flag pointing if object is showing
102 void EmitShowing(bool isShowing);
105 * @brief Emits "visible" event.
106 * The method informs accessibility clients about "visible" state.
108 * @param[in] isVisible The flag pointing if object is visible
110 void EmitVisible(bool isVisible);
113 * @brief Emits "highlighted" event.
114 * The method informs accessibility clients about "highlighted" state.
116 * @param[in] isHighlighted The flag pointing if object is highlighted
118 void EmitHighlighted(bool isHighlighted);
121 * @brief Emits "focused" event.
122 * The method informs accessibility clients about "focused" state.
124 * @param[in] isFocused The flag pointing if object is focused
126 void EmitFocused(bool isFocused);
129 * @brief Emits "text inserted" event.
131 * @param[in] position The cursor position
132 * @param[in] length The text length
133 * @param[in] content The inserted text
135 void EmitTextInserted(unsigned int position, unsigned int length, const std::string& content);
138 * @brief Emits "text deleted" event.
140 * @param[in] position The cursor position
141 * @param[in] length The text length
142 * @param[in] content The deleted text
144 void EmitTextDeleted(unsigned int position, unsigned int length, const std::string& content);
147 * @brief Emits "cursor moved" event.
149 * @param[in] cursorPosition The new cursor position
151 void EmitTextCursorMoved(unsigned int cursorPosition);
154 * @brief Emits "MoveOuted" event.
156 * @param[in] type moved out of screen type
158 void EmitMovedOutOfScreen(ScreenRelativeMoveType type);
161 * @brief Emits "highlighted" event.
163 * @param[in] event The enumerated window event
164 * @param[in] detail The additional parameter which interpretation depends on chosen event
166 void Emit(WindowEvent event, unsigned int detail = 0);
169 * @brief Emits property-changed event.
171 * @param[in] event Property changed event
173 void Emit(ObjectPropertyChangeEvent event);
176 * @brief Gets accessibility name.
178 * @return The string with name
180 virtual std::string GetName() const = 0;
183 * @brief Gets accessibility description.
185 * @return The string with description
187 virtual std::string GetDescription() const = 0;
190 * @brief Gets parent.
192 * @return The handler to accessibility object
194 virtual Accessible* GetParent() = 0;
197 * @brief Gets the number of children.
199 * @return The number of children
201 virtual std::size_t GetChildCount() const = 0;
204 * @brief Gets collection with all children.
206 * @return The collection of accessibility objects
208 virtual std::vector<Accessible*> GetChildren() = 0;
211 * @brief Gets child of the index.
213 * @return The child object
215 virtual Accessible* GetChildAtIndex(std::size_t index) = 0;
218 * @brief Gets index that current object has in its parent's children collection.
220 * @return The index of the current object
222 virtual std::size_t GetIndexInParent() = 0;
225 * @brief Gets accessibility role.
227 * @return Role enumeration
229 * @see Dali::Accessibility::Role
231 virtual Role GetRole() const = 0;
234 * @brief Gets name of accessibility role.
236 * @return The string with human readable role converted from enumeration
238 * @see Dali::Accessibility::Role
239 * @see Accessibility::Accessible::GetRole
241 virtual std::string GetRoleName() const;
244 * @brief Gets localized name of accessibility role.
246 * @return The string with human readable role translated according to current
249 * @see Dali::Accessibility::Role
250 * @see Accessibility::Accessible::GetRole
251 * @see Accessibility::Accessible::GetRoleName
253 * @note translation is not supported in this version
255 virtual std::string GetLocalizedRoleName() const;
258 * @brief Gets accessibility states.
260 * @return The collection of states
262 * @note States class is instatation of ArrayBitset template class
264 * @see Dali::Accessibility::State
265 * @see Dali::Accessibility::ArrayBitset
267 virtual States GetStates() = 0;
270 * @brief Gets accessibility attributes.
272 * @return The map of attributes and their values
274 virtual Attributes GetAttributes() const = 0;
277 * @brief Checks if this is hidden.
279 * @return True if this is hidden
281 * @note Hidden means not present in the AT-SPI tree.
283 virtual bool IsHidden() const;
286 * @brief Checks if this is proxy.
288 * @return True if this is proxy
290 virtual bool IsProxy() const;
293 * @brief Gets unique address on accessibility bus.
295 * @return The Address class containing address
297 * @see Dali::Accessibility::Address
299 virtual Address GetAddress() const;
302 * @brief Deputes an object to perform provided gesture.
304 * @param[in] gestureInfo The structure describing the gesture
306 * @return true on success, false otherwise
308 * @see Dali::Accessibility::GestureInfo
310 virtual bool DoGesture(const GestureInfo& gestureInfo) = 0;
313 * @brief Re-emits selected states of an Accessibility Object.
315 * @param[in] states The chosen states to re-emit
316 * @param[in] isRecursive If true, all children of the Accessibility object will also re-emit the states
318 void NotifyAccessibilityStateChange(Dali::Accessibility::States states, bool isRecursive);
321 * @brief Gets information about current object and all relations that connects
322 * it with other accessibility objects.
324 * @return The iterable collection of Relation objects
326 * @see Dali::Accessibility::Relation
328 virtual std::vector<Relation> GetRelationSet() = 0;
331 * @brief Gets internal Actor to be saved before.
333 * @return The internal Actor
335 virtual Dali::Actor GetInternalActor() = 0;
338 * @brief Gets all implemented interfaces.
340 * @return The collection of strings with implemented interfaces
342 std::vector<std::string> GetInterfaces() const;
345 * @brief Checks if object is on root level.
347 * @return Whether object is on root level or not
349 bool IsOnRootLevel() const
351 return mIsOnRootLevel;
356 Accessible(const Accessible&) = delete;
357 Accessible(Accessible&&) = delete;
358 Accessible& operator=(const Accessible&) = delete;
359 Accessible& operator=(Accessible&&) = delete;
360 std::shared_ptr<Bridge::Data> GetBridgeData() const;
364 * @brief Gets the highlight actor.
366 * This method is to get the highlight itself.
367 * @return The highlight actor
369 static Dali::Actor GetHighlightActor();
372 * @brief Sets the highlight actor.
374 * This method is to set the highlight itself.
375 * @param[in] actor The highlight actor
377 static void SetHighlightActor(Dali::Actor actor);
380 * @brief Gets the currently highlighted actor.
382 * @return The current highlighted actor
384 static Dali::Actor GetCurrentlyHighlightedActor();
387 * @brief Sets currently highlighted actor.
389 * @param[in] actor The highlight actor
391 static void SetCurrentlyHighlightedActor(Dali::Actor actor);
394 * @brief Sets ObjectRegistry.
396 * @param[in] registry ObjectRegistry instance
398 static void SetObjectRegistry(ObjectRegistry registry);
401 * @brief The method registers functor resposible for converting Actor into Accessible.
402 * @param functor The returning Accessible handle from Actor object
404 static void RegisterExternalAccessibleGetter(std::function<Accessible*(Dali::Actor)> functor);
407 * @brief Acquires Accessible object from Actor object.
409 * @param[in] actor Actor object
410 * @param[in] isRoot True, if it's top level object (window)
412 * @return The handle to Accessible object
414 static Accessible* Get(Dali::Actor actor, bool isRoot = false);
419 mutable std::weak_ptr<Bridge::Data> mBridgeData;
420 bool mIsOnRootLevel = false;
422 }; // Accessible class
424 } // namespace Dali::Accessibility
426 #endif // DALI_ADAPTOR_ATSPI_ACCESSIBLE_H