Commit 7ed06480 authored by Emmanuele Bassi's avatar Emmanuele Bassi
Browse files

a11y: Add private API to clone a GtkATContext

Some widgets might want to override GtkAccessible and create their own
context in order to control the accessible role post-construction time.
To avoid explicitly copying the existing state over from the original
ATContext to the new one, we need a way to clone the context's state
from inside the ATContext itself.
parent f9db651f
......@@ -538,6 +538,61 @@ gtk_at_context_create (GtkAccessibleRole accessible_role,
return res;
}
/*< private >
* gtk_at_context_clone: (constructor)
* @self: the #GtkATContext to clone
* @role: the accessible role of the clone, or %GTK_ACCESSIBLE_ROLE_NONE to
* use the same accessible role of @self
* @accessible: (nullable): the accessible creating the context, or %NULL to
* use the same #GtkAccessible of @self
* @display: (nullable): the display connection, or %NULL to use the same
* #GdkDisplay of @self
*
* Clones the state of the given #GtkATContext, using @role, @accessible,
* and @display.
*
* If @self is realized, the returned #GtkATContext will also be realized.
*
* Returns: (transfer full): the newly created #GtkATContext
*/
GtkATContext *
gtk_at_context_clone (GtkATContext *self,
GtkAccessibleRole role,
GtkAccessible *accessible,
GdkDisplay *display)
{
g_return_val_if_fail (self == NULL || GTK_IS_AT_CONTEXT (self), NULL);
g_return_val_if_fail (accessible == NULL || GTK_IS_ACCESSIBLE (accessible), NULL);
g_return_val_if_fail (display == NULL || GDK_IS_DISPLAY (display), NULL);
if (self != NULL && role == GTK_ACCESSIBLE_ROLE_NONE)
role = self->accessible_role;
if (self != NULL && accessible == NULL)
accessible = self->accessible;
if (self != NULL && display == NULL)
display = self->display;
GtkATContext *res = gtk_at_context_create (role, accessible, display);
if (self != NULL)
{
g_clear_pointer (&res->states, gtk_accessible_attribute_set_unref);
g_clear_pointer (&res->properties, gtk_accessible_attribute_set_unref);
g_clear_pointer (&res->relations, gtk_accessible_attribute_set_unref);
res->states = gtk_accessible_attribute_set_ref (self->states);
res->properties = gtk_accessible_attribute_set_ref (self->properties);
res->relations = gtk_accessible_attribute_set_ref (self->relations);
if (self->realized)
gtk_at_context_realize (res);
}
return res;
}
gboolean
gtk_at_context_is_realized (GtkATContext *self)
{
......
......@@ -145,6 +145,11 @@ struct _GtkATContextClass
void (* unrealize) (GtkATContext *self);
};
GtkATContext * gtk_at_context_clone (GtkATContext *self,
GtkAccessibleRole role,
GtkAccessible *accessible,
GdkDisplay *display);
GdkDisplay * gtk_at_context_get_display (GtkATContext *self);
void gtk_at_context_realize (GtkATContext *self);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment