css: Introduce _gtk_css_value_compute()
This commit is essentially a large reorganization. Instead of all value subtypes having their own compute function, there is the general _gtk_css_value_compute() function that then calls a vfunc on the subtype.
This commit is contained in:
@ -40,6 +40,33 @@ gtk_css_value_array_free (GtkCssValue *value)
|
||||
g_slice_free1 (sizeof (GtkCssValue) + sizeof (GtkCssValue *) * (value->n_values - 1), value);
|
||||
}
|
||||
|
||||
static GtkCssValue *
|
||||
gtk_css_value_array_compute (GtkCssValue *value,
|
||||
GtkStyleContext *context)
|
||||
{
|
||||
GtkCssValue *result;
|
||||
gboolean changed = FALSE;
|
||||
guint i;
|
||||
|
||||
if (value->n_values == 0)
|
||||
return _gtk_css_value_ref (value);
|
||||
|
||||
result = _gtk_css_array_value_new_from_array (value->values, value->n_values);
|
||||
for (i = 0; i < value->n_values; i++)
|
||||
{
|
||||
result->values[i] = _gtk_css_value_compute (value->values[i], context);
|
||||
changed |= (result->values[i] != value->values[i]);
|
||||
}
|
||||
|
||||
if (!changed)
|
||||
{
|
||||
_gtk_css_value_unref (result);
|
||||
return _gtk_css_value_ref (value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_css_value_array_equal (const GtkCssValue *value1,
|
||||
const GtkCssValue *value2)
|
||||
@ -89,6 +116,7 @@ gtk_css_value_array_print (const GtkCssValue *value,
|
||||
|
||||
static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
|
||||
gtk_css_value_array_free,
|
||||
gtk_css_value_array_compute,
|
||||
gtk_css_value_array_equal,
|
||||
gtk_css_value_array_transition,
|
||||
gtk_css_value_array_print
|
||||
@ -153,37 +181,6 @@ _gtk_css_array_value_parse (GtkCssParser *parser,
|
||||
return result;
|
||||
}
|
||||
|
||||
GtkCssValue *
|
||||
_gtk_css_array_value_compute (GtkCssValue *value,
|
||||
GtkCssValue * (* compute_func) (GtkCssValue *, GtkStyleContext *),
|
||||
GtkStyleContext *context)
|
||||
{
|
||||
GtkCssValue *result;
|
||||
gboolean changed = FALSE;
|
||||
guint i;
|
||||
|
||||
g_return_val_if_fail (value->class == >K_CSS_VALUE_ARRAY, NULL);
|
||||
g_return_val_if_fail (compute_func != NULL, NULL);
|
||||
|
||||
if (value->n_values == 0)
|
||||
return _gtk_css_value_ref (value);
|
||||
|
||||
result = _gtk_css_array_value_new_from_array (value->values, value->n_values);
|
||||
for (i = 0; i < value->n_values; i++)
|
||||
{
|
||||
result->values[i] = (* compute_func) (value->values[i], context);
|
||||
changed |= (result->values[i] != value->values[i]);
|
||||
}
|
||||
|
||||
if (!changed)
|
||||
{
|
||||
_gtk_css_value_unref (result);
|
||||
return _gtk_css_value_ref (value);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
GtkCssValue *
|
||||
_gtk_css_array_value_get_nth (const GtkCssValue *value,
|
||||
guint i)
|
||||
|
||||
Reference in New Issue
Block a user