Merge branch 'a11y-inspector-tweaks' into 'main'

Move the a11y naming data into gtk proper

See merge request GNOME/gtk!6118
This commit is contained in:
Matthias Clasen 2023-06-19 16:21:31 +00:00
commit 1f029229dc
15 changed files with 281 additions and 161 deletions

View File

@ -257,6 +257,13 @@ turn automatically any widget into a `GtkButton`; but if your widget behaves
like a button, using the %GTK_ACCESSIBLE_ROLE_BUTTON will allow any like a button, using the %GTK_ACCESSIBLE_ROLE_BUTTON will allow any
assistive technology to handle it like they would a `GtkButton`. assistive technology to handle it like they would a `GtkButton`.
For widgets that act as containers of other widgets, you should use
%GTK_ACCESSIBLE_ROLE_GROUP if the grouping of the children is semantic
in nature; for instance, the children of a [class@Gtk.HeaderBar] are
grouped together on the header of a window. For generic containers that
only impose a layout on their children, you should use
%GTK_ACCESSIBLE_ROLE_GENERIC instead.
### Attributes can both hide and enhance ### Attributes can both hide and enhance
Accessible attributes can be used to override the content of a UI element, Accessible attributes can be used to override the content of a UI element,

View File

@ -169,7 +169,7 @@ gtk_accessible_role_to_atspi_role (GtkAccessibleRole role)
return ATSPI_ROLE_OPTION_PANE; return ATSPI_ROLE_OPTION_PANE;
case GTK_ACCESSIBLE_ROLE_PRESENTATION: case GTK_ACCESSIBLE_ROLE_PRESENTATION:
return ATSPI_ROLE_FILLER; return ATSPI_ROLE_INVALID;
case GTK_ACCESSIBLE_ROLE_PROGRESS_BAR: case GTK_ACCESSIBLE_ROLE_PROGRESS_BAR:
return ATSPI_ROLE_PROGRESS_BAR; return ATSPI_ROLE_PROGRESS_BAR;

View File

@ -57,6 +57,35 @@ const char * gtk_accessible_role_to_name (GtkAccessibleRole role,
gboolean gtk_accessible_role_is_range_subclass (GtkAccessibleRole role); gboolean gtk_accessible_role_is_range_subclass (GtkAccessibleRole role);
/* < private >
* GtkAccessibleNaming:
* @GTK_ACCESSIBLE_NAME_ALLOWED:
* The role allows an accessible name and description
* @GTK_ACCESSIBLE_NAME_PROHIBITED:
* The role does not allow an accessible name and descirption
* @GTK_ACCESSIBLE_NAME_REQUIRED:
* The role requires an accessible name and description
* @GTK_ACCESSIBLE_NAME_RECOMMENDED:
* It is recommended to set the label property or labelled-by relation
* for this role
* @GTK_ACCESSIBLE_NAME_NOT_RECOMMENDED:
* It is recommended not to set the label property or labelled-by relation
* for this role
*
* Information about naming requirements for accessible roles.
*/
typedef enum {
GTK_ACCESSIBLE_NAME_ALLOWED,
GTK_ACCESSIBLE_NAME_PROHIBITED,
GTK_ACCESSIBLE_NAME_REQUIRED,
GTK_ACCESSIBLE_NAME_RECOMMENDED,
GTK_ACCESSIBLE_NAME_NOT_RECOMMENDED,
} GtkAccessibleNaming;
gboolean gtk_accessible_role_supports_name_from_author (GtkAccessibleRole role);
gboolean gtk_accessible_role_supports_name_from_content (GtkAccessibleRole role);
GtkAccessibleNaming gtk_accessible_role_get_naming (GtkAccessibleRole role);
gboolean gtk_accessible_should_present (GtkAccessible *self); gboolean gtk_accessible_should_present (GtkAccessible *self);
void gtk_accessible_update_children (GtkAccessible *self, void gtk_accessible_update_children (GtkAccessible *self,

View File

@ -38,6 +38,13 @@
* # CSS nodes * # CSS nodes
* *
* `GtkAspectFrame` uses a CSS node with name `frame`. * `GtkAspectFrame` uses a CSS node with name `frame`.
*
* # Accessibility
*
* Until GTK 4.10, `GtkAspectFrame` used the `GTK_ACCESSIBLE_ROLE_GROUP` role.
*
* Starting from GTK 4.12, `GtkAspectFrame` uses the `GTK_ACCESSIBLE_ROLE_GENERIC` role.
*/ */
#include "config.h" #include "config.h"
@ -187,7 +194,7 @@ gtk_aspect_frame_class_init (GtkAspectFrameClass *class)
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (class), I_("aspectframe")); gtk_widget_class_set_css_name (GTK_WIDGET_CLASS (class), I_("aspectframe"));
gtk_widget_class_set_accessible_role (GTK_WIDGET_CLASS (class), GTK_ACCESSIBLE_ROLE_GROUP); gtk_widget_class_set_accessible_role (GTK_WIDGET_CLASS (class), GTK_ACCESSIBLE_ROLE_GENERIC);
} }
static void static void

