From 6d562b61766bc6fd99df2439a4acddafa5f2b406 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Wed, 14 Oct 2020 23:34:51 -0400 Subject: [PATCH] listview: Set accessible roles Use the LIST and LIST_ITEM roles for GtkListView and its children. Use the GRID and GRID_CELL roles for GtkGridView and its children. --- gtk/gtkcolumnview.c | 2 +- gtk/gtkgridview.c | 7 +++++++ gtk/gtklistbase.c | 1 + gtk/gtklistbaseprivate.h | 1 + gtk/gtklistitemmanager.c | 6 +++++- gtk/gtklistitemmanagerprivate.h | 2 ++ gtk/gtklistitemwidget.c | 8 +++++++- gtk/gtklistitemwidgetprivate.h | 3 ++- gtk/gtklistview.c | 7 +++++++ 9 files changed, 33 insertions(+), 4 deletions(-) diff --git a/gtk/gtkcolumnview.c b/gtk/gtkcolumnview.c index 0f1ca8fd42..2e680fa4b7 100644 --- a/gtk/gtkcolumnview.c +++ b/gtk/gtkcolumnview.c @@ -1136,7 +1136,7 @@ gtk_column_view_init (GtkColumnView *self) self->columns = g_list_store_new (GTK_TYPE_COLUMN_VIEW_COLUMN); - self->header = gtk_list_item_widget_new (NULL, "header"); + self->header = gtk_list_item_widget_new (NULL, "header", GTK_ACCESSIBLE_ROLE_WIDGET); gtk_widget_set_can_focus (self->header, FALSE); gtk_widget_set_layout_manager (self->header, gtk_column_view_layout_new (self)); gtk_widget_set_parent (self->header, GTK_WIDGET (self)); diff --git a/gtk/gtkgridview.c b/gtk/gtkgridview.c index ba8ce422af..8c24afc9e1 100644 --- a/gtk/gtkgridview.c +++ b/gtk/gtkgridview.c @@ -30,6 +30,7 @@ #include "gtkprivate.h" #include "gtksingleselection.h" #include "gtkwidgetprivate.h" +#include "gtkmultiselection.h" /* Maximum number of list items created by the gridview. * For debugging, you can set this to G_MAXUINT to ensure @@ -1025,6 +1026,7 @@ gtk_grid_view_class_init (GtkGridViewClass *klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); list_base_class->list_item_name = "child"; + list_base_class->list_item_role = GTK_ACCESSIBLE_ROLE_GRID_CELL; list_base_class->list_item_size = sizeof (Cell); list_base_class->list_item_augment_size = sizeof (CellAugment); list_base_class->list_item_augment_func = cell_augment; @@ -1157,6 +1159,7 @@ gtk_grid_view_class_init (GtkGridViewClass *klass) gtk_grid_view_activate_item); gtk_widget_class_set_css_name (widget_class, I_("gridview")); + gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GRID); } static void @@ -1246,6 +1249,10 @@ gtk_grid_view_set_model (GtkGridView *self, if (!gtk_list_base_set_model (GTK_LIST_BASE (self), model)) return; + gtk_accessible_update_property (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_PROPERTY_MULTI_SELECTABLE, GTK_IS_MULTI_SELECTION (model), + -1); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]); } diff --git a/gtk/gtklistbase.c b/gtk/gtklistbase.c index 201bcb0844..ed4f84ad2a 100644 --- a/gtk/gtklistbase.c +++ b/gtk/gtklistbase.c @@ -1794,6 +1794,7 @@ gtk_list_base_init_real (GtkListBase *self, priv->item_manager = gtk_list_item_manager_new_for_size (GTK_WIDGET (self), g_class->list_item_name, + g_class->list_item_role, g_class->list_item_size, g_class->list_item_augment_size, g_class->list_item_augment_func); diff --git a/gtk/gtklistbaseprivate.h b/gtk/gtklistbaseprivate.h index fe640978b2..75d7466784 100644 --- a/gtk/gtklistbaseprivate.h +++ b/gtk/gtklistbaseprivate.h @@ -35,6 +35,7 @@ struct _GtkListBaseClass GtkWidgetClass parent_class; const char * list_item_name; + GtkAccessibleRole list_item_role; gsize list_item_size; gsize list_item_augment_size; GtkRbTreeAugmentFunc list_item_augment_func; diff --git a/gtk/gtklistitemmanager.c b/gtk/gtklistitemmanager.c index 7cad397ffa..c795653004 100644 --- a/gtk/gtklistitemmanager.c +++ b/gtk/gtklistitemmanager.c @@ -35,6 +35,7 @@ struct _GtkListItemManager GtkListItemFactory *factory; gboolean single_click_activate; const char *item_css_name; + GtkAccessibleRole item_role; GtkRbTree *items; GSList *trackers; @@ -111,6 +112,7 @@ gtk_list_item_manager_clear_node (gpointer _item) GtkListItemManager * gtk_list_item_manager_new_for_size (GtkWidget *widget, const char *item_css_name, + GtkAccessibleRole item_role, gsize element_size, gsize augment_size, GtkRbTreeAugmentFunc augment_func) @@ -126,6 +128,7 @@ gtk_list_item_manager_new_for_size (GtkWidget *widget, /* not taking a ref because the widget refs us */ self->widget = widget; self->item_css_name = g_intern_string (item_css_name); + self->item_role = item_role; self->items = gtk_rb_tree_new_for_size (element_size, augment_size, @@ -923,7 +926,8 @@ gtk_list_item_manager_acquire_list_item (GtkListItemManager *self, g_return_val_if_fail (prev_sibling == NULL || GTK_IS_WIDGET (prev_sibling), NULL); result = gtk_list_item_widget_new (self->factory, - self->item_css_name); + self->item_css_name, + self->item_role); gtk_list_item_widget_set_single_click_activate (GTK_LIST_ITEM_WIDGET (result), self->single_click_activate); diff --git a/gtk/gtklistitemmanagerprivate.h b/gtk/gtklistitemmanagerprivate.h index baf4c51442..d2b4bbc433 100644 --- a/gtk/gtklistitemmanagerprivate.h +++ b/gtk/gtklistitemmanagerprivate.h @@ -22,6 +22,7 @@ #define __GTK_LIST_ITEM_MANAGER_H__ #include "gtk/gtktypes.h" +#include "gtk/gtkenums.h" #include "gtk/gtklistitemfactory.h" #include "gtk/gtkrbtreeprivate.h" @@ -58,6 +59,7 @@ GType gtk_list_item_manager_get_type (void) G_GNUC_CO GtkListItemManager * gtk_list_item_manager_new_for_size (GtkWidget *widget, const char *item_css_name, + GtkAccessibleRole item_role, gsize element_size, gsize augment_size, GtkRbTreeAugmentFunc augment_func); diff --git a/gtk/gtklistitemwidget.c b/gtk/gtklistitemwidget.c index ce4f505039..8f6a5c5633 100644 --- a/gtk/gtklistitemwidget.c +++ b/gtk/gtklistitemwidget.c @@ -453,12 +453,14 @@ gtk_list_item_widget_init (GtkListItemWidget *self) GtkWidget * gtk_list_item_widget_new (GtkListItemFactory *factory, - const char *css_name) + const char *css_name, + GtkAccessibleRole role) { g_return_val_if_fail (css_name != NULL, NULL); return g_object_new (GTK_TYPE_LIST_ITEM_WIDGET, "css-name", css_name, + "accessible-role", role, "factory", factory, NULL); } @@ -480,6 +482,10 @@ gtk_list_item_widget_update (GtkListItemWidget *self, gtk_widget_set_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED, FALSE); else gtk_widget_unset_state_flags (GTK_WIDGET (self), GTK_STATE_FLAG_SELECTED); + + gtk_accessible_update_state (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_STATE_SELECTED, selected, + -1); } void diff --git a/gtk/gtklistitemwidgetprivate.h b/gtk/gtklistitemwidgetprivate.h index 3042d08789..8f78b1a7a2 100644 --- a/gtk/gtklistitemwidgetprivate.h +++ b/gtk/gtklistitemwidgetprivate.h @@ -50,7 +50,8 @@ struct _GtkListItemWidgetClass GType gtk_list_item_widget_get_type (void) G_GNUC_CONST; GtkWidget * gtk_list_item_widget_new (GtkListItemFactory *factory, - const char *css_name); + const char *css_name, + GtkAccessibleRole role); void gtk_list_item_widget_update (GtkListItemWidget *self, guint position, diff --git a/gtk/gtklistview.c b/gtk/gtklistview.c index d04799b3a4..4953e1488e 100644 --- a/gtk/gtklistview.c +++ b/gtk/gtklistview.c @@ -30,6 +30,7 @@ #include "gtkrbtreeprivate.h" #include "gtkstylecontext.h" #include "gtkwidgetprivate.h" +#include "gtkmultiselection.h" /* Maximum number of list items created by the listview. * For debugging, you can set this to G_MAXUINT to ensure @@ -800,6 +801,7 @@ gtk_list_view_class_init (GtkListViewClass *klass) GObjectClass *gobject_class = G_OBJECT_CLASS (klass); list_base_class->list_item_name = "row"; + list_base_class->list_item_role = GTK_ACCESSIBLE_ROLE_LIST_ITEM; list_base_class->list_item_size = sizeof (ListRow); list_base_class->list_item_augment_size = sizeof (ListRowAugment); list_base_class->list_item_augment_func = list_row_augment; @@ -916,6 +918,7 @@ gtk_list_view_class_init (GtkListViewClass *klass) gtk_list_view_activate_item); gtk_widget_class_set_css_name (widget_class, I_("listview")); + gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_LIST); } static void @@ -1001,6 +1004,10 @@ gtk_list_view_set_model (GtkListView *self, if (!gtk_list_base_set_model (GTK_LIST_BASE (self), model)) return; + gtk_accessible_update_property (GTK_ACCESSIBLE (self), + GTK_ACCESSIBLE_PROPERTY_MULTI_SELECTABLE, GTK_IS_MULTI_SELECTION (model), + -1); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MODEL]); }