Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Clasen
c15bef545e gtk-demo: Use the new API
Make the app launcher demo get read by orca
using the new list item api.
2023-06-19 19:29:28 -04:00
Matthias Clasen
0025460866 Add a11y api to GtkListItem
The new function, gtk_list_item_update_accessible_names,
copyies the naming-related properties and relations
from the child to the GtkListItemWidget.
2023-06-19 19:29:28 -04:00
3 changed files with 85 additions and 1 deletions

View File

@@ -69,16 +69,23 @@ static void
bind_listitem_cb (GtkListItemFactory *factory,
GtkListItem *list_item)
{
GtkWidget *child;
GtkWidget *image;
GtkWidget *label;
GAppInfo *app_info;
image = gtk_widget_get_first_child (gtk_list_item_get_child (list_item));
child = gtk_list_item_get_child (list_item);
image = gtk_widget_get_first_child (child);
label = gtk_widget_get_next_sibling (image);
app_info = gtk_list_item_get_item (list_item);
gtk_image_set_from_gicon (GTK_IMAGE (image), g_app_info_get_icon (app_info));
gtk_label_set_label (GTK_LABEL (label), g_app_info_get_display_name (app_info));
gtk_accessible_update_relation (GTK_ACCESSIBLE (child),
GTK_ACCESSIBLE_RELATION_LABELLED_BY, label, NULL,
-1);
gtk_list_item_update_accessible_names (list_item);
}
/* In more complex code, we would also need functions to unbind and teardown

View File

@@ -22,6 +22,8 @@
#include "gtklistitemprivate.h"
#include "gtkcolumnviewcell.h"
#include "gtkaccessible.h"
#include "gtkatcontextprivate.h"
/**
* GtkListItem:
@@ -358,6 +360,78 @@ gtk_list_item_set_child (GtkListItem *self,
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CHILD]);
}
static void
copy_accessible_property (GtkAccessible *from,
GtkAccessible *to,
GtkAccessibleProperty property)
{
GtkATContext *source, *target;
GtkAccessibleValue *value;
source = gtk_accessible_get_at_context (from);
target = gtk_accessible_get_at_context (to);
if (gtk_at_context_has_accessible_property (source, property))
value = gtk_at_context_get_accessible_property (source, property);
else
value = NULL;
gtk_at_context_set_accessible_property (target, property, value);
}
static void
copy_accessible_relation (GtkAccessible *from,
GtkAccessible *to,
GtkAccessibleProperty relation)
{
GtkATContext *source, *target;
GtkAccessibleValue *value;
source = gtk_accessible_get_at_context (from);
target = gtk_accessible_get_at_context (to);
if (gtk_at_context_has_accessible_relation (source, relation))
value = gtk_at_context_get_accessible_relation (source, relation);
else
value = NULL;
gtk_at_context_set_accessible_relation (target, relation, value);
}
/**
* gtk_list_item_update_accessible_names:
* @self: a `GtkListItem`
*
* Copy the values of `GTK_ACCESSIBLE_PROPERTY_LABEL`,
* `GTK_ACCESSIBLE_RELATION_LABELLED_BY`, `GTK_ACCESSIBLE_PROPERTY_DESCIPTION`
* and `GTK_ACCESSIBLE_RELATION_DESCRIBED_BY` from the
* child to the widget with the `GTK_ACCESSIBLE_ROLE_LIST_ITEM` role.
*
* This function should be called on a bound `GtkListItem`
* when any of these accessible attributes change. Typically,
* this happens in the `bind` callback.
*
* Since: 4.12
*/
void
gtk_list_item_update_accessible_names (GtkListItem *self)
{
GtkAccessible *child, *owner;
g_return_if_fail (GTK_IS_LIST_ITEM (self));
if (self->child == NULL || self->owner == NULL)
return;
child = GTK_ACCESSIBLE (self->child);
owner = GTK_ACCESSIBLE (self->owner);
copy_accessible_property (child, owner, GTK_ACCESSIBLE_PROPERTY_LABEL);
copy_accessible_relation (child, owner, GTK_ACCESSIBLE_RELATION_LABELLED_BY);
copy_accessible_property (child, owner, GTK_ACCESSIBLE_PROPERTY_DESCRIPTION);
copy_accessible_relation (child, owner, GTK_ACCESSIBLE_RELATION_DESCRIBED_BY);
}
/**
* gtk_list_item_get_position: (attributes org.gtk.Method.get_property=position)
* @self: a `GtkListItem`

View File

@@ -59,5 +59,8 @@ void gtk_list_item_set_child (GtkListItem
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_list_item_get_child (GtkListItem *self);
GDK_AVAILABLE_IN_4_12
void gtk_list_item_update_accessible_names (GtkListItem *self);
G_END_DECLS