Add gtk_accessible_role_is_abstract

Move this code from the a11y overlay in the inspector.
It will be used more widely, going forward.
This commit is contained in:
Matthias Clasen 2023-06-16 14:55:06 -04:00
parent b84650c2a3
commit 152a335cee
3 changed files with 42 additions and 27 deletions

View File

@ -881,6 +881,42 @@ gtk_accessible_role_is_range_subclass (GtkAccessibleRole role)
return FALSE; return FALSE;
} }
/* < private >
* gtk_accessible_role_is_abstract:
* @role: a `GtkAccessibleRole`
*
* Checks if @role is considered abstract and should not be used
* for concrete widgets.
*
* Returns: whether the role is abstract
*/
gboolean
gtk_accessible_role_is_abstract (GtkAccessibleRole role)
{
switch ((int) role)
{
case GTK_ACCESSIBLE_ROLE_COMMAND:
case GTK_ACCESSIBLE_ROLE_COMPOSITE:
case GTK_ACCESSIBLE_ROLE_INPUT:
case GTK_ACCESSIBLE_ROLE_LANDMARK:
case GTK_ACCESSIBLE_ROLE_RANGE:
case GTK_ACCESSIBLE_ROLE_SECTION:
case GTK_ACCESSIBLE_ROLE_SECTION_HEAD:
case GTK_ACCESSIBLE_ROLE_SELECT:
case GTK_ACCESSIBLE_ROLE_STRUCTURE:
#if 0
/* FIXME: ARIA considers these abstract.
* But we are using them for widgets
*/
case GTK_ACCESSIBLE_ROLE_WIDGET:
case GTK_ACCESSIBLE_ROLE_WINDOW:
#endif
return TRUE;
default:
return FALSE;
}
}
/*< private > /*< private >
* gtk_accessible_platform_changed: * gtk_accessible_platform_changed:
* @self: a `GtkAccessible` * @self: a `GtkAccessible`

View File

@ -55,7 +55,9 @@ typedef enum {
const char * gtk_accessible_role_to_name (GtkAccessibleRole role, const char * gtk_accessible_role_to_name (GtkAccessibleRole role,
const char *domain); const char *domain);
gboolean gtk_accessible_role_is_range_subclass (GtkAccessibleRole role); gboolean gtk_accessible_role_is_range_subclass (GtkAccessibleRole role);
gboolean gtk_accessible_role_is_abstract (GtkAccessibleRole role);
/* < private > /* < private >
* GtkAccessibleNaming: * GtkAccessibleNaming:

View File

@ -46,25 +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)
static GtkAccessibleRole abstract_roles[] = {
GTK_ACCESSIBLE_ROLE_COMMAND,
GTK_ACCESSIBLE_ROLE_COMPOSITE,
GTK_ACCESSIBLE_ROLE_INPUT,
GTK_ACCESSIBLE_ROLE_LANDMARK,
GTK_ACCESSIBLE_ROLE_RANGE,
GTK_ACCESSIBLE_ROLE_SECTION,
GTK_ACCESSIBLE_ROLE_SECTION_HEAD,
GTK_ACCESSIBLE_ROLE_SELECT,
GTK_ACCESSIBLE_ROLE_STRUCTURE,
#if 0
/* FIXME: ARIA considers these abstract.
* But we are using them for widgets
*/
GTK_ACCESSIBLE_ROLE_WIDGET,
GTK_ACCESSIBLE_ROLE_WINDOW
#endif
};
typedef enum typedef enum
{ {
SEVERITY_GOOD, SEVERITY_GOOD,
@ -152,14 +133,10 @@ check_accessibility_errors (GtkWidget *widget,
gtk_at_context_realize (context); gtk_at_context_realize (context);
/* Check for abstract roles */ /* Check for abstract roles */
for (unsigned int i = 0; i < G_N_ELEMENTS (abstract_roles); i++) if (gtk_accessible_role_is_abstract (role))
{ {
if (role == abstract_roles[i]) *hint = g_strdup_printf ("%s is an abstract role", role_name);
{ return SEVERITY_ERROR;
*hint = g_strdup_printf ("%s is an abstract role", role_name);
return SEVERITY_ERROR;
}
} }
/* Check for name and description */ /* Check for name and description */