1 #ifndef DALI_TOOLKIT_ACCESSIBILITY_MANAGER_H
2 #define DALI_TOOLKIT_ACCESSIBILITY_MANAGER_H
5 * Copyright (c) 2020 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.
22 #include <dali/public-api/actors/actor.h>
25 #include <dali-toolkit/public-api/dali-toolkit-common.h>
31 namespace Internal DALI_INTERNAL
33 class AccessibilityManager;
36 * @addtogroup dali_toolkit_managers
41 * @brief Manages registration of actors in an accessibility focus chain and changing the
42 * focused actor within that chain.
44 * This class provides the functionality of registering the focus order and description
45 * of actors and maintaining the focus chain.
47 * It provides functionality of setting the
48 * focus and moving the focus forward and backward. It also draws a highlight for the
49 * focused actor and emits a signal when the focus is changed.
52 * | %Signal Name | Method |
53 * |-----------------------|------------------------------------|
54 * | focusChanged | @ref FocusChangedSignal() |
55 * | focusOvershot | @ref FocusOvershotSignal() |
56 * | focusedActorActivated | @ref FocusedActorActivatedSignal() |
59 class DALI_TOOLKIT_API AccessibilityManager : public BaseHandle
65 * @brief Accessibility Action Signal.
67 * The connected signal callback should return true if handled.
70 typedef Signal<bool(AccessibilityManager&)> AccessibilityActionSignalType; ///< Generic signal type @SINCE_1_0.0
71 typedef Signal<bool(AccessibilityManager&, const Dali::TouchEvent&)> AccessibilityActionScrollSignalType; ///< Scroll signal type @SINCE_1_0.0
74 * @brief Enumeration for accessibility that needs four information which will be read by screen-reader.
76 * Reading order : Label -> Trait -> Optional (Value and Hint)
79 enum AccessibilityAttribute
81 ACCESSIBILITY_LABEL = 0, ///< Simple text which contained in ui-control @SINCE_1_0.0
82 ACCESSIBILITY_TRAIT, ///< Description of ui-control trait @SINCE_1_0.0
83 ACCESSIBILITY_VALUE, ///< Current value of ui-control (Optional) @SINCE_1_0.0
84 ACCESSIBILITY_HINT, ///< Hint for action (Optional) @SINCE_1_0.0
85 ACCESSIBILITY_ATTRIBUTE_NUM ///< Number of attributes @SINCE_1_0.0
89 * @brief Enumeration for overshoot direction.
92 enum FocusOvershotDirection
94 OVERSHOT_PREVIOUS = -1, ///< Try to move previous of the first actor @SINCE_1_0.0
95 OVERSHOT_NEXT = 1, ///< Try to move next of the last actor @SINCE_1_0.0
99 /// @brief Focus changed signal
101 typedef Signal<void(Actor, Actor)> FocusChangedSignalType;
103 /// @brief Focus overshooted signal
105 typedef Signal<void(Actor, FocusOvershotDirection)> FocusOvershotSignalType;
107 /// @brief Focused actor activated signal
109 typedef Signal<void(Actor)> FocusedActorActivatedSignalType;
112 * @brief Creates an AccessibilityManager handle; this can be initialised with AccessibilityManager::New().
114 * Calling member functions with an uninitialized handle is not allowed.
117 AccessibilityManager();
122 * This is non-virtual since derived Handle types must not contain data or virtual methods.
125 ~AccessibilityManager();
128 * @brief Gets the singleton of AccessibilityManager object.
131 * @return A handle to the AccessibilityManager control
133 static AccessibilityManager Get();
136 * @brief Sets the information of the specified actor's accessibility attribute.
139 * @param actor The actor, the text to be set with
140 * @param type The attribute type the text to be set with
141 * @param text The text for the actor's accessibility information
142 * @pre The AccessibilityManager has been initialized.
143 * @pre The Actor has been initialized.
145 void SetAccessibilityAttribute(Actor actor, AccessibilityAttribute type, const std::string& text);
148 * @brief Gets the text of the specified actor's accessibility attribute.
151 * @param actor The actor to be queried
152 * @param type The attribute type to be queried
153 * @return The text of the actor's accessibility information
154 * @pre The AccessibilityManager has been initialized.
155 * @pre The Actor has been initialized.
157 std::string GetAccessibilityAttribute(Actor actor, AccessibilityAttribute type) const;
160 * @brief Sets the focus order of the actor.
162 * The focus order of each actor in the focus chain is unique.
163 * If there is another actor assigned with the same focus order
164 * already, the new actor will be inserted to the focus chain with
165 * that focus order, and the focus order of the original actor and
166 * all the actors followed in the focus chain will be increased
167 * accordingly. If the focus order assigned to the actor is 0, it
168 * means that actor's focus order is undefined (e.g. the actor has a
169 * description but with no focus order being set yet) and therefore
170 * that actor is not focusable.
173 * @param actor The actor the focus order to be set with
174 * @param order The focus order of the actor
175 * @pre The AccessibilityManager has been initialized.
176 * @pre The Actor has been initialized.
178 void SetFocusOrder(Actor actor, const unsigned int order);
181 * @brief Gets the focus order of the actor.
183 * When the focus order is 0, it means the focus order of the actor
187 * @param actor The actor to be queried
188 * @return The focus order of the actor
189 * @pre The AccessibilityManager has been initialized.
190 * @pre The Actor has been initialized.
192 unsigned int GetFocusOrder(Actor actor) const;
195 * @brief Generates a new focus order number which can be used to
196 * assign to actors which need to be appended to the end of the
197 * current focus order chain.
199 * The new number will be an increment over the very last focus
200 * order number in the focus chain. If the focus chain is empty then
201 * the function returns 1, else the number returned will be FOLast +
202 * 1 where FOLast is the focus order of the very last control in the
206 * @return The focus order of the actor
207 * @pre The AccessibilityManager has been initialized.
209 unsigned int GenerateNewFocusOrder() const;
212 * @brief Gets the actor that has the specified focus order.
214 * It will return an empty handle if no actor in the stage
215 * has the specified focus order.
218 * @param order The focus order of the actor
220 * @return The actor that has the specified focus order or an empty
221 * handle if no actor in the stage has the specified focus order
222 * @pre The AccessibilityManager has been initialized.
224 Actor GetActorByFocusOrder(const unsigned int order);
227 * @brief Moves the focus to the specified actor.
229 * Only one actor can be focused at the same time. The actor must
230 * have a defined focus order and must be focusable, visible and in
234 * @param actor The actor to be focused
235 * @return Whether the focus is successful or not
236 * @pre The AccessibilityManager has been initialized.
237 * @pre The Actor has been initialized.
239 bool SetCurrentFocusActor(Actor actor);
242 * @brief Gets the current focused actor.
245 * @return A handle to the current focused actor or an empty handle if no actor is focused
246 * @pre The AccessibilityManager has been initialized.
248 Actor GetCurrentFocusActor();
251 * @brief Gets the focus group of current focused actor.
254 * @return A handle to the immediate parent of the current focused
255 * actor which is also a focus group, or an empty handle if no actor
257 * @pre The AccessibilityManager has been initialized.
260 Actor GetCurrentFocusGroup();
263 * @brief Gets the focus order of currently focused actor.
265 * @return The focus order of the currently focused actor or 0 if no
267 * @pre The AccessibilityManager has been initialized.
270 unsigned int GetCurrentFocusOrder();
273 * @brief Moves the focus to the next focusable actor in the focus
274 * chain (according to the focus traversal order).
276 * When the focus movement is wrapped around, the focus will be moved
277 * to the first focusable actor when it reaches the end of the focus chain.
280 * @return true if the moving was successful
281 * @pre The AccessibilityManager has been initialized.
283 bool MoveFocusForward();
286 * @brief Moves the focus to the previous focusable actor in the
287 * focus chain (according to the focus traversal order).
289 * When the focus movement is wrapped around, the focus will be
290 * moved to the last focusable actor when it reaches the beginning
291 * of the focus chain.
294 * @return true if the moving was successful
295 * @pre The AccessibilityManager has been initialized.
297 bool MoveFocusBackward();
300 * @brief Clears the focus from the current focused actor if any, so
301 * that no actor is focused in the focus chain.
303 * It will emit focus changed signal without current focused actor.
305 * @pre The AccessibilityManager has been initialized.
310 * @brief Clears every registered focusable actor from focus-manager.
312 * @pre The AccessibilityManager has been initialized.
317 * @brief Sets whether an actor is a focus group that can limit the
318 * scope of focus movement to its child actors in the focus chain.
321 * @param actor The actor to be set as a focus group
322 * @param isFocusGroup Whether to set the actor to be a focus group or not
323 * @pre The AccessibilityManager has been initialized.
324 * @pre The Actor has been initialized.
326 void SetFocusGroup(Actor actor, bool isFocusGroup);
329 * @brief Checks whether the actor is set as a focus group or not.
332 * @param actor The actor to be checked
333 * @return Whether the actor is set as a focus group
334 * @pre The AccessibilityManager has been initialized.
335 * @pre The Actor has been initialized.
337 bool IsFocusGroup(Actor actor) const;
340 * @brief Sets whether the group mode is enabled or not.
342 * When the group mode is enabled, the focus movement will be limited to the child actors
343 * of the current focus group including the current focus group itself. The current focus
344 * group is the closest ancestor of the current focused actor that is set as a focus group.
346 * @param enabled Whether the group mode is enabled or not
347 * @pre The AccessibilityManager has been initialized.
349 void SetGroupMode(bool enabled);
352 * @brief Gets whether the group mode is enabled or not.
355 * @return Whether the group mode is enabled or not.
356 * @pre The AccessibilityManager has been initialized.
358 bool GetGroupMode() const;
361 * @brief Sets whether focus will be moved to the beginning of the
362 * focus chain when it reaches the end or vice versa.
364 * When both the wrap mode and the group mode are enabled, focus will be
365 * wrapped within the current focus group. Focus will not be wrapped in default.
367 * @param wrapped Whether the focus movement is wrapped around or not
368 * @pre The AccessibilityManager has been initialized.
370 void SetWrapMode(bool wrapped);
373 * @brief Gets whether the wrap mode is enabled or not.
376 * @return Whether the wrap mode is enabled or not.
377 * @pre The AccessibilityManager has been initialized.
379 bool GetWrapMode() const;
382 * @brief Sets the focus indicator actor.
384 * This will replace the default focus indicator actor in
385 * AccessibilityManager and will be added to the focused actor as a
389 * @param indicator The indicator actor to be added
390 * @pre The AccessibilityManager has been initialized.
391 * @pre The indicator actor has been initialized.
393 void SetFocusIndicatorActor(Actor indicator);
396 * @brief Gets the focus indicator actor.
399 * @return A handle to the focus indicator actor
400 * @pre The AccessibilityManager has been initialized.
402 Actor GetFocusIndicatorActor();
405 * @brief Returns the closest ancestor of the given actor that is a focus group.
408 * @param actor The actor to be checked for its focus group
409 * @return The focus group the given actor belongs to or an empty handle if the given actor doesn't belong to any focus group
411 Actor GetFocusGroup(Actor actor);
414 * @brief Returns the current position of the read action.
416 * @return The current event position
418 Vector2 GetReadPosition() const;
422 * @brief This signal is emitted when the current focused actor is changed.
424 * A callback of the following type may be connected:
426 * void YourCallbackName(Actor originalFocusedActor, Actor currentFocusedActor);
429 * @return The signal to connect to
430 * @pre The Object has been initialized.
432 FocusChangedSignalType& FocusChangedSignal();
435 * @brief This signal is emitted when there is no way to move focus further.
437 * A callback of the following type may be connected:
439 * void YourCallbackName(Actor currentFocusedActor, FocusOvershotDirection direction);
442 * @return The signal to connect to
443 * @pre The Object has been initialized.
445 FocusOvershotSignalType& FocusOvershotSignal();
448 * @brief This signal is emitted when the current focused actor is activated.
450 * A callback of the following type may be connected:
452 * void YourCallbackName(Actor activatedActor);
455 * @return The signal to connect to
456 * @pre The Object has been initialized.
458 FocusedActorActivatedSignalType& FocusedActorActivatedSignal();
460 public: // Accessibility action signals
462 * @brief This is emitted when accessibility(screen-reader) feature turned on or off.
464 * A callback of the following type may be connected:
466 * bool YourCallback( AccessibilityManager& manager );
469 * @return The signal to connect to
471 AccessibilityActionSignalType& StatusChangedSignal();
474 * @brief This is emitted when accessibility action is received to move focus to the next
475 * focusable actor (by one finger flick down).
477 * A callback of the following type may be connected:
479 * bool YourCallback( AccessibilityManager& manager );
482 * @return The signal to connect to
484 AccessibilityActionSignalType& ActionNextSignal();
487 * @brief This is emitted when accessibility action is received to move focus to the previous
488 * focusable actor (by one finger flick up).
490 * A callback of the following type may be connected:
492 * bool YourCallback( AccessibilityManager& manager );
495 * @return The signal to connect to
497 AccessibilityActionSignalType& ActionPreviousSignal();
500 * @brief This is emitted when accessibility action is received to activate the current focused
501 * actor (by one finger double tap).
503 * A callback of the following type may be connected:
505 * bool YourCallback( AccessibilityManager& manager );
508 * @return The signal to connect to
510 AccessibilityActionSignalType& ActionActivateSignal();
513 * @brief This is emitted when accessibility action is received to focus and read the actor
514 * (by one finger tap).
516 * A callback of the following type may be connected:
518 * bool YourCallback( AccessibilityManager& manager );
521 * @return The signal to connect to
523 AccessibilityActionSignalType& ActionReadSignal();
526 * @brief This is emitted when accessibility action is received to focus and read the actor
527 * (by one finger move).
529 * A callback of the following type may be connected:
531 * bool YourCallback( AccessibilityManager& manager );
534 * @return The signal to connect to
536 AccessibilityActionSignalType& ActionOverSignal();
539 * @brief This is emitted when accessibility action is received to move focus to the next
540 * focusable actor (by one finger flick right).
542 * A callback of the following type may be connected:
544 * bool YourCallback( AccessibilityManager& manager );
547 * @return The signal to connect to
549 AccessibilityActionSignalType& ActionReadNextSignal();
552 * @brief This is emitted when accessibility action is received to move focus to the previous
553 * focusable actor (by one finger flick left).
555 * A callback of the following type may be connected:
557 * bool YourCallback( AccessibilityManager& manager );
560 * @return The signal to connect to
562 AccessibilityActionSignalType& ActionReadPreviousSignal();
565 * @brief This is emitted when accessibility action is received to change the value when the
566 * current focused actor is a slider (by double finger down and move up and right).
568 * A callback of the following type may be connected:
570 * bool YourCallback( AccessibilityManager& manager );
573 * @return The signal to connect to
575 AccessibilityActionSignalType& ActionUpSignal();
578 * @brief This is emitted when accessibility action is received to change the value when the
579 * current focused actor is a slider (by double finger down and move down and left).
581 * A callback of the following type may be connected:
583 * bool YourCallback( AccessibilityManager& manager );
586 * @return The signal to connect to
588 AccessibilityActionSignalType& ActionDownSignal();
591 * @brief This is emitted when accessibility action is received to clear the focus from the
592 * current focused actor if any, so that no actor is focused in the focus chain.
594 * A callback of the following type may be connected:
596 * bool YourCallback( AccessibilityManager& manager );
599 * @return The signal to connect to
601 AccessibilityActionSignalType& ActionClearFocusSignal();
604 * @brief This is emitted when accessibility action is received to navigate back (by two
605 * fingers circle draw).
607 * A callback of the following type may be connected:
609 * bool YourCallback( AccessibilityManager& manager );
612 * @return The signal to connect to
614 AccessibilityActionSignalType& ActionBackSignal();
617 * @brief This is emitted when accessibility action is received to scroll up the list
618 * (by two finger swipe up).
620 * A callback of the following type may be connected:
622 * bool YourCallback( AccessibilityManager& manager );
625 * @return The signal to connect to
627 AccessibilityActionSignalType& ActionScrollUpSignal();
630 * @brief This is emitted when accessibility action is received to scroll down the list
631 * (by two finger swipe down).
633 * A callback of the following type may be connected:
635 * bool YourCallback( AccessibilityManager& manager );
638 * @return The signal to connect to
640 AccessibilityActionSignalType& ActionScrollDownSignal();
643 * @brief This is emitted when accessibility action is received to scroll left to the
644 * previous page (by two finger swipe left).
646 * A callback of the following type may be connected:
648 * bool YourCallback( AccessibilityManager& manager );
651 * @return The signal to connect to
653 AccessibilityActionSignalType& ActionPageLeftSignal();
656 * @brief This is emitted when accessibility action is received to scroll right to the
657 * next page (by two finger swipe right).
659 * A callback of the following type may be connected:
661 * bool YourCallback( AccessibilityManager& manager );
664 * @return The signal to connect to
666 AccessibilityActionSignalType& ActionPageRightSignal();
669 * @brief This is emitted when accessibility action is received to scroll up to the
670 * previous page (by one finger swipe left and right).
672 * A callback of the following type may be connected:
674 * bool YourCallback( AccessibilityManager& manager );
677 * @return The signal to connect to
679 AccessibilityActionSignalType& ActionPageUpSignal();
682 * @brief This is emitted when accessibility action is received to scroll down to the
683 * next page (by one finger swipe right and left).
685 * A callback of the following type may be connected:
687 * bool YourCallback( AccessibilityManager& manager );
690 * @return The signal to connect to
692 AccessibilityActionSignalType& ActionPageDownSignal();
695 * @brief This is emitted when accessibility action is received to move the focus to
696 * the first item on the screen (by one finger swipe up and down).
698 * A callback of the following type may be connected:
700 * bool YourCallback( AccessibilityManager& manager );
703 * @return The signal to connect to
705 AccessibilityActionSignalType& ActionMoveToFirstSignal();
708 * @brief This is emitted when accessibility action is received to move the focus to
709 * the last item on the screen (by one finger swipe down and up).
711 * A callback of the following type may be connected:
713 * bool YourCallback( AccessibilityManager& manager );
716 * @return The signal to connect to
718 AccessibilityActionSignalType& ActionMoveToLastSignal();
721 * @brief This is emitted when accessibility action is received to focus and read from the
722 * first item on the top continuously (by three fingers single tap).
724 * A callback of the following type may be connected:
726 * bool YourCallback( AccessibilityManager& manager );
729 * @return The signal to connect to.
731 AccessibilityActionSignalType& ActionReadFromTopSignal();
734 * @brief This is emitted when accessibility action is received to move the focus to and
735 * read from the next item continuously (by three fingers double tap).
737 * A callback of the following type may be connected:
739 * bool YourCallback( AccessibilityManager& manager );
742 * @return The signal to connect to
744 AccessibilityActionSignalType& ActionReadFromNextSignal();
747 * @brief This is emitted when accessibility action is received to zoom (by one finger
750 * A callback of the following type may be connected:
752 * bool YourCallback( AccessibilityManager& manager );
755 * @return The signal to connect to
757 AccessibilityActionSignalType& ActionZoomSignal();
760 * @brief This is emitted when accessibility action is received to pause/resume the
761 * current speech (by two fingers single tap).
763 * A callback of the following type may be connected:
765 * bool YourCallback( AccessibilityManager& manager );
768 * @return The signal to connect to
770 AccessibilityActionSignalType& ActionReadPauseResumeSignal();
773 * @brief This is emitted when accessibility action is received to start/stop the
774 * current action (by two fingers double tap).
776 * A callback of the following type may be connected:
778 * bool YourCallback( AccessibilityManager& manager );
781 * @return The signal to connect to
783 AccessibilityActionSignalType& ActionStartStopSignal();
786 * @brief This is emitted when accessibility action is received to handle scroll event (by two
789 * A callback of the following type may be connected:
791 * bool YourCallback( AccessibilityManager& manager, const TouchEvent& event );
794 * @return The signal to connect to
796 AccessibilityActionScrollSignalType& ActionScrollSignal();
799 explicit DALI_INTERNAL AccessibilityManager(Internal::AccessibilityManager* impl);
801 }; // class AccessibilityManager
806 } // namespace Toolkit
810 #endif // DALI_TOOLKIT_ACCESSIBILITY_MANAGER_H