1 #ifndef DALI_TOOLKIT_INTERNAL_ACCESSIBILITY_MANAGER_H
2 #define DALI_TOOLKIT_INTERNAL_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.
23 #include <dali/devel-api/common/map-wrapper.h>
24 #include <dali/devel-api/adaptor-framework/accessibility-action-handler.h>
25 #include <dali/devel-api/adaptor-framework/accessibility-gesture-handler.h>
26 #include <dali/devel-api/adaptor-framework/accessibility-gesture-event.h>
27 #include <dali/public-api/object/base-object.h>
30 #include <dali-toolkit/devel-api/accessibility-manager/accessibility-manager.h>
31 #include <dali/public-api/adaptor-framework/tts-player.h>
42 class AccessibilityManager;
45 * @copydoc Toolkit::AccessibilityManager
47 class AccessibilityManager : public Dali::BaseObject, Dali::AccessibilityActionHandler, Dali::AccessibilityGestureHandler, public Dali::ConnectionTracker
51 typedef Dali::Toolkit::AccessibilityManager::AccessibilityActionSignalType AccessibilityActionSignalType;
52 typedef Dali::Toolkit::AccessibilityManager::AccessibilityActionScrollSignalType AccessibilityActionScrollSignalType;
54 struct ActorAdditionalInfo
61 unsigned int mFocusOrder; ///< The focus order of the actor. It is undefined by default.
63 std::string mAccessibilityAttributes[Toolkit::AccessibilityManager::ACCESSIBILITY_ATTRIBUTE_NUM]; ///< The array of attribute texts
66 typedef std::pair<unsigned int, unsigned int> FocusIDPair;
67 typedef std::map<unsigned int, unsigned int> FocusIDContainer;
68 typedef FocusIDContainer::iterator FocusIDIter;
69 typedef FocusIDContainer::const_iterator FocusIDConstIter;
71 typedef std::pair<unsigned int, ActorAdditionalInfo> IDAdditionalInfoPair;
72 typedef std::map<unsigned int, ActorAdditionalInfo> IDAdditionalInfoContainer;
73 typedef IDAdditionalInfoContainer::iterator IDAdditionalInfoIter;
74 typedef IDAdditionalInfoContainer::const_iterator IDAdditionalInfoConstIter;
77 * Construct a new AccessibilityManager.
79 AccessibilityManager();
82 * Initialise the AccessibilityManager
87 * @copydoc Toolkit::AccessibilityManager::SetAccessibilityAttribute
89 void SetAccessibilityAttribute(Actor actor, Toolkit::AccessibilityManager::AccessibilityAttribute type, const std::string& text);
92 * @copydoc Toolkit::AccessibilityManager::DeleteAccessibilityAttribute
94 void DeleteAccessibilityAttribute(Actor actor);
97 * @copydoc Toolkit::AccessibilityManager::GetAccessibilityAttribute
99 std::string GetAccessibilityAttribute(Actor actor, Toolkit::AccessibilityManager::AccessibilityAttribute type) const;
102 * @copydoc Toolkit::AccessibilityManager::SetFocusOrder
104 void SetFocusOrder(Actor actor, const unsigned int order);
107 * @copydoc Toolkit::AccessibilityManager::GetFocusOrder
109 unsigned int GetFocusOrder(Actor actor) const;
112 * @copydoc Toolkit::AccessibilityManager::GenerateNewFocusOrder
114 unsigned int GenerateNewFocusOrder() const;
117 * @copydoc Toolkit::AccessibilityManager::GetActorByFocusOrder
119 Actor GetActorByFocusOrder(const unsigned int order);
122 * @copydoc Toolkit::AccessibilityManager::SetCurrentFocusActor
124 bool SetCurrentFocusActor(Actor actor);
127 * @copydoc Toolkit::AccessibilityManager::GetCurrentFocusActor
129 Actor GetCurrentFocusActor();
132 * @copydoc Toolkit::AccessibilityManager::GetCurrentFocusGroup
134 Actor GetCurrentFocusGroup();
137 * @copydoc Toolkit::AccessibilityManager::GetCurrentFocusOrder
139 unsigned int GetCurrentFocusOrder();
142 * @copydoc Toolkit::AccessibilityManager::MoveFocusForward
144 bool MoveFocusForward();
147 * @copydoc Toolkit::AccessibilityManager::MoveFocusBackward
149 bool MoveFocusBackward();
152 * @copydoc Toolkit::AccessibilityManager::ClearFocus
157 * @copydoc Toolkit::AccessibilityManager::Reset
162 * @copydoc Toolkit::AccessibilityManager::SetFocusGroup
164 void SetFocusGroup(Actor actor, bool isFocusGroup);
167 * @copydoc Toolkit::AccessibilityManager::IsFocusGroup
169 bool IsFocusGroup(Actor actor) const;
172 * @copydoc Toolkit::AccessibilityManager::SetGroupMode
174 void SetGroupMode(bool enabled);
177 * @copydoc Toolkit::AccessibilityManager::GetGroupMode
179 bool GetGroupMode() const;
182 * @copydoc Toolkit::AccessibilityManager::SetWrapMode
184 void SetWrapMode(bool wrapped);
187 * @copydoc Toolkit::AccessibilityManager::GetWrapMode
189 bool GetWrapMode() const;
192 * @copydoc Toolkit::AccessibilityManager::SetFocusIndicatorActor
194 void SetFocusIndicatorActor(Actor indicator);
197 * @copydoc Toolkit::AccessibilityManager::GetFocusIndicatorActor
199 Actor GetFocusIndicatorActor();
202 * @copydoc Toolkit::AccessibilityManager::GetFocusGroup
204 Actor GetFocusGroup(Actor actor);
207 * @copydoc Toolkit::AccessibilityManager::GetReadPosition
209 Vector2 GetReadPosition() const;
212 * @copydoc Toolkit::AccessibilityManager::EnableAccessibility
214 void EnableAccessibility( bool enabled );
217 * @copydoc Toolkit::AccessibilityManager::IsEnabled
219 bool IsEnabled() const;
224 * @copydoc Toolkit::AccessibilityManager::FocusChangedSignal()
226 Toolkit::AccessibilityManager::FocusChangedSignalType& FocusChangedSignal();
229 * @copydoc Toolkit::AccessibilityManager::FocusOvershotSignal()
231 Toolkit::AccessibilityManager::FocusOvershotSignalType& FocusOvershotSignal();
234 * @copydoc Toolkit::AccessibilityManager::FocusedActorActivatedSignal()
236 Toolkit::AccessibilityManager::FocusedActorActivatedSignalType& FocusedActorActivatedSignal();
241 * @copydoc Dali::Toolkit::AccessibilityManager::StatusChangedSignal
243 AccessibilityActionSignalType& StatusChangedSignal()
245 return mStatusChangedSignal;
249 * @copydoc Dali::Toolkit::AccessibilityManager::AccessibilityAdaptor::ActionNextSignal
251 AccessibilityActionSignalType& ActionNextSignal()
253 return mActionNextSignal;
257 * @copydoc Dali::Toolkit::AccessibilityManager::ActionPreviousSignal
259 AccessibilityActionSignalType& ActionPreviousSignal()
261 return mActionPreviousSignal;
265 * @copydoc Dali::Toolkit::AccessibilityManager::ActionActivateSignal
267 AccessibilityActionSignalType& ActionActivateSignal()
269 return mActionActivateSignal;
273 * @copydoc Dali::Toolkit::AccessibilityManager::ActionOverSignal
275 AccessibilityActionSignalType& ActionOverSignal()
277 return mActionOverSignal;
281 * @copydoc Dali::Toolkit::AccessibilityManager::ActionReadSignal
283 AccessibilityActionSignalType& ActionReadSignal()
285 return mActionReadSignal;
289 * @copydoc Dali::Toolkit::AccessibilityManager::ActionReadNextSignal
291 AccessibilityActionSignalType& ActionReadNextSignal()
293 return mActionReadNextSignal;
297 * @copydoc Dali::Toolkit::AccessibilityManager::ActionReadPreviousSignal
299 AccessibilityActionSignalType& ActionReadPreviousSignal()
301 return mActionReadPreviousSignal;
305 * @copydoc Dali::Toolkit::AccessibilityManager::ActionUpSignal
307 AccessibilityActionSignalType& ActionUpSignal()
309 return mActionUpSignal;
313 * @copydoc Dali::Toolkit::AccessibilityManager::ActionDownSignal
315 AccessibilityActionSignalType& ActionDownSignal()
317 return mActionDownSignal;
321 * @copydoc Dali::Toolkit::AccessibilityManager::ActionClearFocusSignal
323 AccessibilityActionSignalType& ActionClearFocusSignal()
325 return mActionClearFocusSignal;
329 * @copydoc Dali::Toolkit::AccessibilityManager::ActionBackSignal
331 AccessibilityActionSignalType& ActionBackSignal()
333 return mActionBackSignal;
337 * @copydoc Dali::Toolkit::AccessibilityManager::ActionScrollUpSignal
339 AccessibilityActionSignalType& ActionScrollUpSignal()
341 return mActionScrollUpSignal;
345 * @copydoc Dali::Toolkit::AccessibilityManager::ActionScrollDownSignal
347 AccessibilityActionSignalType& ActionScrollDownSignal()
349 return mActionScrollDownSignal;
353 * @copydoc Dali::Toolkit::AccessibilityManager::ActionPageLeftSignal
355 AccessibilityActionSignalType& ActionPageLeftSignal()
357 return mActionPageLeftSignal;
361 * @copydoc Dali::Toolkit::AccessibilityManager::ActionPageRightSignal
363 AccessibilityActionSignalType& ActionPageRightSignal()
365 return mActionPageRightSignal;
369 * @copydoc Dali::Toolkit::AccessibilityManager::ActionPageUpSignal
371 AccessibilityActionSignalType& ActionPageUpSignal()
373 return mActionPageUpSignal;
377 * @copydoc Dali::Toolkit::AccessibilityManager::ActionPageDownSignal
379 AccessibilityActionSignalType& ActionPageDownSignal()
381 return mActionPageDownSignal;
385 * @copydoc Dali::Toolkit::AccessibilityManager::ActionMoveToFirstSignal
387 AccessibilityActionSignalType& ActionMoveToFirstSignal()
389 return mActionMoveToFirstSignal;
393 * @copydoc Dali::Toolkit::AccessibilityManager::ActionMoveToLastSignal
395 AccessibilityActionSignalType& ActionMoveToLastSignal()
397 return mActionMoveToLastSignal;
401 * @copydoc Dali::Toolkit::AccessibilityManager::ActionReadFromTopSignal
403 AccessibilityActionSignalType& ActionReadFromTopSignal()
405 return mActionReadFromTopSignal;
409 * @copydoc Dali::Toolkit::AccessibilityManager::ActionReadFromNextSignal
411 AccessibilityActionSignalType& ActionReadFromNextSignal()
413 return mActionReadFromNextSignal;
417 * @copydoc Dali::Toolkit::AccessibilityManager::ActionZoomSignal
419 AccessibilityActionSignalType& ActionZoomSignal()
421 return mActionZoomSignal;
425 * @copydoc Dali::Toolkit::AccessibilityManager::ActionReadPauseResumeSignal
427 AccessibilityActionSignalType& ActionReadPauseResumeSignal()
429 return mActionReadPauseResumeSignal;
433 * @copydoc Dali::Toolkit::AccessibilityManager::ActionStartStopSignal
435 AccessibilityActionSignalType& ActionStartStopSignal()
437 return mActionStartStopSignal;
441 * @copydoc Dali::Toolkit::AccessibilityManager::ActionScrollSignal
443 AccessibilityActionScrollSignalType& ActionScrollSignal()
445 return mActionScrollSignal;
453 virtual ~AccessibilityManager();
458 * Get the additional information (e.g. focus order and description) of the given actor.
459 * @param actorID The ID of the actor to be queried
460 * @return The additional information of the actor
462 ActorAdditionalInfo GetActorAdditionalInfo(const unsigned int actorID) const;
465 * Synchronize the actor's additional information to reflect its latest focus order
466 * @param actorID The ID of the actor
467 * @param order The focus order of the actor
468 * @return The additional information of the actor
470 void SynchronizeActorAdditionalInfo(const unsigned int actorID, const unsigned int order);
473 * Move the focus to the specified actor and send notification for the focus change.
474 * @param actorID The ID of the actor to be queried
475 * @return Whether the focus is successful or not
477 bool DoSetCurrentFocusActor(const unsigned int actorID);
480 * Move the focus to the next actor in the focus chain towards the specified direction.
481 * @param focusIDIter The iterator pointing to the current focused actor
482 * @param forward Whether the focus movement is forward or not. The focus movement will be backward if this is false.
483 * @param wrapped Whether the focus shoule be moved wrapped around or not
484 * @return Whether the focus is successful or not
486 bool DoMoveFocus(FocusIDIter focusIDIter, bool forward, bool wrapped);
489 * Activate the actor. If the actor is control, call OnAccessibilityActivated virtual function.
490 * This function will emit FocusedActorActivatedSignal.
491 * @param actor The actor to activate
493 void DoActivate(Actor actor);
496 * Set whether the actor is focusable or not. A focusable property will be registered for
497 * the actor if not yet.
498 * @param actor The actor to be focused
499 * @param focusable Whether the actor is focusable or not
501 void SetFocusable(Actor actor, bool focusable);
504 * Handle the accessibility pan gesture.
505 * @param[in] panEvent The pan event to be handled.
506 * @return whether the gesture is handled successfully or not.
508 bool HandlePanGesture(const AccessibilityGestureEvent& panEvent) override;
511 * Change the accessibility status when Accessibility feature(screen-reader) turned on or off.
512 * @return whether the status is changed or not.
514 bool ChangeAccessibilityStatus() override;
517 * Clear the accessibility focus from the current focused actor.
518 * @return whether the focus is cleared or not.
520 bool ClearAccessibilityFocus() override;
523 * Perform the accessibility action associated with a scroll event.
524 * @param touch The touch point (and time) of the event.
525 * @return whether the focus is cleared or not.
527 bool AccessibilityActionScroll( Dali::TouchEvent& touch ) override;
530 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick up).
531 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
532 * @return whether the accessibility action is performed or not.
534 bool AccessibilityActionPrevious(bool allowEndFeedback) override;
537 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick down).
538 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
539 * @return whether the accessibility action is performed or not.
541 bool AccessibilityActionNext(bool allowEndFeedback) override;
544 * Perform the accessibility action to move focus to the previous focusable actor (by one finger flick left).
545 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
546 * @return whether the accessibility action is performed or not.
548 bool AccessibilityActionReadPrevious(bool allowEndFeedback) override;
551 * Perform the accessibility action to move focus to the next focusable actor (by one finger flick right).
552 * @param allowEndFeedback true if end of list feedback should be played when the focus is alread reached to the end
553 * @return whether the accessibility action is performed or not.
555 bool AccessibilityActionReadNext(bool allowEndFeedback) override;
558 * Perform the accessibility action to focus and read the actor (by one finger tap or move).
559 * @param allowReadAgain true if the action read again the same object (i.e. read action)
560 * false if the action just read when the focus object is changed (i.e. over action)
561 * @return whether the accessibility action is performed or not.
563 bool AccessibilityActionRead(bool allowReadAgain) override;
566 * Perform the accessibility action to activate the current focused actor (by one finger double tap).
567 * @return whether the accessibility action is performed or not.
569 bool AccessibilityActionActivate() override;
572 * Perform the accessibility action to change the value when the current focused actor is a slider
573 * (by double finger down and move up and right).
574 * @return whether the accessibility action is performed or not.
576 bool AccessibilityActionUp() override;
579 * Perform the accessibility action to change the value when the current focused actor is a slider
580 * (by double finger down and move down and left).
581 * @return whether the accessibility action is performed or not.
583 bool AccessibilityActionDown() override;
586 * Perform the accessibility action to navigate back (by two fingers circle draw).
587 * @return whether the accessibility action is performed or not.
589 bool AccessibilityActionBack() override;
592 * Perform the accessibility action to scroll up the list and focus on the first item on the list
593 * after the scrolling and read the item (by two finger swipe up).
594 * @return whether the accessibility action is performed or not.
596 bool AccessibilityActionScrollUp() override;
599 * Perform the accessibility action to scroll down the list and focus on the first item on the list
600 * after the scrolling and read the item (by two finger swipe down).
601 * @return whether the accessibility action is performed or not.
603 bool AccessibilityActionScrollDown() override;
606 * Perform the accessibility action to scroll left to the previous page (by two finger swipe left).
607 * @return whether the accessibility action is performed or not.
609 bool AccessibilityActionPageLeft() override;
612 * Perform the accessibility action to scroll right to the next page (by two finger swipe right).
613 * @return whether the accessibility action is performed or not.
615 bool AccessibilityActionPageRight() override;
618 * Perform the accessibility action to scroll up to the previous page (by one finger swipe left and right).
619 * @return whether the accessibility action is performed or not.
621 bool AccessibilityActionPageUp() override;
624 * Perform the accessibility action to scroll down to the next page (by one finger swipe right and left).
625 * @return whether the accessibility action is performed or not.
627 bool AccessibilityActionPageDown() override;
630 * Perform the accessibility action to move the focus to the first item on the screen
631 * (by one finger swipe up and down).
632 * @return whether the accessibility action is performed or not.
634 bool AccessibilityActionMoveToFirst() override;
637 * Perform the accessibility action to move the focus to the last item on the screen
638 * (by one finger swipe down and up).
639 * @return whether the accessibility action is performed or not.
641 bool AccessibilityActionMoveToLast() override;
644 * Perform the accessibility action to move the focus to the first item on the top
645 * and read from the top item continuously (by three fingers single tap).
646 * @return whether the accessibility action is performed or not.
648 bool AccessibilityActionReadFromTop() override;
651 * Perform the accessibility action to move the focus to and read from the next item
652 * continuously (by three fingers double tap).
653 * @return whether the accessibility action is performed or not.
655 bool AccessibilityActionReadFromNext() override;
658 * Perform the accessibility action to move the focus to do the zooming (by one finger triple tap).
659 * @return whether the accessibility action is performed or not.
661 bool AccessibilityActionZoom() override;
664 * Perform the accessibility action to pause/resume the current read out (by two fingers single tap).
665 * @return whether the accessibility action is performed or not.
667 bool AccessibilityActionReadPauseResume() override;
670 * Perform the accessibility action to start/stop the current action (by two fingers double tap).
671 * @return whether the accessibility action is performed or not.
673 bool AccessibilityActionStartStop() override;
676 * This function is connected to the TtsPlayer StateChangeSignal.
677 * It is called when the TTS players state changes.
678 * @param previousState The previous state of the TTS player (for comparison)
679 * @param currentState The current state of the TTS player
681 void TtsStateChanged( const Dali::TtsPlayer::State previousState, const Dali::TtsPlayer::State currentState );
686 AccessibilityManager(const AccessibilityManager&);
688 AccessibilityManager& operator=(const AccessibilityManager& rhs);
692 Toolkit::AccessibilityManager::FocusChangedSignalType mFocusChangedSignal; ///< The signal to notify the focus change
693 Toolkit::AccessibilityManager::FocusOvershotSignalType mFocusOvershotSignal; ///< The signal to notify the focus overshooted
694 Toolkit::AccessibilityManager::FocusedActorActivatedSignalType mFocusedActorActivatedSignal; ///< The signal to notify the activation of focused actor
697 AccessibilityActionSignalType mStatusChangedSignal;
698 AccessibilityActionSignalType mActionNextSignal;
699 AccessibilityActionSignalType mActionPreviousSignal;
700 AccessibilityActionSignalType mActionActivateSignal;
701 AccessibilityActionSignalType mActionOverSignal;
702 AccessibilityActionSignalType mActionReadSignal;
703 AccessibilityActionSignalType mActionReadNextSignal;
704 AccessibilityActionSignalType mActionReadPreviousSignal;
705 AccessibilityActionSignalType mActionUpSignal;
706 AccessibilityActionSignalType mActionDownSignal;
707 AccessibilityActionSignalType mActionClearFocusSignal;
708 AccessibilityActionSignalType mActionBackSignal;
709 AccessibilityActionSignalType mActionScrollUpSignal;
710 AccessibilityActionSignalType mActionScrollDownSignal;
711 AccessibilityActionSignalType mActionPageLeftSignal;
712 AccessibilityActionSignalType mActionPageRightSignal;
713 AccessibilityActionSignalType mActionPageUpSignal;
714 AccessibilityActionSignalType mActionPageDownSignal;
715 AccessibilityActionSignalType mActionMoveToFirstSignal;
716 AccessibilityActionSignalType mActionMoveToLastSignal;
717 AccessibilityActionSignalType mActionReadFromTopSignal;
718 AccessibilityActionSignalType mActionReadFromNextSignal;
719 AccessibilityActionSignalType mActionZoomSignal;
720 AccessibilityActionSignalType mActionReadPauseResumeSignal;
721 AccessibilityActionSignalType mActionStartStopSignal;
722 AccessibilityActionScrollSignalType mActionScrollSignal;
724 FocusIDContainer mFocusIDContainer; ///< The container to look up actor ID by focus order
725 IDAdditionalInfoContainer mIDAdditionalInfoContainer; ///< The container to look up additional information by actor ID
726 FocusIDPair mCurrentFocusActor; ///< The focus order and actor ID of current focused actor
727 Actor mCurrentGesturedActor; ///< The actor that will handle the gesture
728 Actor mFocusIndicatorActor; ///< The focus indicator actor shared by all the focusable actors for highlight
729 Vector2 mPreviousPosition; ///< The previous pan position; useful for calculating velocity for GestureState::FINISHED events
730 unsigned int mRecursiveFocusMoveCounter; ///< The counter to count the number of recursive focus movement attempted before the focus movement is successful.
731 std::string mFocusSoundFilePath; ///< The path of the focus sound file
732 std::string mFocusChainEndSoundFilePath; ///< The path of the focus chain end sound file
734 bool mIsWrapped:1; ///< Whether the focus movement is wrapped around or not
735 bool mIsFocusWithinGroup:1; ///< Whether the focus movement is limited to the current focus group or not
736 bool mIsEndcapFeedbackEnabled:1; ///< Whether the endcap feedback need to be played when the focus leaves the end or vice versa
737 bool mIsEndcapFeedbackPlayed:1; ///< Whether the endcap feedback was played or not
738 bool mIsAccessibilityTtsEnabled:1; ///< Whether accessibility feature(screen-reader) turned on/off
739 bool mTtsCreated:1; ///< Whether the TTS Player has been accessed
740 bool mIsFocusIndicatorEnabled:1; ///< Whether indicator should be shown / hidden. It could be enabled when TTS enabled or 'Tab' key operated.
741 bool mContinuousPlayMode:1; ///< Keeps track of whether or not we are in continuous play mode
742 bool mIsFocusSoundFilePathSet:1; ///< Whether the path of the focus sound file has been set
743 bool mIsFocusChainEndSoundFilePathSet:1; ///< Whether the path of the focus chain end sound file has been set
747 } // namespace Internal
749 inline Internal::AccessibilityManager& GetImpl(Dali::Toolkit::AccessibilityManager& obj)
751 DALI_ASSERT_ALWAYS(obj);
753 Dali::BaseObject& handle = obj.GetBaseObject();
755 return static_cast<Internal::AccessibilityManager&>(handle);
758 inline const Internal::AccessibilityManager& GetImpl(const Dali::Toolkit::AccessibilityManager& obj)
760 DALI_ASSERT_ALWAYS(obj);
762 const Dali::BaseObject& handle = obj.GetBaseObject();
764 return static_cast<const Internal::AccessibilityManager&>(handle);
767 } // namespace Toolkit
771 #endif // DALI_TOOLKIT_INTERNAL_ACCESSIBILITY_MANAGER_H