The GtkAccessible interface provides the accessibility information about an application’s user interface elements. Assistive technology (AT) applications, like Orca, convey this information to users with disabilities, or reduced abilities, to help them use the application.
Standard GTK controls implement the GtkAccessible interface and are thus accessible to ATs by default. This means that if you use GTK controls such as GtkButton, GtkEntry, or GtkListView, you only need to supply application-specific details when the defaults values are incomplete. You can do this by setting the appropriate properties in your GtkBuilder template and UI definition files, or by setting the properties defined by the GtkAccessible interface.
The fundamental concepts of an accessible widget are roles and attributes; each GTK control has a role, while its functionality is described by a set of attributes.
Roles define the taxonomy and semantics of a UI control to any assistive technology application; for instance, a button will have a role of
GTK_ACCESSIBLE_ROLE_BUTTON; an entry will have a role of
GTK_ACCESSIBLE_ROLE_TEXTBOX; a toggle button will have a role of
Each role is part of the widget’s instance, and cannot be changed over time or as the result of a user action. Roles allows assistive technology applications to identify a UI control and decide how to present it to a user; if a part of the application’s UI changes role, the control needs to be removed and replaced with another one with the appropriate role.
Each role name is part of the GtkAccessibleRole enumeration.
|Role name||Description||Related GTK widget|
| ||A control that performs an action when pressed||GtkButton, GtkLinkButton, GtkExpander|
| || A control that has three possible value: ||GtkCheckButton|
| ||A control that can be expanded to show a list of possible values to select||GtkComboBox|
| ||A header in a columned list||GtkColumnView|
| ||A dialog that prompts the user to enter information or require a response||GtkDialog and subclasses|
| ||A grid of items||GtkFlowBox, GtkGridView|
| ||An item in a grid||GtkFlowBoxChild, GtkGridView, GtkColumnView|
| ||An image||GtkImage, GtkPicture|
| ||A visible name or caption for a user interface component||GtkLabel|
| ||A clickable hyperlink||GtkLinkButton|
| ||A list of items||GtkListBox|
| ||An item in a list||GtkListBoxRow|
| ||A menu||GtkPopoverMenu|
| ||A menubar||GtkPopoverMenuBar|
| ||A menu item||Items in GtkPopoverMenu|
| ||Check menu item||Items in GtkPopoverMenu|
| ||Radio menu item||Items in GtkPopoverMenu|
| ||Represents a value within a known range||GtkLevelBar|
| ||Not represented in the accessibility tree||the slider of a GtkScale|
| ||An element that display progress||GtkProgressBar|
| ||A checkable input in a group of radio roles||GtkCheckButton|
| ||A row in a columned list||GtkColumnView|
| ||A graphical object controlling the scrolling of content||GtkScrollbar|
| ||A text box for entering search criteria||GtkSearchEntry|
| ||A divider that separates sections of content or groups of items||GtkSeparator|
| ||A range control that allows seelcting among discrete choices||GtkSpinButton|
| ||A control that represents on/off values||GtkSwitch|
| ||A tab in a list of tabs for switching pages||GtkStackSwitcher, GtkNotebook|
| ||A list of tabs for switching pages||GtkStackSwitcher, GtkNotebook|
| ||A page in a notebook or stack||GtkStack|
| ||A type of input that allows free-form text as its value.||GtkEntry, GtkPasswordEntry, GtkTextView|
| ||A treeview-like columned list||GtkColumnView|
| ||An application window||GtkWindow|
See the WAI-ARIA list of roles for additional information.
Attributes provide specific information about an accessible UI control, and describe it for the assistive technology applications. GTK divides the accessible attributes into three categories:
Each attribute accepts a value of a specific type.
Unlike roles, attributes may change over time, or in response to user action; for instance:
a toggle button will change its
GTK_ACCESSIBLE_STATE_CHECKED state every time it is toggled, either by the user or programmatically
changing the GtkAdjustment instance on a GtkScrollbar will change the
GTK_ACCESSIBLE_PROPERTY_VALUE_NOW properties with the upper, lower, and value properties of the GtkAdjustment
See the WAI-ARIA list of attributes for additional information.
Each state name is part of the GtkAccessibleState enumeration.
|State name||ARIA attribute||Value type||Notes|
| ||“aria-checked”||GtkAccessibleTristate||Indicates the current state of a GtkCheckButton|
| ||“aria-disabled”||boolean||Corresponds to the “sensitive” property on GtkWidget|
| ||“aria-expanded”||boolean or undefined||Corresponds to the “expanded” property on GtkExpander|
| ||“aria-hidden”||boolean||Corresponds to the “visible” property on GtkWidget|
| ||“aria-invalid”||GtkAccessibleInvalidState||Set when a widget is showing an error|
| ||“aria-pressed”||GtkAccessibleTristate||Indicates the current state of a GtkToggleButton|
| ||“aria-selected”||boolean or undefined||Set when a widget is selected|
Each property name is part of the GtkAccessibleProperty enumeration.
|State name||ARIA attribute||Value type|
| ||“aria-description”||translatable string|
| ||“aria-label”||translatable string|
| ||“aria-placeholder”||translatable string|
| ||“aria-roledescription”||translatable string|
| ||“aria-valuetext”||translatable string|
Each relation name is part of the GtkAccessibleRelation enumeration.
|State name||ARIA attribute||Value type|
| ||“aria-colindextext”||translatable string|
| ||“aria-controls”||a list of GtkAccessible|
| ||“aria-describedby”||a list of GtkAccessible|
| ||“aria-details”||a list of GtkAccessible|
| ||“aria-flowto”||a list of GtkAccessible|
| ||“aria-labelledby”||a list of GtkAccessible|
| ||“aria-owns”||a list of GtkAccessible|
| ||“aria-rowindextext”||translatable string|
Even if standard UI controls provided by GTK have accessibility information out of the box, there are some additional properties and considerations for application developers. For instance, if your application presents the user with a form to fill out, you should ensure that:
the container of the form has a
each text entry widget in the form has the
GTK_ACCESSIBLE_RELATION_LABELLED_BY relation pointing to the label widget that describes it
Another example: if you create a toolbar containing buttons with only icons, you should ensure that:
the container has a
each button has a
GTK_ACCESSIBLE_PROPERTY_LABEL property set with the user readable and localised action performed when pressed; for instance “Copy”, “Paste”, “Add layer”, or “Remove”
GTK will try to fill in some information by using ancillary UI control properties, for instance the accessible label will be taken from the label or placeholder text used by the UI control, or from its tooltip, if the
GTK_ACCESSIBLE_PROPERTY_LABEL property or the
GTK_ACCESSIBLE_RELATION_LABELLED_BY relation are unset. Nevertheless, it is good practice and project hygiene to explicitly specify the accessible properties, just like it’s good practice to specify tooltips and style classes.
Application developers using GTK should ensure that their UI controls are accessible as part of the development process. When using
GtkBuilder templates and UI definition files, GTK provides a validation tool that verifies that each UI element has a valid role and properties; this tool can be used as part of the application’s test suite to avoid regressions.
Each UI control implements the GtkAccessible interface to allow widget and application developers to specify the roles, state, and relations between UI controls. This API is purely descriptive.
GtkAccessible implementation must provide a GtkATContext instance, which acts as a proxy to the specific platform’s accessibility API:
AT-SPI on Linux/BSD
NSAccessibility on macOS
Active Accessibility on Windows
Additionally, an ad hoc accessibility backend is available for the GTK testsuite, to ensure reproducibility of issues in the CI pipeline.
The authoring practices are aimed at application developers, as well as developers of GUI elements based on GTK.
Functionally, GtkAccessible roles, states, properties, and relations are analogous to a CSS for assistive technologies. For screen reader users, for instance, the various accessible attributes control the rendering of their non-visual experience. Incorrect roles and attributes may result in a completely inaccessible user interface.
The following code:
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_BUTTON);
is a promise that the widget being created will provide the same keyboard interactions expected for a button. An accessible role of a button will not turn automatically any widget into a GtkButton; but if your widget behaves like a button, using the
GTK_ACCESSIBLE_ROLE_BUTTON will allow any assistive technology to handle it like they would a GtkButton.
Accessible attributes can be used to override the content of a UI element, for instance:
gtk_label_set_text (GTK_LABEL (label), "Some text"); gtk_accessible_update_property (GTK_ACCESSIBLE (label), GTK_ACCESSIBLE_PROPERTY_LABEL, "Assistive technologies users will perceive " "this text, not the contents of the label", -1);
In the example above, the “label” property will override the contents of the label widget.
The attributes can also enhance the UI:
gtk_button_set_label (GTK_BUTTON (button), "Download"); gtk_box_append (GTK_BOX (button), button); gtk_label_set_text (GTK_LABEL (label), "Final report.pdf"); gtk_box_append (GTK_BOX (box), label); gtk_accessible_update_relation (GTK_ACCESSIBLE (button), GTK_ACCESSIBLE_RELATION_LABELLED_BY, g_list_append (NULL, label), -1);
In the example above, an assistive technology will read the button’s accessible label as “Download Final report.pdf”.
The power of hiding and enhancing can be a double-edged sword, as it can lead to inadvertently overriding the accessible semantics of existing widgets.
The accessibility API is mainly used to express semantics useful for assistive technologies, but it can also be used to hide elements. The canonical way to do so is to use the
GTK_ACCESSIBLE_ROLE_PRESENTATION, which declares that a UI element is purely meant for presentation purposes, and as such it has no meaningful impact on the accessibility of the interface.
A “presentation” role should not be confused with the
GTK_ACCESSIBLE_STATE_HIDDEN state; the “hidden” state is transient, and is typically controlled by showing and hiding a widget using the GtkWidget API.
When creating custom widgets, following established patterns can help ensuring that the widgets work well for users of accessible technologies as well.
A button is a widget that enables users to trigger an action. While it is recommended you use GtkButton for anything that looks and behaves like a button, it is possible to apply a button behavior to UI elements like images by using a GtkGestureClick gesture. When doing so, you should:
Give your widget the role
Install an action with no parameters, which will activate the widget
For custom entries, it is highly recommended that you implement the GtkEditable interface by using a GtkText widget as delegate. If you do this, GTK will make your widgets text editing functionality accessible in the same way as a GtkSpinButton or GtkSearchEntry.
If you make a tab-based interface, you should consider using GtkStack as the core, and just make a custom tab widget to control the active stack page. When doing so, the following extra steps will ensure that your tabs are accessible in the same way as GtkStackSwitcher or GtkNotebook:
Give your tab container the role
Give your tab widgets the role
GTK_ACCESSIBLE_PROPERTY_SELECTED property on each tab, with the active tab getting the value
TRUE, all others
To allow changing the active tab via accessible technologies, you can export actions. Since the accessibility interfaces only support actions without parameters, you can either provide
next-tab actions on the tab container that let users step through the tabs one-by-one, or add a
activate-tab action on each tab.
A value control (ie a widget that controls a one-dimensional quantity that can be represented by a GtkAdjustment) can be represented to accessible technologies by setting the
To allow changing the value via accessible technologies, you can export actions. Since the accessibility interfaces only support actions without parameters, you should provide actions such as
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.