Base class for accessible Components. More...
Classes | |
struct | Interfaces |
Utility struct which holds one or more accessibility interfaces. More... | |
Public Types | |
enum class | AnnouncementPriority { low , medium , high } |
A priority level that can help an accessibility client determine how to handle an announcement request. More... | |
Public Member Functions | |
AccessibilityHandler (Component &componentToWrap, AccessibilityRole accessibilityRole, AccessibilityActions actions={}, Interfaces interfaces={}) | |
Constructor. | |
virtual | ~AccessibilityHandler () |
Destructor. | |
const Component & | getComponent () const noexcept |
Returns the Component that this handler represents. | |
Component & | getComponent () noexcept |
Returns the Component that this handler represents. | |
AccessibilityRole | getRole () const noexcept |
The type of UI element that this accessibility handler represents. | |
virtual String | getTitle () const |
The title of the UI element. | |
virtual String | getDescription () const |
A short description of the UI element. | |
virtual String | getHelp () const |
Some help text for the UI element (if required). | |
virtual AccessibleState | getCurrentState () const |
Returns the current state of the UI element. | |
bool | isIgnored () const |
Returns true if this UI element should be ignored by accessibility clients. | |
bool | isVisibleWithinParent () const |
Returns true if this UI element is visible within its parent. | |
const AccessibilityActions & | getActions () const noexcept |
Returns the set of actions that the UI element supports and the associated callbacks. | |
AccessibilityValueInterface * | getValueInterface () const |
Returns the value interface for this UI element, or nullptr if it is not supported. | |
AccessibilityTableInterface * | getTableInterface () const |
Returns the table interface for this UI element, or nullptr if it is not supported. | |
AccessibilityCellInterface * | getCellInterface () const |
Returns the cell interface for this UI element, or nullptr if it is not supported. | |
AccessibilityTextInterface * | getTextInterface () const |
Returns the text interface for this UI element, or nullptr if it is not supported. | |
AccessibilityHandler * | getParent () const |
Returns the first unignored parent of this UI element in the accessibility hierarchy, or nullptr if this is a root element without a parent. | |
std::vector< AccessibilityHandler * > | getChildren () const |
Returns the unignored children of this UI element in the accessibility hierarchy. | |
bool | isParentOf (const AccessibilityHandler *possibleChild) const noexcept |
Checks whether a given UI element is a child of this one in the accessibility hierarchy. | |
AccessibilityHandler * | getChildAt (Point< int > screenPoint) |
Returns the deepest child of this UI element in the accessibility hierarchy that contains the given screen point, or nullptr if there is no child at this point. | |
AccessibilityHandler * | getChildFocus () |
Returns the deepest UI element which currently has focus. | |
bool | hasFocus (bool trueIfChildFocused) const |
Returns true if this UI element has the focus. | |
void | grabFocus () |
Tries to give focus to this UI element. | |
void | giveAwayFocus () const |
If this UI element or any of its children in the accessibility hierarchy currently have focus, this will defocus it. | |
void | notifyAccessibilityEvent (AccessibilityEvent event) const |
Used to send a notification to any observing accessibility clients that something has changed in the UI element. | |
AccessibilityNativeHandle * | getNativeImplementation () const |
std::type_index | getTypeIndex () const |
Static Public Member Functions | |
static void | postAnnouncement (const String &announcementString, AnnouncementPriority priority) |
Posts an announcement to be made to the user. | |
static void | postSystemNotification (const String ¬ificationTitle, const String ¬ificationBody) |
Posts a local system notification. | |
static void | clearCurrentlyFocusedHandler () |
static void * | getNativeChildForComponent (Component &component) |
static void | setNativeChildForComponent (Component &component, void *nativeChild) |
static Component * | getComponentForNativeChild (void *nativeChild) |
Base class for accessible Components.
This class wraps a Component and provides methods that allow an accessibility client, such as VoiceOver on macOS, or Narrator on Windows, to control it.
It handles hierarchical navigation, properties, state, and various interfaces.
|
strong |
A priority level that can help an accessibility client determine how to handle an announcement request.
Exactly what this controls is platform-specific, but generally a low priority announcement will be read when the screen reader is free, whereas a high priority announcement will interrupt the current speech.
Enumerator | |
---|---|
low | |
medium | |
high |
AccessibilityHandler::AccessibilityHandler | ( | Component & | componentToWrap, |
AccessibilityRole | accessibilityRole, | ||
AccessibilityActions | actions = {}, | ||
Interfaces | interfaces = {} ) |
Constructor.
This will create a AccessibilityHandler which wraps the provided Component and makes it visible to accessibility clients. You must also specify a role for the UI element from the AccessibilityRole
list which best describes it.
To enable users to interact with the UI element you should provide the set of supported actions and their associated callbacks via the accessibilityActions
parameter.
For UI elements that support more complex interaction the value, text, table, and cell interfaces should be implemented as required and passed as the final argument of this constructor. See the documentation of these classes for more information about the types of control they represent and which methods need to be implemented.
References Component.
Referenced by AccessibilityNativeHandle, getChildAt(), getChildFocus(), getChildren(), getParent(), and isParentOf().
|
virtual |
Destructor.
|
noexcept |
|
noexcept |
|
noexcept |
The type of UI element that this accessibility handler represents.
|
virtual |
The title of the UI element.
This will be read out by the system and should be concise, preferably matching the visible title of the UI element (if any). For example, this might be the text of a button or a simple label.
The default implementation will call Component::getTitle()
, but you can override this to return a different string if required.
If neither a name nor a description is provided then the UI element may be ignored by accessibility clients.
This must be a localised string.
|
virtual |
A short description of the UI element.
This may be read out by the system. It should not include the type of the UI element and should ideally be a single word, for example "Open" for a button that opens a window.
The default implementation will call Component::getDescription()
, but you can override this to return a different string if required.
If neither a name nor a description is provided then the UI element may be ignored by accessibility clients.
This must be a localised string.
|
virtual |
Some help text for the UI element (if required).
This may be read out by the system. This string functions in a similar way to a tooltip, for example "Click to open window." for a button which opens a window.
The default implementation will call Component::getHelpText()
, but you can override this to return a different string if required.
This must be a localised string.
|
virtual |
Returns the current state of the UI element.
The default implementation of this method will set the focusable flag and, if this UI element is currently focused, will also set the focused flag.
bool AccessibilityHandler::isIgnored | ( | ) | const |
Returns true if this UI element should be ignored by accessibility clients.
bool AccessibilityHandler::isVisibleWithinParent | ( | ) | const |
Returns true if this UI element is visible within its parent.
This will always return true for UI elements with the AccessibleState::accessibleOffscreen flag set.
|
noexcept |
Returns the set of actions that the UI element supports and the associated callbacks.
AccessibilityValueInterface * AccessibilityHandler::getValueInterface | ( | ) | const |
Returns the value interface for this UI element, or nullptr if it is not supported.
References getValueInterface().
Referenced by getValueInterface().
AccessibilityTableInterface * AccessibilityHandler::getTableInterface | ( | ) | const |
Returns the table interface for this UI element, or nullptr if it is not supported.
References getTableInterface().
Referenced by getTableInterface().
AccessibilityCellInterface * AccessibilityHandler::getCellInterface | ( | ) | const |
Returns the cell interface for this UI element, or nullptr if it is not supported.
References getCellInterface().
Referenced by getCellInterface().
AccessibilityTextInterface * AccessibilityHandler::getTextInterface | ( | ) | const |
Returns the text interface for this UI element, or nullptr if it is not supported.
References getTextInterface().
Referenced by getTextInterface().
AccessibilityHandler * AccessibilityHandler::getParent | ( | ) | const |
Returns the first unignored parent of this UI element in the accessibility hierarchy, or nullptr if this is a root element without a parent.
References AccessibilityHandler(), and getParent().
Referenced by getParent().
std::vector< AccessibilityHandler * > AccessibilityHandler::getChildren | ( | ) | const |
Returns the unignored children of this UI element in the accessibility hierarchy.
References AccessibilityHandler(), and getChildren().
Referenced by getChildren().
|
noexcept |
Checks whether a given UI element is a child of this one in the accessibility hierarchy.
References AccessibilityHandler(), and isParentOf().
Referenced by isParentOf().
AccessibilityHandler * AccessibilityHandler::getChildAt | ( | Point< int > | screenPoint | ) |
Returns the deepest child of this UI element in the accessibility hierarchy that contains the given screen point, or nullptr if there is no child at this point.
References AccessibilityHandler(), getChildAt(), and Point.
Referenced by getChildAt().
AccessibilityHandler * AccessibilityHandler::getChildFocus | ( | ) |
Returns the deepest UI element which currently has focus.
This can be a child of this UI element or, if no child is focused, this element itself.
Note that this can be different to the value of the Component with keyboard focus returned by Component::getCurrentlyFocusedComponent().
References AccessibilityHandler(), and getChildFocus().
Referenced by getChildFocus().
bool AccessibilityHandler::hasFocus | ( | bool | trueIfChildFocused | ) | const |
Returns true if this UI element has the focus.
trueIfChildFocused | if this is true, this method will also return true if any child of this UI element in the accessibility hierarchy has focus |
References hasFocus().
Referenced by hasFocus().
void AccessibilityHandler::grabFocus | ( | ) |
Tries to give focus to this UI element.
If the UI element is focusable and not ignored this will update the currently focused element, try to give keyboard focus to the Component it represents, and notify any listening accessibility clients that the current focus has changed.
References grabFocus().
Referenced by grabFocus().
void AccessibilityHandler::giveAwayFocus | ( | ) | const |
If this UI element or any of its children in the accessibility hierarchy currently have focus, this will defocus it.
This will also give away the keyboard focus from the Component it represents, and notify any listening accessibility clients that the current focus has changed.
References giveAwayFocus().
Referenced by giveAwayFocus().
void AccessibilityHandler::notifyAccessibilityEvent | ( | AccessibilityEvent | event | ) | const |
Used to send a notification to any observing accessibility clients that something has changed in the UI element.
References notifyAccessibilityEvent().
Referenced by notifyAccessibilityEvent().
|
static |
Posts an announcement to be made to the user.
announcementString | a localised string containing the announcement to be read out |
priority | the appropriate priority level for the announcement |
|
static |
Posts a local system notification.
In order for this to do anything, the following conditions must be met.
Additionally, on Android, an icon is required for notifications. This must be specified by adding the path to the icon file called "accessibilitynotificationicon" in the "Extra Android Raw Resources" setting in the Projucer.
This will use the push notification client on macOS, iOS and Android. On Windows this will create a system tray icon to post the notification.
notificationTitle | the title of the notification |
notificationBody | the main body text of the notification |
AccessibilityNativeHandle * AccessibilityHandler::getNativeImplementation | ( | ) | const |
References AccessibilityNativeHandle.
std::type_index AccessibilityHandler::getTypeIndex | ( | ) | const |
|
static |
|
static |
References Component.
|
static |
References Component.