View File

@ -46,6 +46,7 @@
#include "gtkdropdown.h" #include "gtkdropdown.h"
#include "gtkcolordialogbutton.h" #include "gtkcolordialogbutton.h"
#include "gtkfontdialogbutton.h" #include "gtkfontdialogbutton.h"
#include "print/gtkprinteroptionwidgetprivate.h"
#if defined(GDK_WINDOWING_X11) || defined(GDK_WINDOWING_WAYLAND) #if defined(GDK_WINDOWING_X11) || defined(GDK_WINDOWING_WAYLAND)
#include "a11y/gtkatspicontextprivate.h" #include "a11y/gtkatspicontextprivate.h"
@ -1009,7 +1010,146 @@ gtk_at_context_get_accessible_relation (GtkATContext *self,
return gtk_accessible_attribute_set_get_value (self->relations, relation); return gtk_accessible_attribute_set_get_value (self->relations, relation);
} }
/* See the WAI-ARIA § 4.3, "Accessible Name and Description Computation" */ /* See the WAI-ARIA § 4.3, "Accessible Name and Description Computation",
* and https://www.w3.org/TR/accname-1.2/
*/
/* See ARIA 5.2.8.4, 5.2.8.5 and 5.2.8.6 for the prohibited, from author
* and from content parts, and the table in
* https://www.w3.org/WAI/ARIA/apg/practices/names-and-descriptions/
* for the recommended / not recommended parts.
*/
#define NAME_FROM_AUTHOR (1 << 6)
#define NAME_FROM_CONTENT (1 << 7)
static guint8 naming[] = {
[GTK_ACCESSIBLE_ROLE_ALERT] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_ALERT_DIALOG] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_BANNER] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_BUTTON] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_CAPTION] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_CELL] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT,
[GTK_ACCESSIBLE_ROLE_CHECKBOX] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_COLUMN_HEADER] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_COMBO_BOX] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_COMMAND] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_COMPOSITE] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_DIALOG] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_DOCUMENT] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_FEED] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_FORM] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_GENERIC] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_GRID] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_GRID_CELL] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT,
[GTK_ACCESSIBLE_ROLE_GROUP] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_HEADING] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_IMG] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_INPUT] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_LABEL] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT,
[GTK_ACCESSIBLE_ROLE_LANDMARK] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_LEGEND] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_LINK] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_LIST] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_LIST_BOX] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_LIST_ITEM] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_NOT_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_LOG] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_MAIN] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_MARQUEE] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_MATH] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_METER] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_MENU] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_MENU_BAR] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_MENU_ITEM] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_MENU_ITEM_CHECKBOX] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_MENU_ITEM_RADIO] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_NAVIGATION] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_NONE] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_NOTE] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_OPTION] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_PRESENTATION] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_PROGRESS_BAR] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_RADIO] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_RADIO_GROUP] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_RANGE] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_REGION] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_ROW] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT,
[GTK_ACCESSIBLE_ROLE_ROW_GROUP] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_NOT_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_ROW_HEADER] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_SCROLLBAR] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_SEARCH] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_SEARCH_BOX] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_SECTION] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_SECTION_HEAD] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_SELECT] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_SEPARATOR] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_SLIDER] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_SPIN_BUTTON] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_STATUS] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_STRUCTURE] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_SWITCH] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_TAB] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_TABLE] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_TAB_LIST] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_TAB_PANEL] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_TEXT_BOX] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_TIME] = GTK_ACCESSIBLE_NAME_PROHIBITED,
[GTK_ACCESSIBLE_ROLE_TIMER] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_TOOLBAR] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_RECOMMENDED,
[GTK_ACCESSIBLE_ROLE_TOOLTIP] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT,
[GTK_ACCESSIBLE_ROLE_TREE] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_TREE_GRID] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_TREE_ITEM] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT|GTK_ACCESSIBLE_NAME_REQUIRED,
[GTK_ACCESSIBLE_ROLE_WIDGET] = NAME_FROM_AUTHOR|NAME_FROM_CONTENT,
[GTK_ACCESSIBLE_ROLE_WINDOW] = NAME_FROM_AUTHOR,
[GTK_ACCESSIBLE_ROLE_TOGGLE_BUTTON] = NAME_FROM_AUTHOR|GTK_ACCESSIBLE_NAME_REQUIRED,
};
/* < private >
* gtk_accessible_role_supports_name_from_author:
* @role: a `GtkAccessibleRole`
*
* Returns whether this role supports setting the label and description
* properties or the labelled-by and described-by relations.
*
* Returns: %TRUE if the role allows labelling
*/
gboolean
gtk_accessible_role_supports_name_from_author (GtkAccessibleRole role)
{
return (naming[role] & NAME_FROM_AUTHOR) != 0;
}
/* < private >
* gtk_accessible_role_supports_name_from_content:
* @role: a `GtkAccessibleRole`
*
* Returns whether this role will use content of child widgets such
* as labels for its accessible name and description if no explicit
* labels are provided.
*
* Returns: %TRUE if the role content naming
*/
gboolean
gtk_accessible_role_supports_name_from_content (GtkAccessibleRole role)
{
return (naming[role] & NAME_FROM_CONTENT) != 0;
}
/* < private >
* gtk_accessible_role_get_nameing:
* @role: a `GtkAccessibleRole`
*
* Returns naming information for this role.
*
* Returns: information about naming requirements for the role
*/
GtkAccessibleNaming
gtk_accessible_role_get_naming (GtkAccessibleRole role)
{
return (GtkAccessibleNaming) (naming[role] & ~(NAME_FROM_AUTHOR|NAME_FROM_CONTENT));
}
static void static void
gtk_at_context_get_name_accumulate (GtkATContext *self, gtk_at_context_get_name_accumulate (GtkATContext *self,
GPtrArray *names, GPtrArray *names,
@ -1176,13 +1316,6 @@ gtk_at_context_get_description_accumulate (GtkATContext *self,
} }
} }
static GtkAccessibleRole name_forbidden[] = {
GTK_ACCESSIBLE_ROLE_CAPTION,
GTK_ACCESSIBLE_ROLE_GENERIC,
GTK_ACCESSIBLE_ROLE_PRESENTATION,
GTK_ACCESSIBLE_ROLE_NONE,
};
static gboolean static gboolean
is_nested_button (GtkATContext *self) is_nested_button (GtkATContext *self)
{ {
@ -1200,7 +1333,17 @@ is_nested_button (GtkATContext *self)
if ((GTK_IS_TOGGLE_BUTTON (widget) && GTK_IS_DROP_DOWN (parent)) || if ((GTK_IS_TOGGLE_BUTTON (widget) && GTK_IS_DROP_DOWN (parent)) ||
(GTK_IS_TOGGLE_BUTTON (widget) && GTK_IS_MENU_BUTTON (parent)) || (GTK_IS_TOGGLE_BUTTON (widget) && GTK_IS_MENU_BUTTON (parent)) ||
(GTK_IS_BUTTON (widget) && GTK_IS_COLOR_DIALOG_BUTTON (parent)) || (GTK_IS_BUTTON (widget) && GTK_IS_COLOR_DIALOG_BUTTON (parent)) ||
(GTK_IS_BUTTON (widget) && GTK_IS_FONT_DIALOG_BUTTON (parent))) (GTK_IS_BUTTON (widget) && GTK_IS_FONT_DIALOG_BUTTON (parent))
#ifdef G_OS_UNIX
|| (GTK_IS_PRINTER_OPTION_WIDGET (parent) &&
(GTK_IS_CHECK_BUTTON (widget) ||
GTK_IS_DROP_DOWN (widget) ||
GTK_IS_ENTRY (widget) ||
GTK_IS_IMAGE (widget) ||
GTK_IS_LABEL (widget) ||
GTK_IS_BUTTON (widget)))
#endif
)
return TRUE; return TRUE;
return FALSE; return FALSE;
@ -1241,11 +1384,8 @@ gtk_at_context_get_name (GtkATContext *self)
g_return_val_if_fail (GTK_IS_AT_CONTEXT (self), NULL); g_return_val_if_fail (GTK_IS_AT_CONTEXT (self), NULL);
for (unsigned int i = 0; i < G_N_ELEMENTS (name_forbidden); i++) if (gtk_accessible_role_get_naming (self->accessible_role) == GTK_ACCESSIBLE_NAME_PROHIBITED)
{ return g_strdup ("");
if (self->accessible_role == name_forbidden[i])
return g_strdup ("");
}
/* We special case this here since it is a common pattern: /* We special case this here since it is a common pattern:
* We have a 'wrapper' object, like a GtkDropdown which * We have a 'wrapper' object, like a GtkDropdown which
@ -1257,6 +1397,12 @@ gtk_at_context_get_name (GtkATContext *self)
{ {
parent = get_parent_context (self); parent = get_parent_context (self);
self = parent; self = parent;
if (is_nested_button (self))
{
parent = get_parent_context (parent);
g_object_unref (self);
self = parent;
}
} }
GPtrArray *names = g_ptr_array_new (); GPtrArray *names = g_ptr_array_new ();
@ -1303,11 +1449,8 @@ gtk_at_context_get_description (GtkATContext *self)
g_return_val_if_fail (GTK_IS_AT_CONTEXT (self), NULL); g_return_val_if_fail (GTK_IS_AT_CONTEXT (self), NULL);
for (unsigned int i = 0; i < G_N_ELEMENTS (name_forbidden); i++) if (gtk_accessible_role_get_naming (self->accessible_role) == GTK_ACCESSIBLE_NAME_PROHIBITED)
{ return g_strdup ("");
if (self->accessible_role == name_forbidden[i])
return g_strdup ("");
}
/* We special case this here since it is a common pattern: /* We special case this here since it is a common pattern:
* We have a 'wrapper' object, like a GtkDropdown which * We have a 'wrapper' object, like a GtkDropdown which

View File

@ -56,7 +56,9 @@
* *
* # Accessibility * # Accessibility
* *
* `GtkBox` uses the %GTK_ACCESSIBLE_ROLE_GROUP role. * Until GTK 4.10, `GtkBox` used the `GTK_ACCESSIBLE_ROLE_GROUP` role.
*
* Starting from GTK 4.12, `GtkBox` uses the `GTK_ACCESSIBLE_ROLE_GENERIC` role.
*/ */
#include "config.h" #include "config.h"
@ -304,8 +306,9 @@ gtk_box_class_init (GtkBoxClass *class)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("box")); gtk_widget_class_set_css_name (widget_class, I_("box"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GENERIC);
} }
static void static void
gtk_box_init (GtkBox *box) gtk_box_init (GtkBox *box)
{ {

View File

@ -52,7 +52,9 @@
* *
* # Accessibility * # Accessibility
* *
* `GtkCenterBox` uses the %GTK_ACCESSIBLE_ROLE_GROUP role. * Until GTK 4.10, `GtkCenterBox` used the `GTK_ACCESSIBLE_ROLE_GROUP` role.
*
* Starting from GTK 4.12, `GtkCenterBox` uses the `GTK_ACCESSIBLE_ROLE_GENERIC` role.
*/ */
#include "config.h" #include "config.h"
@ -321,7 +323,7 @@ gtk_center_box_class_init (GtkCenterBoxClass *klass)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_CENTER_LAYOUT); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_CENTER_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("box")); gtk_widget_class_set_css_name (widget_class, I_("box"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GENERIC);
} }
static void static void

