diff --git a/gtk/gtkaccessible.c b/gtk/gtkaccessible.c index dc56e7d3b3..3f1619e708 100644 --- a/gtk/gtkaccessible.c +++ b/gtk/gtkaccessible.c @@ -48,8 +48,8 @@ * Also note that when an accessible object does not correspond to a widget, * and it has children, whose implementation you don't control, * it is necessary to ensure the correct shape of the a11y tree - * by calling gtk_accessible_set_accessible_parent() and - * updating the sibling by gtk_accessible_update_next_accessible_sibling(). + * by calling [method@Gtk.Accessible.set_accessible_parent] and + * updating the sibling by [method@Gtk.Accessible.update_next_accessible_sibling]. */ #include "config.h" @@ -135,11 +135,19 @@ gtk_accessible_get_accessible_parent (GtkAccessible *self) /** * gtk_accessible_set_accessible_parent: - * @self: a `GtkAccessible` - * @parent: the parent `GtkAccessible` - * @next_sibling: the next accessible sibling of this `GtkAccessible` + * @self: an accessible object + * @parent: (nullable): the parent accessible object + * @next_sibling: (nullable): the sibling accessible object * - * Sets the parent and next sibling accessible of an accessible object + * Sets the parent and sibling of an accessible object. + * + * This function is meant to be used by accessible implementations that are + * not part of the widget hierarchy, and but act as a logical bridge between + * widgets. For instance, if a widget creates an object that holds metadata + * for each child, and you want that object to implement the `GtkAccessible` + * interface, you will use this function to ensure that the parent of each + * child widget is the metadata object, and the parent of each metadata + * object is the container widget. * * Since: 4.10 */ @@ -149,14 +157,16 @@ gtk_accessible_set_accessible_parent (GtkAccessible *self, GtkAccessible *next_sibling) { g_return_if_fail (GTK_IS_ACCESSIBLE (self)); + g_return_if_fail (parent == NULL || GTK_IS_ACCESSIBLE (parent)); + g_return_if_fail (next_sibling == NULL || GTK_IS_ACCESSIBLE (parent)); GtkATContext *context; context = gtk_accessible_get_at_context (self); if (context != NULL) - { - gtk_at_context_set_accessible_parent (context, parent); - gtk_at_context_set_next_accessible_sibling (context, next_sibling); - } + { + gtk_at_context_set_accessible_parent (context, parent); + gtk_at_context_set_next_accessible_sibling (context, next_sibling); + } } /** diff --git a/gtk/gtkatcontext.c b/gtk/gtkatcontext.c index 040bc43850..5b25a74703 100644 --- a/gtk/gtkatcontext.c +++ b/gtk/gtkatcontext.c @@ -476,12 +476,7 @@ gtk_at_context_set_accessible_parent (GtkATContext *self, { g_return_if_fail (GTK_IS_AT_CONTEXT (self)); - if (self->accessible_parent != parent) - { - if (self->accessible_parent != NULL) - g_object_unref (self->accessible_parent); - self->accessible_parent = g_object_ref (parent); - } + g_set_object (&self->accessible_parent, parent); } /*< private > @@ -513,12 +508,7 @@ gtk_at_context_set_next_accessible_sibling (GtkATContext *self, { g_return_if_fail (GTK_IS_AT_CONTEXT (self)); - if (self->next_accessible_sibling != sibling) - { - if (self->next_accessible_sibling != NULL) - g_object_unref (self->next_accessible_sibling); - self->next_accessible_sibling = g_object_ref (sibling); - } + g_set_object (&self->next_accessible_sibling, sibling); } /*< private > diff --git a/gtk/gtkstack.c b/gtk/gtkstack.c index 025bd663c7..e2e070a103 100644 --- a/gtk/gtkstack.c +++ b/gtk/gtkstack.c @@ -411,9 +411,9 @@ gtk_stack_page_set_property (GObject *object, case CHILD_PROP_CHILD: g_set_object (&info->widget, g_value_get_object (value)); gtk_accessible_set_accessible_parent ( - GTK_ACCESSIBLE (info->widget), - GTK_ACCESSIBLE (info), - NULL); + gtk_accessible_set_accessible_parent (GTK_ACCESSIBLE (info->widget), + GTK_ACCESSIBLE (info), + NULL); break; case CHILD_PROP_NAME: