1 #ifndef DALI_INTERNAL_ATSPI_ACCESSIBILITY_IMPL_H
2 #define DALI_INTERNAL_ATSPI_ACCESSIBILITY_IMPL_H
5 * Copyright (c) 2019 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>
23 #include <dali/public-api/math/rect.h>
24 #include <dali/public-api/object/object-registry.h>
31 #include <unordered_map>
32 #include <unordered_set>
37 #include <dali/devel-api/adaptor-framework/accessibility.h>
38 #include <dali/integration-api/debug.h>
42 namespace Accessibility
44 class DALI_ADAPTOR_API Accessible;
45 class DALI_ADAPTOR_API Text;
46 class DALI_ADAPTOR_API Value;
47 class DALI_ADAPTOR_API Component;
48 class DALI_ADAPTOR_API Collection;
49 class DALI_ADAPTOR_API Action;
52 * @brief Base class for different accessibility bridges
54 * Bridge is resposible for initializing and managing connection on accessibility bus.
55 * Accessibility clients will not get any information about UI without initialized and upraised bridge.
56 * Concrete implementation depends on the accessibility technology available on the platform.
58 * @note This class is singleton.
60 struct DALI_ADAPTOR_API Bridge
62 enum class ForceUpResult
71 virtual ~Bridge() = default;
74 * @brief Get bus name which bridge is initialized on
76 virtual const std::string& GetBusName() const = 0;
79 * @brief Registers top level window
81 * Hierarchy of objects visible for accessibility clients is based on tree-like
82 * structure created from Actors objects. This method allows to connect chosen
83 * object as direct ancestor of application and therefore make it visible for
84 * accessibility clients.
86 virtual void AddTopLevelWindow( Accessible* ) = 0;
89 * @brief Removes top level window
91 * Hierarchy of objects visible for accessibility clients is based on tree-like
92 * structure created from Actors objects. This method removes previously added
93 * window from visible accessibility objects.
95 virtual void RemoveTopLevelWindow( Accessible* ) = 0;
98 * @brief Adds popup window
100 * Hierarchy of objects visible for accessibility clients is based on tree-like
101 * structure created from Actors objects. This method adds new popup to the tree.
103 virtual void AddPopup( Accessible* ) = 0;
106 * @brief Removes popup window
108 * Hierarchy of objects visible for accessibility clients is based on tree-like
109 * structure created from Actors objects. This method removes previously added
112 virtual void RemovePopup( Accessible* ) = 0;
115 * @brief Set name of current application which will be visible on accessibility bus
117 virtual void SetApplicationName( std::string ) = 0;
120 * @brief Get object being root of accessibility tree
122 * @return handler to accessibility object
124 virtual Accessible* GetApplication() const = 0;
127 * @brief Find an object in accessibility tree
129 * @param[in] s path to object
131 * @return handler to accessibility object
133 virtual Accessible* FindByPath( const std::string& s) const = 0;
136 * @brief Show application on accessibility bus
138 virtual void ApplicationShown() = 0;
141 * @brief Hide application on accessibility bus
143 virtual void ApplicationHidden() = 0;
146 * @brief Initialize accessibility bus
148 virtual void Initialize() = 0;
151 * @brief Terminate accessibility bus
153 virtual void Terminate() = 0;
156 * @brief This method is called, when bridge is being activated.
158 virtual ForceUpResult ForceUp()
162 return ForceUpResult::ALREADY_UP;
164 data = std::make_shared< Data >();
166 return ForceUpResult::JUST_STARTED;
170 * @brief This method is called, when bridge is being deactivated.
172 virtual void ForceDown() = 0;
175 * @brief Check if bridge is activated or not.
176 * @return True if brige is activated.
184 * @brief Emits caret-moved event on at-spi bus.
186 virtual void EmitCaretMoved( Accessible* obj, unsigned int cursorPosition ) = 0;
189 * @brief Emits active-descendant-changed event on at-spi bus.
191 virtual void EmitActiveDescendantChanged( Accessible* obj, Accessible *child ) = 0;
194 * @brief Emits text-changed event on at-spi bus.
196 virtual void EmitTextChanged( Accessible* obj, TextChangedState state, unsigned int position, unsigned int length, const std::string &content ) = 0;
199 * @brief Emits state-changed event on at-spi bus.
201 virtual void EmitStateChanged( Accessible* obj, State state, int val1, int val2 = 0 ) = 0;
204 * @brief Emits window event on at-spi bus.
206 virtual void Emit( Accessible* obj, WindowEvent we, unsigned int detail1 = 0 ) = 0;
209 * @brief Emits property-changed event on at-spi bus.
211 virtual void Emit( Accessible* obj, ObjectPropertyChangeEvent event ) = 0;
214 * @brief Emits bounds-changed event on at-spi bus.
216 virtual void EmitBoundsChanged( Accessible* obj, Rect<> rect ) = 0;
219 * @brief Emits key event on at-spi bus.
221 * Screen-reader might receive this event and reply, that given keycode is consumed. In that case
222 * further processing of the keycode should be ignored.
224 virtual Consumed Emit( KeyEventType type, unsigned int keyCode, const std::string& keyName, unsigned int timeStamp, bool isText ) = 0;
227 * @brief Reads given text by screen reader
229 * @param text The text to read
230 * @param discardable If TRUE, reading can be discarded by subsequent reading requests,
231 * if FALSE the reading must finish before next reading request can be started
232 * @param callback the callback function that is called on reading signals emitted
233 * during processing of this reading request.
234 * Callback can be one of the following signals:
235 * ReadingCancelled, ReadingStopped, ReadingSkipped
237 virtual void Say( const std::string& text, bool discardable, std::function<void(std::string)> callback ) = 0;
240 * @brief Force accessibility client to pause.
242 virtual void Pause() = 0;
245 * @brief Force accessibility client to resume.
247 virtual void Resume() = 0;
250 * @brief Get screen reader status.
252 virtual bool GetScreenReaderEnabled() = 0;
255 * @brief Get ATSPI status.
257 virtual bool GetIsEnabled() = 0;
260 * @brief Returns instance of bridge singleton object.
262 static Bridge* GetCurrentBridge();
267 std::unordered_set< Accessible* > knownObjects;
269 Bridge* bridge = nullptr;
270 Actor highlightActor, currentlyHighlightedActor;
272 std::shared_ptr< Data > data;
273 friend class Accessible;
276 * @brief Registers accessible object to be known in bridge object
278 * Bridge must known about all currently alive accessible objects, as some requst
279 * might come and object will be identified by number id (it's memory address).
280 * To avoid memory corruption number id is checked against set of known objects.
282 void RegisterOnBridge( Accessible* );
285 * @brief Tells bridge, that given object is considered root (doesn't have any parents).
287 * All root objects will have the same parent - application object. Application object
288 * is controlled by bridge and private.
290 void SetIsOnRootLevel( Accessible* );
294 * @brief Check if ATSPI is activated or not.
295 * @return True if ATSPI is activated.
299 if( Bridge::GetCurrentBridge() == nullptr )
303 if( Bridge::GetCurrentBridge()->GetIsEnabled() == false )
307 return Bridge::GetCurrentBridge()->IsUp();
311 * @brief Basic interface implemented by all accessibility objects
316 virtual ~Accessible();
318 using utf8_t = unsigned char;
321 * @brief Calculaties word boundaries in given utf8 text.
323 * s and length represents source text pointer and it's length respectively. langauge represents
324 * language to use. Word boundaries are returned as non-zero values in table breaks, which
325 * must be of size at least length.
327 void FindWordSeparationsUtf8( const utf8_t *s, size_t length, const char *language, char *breaks );
330 * @brief Calculaties line boundaries in given utf8 text.
332 * s and length represents source text pointer and it's length respectively. langauge represents
333 * language to use. Line boundaries are returned as non-zero values in table breaks, which
334 * must be of size at least length.
336 void FindLineSeparationsUtf8( const utf8_t *s, size_t length, const char *language, char *breaks );
339 * @brief Helper function for emiting active-descendant-changed event
341 void EmitActiveDescendantChanged( Accessible* obj, Accessible *child );
344 * @brief Helper function for emiting state-changed event
346 void EmitStateChanged( State state, int newValue1, int newValue2 = 0 );
349 * @brief Helper function for emiting bounds-changed event
351 void EmitBoundsChanged( Rect<> rect );
354 * @brief Emit "showing" event.
355 * The method inform accessibility clients about "showing" state
357 * @param[in] showing flag pointing if object is showing
359 void EmitShowing( bool showing );
362 * @brief Emit "visible" event.
363 * The method inform accessibility clients about "visible" state
365 * @param[in] visible flag pointing if object is visible
367 void EmitVisible( bool visible );
370 * @brief Emit "highlighted" event.
371 * The method inform accessibility clients about "highlighted" state
373 * @param[in] set flag pointing if object is highlighted
375 void EmitHighlighted( bool set );
378 * @brief Emit "focused" event.
379 * The method inform accessibility clients about "focused" state
381 * @param[in] set flag pointing if object is focused
383 void EmitFocused( bool set );
386 * @brief Emit "text inserted" event
388 * @param[in] position caret position
389 * @param[in] length text length
390 * @param[in] content inserted text
392 void EmitTextInserted( unsigned int position, unsigned int length, const std::string &content );
395 * @brief Emit "text deleted" event
397 * @param[in] position caret position
398 * @param[in] length text length
399 * @param[in] content deleted text
401 void EmitTextDeleted( unsigned int position, unsigned int length, const std::string &content );
404 * @brief Emit "caret moved" event
406 * @param[in] cursorPosition new caret position
408 void EmitTextCaretMoved( unsigned int cursorPosition );
411 * @brief Emit "highlighted" event
413 * @param[in] we enumerated window event
414 * @param[in] detail1 additional parameter which interpretation depends on chosen event
416 void Emit( WindowEvent we, unsigned int detail1 = 0 );
419 * @brief Emits property-changed event
420 * @param[in] event Property changed event
422 void Emit( ObjectPropertyChangeEvent event );
425 * @brief Get accessibility name
427 * @return string with name
429 virtual std::string GetName() = 0;
432 * @brief Get accessibility description
434 * @return string with description
436 virtual std::string GetDescription() = 0;
441 * @return handler to accessibility object
443 virtual Accessible* GetParent() = 0;
446 * @brief Get count of children
448 * @return unsigned integer value
450 virtual size_t GetChildCount() = 0;
453 * @brief Get collection with all children
455 * @return collection of accessibility objects
457 virtual std::vector< Accessible* > GetChildren();
460 * @brief Get nth child
462 * @return accessibility object
464 virtual Accessible* GetChildAtIndex( size_t index ) = 0;
467 * @brief Get index that current object has in its parent's children collection
469 * @return unsigned integer index
471 virtual size_t GetIndexInParent() = 0;
474 * @brief Get accessibility role
476 * @return Role enumeration
478 * @see Dali::Accessibility::Role
480 virtual Role GetRole() = 0;
483 * @brief Get name of accessibility role
485 * @return string with human readable role converted from enumeration
487 * @see Dali::Accessibility::Role
488 * @see Accessibility::Accessible::GetRole
490 virtual std::string GetRoleName();
493 * @brief Get localized name of accessibility role
495 * @return string with human readable role translated according to current
498 * @see Dali::Accessibility::Role
499 * @see Accessibility::Accessible::GetRole
500 * @see Accessibility::Accessible::GetRoleName
502 * @note translation is not supported in this version
504 virtual std::string GetLocalizedRoleName();
507 * @brief Get accessibility states
509 * @return collection of states
511 * @note States class is instatation of ArrayBitset template class
513 * @see Dali::Accessibility::State
514 * @see Dali::Accessibility::ArrayBitset
516 virtual States GetStates() = 0;
519 * @brief Get accessibility attributes
521 * @return map of attributes and their values
523 virtual Attributes GetAttributes() = 0;
526 * @brief Check if this is proxy
528 * @return True if this is proxy
530 virtual bool IsProxy();
533 * @brief Get unique address on accessibility bus
535 * @return class containing address
537 * @see Dali::Accessibility::Address
539 virtual Address GetAddress();
542 * @brief Get accessibility object, which is "default label" for this object
544 virtual Accessible* GetDefaultLabel();
547 * @brief Depute an object to perform provided gesture
549 * @param[in] gestureInfo structure describing the gesture
551 * @return true on success, false otherwise
553 * @see Dali::Accessibility::GestureInfo
555 virtual bool DoGesture(const GestureInfo &gestureInfo) = 0;
558 * @brief Re-emits selected states of an Accessibility Object
560 * @param[in] states chosen states to re-emit
561 * @param[in] doRecursive if true all children of the Accessibility Object will also re-emit the states
563 void NotifyAccessibilityStateChange( Dali::Accessibility::States states, bool doRecursive );
566 * @brief Get information about current object and all relations that connects
567 * it with other accessibility objects
569 * @return iterable collection of Relation objects
571 * @see Dali::Accessibility::Relation
573 virtual std::vector<Relation> GetRelationSet() = 0;
576 * @brief Get all implemented interfaces
578 * @return collection of strings with implemented interfaces
580 std::vector< std::string > GetInterfaces();
583 * @brief Check if object is on root level
585 bool GetIsOnRootLevel() const { return isOnRootLevel; }
588 * @brief The method registers functor resposible for converting Actor into Accessible
589 * @param functor returning Accessible handle from Actor object
591 static void RegisterControlAccessibilityGetter( std::function< Accessible*( Dali::Actor ) > functor);
594 * @brief Acquire Accessible object from Actor object
596 * @param[in] actor Actor object
597 * @param[in] root true, if it's top level object (window)
599 * @return handle to Accessible object
601 static Accessible* Get( Dali::Actor actor, bool root = false );
605 Accessible( const Accessible& ) = delete;
606 Accessible( Accessible&& ) = delete;
607 Accessible& operator=( const Accessible& ) = delete;
608 Accessible& operator=( Accessible&& ) = delete;
609 std::shared_ptr< Bridge::Data > GetBridgeData();
612 static Dali::Actor GetHighlightActor();
613 static void SetHighlightActor(Dali::Actor actor);
614 static Dali::Actor GetCurrentlyHighlightedActor();
615 static void SetCurrentlyHighlightedActor(Dali::Actor);
616 static void SetObjectRegistry(ObjectRegistry registry);
621 std::weak_ptr< Bridge::Data > bridgeData;
622 bool isOnRootLevel = false;
626 * @brief Interface enabling to perform provided actions
628 class Action : public virtual Accessible
632 * @brief Get name of action with given index
634 * @param[in] index index of action
636 * @return string with name of action
638 virtual std::string GetActionName( size_t index ) = 0;
641 * @brief Get translated name of action with given index
643 * @param[in] index index of action
645 * @return string with name of action translated according to current translation domain
647 * @note translation is not supported in this version
649 virtual std::string GetLocalizedActionName( size_t index ) = 0;
652 * @brief Get description of action with given index
654 * @param[in] index index of action
656 * @return string with description of action
658 virtual std::string GetActionDescription( size_t index ) = 0;
661 * @brief Get key code binded to action with given index
663 * @param[in] index index of action
665 * @return string with key name
667 virtual std::string GetActionKeyBinding( size_t index ) = 0;
670 * @brief Get number of provided actions
672 * @return unsigned integer with number of actions
674 virtual size_t GetActionCount() = 0;
677 * @brief Perform an action with given index
679 * @param index index of action
681 * @return true on success, false otherwise
683 virtual bool DoAction( size_t index ) = 0;
686 * @brief Perform an action with given name
688 * @param name name of action
690 * @return true on success, false otherwise
692 virtual bool DoAction( const std::string& name ) = 0;
697 * @brief Interface enabling advanced quering of accessibility objects
699 * @note since all mathods can be implemented inside bridge,
700 * none methods have to be overrided
702 class Collection : public virtual Accessible
708 * @brief Interface representing objects having screen coordinates
710 class Component : public virtual Accessible
714 * @brief Get rectangle describing size
716 * @param[in] ctype enumeration with type of coordinate systems
718 * @return Rect<> object
722 virtual Rect<> GetExtents( CoordType ctype ) = 0;
725 * @brief Get layer current object is localized on
727 * @return enumeration pointing layer
729 * @see Dali::Accessibility::ComponentLayer
731 virtual ComponentLayer GetLayer() = 0;
734 * @brief Get value of z-order
736 * @return value of z-order
738 virtual int16_t GetMdiZOrder() = 0;
741 * @brief Set current object as "focused"
743 * @return true on success, false otherwise
745 virtual bool GrabFocus() = 0;
748 * @brief Get value of alpha channel
750 * @return alpha channel value in range [0.0, 1.0]
752 virtual double GetAlpha() = 0;
755 * @brief Set current object as "highlighted"
757 * The method assings "highlighted" state, simultaneously removing it
758 * from currently highlighted object.
760 * @return true on success, false otherwise
762 virtual bool GrabHighlight() = 0;
765 * @brief Set current object as "unhighlighted"
767 * The method removes "highlighted" state from object.
769 * @return true on success, false otherwise
771 * @see Dali:Accessibility::State
773 virtual bool ClearHighlight() = 0;
776 * @brief Check whether object can be scrolled
778 * @return true if object is scrollable, false otherwise
780 * @see Dali:Accessibility::State
782 virtual bool IsScrollable();
785 * @brief Get Accessible object containing given point
787 * @param[in] p two-dimensional point
788 * @param[in] ctype enumeration with type of coordinate system
790 * @return handle to last child of current object which contains given point
792 * @see Dali::Accessibility::Point
794 virtual Accessible* GetAccessibleAtPoint( Point p, CoordType ctype );
797 * @brief Check if current object contains given point
799 * @param[in] p two-dimensional point
800 * @param[in] ctype enumeration with type of coordinate system
802 * @return handle to Accessible object
804 * @see Dali::Accessibility::Point
806 virtual bool Contains( Point p, CoordType ctype );
810 * @brief Interface representing objects which can store numeric value
812 class Value : public virtual Accessible
816 * @brief Get the lowest possible value
818 * @return double value
820 virtual double GetMinimum() = 0;
823 * @brief Get current value
825 * @return double value
827 virtual double GetCurrent() = 0;
830 * @brief Get the highest possible value
832 * @return double value
834 virtual double GetMaximum() = 0;
839 * @param[in] val double value
841 * @return true if value could have been assigned, false otherwise
843 virtual bool SetCurrent( double val) = 0;
846 * @brief Get the lowest increment that can be distinguished
848 * @return double value
850 virtual double GetMinimumIncrement() = 0;
854 * @brief Interface representing objects which can store immutable texts
856 * @see Dali::Accessibility::EditableText
858 class DALI_ADAPTOR_API Text : public virtual Accessible
862 * @brief Get stored text in given range
864 * @param[in] startOffset index of first character
865 * @param[in] endOffset index of first character after the last one expected
867 * @return substring of stored text
869 virtual std::string GetText( size_t startOffset, size_t endOffset ) = 0;
872 * @brief Get number of all stored characters
874 * @return number of characters
876 virtual size_t GetCharacterCount() = 0;
879 * @brief Get caret offset
881 * @return Value of caret offset
883 virtual size_t GetCaretOffset() = 0;
886 * @brief Set caret offset
888 * @param[in] offset Caret offset
890 * @return True if successful
892 virtual bool SetCaretOffset(size_t offset) = 0;
895 * @brief Get substring of stored text truncated in concrete gradation
897 * @param[in] offset position in stored text
898 * @param[in] boundary enumeration describing text gradation
900 * @return Range structure containing acquired text and offsets in original string
902 * @see Dali::Accessibility::Range
904 virtual Range GetTextAtOffset( size_t offset, TextBoundary boundary ) = 0;
907 * @brief Get selected text
909 * @param[in] selectionNum selection index
910 * @note Currently only one selection (i.e. with index = 0) is supported
912 * @return Range structure containing acquired text and offsets in original string
914 * @see Dali::Accessibility::Range
916 virtual Range GetSelection( size_t selectionNum ) = 0;
919 * @brief Remove selection
921 * @param[in] selectionNum selection index
922 * @note Currently only one selection (i.e. with index = 0) is supported
924 * @return bool on success, false otherwise
926 virtual bool RemoveSelection( size_t selectionNum ) = 0;
929 * @brief Get selected text
931 * @param[in] selectionNum selection index
932 * @param[in] startOffset index of first character
933 * @param[in] endOffset index of first character after the last one expected
935 * @note Currently only one selection (i.e. with index = 0) is supported
937 * @return true on success, false otherwise
939 virtual bool SetSelection( size_t selectionNum, size_t startOffset, size_t endOffset ) = 0;
943 * @brief Interface representing objects which can store editable texts
945 * @note Paste method is entirely implemented inside bridge
947 * @see Dali::Accessibility::EditableText
949 class DALI_ADAPTOR_API EditableText : public virtual Accessible
953 * @brief Copy text in range to system clipboard
955 * @param[in] startPosition index of first character
956 * @param[in] endPosition index of first character after the last one expected
958 * @return true on success, false otherwise
960 virtual bool CopyText( size_t startPosition, size_t endPosition ) = 0;
963 * @brief Cut text in range to system clipboard
965 * @param[in] startPosition index of first character
966 * @param[in] endPosition index of first character after the last one expected
968 * @return true on success, false otherwise
970 virtual bool CutText( size_t startPosition, size_t endPosition ) = 0;
974 * @brief minimalistic, always empty Accessible object with settable address
976 * For those situations, where you want to return address in different bridge
977 * (embedding for example), but the object itself ain't planned to be used otherwise.
978 * This object has null parent, no children, empty name and so on
980 class DALI_ADAPTOR_API EmptyAccessibleWithAddress : public virtual Accessible
983 EmptyAccessibleWithAddress() = default;
984 EmptyAccessibleWithAddress( Address address ) : address( std::move( address ) ) {}
986 void SetAddress( Address address ) { this->address = std::move( address ); }
988 std::string GetName() override { return ""; }
989 std::string GetDescription() override { return ""; }
990 Accessible* GetParent() override { return nullptr; }
991 size_t GetChildCount() override { return 0; }
992 std::vector< Accessible* > GetChildren() override { return {}; }
993 Accessible* GetChildAtIndex( size_t index ) override
995 throw std::domain_error{"out of bounds index (" + std::to_string( index ) + ") - no children"};
997 size_t GetIndexInParent() override { return static_cast< size_t >( -1 ); }
998 Role GetRole() override { return {}; }
999 std::string GetRoleName() override;
1000 States GetStates() override { return {}; }
1001 Attributes GetAttributes() override { return {}; }
1002 Address GetAddress() override
1006 bool DoGesture(const GestureInfo &gestureInfo) override
1010 std::vector<Relation> GetRelationSet() override
1022 #endif // DALI_INTERNAL_ATSPI_ACCESSIBILITY_IMPL_H