View File

@ -1259,11 +1259,12 @@ typedef enum {
* @GTK_ACCESSIBLE_ROLE_DOCUMENT: Unused * @GTK_ACCESSIBLE_ROLE_DOCUMENT: Unused
* @GTK_ACCESSIBLE_ROLE_FEED: Unused * @GTK_ACCESSIBLE_ROLE_FEED: Unused
* @GTK_ACCESSIBLE_ROLE_FORM: Unused * @GTK_ACCESSIBLE_ROLE_FORM: Unused
* @GTK_ACCESSIBLE_ROLE_GENERIC: Unused * @GTK_ACCESSIBLE_ROLE_GENERIC: A nameless container that has no semantic meaning
* of its own. This is the role that GTK uses by default for widgets and most containers.
* @GTK_ACCESSIBLE_ROLE_GRID: A grid of items. * @GTK_ACCESSIBLE_ROLE_GRID: A grid of items.
* @GTK_ACCESSIBLE_ROLE_GRID_CELL: An item in a grid or tree grid. * @GTK_ACCESSIBLE_ROLE_GRID_CELL: An item in a grid or tree grid.
* @GTK_ACCESSIBLE_ROLE_GROUP: An element that groups multiple widgets. GTK uses * @GTK_ACCESSIBLE_ROLE_GROUP: An element that groups multiple related widgets. GTK uses
* this role for various containers, like [class@Box], [class@Viewport], and [class@HeaderBar]. * this role for various containers, like [class@Gtk.HeaderBar] or [class@Gtk.Notebook].
* @GTK_ACCESSIBLE_ROLE_HEADING: Unused * @GTK_ACCESSIBLE_ROLE_HEADING: Unused
* @GTK_ACCESSIBLE_ROLE_IMG: An image. * @GTK_ACCESSIBLE_ROLE_IMG: An image.
* @GTK_ACCESSIBLE_ROLE_INPUT: Abstract role. * @GTK_ACCESSIBLE_ROLE_INPUT: Abstract role.

View File

@ -116,7 +116,9 @@
* *
* # Accessibility * # Accessibility
* *
* `GtkGrid` uses the %GTK_ACCESSIBLE_ROLE_GROUP role. * Until GTK 4.10, `GtkGrid` used the `GTK_ACCESSIBLE_ROLE_GROUP` role.
*
* Starting from GTK 4.12, `GtkGrid` uses the `GTK_ACCESSIBLE_ROLE_GENERIC` role.
*/ */
typedef struct typedef struct
@ -477,7 +479,7 @@ gtk_grid_class_init (GtkGridClass *class)
gtk_widget_class_set_css_name (widget_class, I_("grid")); gtk_widget_class_set_css_name (widget_class, I_("grid"));
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_GRID_LAYOUT); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_GRID_LAYOUT);
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GENERIC);
} }
static GtkBuildableIface *parent_buildable_iface; static GtkBuildableIface *parent_buildable_iface;

