mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 06:00:22 +00:00
a11y: Don't copy attribute names in attribute sets
We only need these names when serializing a11y information for tests. And copying these strings is entirely unnecessary. So, just pass a callback instead.
This commit is contained in:
parent
b9da74590b
commit
3cfe69d711
@ -29,44 +29,41 @@ struct _GtkAccessibleAttributeSet
|
|||||||
{
|
{
|
||||||
gsize n_attributes;
|
gsize n_attributes;
|
||||||
|
|
||||||
|
GtkAccessibleAttributeNameFunc name_func;
|
||||||
GtkAccessibleAttributeDefaultFunc default_func;
|
GtkAccessibleAttributeDefaultFunc default_func;
|
||||||
|
|
||||||
GtkBitmask *attributes_set;
|
GtkBitmask *attributes_set;
|
||||||
|
|
||||||
char **attribute_names;
|
|
||||||
GtkAccessibleValue **attribute_values;
|
GtkAccessibleValue **attribute_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
static GtkAccessibleAttributeSet *
|
static GtkAccessibleAttributeSet *
|
||||||
gtk_accessible_attribute_set_init (GtkAccessibleAttributeSet *self,
|
gtk_accessible_attribute_set_init (GtkAccessibleAttributeSet *self,
|
||||||
gsize n_attributes,
|
gsize n_attributes,
|
||||||
const char **attribute_names,
|
GtkAccessibleAttributeNameFunc name_func,
|
||||||
GtkAccessibleAttributeDefaultFunc default_func)
|
GtkAccessibleAttributeDefaultFunc default_func)
|
||||||
{
|
{
|
||||||
self->n_attributes = n_attributes;
|
self->n_attributes = n_attributes;
|
||||||
|
self->name_func = name_func;
|
||||||
self->default_func = default_func;
|
self->default_func = default_func;
|
||||||
self->attribute_names = g_new (char *, n_attributes);
|
|
||||||
self->attribute_values = g_new (GtkAccessibleValue *, n_attributes);
|
self->attribute_values = g_new (GtkAccessibleValue *, n_attributes);
|
||||||
self->attributes_set = _gtk_bitmask_new ();
|
self->attributes_set = _gtk_bitmask_new ();
|
||||||
|
|
||||||
/* Initialize all attribute values, so we can always get the full attribute */
|
/* Initialize all attribute values, so we can always get the full attribute */
|
||||||
for (int i = 0; i < self->n_attributes; i++)
|
for (int i = 0; i < self->n_attributes; i++)
|
||||||
{
|
self->attribute_values[i] = (* self->default_func) (i);
|
||||||
self->attribute_names[i] = g_strdup (attribute_names[i]);
|
|
||||||
self->attribute_values[i] = (* self->default_func) (i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkAccessibleAttributeSet *
|
GtkAccessibleAttributeSet *
|
||||||
gtk_accessible_attribute_set_new (gsize n_attributes,
|
gtk_accessible_attribute_set_new (gsize n_attributes,
|
||||||
const char **attribute_names,
|
GtkAccessibleAttributeNameFunc name_func,
|
||||||
GtkAccessibleAttributeDefaultFunc default_func)
|
GtkAccessibleAttributeDefaultFunc default_func)
|
||||||
{
|
{
|
||||||
GtkAccessibleAttributeSet *set = g_rc_box_new0 (GtkAccessibleAttributeSet);
|
GtkAccessibleAttributeSet *set = g_rc_box_new0 (GtkAccessibleAttributeSet);
|
||||||
|
|
||||||
return gtk_accessible_attribute_set_init (set, n_attributes, attribute_names, default_func);
|
return gtk_accessible_attribute_set_init (set, n_attributes, name_func, default_func);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkAccessibleAttributeSet *
|
GtkAccessibleAttributeSet *
|
||||||
@ -84,13 +81,10 @@ gtk_accessible_attribute_set_free (gpointer data)
|
|||||||
|
|
||||||
for (int i = 0; i < self->n_attributes; i++)
|
for (int i = 0; i < self->n_attributes; i++)
|
||||||
{
|
{
|
||||||
g_free (self->attribute_names[i]);
|
|
||||||
|
|
||||||
if (self->attribute_values[i] != NULL)
|
if (self->attribute_values[i] != NULL)
|
||||||
gtk_accessible_value_unref (self->attribute_values[i]);
|
gtk_accessible_value_unref (self->attribute_values[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_free (self->attribute_names);
|
|
||||||
g_free (self->attribute_values);
|
g_free (self->attribute_values);
|
||||||
|
|
||||||
_gtk_bitmask_free (self->attributes_set);
|
_gtk_bitmask_free (self->attributes_set);
|
||||||
@ -247,7 +241,7 @@ gtk_accessible_attribute_set_print (GtkAccessibleAttributeSet *self,
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_string_append (buffer, " ");
|
g_string_append (buffer, " ");
|
||||||
g_string_append (buffer, self->attribute_names[i]);
|
g_string_append (buffer, self->name_func (i));
|
||||||
g_string_append (buffer, ": ");
|
g_string_append (buffer, ": ");
|
||||||
|
|
||||||
gtk_accessible_value_print (self->attribute_values[i], buffer);
|
gtk_accessible_value_print (self->attribute_values[i], buffer);
|
||||||
|
@ -27,10 +27,11 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
typedef struct _GtkAccessibleAttributeSet GtkAccessibleAttributeSet;
|
typedef struct _GtkAccessibleAttributeSet GtkAccessibleAttributeSet;
|
||||||
|
|
||||||
|
typedef const char *(* GtkAccessibleAttributeNameFunc) (int attribute);
|
||||||
typedef GtkAccessibleValue *(* GtkAccessibleAttributeDefaultFunc) (int attribute);
|
typedef GtkAccessibleValue *(* GtkAccessibleAttributeDefaultFunc) (int attribute);
|
||||||
|
|
||||||
GtkAccessibleAttributeSet * gtk_accessible_attribute_set_new (gsize n_attributes,
|
GtkAccessibleAttributeSet * gtk_accessible_attribute_set_new (gsize n_attributes,
|
||||||
const char **attr_names,
|
GtkAccessibleAttributeNameFunc name_func,
|
||||||
GtkAccessibleAttributeDefaultFunc default_func);
|
GtkAccessibleAttributeDefaultFunc default_func);
|
||||||
GtkAccessibleAttributeSet * gtk_accessible_attribute_set_ref (GtkAccessibleAttributeSet *self);
|
GtkAccessibleAttributeSet * gtk_accessible_attribute_set_ref (GtkAccessibleAttributeSet *self);
|
||||||
void gtk_accessible_attribute_set_unref (GtkAccessibleAttributeSet *self);
|
void gtk_accessible_attribute_set_unref (GtkAccessibleAttributeSet *self);
|
||||||
|
@ -384,15 +384,15 @@ gtk_at_context_init (GtkATContext *self)
|
|||||||
|
|
||||||
self->properties =
|
self->properties =
|
||||||
gtk_accessible_attribute_set_new (G_N_ELEMENTS (property_attrs),
|
gtk_accessible_attribute_set_new (G_N_ELEMENTS (property_attrs),
|
||||||
property_attrs,
|
(GtkAccessibleAttributeNameFunc) gtk_accessible_property_get_attribute_name,
|
||||||
(GtkAccessibleAttributeDefaultFunc) gtk_accessible_value_get_default_for_property);
|
(GtkAccessibleAttributeDefaultFunc) gtk_accessible_value_get_default_for_property);
|
||||||
self->relations =
|
self->relations =
|
||||||
gtk_accessible_attribute_set_new (G_N_ELEMENTS (relation_attrs),
|
gtk_accessible_attribute_set_new (G_N_ELEMENTS (relation_attrs),
|
||||||
relation_attrs,
|
(GtkAccessibleAttributeNameFunc) gtk_accessible_relation_get_attribute_name,
|
||||||
(GtkAccessibleAttributeDefaultFunc) gtk_accessible_value_get_default_for_relation);
|
(GtkAccessibleAttributeDefaultFunc) gtk_accessible_value_get_default_for_relation);
|
||||||
self->states =
|
self->states =
|
||||||
gtk_accessible_attribute_set_new (G_N_ELEMENTS (state_attrs),
|
gtk_accessible_attribute_set_new (G_N_ELEMENTS (state_attrs),
|
||||||
state_attrs,
|
(GtkAccessibleAttributeNameFunc) gtk_accessible_state_get_attribute_name,
|
||||||
(GtkAccessibleAttributeDefaultFunc) gtk_accessible_value_get_default_for_state);
|
(GtkAccessibleAttributeDefaultFunc) gtk_accessible_value_get_default_for_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user