1 #ifndef DALI_ACCESSIBILITY_H
2 #define DALI_ACCESSIBILITY_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>
32 #include <unordered_map>
40 #include <dali/public-api/dali-adaptor-common.h>
45 * @addtogroup dali_adaptor_framework
50 namespace Accessibility
54 * @brief Enumeration describing a relation between accessible objects
56 * 1 to 0..N relation model is supported. By default relation is not symmetrical.
57 * Symmetry must be explicitly maintained.
59 enum class RelationType : uint32_t
88 * @brief Enumeration describing if coordinates are relative to screen or window
90 * @see Accessibility::Component::GetExtents
91 * @see Accessibility::Component::Contains
100 * @brief Enumeration indicating relative stacking order
102 * ComponentLayer allows to describe visibility of all parts of UI
103 * basing on the concrete stacking order
105 * @see Accessibility::Component::GetLayer
107 * @note currently only ComponentLayer::Window is supported
109 enum class ComponentLayer
123 * @brief Enumeration describing role of the Accessibility object
125 * Object can be described by only one role.
127 * @see Accessibility::Accessible::GetRole
129 enum class Role : uint32_t
223 DOCUMENT_SPREADSHEET,
224 DOCUMENT_PRESENTATION,
256 * @brief Enumeration describing states of the Accessibility object
258 * Object can be in many states at the same time.
260 * @see Accessibility::Accessible::GetStates
262 enum class State : uint32_t
301 SUPPORTS_AUTOCOMPLETION,
314 * @brief Enumeration describing change of text object
316 enum class TextChangedState : uint32_t
323 enum class ObjectPropertyChangeEvent {
332 * @brief Enumeration describing change of window object
334 * @see Accessibility::Accessible::Emit
336 enum class WindowEvent
360 * @brief Enumeration used to acquire bounded text from accessible object having textual content.
362 * @see Accessibility::Text::GetTextAtOffset
364 * @note Currently only TextBoundary::Character is supported
366 enum class TextBoundary : uint32_t
369 * Only one character is acquired.
396 * @brief Enumeration describing type of gesture
398 * @see Accessibility::Accessible::DoGesture
400 enum class Gesture : int32_t
405 ONE_FINGER_FLICK_LEFT,
406 ONE_FINGER_FLICK_RIGHT,
408 ONE_FINGER_FLICK_DOWN,
409 TWO_FINGERS_FLICK_LEFT,
410 TWO_FINGERS_FLICK_RIGHT,
411 TWO_FINGERS_FLICK_UP,
412 TWO_FINGERS_FLICK_DOWN,
413 THREE_FINGERS_FLICK_LEFT,
414 THREE_FINGERS_FLICK_RIGHT,
415 THREE_FINGERS_FLICK_UP,
416 THREE_FINGERS_FLICK_DOWN,
417 ONE_FINGER_SINGLE_TAP,
418 ONE_FINGER_DOUBLE_TAP,
419 ONE_FINGER_TRIPLE_TAP,
420 TWO_FINGERS_SINGLE_TAP,
421 TWO_FINGERS_DOUBLE_TAP,
422 TWO_FINGERS_TRIPLE_TAP,
423 THREE_FINGERS_SINGLE_TAP,
424 THREE_FINGERS_DOUBLE_TAP,
425 THREE_FINGERS_TRIPLE_TAP,
426 ONE_FINGER_FLICK_LEFT_RETURN,
427 ONE_FINGER_FLICK_RIGHT_RETURN,
428 ONE_FINGER_FLICK_UP_RETURN,
429 ONE_FINGER_FLICK_DOWN_RETURN,
430 TWO_FINGERS_FLICK_LEFT_RETURN,
431 TWO_FINGERS_FLICK_RIGHT_RETURN,
432 TWO_FINGERS_FLICK_UP_RETURN,
433 TWO_FINGERS_FLICK_DOWN_RETURN,
434 THREE_FINGERS_FLICK_LEFT_RETURN,
435 THREE_FINGERS_FLICK_RIGHT_RETURN,
436 THREE_FINGERS_FLICK_UP_RETURN,
437 THREE_FINGERS_FLICK_DOWN_RETURN,
438 ONE_FINGER_DOUBLE_TAP_N_HOLD,
439 TWO_FINGERS_DOUBLE_TAP_N_HOLD,
440 THREE_FINGERS_DOUBLE_TAP_N_HOLD,
445 * @brief Enumeration indicating current state of gesture
447 * @see Dali::Accessibility::GestureInfo
449 enum class GestureState : int32_t
457 enum class ReadingInfoType
466 * @brief Helper class for storing values treated as bit sets
468 * This class provides all bitset-like methods for bitset size larger, than long long int
470 * @see Dali::Accessibility::Accessible::GetStates
471 * @see Dali::Accessibility::Accessible::GetRoles
473 template < size_t I, typename S >
476 std::array< uint32_t, I > data;
479 static constexpr bool _accepts() { return true; }
480 template < typename T > static constexpr bool _accepts()
482 return std::is_enum< T >::value;
484 template < typename T, typename T2, typename ... ARGS > static constexpr bool _accepts()
486 return std::is_enum< T >::value && _accepts< T2, ARGS... >();
488 template < typename T, typename ... ARGS > void _set( T t, ARGS ... args )
490 ( *this )[ t ] = true;
496 for( auto& u : data )
499 BitSets( const BitSets & ) = default;
500 BitSets( BitSets&& ) = default;
501 template < typename T, typename ... ARGS, typename std::enable_if< _accepts< T, ARGS... >() >::type* = nullptr >BitSets(T t, ARGS ... args) {
506 explicit BitSets( std::array< uint32_t, I > d ) {
507 for( auto i = 0u; i < I; ++i )
510 explicit BitSets( std::array< int32_t, I > d ) {
511 for( auto i = 0u; i < I; ++i )
512 data[ i ] = static_cast< uint32_t >( d[ i ]);
514 BitSets &operator = ( const BitSets& ) = default;
515 BitSets &operator = ( BitSets&& ) = default;
519 std::array< uint32_t, I >& data;
521 reference &operator=( reference r )
523 ( *this ) = static_cast< bool >( r );
526 reference &operator=( bool v )
529 data[ pos / 32 ] |= 1 << ( pos & 31 );
531 data[ pos / 32 ] &= ~( 1 << ( pos & 31 ) );
534 operator bool() const
536 auto i = static_cast< size_t >( pos );
537 return ( data[i / 32] & ( 1 << ( i & 31 ) ) ) != 0;
540 reference operator[]( S index ) { return {data, static_cast< size_t >( index )}; }
541 bool operator[]( S index ) const
543 auto i = static_cast< size_t >( index );
544 return ( data[i / 32] & ( 1 << ( i & 31 ) ) ) != 0;
546 std::array< uint32_t, I > GetRawData() const { return data; }
548 BitSets operator|( BitSets b ) const
551 for( auto i = 0u; i < I; ++i )
552 r.data[i] = data[i] | b.data[i];
555 BitSets operator^( BitSets b ) const
558 for( auto i = 0u; i < I; ++i )
559 r.data[i] = data[i] ^ b.data[i];
562 BitSets operator&( BitSets b ) const
565 for( auto i = 0u; i < I; ++i )
566 r.data[i] = data[i] & b.data[i];
569 bool operator==( BitSets b ) const
571 for( auto i = 0u; i < I; ++i )
572 if( data[i] != b.data[i] )
576 bool operator!=( BitSets b ) const
578 return !((*this) == b);
580 explicit operator bool() const
582 for( auto& u : data )
587 size_t size() const { return I; }
590 using ReadingInfoTypes = BitSets<1, ReadingInfoType>;
591 using States = BitSets< 2, State >;
592 using Attributes = std::unordered_map< std::string, std::string >;
595 * @brief Class representing unique object address on accessibility bus
597 * @see Dali::Accessibility::Accessible::GetAddress
599 class DALI_ADAPTOR_API Address
603 Address( std::string bus, std::string path ) : bus( std::move( bus ) ), path( std::move( path ) ) {}
605 explicit operator bool() const { return !path.empty(); }
606 std::string ToString() const
608 return *this ? bus + ":" + path : "::null";
610 const std::string& GetBus() const;
611 const std::string& GetPath() const { return path; }
613 bool operator == (const Address &a) const {
614 return bus == a.bus && path == a.path;
616 bool operator != (const Address &a) const {
617 return !(*this == a);
620 mutable std::string bus, path;
624 * @brief Enumeration describing type of key event
626 * @see Adaptor::AccessibilityObserver::OnAccessibleKeyEvent
628 enum class KeyEventType
635 * @brief Enumeration with human readable values describing state of event
637 * @see Dali::Accessibility::Bridge::Emit
646 * @brief Helper class representing two dimensional point with integer coordinates
648 struct DALI_ADAPTOR_API Point
654 Point( int x, int y ) : x( x ), y( y ) {}
656 bool operator==( Point p ) const
658 return x == p.x && y == p.y;
660 bool operator!=( Point p ) const
662 return !( *this == p );
667 * @brief Helper class representing size of rectangle object with usage of two integer values
669 struct DALI_ADAPTOR_API Size
675 Size( int w, int h ) : width( w ), height( h ) {}
677 bool operator==( Size p ) const
679 return width == p.width && height == p.height;
681 bool operator!=( Size p ) const
683 return !( *this == p );
688 * @brief Helper class used to store data related with Accessibility::Text interface
690 * @see Dali::Accessibility::Text::GetTextAtOffset
691 * @see Dali::Accessibility::Text::GetSelection
693 struct DALI_ADAPTOR_API Range
700 Range( size_t start, size_t end ) : startOffset( start ), endOffset( end )
703 Range( size_t start, size_t end, std::string content ) : startOffset( start ), endOffset( end ), content( content )
709 * @brief Structure containing all values needed to invoke Accessible::DoGesture
712 * enumerated gesture type
714 * point where gesture begins
716 * point where gesture ends
718 * enumerated state of gesture
720 * time when event occured
722 * @see Dali::Accessibility::Accessible::DoGesture
724 struct DALI_ADAPTOR_API GestureInfo
726 GestureInfo() = default;
727 GestureInfo(Gesture type, int32_t xBeg, int32_t xEnd, int32_t yBeg, int32_t yEnd, GestureState state, uint32_t eventTime)
728 : type(type), xBeg(xBeg), xEnd(xEnd), yBeg(yBeg), yEnd(yEnd), state(state), eventTime(eventTime)
736 GestureState state{};
737 uint32_t eventTime{};
743 * @brief Class representing accessibility relations
745 * Class connecting one source object with multiple target objects with usage
746 * of specific relation type.
748 * @note std::string representing source and targets are string values of Accessibility::Address
750 * @see Dali::Accessibility::Accessible::Address
751 * @see Dali::Accessibility::Accessible::RelationType
753 struct DALI_ADAPTOR_API Relation
755 Relation(RelationType relationType, std::vector<Address> targets)
756 : relationType(relationType), targets(targets)
758 RelationType relationType;
759 std::vector<Address> targets;
763 * @brief Reads given text by screen reader
765 * @param text The text to read
766 * @param discardable If TRUE, reading can be discarded by subsequent reading requests,
767 * if FALSE the reading must finish before next reading request can be started
768 * @param callback the callback function that is called on reading signals emitted
769 * during processing of this reading request.
770 * Callback can be one of the following signals:
775 DALI_ADAPTOR_API void Say( const std::string &text, bool discardable, std::function<void(std::string)> callback );
778 * @brief Force accessibility client to pause / resume.
780 * @param[in] pause true if you want to pause, false if you want to resume
782 DALI_ADAPTOR_API void PauseResume( bool pause );
785 } // namespace Accessibility
794 struct hash< Dali::Accessibility::Point >
796 size_t operator()( Dali::Accessibility::Point p )
798 return static_cast< size_t >( p.x ) ^ ( static_cast< size_t >( p.y ) * 11 );
802 struct hash< Dali::Accessibility::Size >
804 size_t operator()( Dali::Accessibility::Size p )
806 return static_cast< size_t >( p.width ) ^ ( static_cast< size_t >( p.height ) * 11 );
811 #endif // DALI_ACCESSIBILITY_H