View File

@ -76,6 +76,7 @@ gtk_popover_content_class_init (GtkPopoverContentClass *klass)
widget_class->css_changed = gtk_popover_content_css_changed; widget_class->css_changed = gtk_popover_content_css_changed;
gtk_widget_class_set_css_name (widget_class, I_("contents")); gtk_widget_class_set_css_name (widget_class, I_("contents"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GENERIC);
} }
static void static void

View File

@ -124,7 +124,9 @@
* *
* # Accessibility * # Accessibility
* *
* `GtkScrolledWindow` uses the %GTK_ACCESSIBLE_ROLE_GROUP role. * Until GTK 4.10, `GtkScrolledWindow` used the `GTK_ACCESSIBLE_ROLE_GROUP` role.
*
* Starting from GTK 4.12, `GtkScrolledWindow` uses the `GTK_ACCESSIBLE_ROLE_GENERIC` role.
*/ */
/* scrolled window policy and size requisition handling: /* scrolled window policy and size requisition handling:
@ -873,7 +875,7 @@ gtk_scrolled_window_class_init (GtkScrolledWindowClass *class)
add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD); add_tab_bindings (widget_class, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
gtk_widget_class_set_css_name (widget_class, I_("scrolledwindow")); gtk_widget_class_set_css_name (widget_class, I_("scrolledwindow"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GENERIC);
} }
static gboolean static gboolean

View File

@ -84,9 +84,10 @@
* *
* ## Accessibility * ## Accessibility
* *
* `GtkTreeExpander` uses the %GTK_ACCESSIBLE_ROLE_GROUP role. The expander icon * Until GTK 4.10, `GtkTreeExpander` used the `GTK_ACCESSIBLE_ROLE_GROUP` role.
* is represented as a %GTK_ACCESSIBLE_ROLE_BUTTON, labelled by the expander's *
* child, and toggling it will change the %GTK_ACCESSIBLE_STATE_EXPANDED state. * Since GTK 4.12, `GtkTreeExpander` uses the `GTK_ACCESSIBLE_ROLE_BUTTON` role.
* Toggling it will change the `GTK_ACCESSIBLE_STATE_EXPANDED` state.
*/ */
struct _GtkTreeExpander struct _GtkTreeExpander
@ -172,7 +173,7 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self)
self->expander_icon = self->expander_icon =
g_object_new (GTK_TYPE_BUILTIN_ICON, g_object_new (GTK_TYPE_BUILTIN_ICON,
"css-name", "expander", "css-name", "expander",
"accessible-role", GTK_ACCESSIBLE_ROLE_BUTTON, "accessible-role", GTK_ACCESSIBLE_ROLE_NONE,
NULL); NULL);
gesture = gtk_gesture_click_new (); gesture = gtk_gesture_click_new ();
@ -189,10 +190,6 @@ gtk_tree_expander_update_for_list_row (GtkTreeExpander *self)
gtk_widget_insert_before (self->expander_icon, gtk_widget_insert_before (self->expander_icon,
GTK_WIDGET (self), GTK_WIDGET (self),
self->child); self->child);
gtk_accessible_update_property (GTK_ACCESSIBLE (self->expander_icon),
GTK_ACCESSIBLE_PROPERTY_LABEL, _("Expand"),
-1);
} }
if (gtk_tree_list_row_get_expanded (self->list_row)) if (gtk_tree_list_row_get_expanded (self->list_row))
@ -684,7 +681,7 @@ gtk_tree_expander_class_init (GtkTreeExpanderClass *klass)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BOX_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("treeexpander")); gtk_widget_class_set_css_name (widget_class, I_("treeexpander"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_BUTTON);
} }
static gboolean static gboolean

