Merge branch 'accessible_help_text' into 'main'

accessible help text

See merge request GNOME/gtk!6992
This commit is contained in:
Matthias Clasen 2024-05-02 17:20:17 +00:00
commit 032a5afc20
7 changed files with 51 additions and 9 deletions

View File

@ -155,6 +155,7 @@ Each property name is part of the `GtkAccessibleProperty` enumeration.
| %GTK_ACCESSIBLE_PROPERTY_VALUE_MIN | “aria-valuemin” | double |
| %GTK_ACCESSIBLE_PROPERTY_VALUE_NOW | “aria-valuenow” | double |
| %GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT | “aria-valuetext” | translatable string |
| %GTK_ACCESSIBLE_PROPERTY_HELP_TEXT | N/A | translatable string |
#### List of accessible relations
@ -216,6 +217,10 @@ are accessible as part of the development process. The GTK Inspector shows
the accessible attributes of each widget, and also provides an overlay that
can highlight accessibility issues.
If you support some non-standard keyboard interactions for a widget, you
**should** set an appropriate `GTK_ACCESSIBLE_PROPERTY_HELP_TEXT` to help
discoverability of the behavior.
It is possible to set accessible attributes in UI files as well:
```xml
<object class="GtkButton" id="button1">

View File

@ -720,6 +720,16 @@ handle_accessible_get_property (GDBusConnection *connection,
res = get_parent_context_ref (accessible);
else if (g_strcmp0 (property_name, "ChildCount") == 0)
res = g_variant_new_int32 (gtk_at_spi_context_get_child_count (self));
else if (g_strcmp0 (property_name, "HelpText"))
{
if (gtk_at_context_has_accessible_property (GTK_AT_CONTEXT (self), GTK_ACCESSIBLE_PROPERTY_HELP_TEXT))
{
GtkAccessibleValue *value = gtk_at_context_get_accessible_property (GTK_AT_CONTEXT (self), GTK_ACCESSIBLE_PROPERTY_HELP_TEXT);
res = g_variant_new_string (gtk_string_accessible_value_get (value));
}
else
res = g_variant_new_string ("");
}
else
g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,
"Unknown property '%s'", property_name);
@ -1136,7 +1146,7 @@ gtk_at_spi_context_state_change (GtkATContext *ctx,
}
if (changed_properties & GTK_ACCESSIBLE_PROPERTY_CHANGE_DESCRIPTION)
{
{
char *label = gtk_at_context_get_description (GTK_AT_CONTEXT (self));
GVariant *v = g_variant_new_take_string (label);
emit_property_changed (self, "accessible-description", v);
@ -1149,6 +1159,14 @@ gtk_at_spi_context_state_change (GtkATContext *ctx,
"accessible-value",
g_variant_new_double (gtk_number_accessible_value_get (value)));
}
if (changed_properties & GTK_ACCESSIBLE_PROPERTY_CHANGE_HELP_TEXT)
{
value = gtk_accessible_attribute_set_get_value (properties, GTK_ACCESSIBLE_PROPERTY_HELP_TEXT);
emit_property_changed (self,
"accessible-help-text",
g_variant_new_string (gtk_string_accessible_value_get (value)));
}
}
static void

View File

@ -808,6 +808,11 @@ static const GtkAccessibleCollect collect_props[] = {
.ctype = GTK_ACCESSIBLE_COLLECT_STRING,
.name = "valuetext"
},
[GTK_ACCESSIBLE_PROPERTY_HELP_TEXT] = {
.value = GTK_ACCESSIBLE_PROPERTY_HELP_TEXT,
.ctype = GTK_ACCESSIBLE_COLLECT_STRING,
.name = "helptext"
},
};
/* § 6.6.4 Relationship Attributes */
@ -1662,7 +1667,7 @@ gtk_accessible_value_get_default_for_property (GtkAccessibleProperty property)
{
const GtkAccessibleCollect *cstate = &collect_props[property];
g_return_val_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT, NULL);
g_return_val_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_HELP_TEXT, NULL);
switch (cstate->value)
{
@ -1692,6 +1697,7 @@ gtk_accessible_value_get_default_for_property (GtkAccessibleProperty property)
case GTK_ACCESSIBLE_PROPERTY_PLACEHOLDER:
case GTK_ACCESSIBLE_PROPERTY_ROLE_DESCRIPTION:
case GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT:
case GTK_ACCESSIBLE_PROPERTY_HELP_TEXT:
return gtk_undefined_accessible_value_new ();
/* Token properties */
@ -1732,7 +1738,7 @@ gtk_accessible_value_collect_for_property (GtkAccessibleProperty property,
{
const GtkAccessibleCollect *cstate = &collect_props[property];
g_return_val_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT, NULL);
g_return_val_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_HELP_TEXT, NULL);
return gtk_accessible_value_collect_valist (cstate, error, args);
}
@ -1760,7 +1766,7 @@ gtk_accessible_value_collect_for_property_value (GtkAccessibleProperty propert
{
const GtkAccessibleCollect *cstate = &collect_props[property];
g_return_val_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT, NULL);
g_return_val_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_HELP_TEXT, NULL);
return gtk_accessible_value_collect_value (cstate, value, error);
}
@ -1773,7 +1779,7 @@ gtk_accessible_value_parse_for_property (GtkAccessibleProperty property,
{
const GtkAccessibleCollect *cstate = &collect_props[property];
g_return_val_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT, NULL);
g_return_val_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_HELP_TEXT, NULL);
return gtk_accessible_value_parse (cstate, str, len, error);
}
@ -1794,7 +1800,7 @@ gtk_accessible_property_init_value (GtkAccessibleProperty property,
{
const GtkAccessibleCollect *cstate = &collect_props[property];
g_return_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT);
g_return_if_fail (property <= GTK_ACCESSIBLE_PROPERTY_HELP_TEXT);
gtk_accessible_attribute_init_value (cstate, value);
}

View File

@ -328,6 +328,7 @@ static const char *property_attrs[] = {
[GTK_ACCESSIBLE_PROPERTY_VALUE_MIN] = "valuemin",
[GTK_ACCESSIBLE_PROPERTY_VALUE_NOW] = "valuenow",
[GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT] = "valuetext",
[GTK_ACCESSIBLE_PROPERTY_HELP_TEXT] = "helptext",
};
/*< private >
@ -342,7 +343,7 @@ const char *
gtk_accessible_property_get_attribute_name (GtkAccessibleProperty property)
{
g_return_val_if_fail (property >= GTK_ACCESSIBLE_PROPERTY_AUTOCOMPLETE &&
property <= GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT,
property <= GTK_ACCESSIBLE_PROPERTY_HELP_TEXT,
"<none>");
return property_attrs[property];

View File

@ -47,7 +47,8 @@ typedef enum {
GTK_ACCESSIBLE_PROPERTY_CHANGE_VALUE_MAX = 1 << GTK_ACCESSIBLE_PROPERTY_VALUE_MAX,
GTK_ACCESSIBLE_PROPERTY_CHANGE_VALUE_MIN = 1 << GTK_ACCESSIBLE_PROPERTY_VALUE_MIN,
GTK_ACCESSIBLE_PROPERTY_CHANGE_VALUE_NOW = 1 << GTK_ACCESSIBLE_PROPERTY_VALUE_NOW,
GTK_ACCESSIBLE_PROPERTY_CHANGE_VALUE_TEXT = 1 << GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT
GTK_ACCESSIBLE_PROPERTY_CHANGE_VALUE_TEXT = 1 << GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT,
GTK_ACCESSIBLE_PROPERTY_CHANGE_HELP_TEXT = 1 << GTK_ACCESSIBLE_PROPERTY_HELP_TEXT,
} GtkAccessiblePropertyChange;
typedef enum {

View File

@ -1632,6 +1632,15 @@ typedef enum {
*
* The possible accessible properties of a [iface@Accessible].
*/
/**
* GTK_ACCESSIBLE_PROPERTY_HELP_TEXT:
*
* Defines a string value that provides a description of non-standard keyboard
* interactions of the current element. Value type: string
*
* Since: 4.16
*/
typedef enum {
GTK_ACCESSIBLE_PROPERTY_AUTOCOMPLETE,
GTK_ACCESSIBLE_PROPERTY_DESCRIPTION,
@ -1651,7 +1660,8 @@ typedef enum {
GTK_ACCESSIBLE_PROPERTY_VALUE_MAX,
GTK_ACCESSIBLE_PROPERTY_VALUE_MIN,
GTK_ACCESSIBLE_PROPERTY_VALUE_NOW,
GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT
GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT,
GTK_ACCESSIBLE_PROPERTY_HELP_TEXT
} GtkAccessibleProperty;
/**

View File

@ -649,6 +649,7 @@ main (int argc, char *argv[])
g_test_add_data_func ("/a11y/property/value-min", GUINT_TO_POINTER (GTK_ACCESSIBLE_PROPERTY_VALUE_MIN), test_number_property);
g_test_add_data_func ("/a11y/property/value-now", GUINT_TO_POINTER (GTK_ACCESSIBLE_PROPERTY_VALUE_NOW), test_number_property);
g_test_add_data_func ("/a11y/property/value-text", GUINT_TO_POINTER (GTK_ACCESSIBLE_PROPERTY_VALUE_TEXT), test_string_property);
g_test_add_data_func ("/a11y/property/help-text", GUINT_TO_POINTER (GTK_ACCESSIBLE_PROPERTY_HELP_TEXT), test_string_property);
g_test_add_func ("/a11y/property/update-multiple", test_update_multiple_properties);