View File

@ -54,7 +54,9 @@
* *
* # Accessibility * # Accessibility
* *
* `GtkViewport` uses the %GTK_ACCESSIBLE_ROLE_GROUP role. * Until GTK 4.10, `GtkViewport` used the `GTK_ACCESSIBLE_ROLE_GROUP` role.
*
* Starting from GTK 4.12, `GtkViewport` uses the `GTK_ACCESSIBLE_ROLE_GENERIC` role.
*/ */
typedef struct _GtkViewportPrivate GtkViewportPrivate; typedef struct _GtkViewportPrivate GtkViewportPrivate;
@ -334,7 +336,7 @@ gtk_viewport_class_init (GtkViewportClass *class)
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
gtk_widget_class_set_css_name (widget_class, I_("viewport")); gtk_widget_class_set_css_name (widget_class, I_("viewport"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GENERIC);
} }
static void static void

View File

@ -50,7 +50,9 @@
* *
* # Accessibility * # Accessibility
* *
* `GtkWindowHandle` uses the %GTK_ACCESSIBLE_ROLE_GROUP role. * Until GTK 4.10, `GtkWindowHandle` used the `GTK_ACCESSIBLE_ROLE_GROUP` role.
*
* Starting from GTK 4.12, `GtkWindowHandle` uses the `GTK_ACCESSIBLE_ROLE_GENERIC` role.
*/ */
struct _GtkWindowHandle { struct _GtkWindowHandle {
@ -544,7 +546,7 @@ gtk_window_handle_class_init (GtkWindowHandleClass *klass)
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
gtk_widget_class_set_css_name (widget_class, I_("windowhandle")); gtk_widget_class_set_css_name (widget_class, I_("windowhandle"));
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP); gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GENERIC);
} }
static void static void

View File

@ -46,97 +46,6 @@ struct _GtkA11yOverlayClass
G_DEFINE_TYPE (GtkA11yOverlay, gtk_a11y_overlay, GTK_TYPE_INSPECTOR_OVERLAY) G_DEFINE_TYPE (GtkA11yOverlay, gtk_a11y_overlay, GTK_TYPE_INSPECTOR_OVERLAY)
typedef enum
{
NAMING_DISCRETIONARY,
NAMING_REQUIRED,
NAMING_RECOMMENDED,
NAMING_CONDITIONAL,
NAMING_PROHIBITED
} NamingNecessity;
static NamingNecessity name_for_role[] = {
NAMING_DISCRETIONARY, // ALERT
NAMING_REQUIRED, // ALERT_DIALOG
NAMING_DISCRETIONARY, // BANNER
NAMING_CONDITIONAL, // BUTTON
NAMING_PROHIBITED, // CAPTION
NAMING_CONDITIONAL, // CELL
NAMING_CONDITIONAL, // CHECKBOX
NAMING_CONDITIONAL, // COLUMN_HEADER
NAMING_REQUIRED, // COMBO_BOX
NAMING_DISCRETIONARY, // COMMAND
NAMING_DISCRETIONARY, // COMPOSITE
NAMING_REQUIRED, // DIALOG
NAMING_DISCRETIONARY, // DOCUMENT
NAMING_RECOMMENDED, // FEED
NAMING_RECOMMENDED, // FORM
NAMING_PROHIBITED, // GENERIC
NAMING_REQUIRED, // GRID
NAMING_CONDITIONAL, // GRID_CELL
NAMING_DISCRETIONARY, // GROUP
NAMING_CONDITIONAL, // HEADING
NAMING_REQUIRED, // IMG
NAMING_DISCRETIONARY, // INPUT
NAMING_DISCRETIONARY, // LABEL
NAMING_DISCRETIONARY, // LANDMARK
NAMING_DISCRETIONARY, // LEGEND
NAMING_CONDITIONAL, // LINK
NAMING_DISCRETIONARY, // LIST
NAMING_REQUIRED, // LIST_BOX
NAMING_PROHIBITED, // LIST_ITEM
NAMING_DISCRETIONARY, // LOG
NAMING_DISCRETIONARY, // MAIN
NAMING_DISCRETIONARY, // MARQUEE
NAMING_RECOMMENDED, // MATH
NAMING_REQUIRED, // METER
NAMING_RECOMMENDED, // MENU
NAMING_RECOMMENDED, // MENU_BAR
NAMING_CONDITIONAL, // MENU_ITEM
NAMING_CONDITIONAL, // MENU_ITEM_CHECKBOX
NAMING_CONDITIONAL, // MENU_ITEM_RADIO
NAMING_RECOMMENDED, // NAVIGATION
NAMING_PROHIBITED, // NONE
NAMING_DISCRETIONARY, // NOTE
NAMING_CONDITIONAL, // OPTION
NAMING_PROHIBITED, // PRESENTATION
NAMING_REQUIRED, // PROGRESS_BAR
NAMING_CONDITIONAL, // RADIO
NAMING_REQUIRED, // RADIO_GROUP
NAMING_DISCRETIONARY, // RANGE
NAMING_REQUIRED, // REGION
NAMING_CONDITIONAL, // ROW
NAMING_PROHIBITED, // ROW_GROUP
NAMING_CONDITIONAL, // ROW_HEADER
NAMING_DISCRETIONARY, // SCROLLBAR
NAMING_RECOMMENDED, // SEARCH
NAMING_REQUIRED, // SEARCH_BOX
NAMING_DISCRETIONARY, // SECTION
NAMING_DISCRETIONARY, // SECTION_HEAD
NAMING_DISCRETIONARY, // SELECT
NAMING_DISCRETIONARY, // SEPARATOR
NAMING_REQUIRED, // SLIDER
NAMING_REQUIRED, // SPIN_BUTTON
NAMING_DISCRETIONARY, // STATUS
NAMING_DISCRETIONARY, // STRUCTURE
NAMING_CONDITIONAL, // SWITCH
NAMING_CONDITIONAL, // TAB
NAMING_REQUIRED, // TABLE
NAMING_RECOMMENDED, // TAB_LIST
NAMING_REQUIRED, // TAB_PANEL
NAMING_REQUIRED, // TEXT_BOX
NAMING_PROHIBITED, // TIME
NAMING_DISCRETIONARY, // TIMER
NAMING_RECOMMENDED, // TOOLBAR
NAMING_CONDITIONAL, // TOOLTIP
NAMING_REQUIRED, // TREE
NAMING_REQUIRED, // TREE_GRID
NAMING_CONDITIONAL, // TREE_ITEM
NAMING_DISCRETIONARY, // WIDGET
NAMING_DISCRETIONARY, // WINDOW
NAMING_CONDITIONAL, // TOGGLE_BUTTON
};
static GtkAccessibleRole abstract_roles[] = { static GtkAccessibleRole abstract_roles[] = {
GTK_ACCESSIBLE_ROLE_COMMAND, GTK_ACCESSIBLE_ROLE_COMMAND,
GTK_ACCESSIBLE_ROLE_COMPOSITE, GTK_ACCESSIBLE_ROLE_COMPOSITE,
@ -257,28 +166,47 @@ check_accessibility_errors (GtkWidget *widget,
label_set = gtk_at_context_has_accessible_property (context, GTK_ACCESSIBLE_PROPERTY_LABEL) || label_set = gtk_at_context_has_accessible_property (context, GTK_ACCESSIBLE_PROPERTY_LABEL) ||
gtk_at_context_has_accessible_relation (context, GTK_ACCESSIBLE_RELATION_LABELLED_BY); gtk_at_context_has_accessible_relation (context, GTK_ACCESSIBLE_RELATION_LABELLED_BY);
switch (name_for_role[role]) switch (gtk_accessible_role_get_naming (role))
{ {
case NAMING_DISCRETIONARY: case GTK_ACCESSIBLE_NAME_ALLOWED:
return SEVERITY_GOOD; return SEVERITY_GOOD;
case NAMING_REQUIRED: case GTK_ACCESSIBLE_NAME_REQUIRED:
if (label_set) if (label_set)
{ {
return SEVERITY_GOOD; return SEVERITY_GOOD;
} }
else else
{ {
*hint = g_strdup_printf ("%s must have label or labelled-by", role_name); if (gtk_accessible_role_supports_name_from_author (role))
{
char *name = gtk_at_context_get_name (context);
return SEVERITY_ERROR; if (strcmp (name, "") == 0)
{
g_free (name);
*hint = g_strdup_printf ("%s must have text content or label", role_name);
return SEVERITY_ERROR;
}
else
{
return SEVERITY_GOOD;
}
}
else
{
*hint = g_strdup_printf ("%s must have label", role_name);
return SEVERITY_ERROR;
}
} }
break; break;
case NAMING_PROHIBITED: case GTK_ACCESSIBLE_NAME_PROHIBITED:
if (label_set) if (label_set)
{ {
*hint = g_strdup_printf ("%s can't have label or labelled-by", role_name); *hint = g_strdup_printf ("%s can't have label", role_name);
return SEVERITY_ERROR; return SEVERITY_ERROR;
} }
@ -288,36 +216,30 @@ check_accessibility_errors (GtkWidget *widget,
} }
break; break;
case NAMING_RECOMMENDED: case GTK_ACCESSIBLE_NAME_RECOMMENDED:
if (label_set) if (label_set)
{ {
return SEVERITY_GOOD; return SEVERITY_GOOD;
} }
else else
{ {
*hint = g_strdup_printf ("label or labelled-by recommended for %s", role_name); *hint = g_strdup_printf ("label recommended for %s", role_name);
return SEVERITY_RECOMMENDATION; return SEVERITY_RECOMMENDATION;
} }
break; break;
case NAMING_CONDITIONAL: case GTK_ACCESSIBLE_NAME_NOT_RECOMMENDED:
{ if (!label_set)
char *name = gtk_at_context_get_name (context); {
return SEVERITY_GOOD;
}
else
{
*hint = g_strdup_printf ("label not recommended for %s", role_name);
if (strcmp (name, "") == 0) return SEVERITY_RECOMMENDATION;
{ }
g_free (name);
*hint = g_strdup_printf ("%s must have text content, label or labelled-by",
role_name);
return SEVERITY_ERROR;
}
else
{
return SEVERITY_GOOD;
}
}
break; break;
default: default: