css: Pass property_id to compute function

This is a reorganization of how value computing should be done.
Previously the GtkCssStyleProperty.compute vfunc was supposed to take
care of special cases when it needed those for computation. However,
this proved to be very complicated in cases where values were nested and
only the last value (of a common type) needed to be special cased.

A common example for this was the fallback handling for unresolvable
colors.

Now, we pass the property's ID along with all compute functions so we
can do the special casing where it's necessary.
Note that no actual changes happen in this commit. This will happen in
follow-ups.
This commit is contained in:
Benjamin Otte 2012-07-12 03:43:15 +02:00
parent 9b953829fb
commit 9b4ed66218
26 changed files with 58 additions and 30 deletions

View File

@ -42,6 +42,7 @@ gtk_css_value_array_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_array_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
GtkCssValue *result;
@ -54,7 +55,7 @@ gtk_css_value_array_compute (GtkCssValue *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);
result->values[i] = _gtk_css_value_compute (value->values[i], property_id, context);
changed |= (result->values[i] != value->values[i]);
}

View File

@ -42,13 +42,14 @@ gtk_css_value_bg_size_free (GtkCssValue *value)
GtkCssValue *
gtk_css_value_bg_size_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
if (value->x == NULL && value->y == NULL)
return _gtk_css_value_ref (value);
return _gtk_css_bg_size_value_new (value->x ? _gtk_css_value_compute (value->x, context) : NULL,
value->y ? _gtk_css_value_compute (value->y, context) : NULL);
return _gtk_css_bg_size_value_new (value->x ? _gtk_css_value_compute (value->x, property_id, context) : NULL,
value->y ? _gtk_css_value_compute (value->y, property_id, context) : NULL);
}
static gboolean

View File

@ -43,6 +43,7 @@ gtk_css_value_border_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_border_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
GtkCssValue *computed;
@ -56,7 +57,7 @@ gtk_css_value_border_compute (GtkCssValue *value,
{
if (value->values[i])
{
computed->values[i] = _gtk_css_value_compute (value->values[i], context);
computed->values[i] = _gtk_css_value_compute (value->values[i], property_id, context);
changed |= (computed->values[i] != value->values[i]);
}
}

View File

@ -38,12 +38,13 @@ gtk_css_value_corner_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_corner_compute (GtkCssValue *corner,
guint property_id,
GtkStyleContext *context)
{
GtkCssValue *x, *y;
x = _gtk_css_value_compute (corner->x, context);
y = _gtk_css_value_compute (corner->y, context);
x = _gtk_css_value_compute (corner->x, property_id, context);
y = _gtk_css_value_compute (corner->y, property_id, context);
if (x == corner->x && y == corner->y)
{
_gtk_css_value_unref (x);

View File

@ -51,6 +51,7 @@ gtk_css_value_ease_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_ease_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);

View File

@ -36,6 +36,7 @@ gtk_css_value_engine_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_engine_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);

View File

@ -37,6 +37,7 @@ gtk_css_value_enum_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_enum_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);

View File

@ -58,6 +58,7 @@ gtk_css_image_real_get_aspect_ratio (GtkCssImage *image)
static GtkCssImage *
gtk_css_image_real_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
{
return g_object_ref (image);
@ -115,6 +116,7 @@ _gtk_css_image_get_aspect_ratio (GtkCssImage *image)
GtkCssImage *
_gtk_css_image_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
{
GtkCssImageClass *klass;
@ -124,7 +126,7 @@ _gtk_css_image_compute (GtkCssImage *image,
klass = GTK_CSS_IMAGE_GET_CLASS (image);
return klass->compute (image, context);
return klass->compute (image, property_id, context);
}
void

View File

@ -28,6 +28,7 @@ G_DEFINE_TYPE (GtkCssImageGradient, _gtk_css_image_gradient, GTK_TYPE_CSS_IMAGE)
static GtkCssImage *
gtk_css_image_gradient_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
{
GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (image);

View File

@ -410,6 +410,7 @@ gtk_css_image_linear_print (GtkCssImage *image,
static GtkCssImage *
gtk_css_image_linear_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
{
static const GdkRGBA transparent = { 0, 0, 0, 0 };
@ -421,7 +422,7 @@ gtk_css_image_linear_compute (GtkCssImage *image,
copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
copy->repeating = linear->repeating;
copy->angle = _gtk_css_value_compute (linear->angle, context);
copy->angle = _gtk_css_value_compute (linear->angle, property_id, context);
fallback = _gtk_css_symbolic_value_new_take_symbolic_color (gtk_symbolic_color_new_literal (&transparent));
g_array_set_size (copy->stops, linear->stops->len);
@ -438,7 +439,7 @@ gtk_css_image_linear_compute (GtkCssImage *image,
FALSE);
if (stop->offset)
scopy->offset = _gtk_css_value_compute (stop->offset, context);
scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context);
else
scopy->offset = NULL;
}

View File

@ -56,6 +56,7 @@ struct _GtkCssImageClass
/* create "computed value" in CSS terms, returns a new reference */
GtkCssImage *(* compute) (GtkCssImage *image,
guint property_id,
GtkStyleContext *context);
/* draw to 0,0 with the given width and height */
@ -81,6 +82,7 @@ int _gtk_css_image_get_height (GtkCssImage *image);
double _gtk_css_image_get_aspect_ratio (GtkCssImage *image);
GtkCssImage * _gtk_css_image_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context);
void _gtk_css_image_draw (GtkCssImage *image,

View File

@ -35,6 +35,7 @@ gtk_css_value_image_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_image_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
GtkCssImage *image, *computed;
@ -44,7 +45,7 @@ gtk_css_value_image_compute (GtkCssValue *value,
if (image == NULL)
return _gtk_css_value_ref (value);
computed = _gtk_css_image_compute (image, context);
computed = _gtk_css_image_compute (image, property_id, context);
if (computed == image)
{

View File

@ -32,6 +32,7 @@ gtk_css_value_inherit_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_inherit_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
/* This value should be caught further up */

View File

@ -32,6 +32,7 @@ gtk_css_value_initial_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_initial_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
/* This value should be caught further up */

View File

@ -35,6 +35,7 @@ gtk_css_value_number_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_number_compute (GtkCssValue *number,
guint property_id,
GtkStyleContext *context)
{
switch (number->unit)

View File

@ -38,12 +38,13 @@ gtk_css_value_position_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_position_compute (GtkCssValue *position,
guint property_id,
GtkStyleContext *context)
{
GtkCssValue *x, *y;
x = _gtk_css_value_compute (position->x, context);
y = _gtk_css_value_compute (position->y, context);
x = _gtk_css_value_compute (position->x, property_id, context);
y = _gtk_css_value_compute (position->y, property_id, context);
if (x == position->x && y == position->y)
{
_gtk_css_value_unref (x);

View File

@ -35,6 +35,7 @@ gtk_css_value_repeat_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_repeat_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);

View File

@ -36,6 +36,7 @@ gtk_css_value_rgba_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_rgba_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);

View File

@ -49,6 +49,7 @@ gtk_css_value_shadows_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_shadows_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
GtkCssValue *result;
@ -60,7 +61,7 @@ gtk_css_value_shadows_compute (GtkCssValue *value,
result = gtk_css_shadows_value_new (value->values, value->len);
for (i = 0; i < value->len; i++)
{
result->values[i] = _gtk_css_value_compute (value->values[i], context);
result->values[i] = _gtk_css_value_compute (value->values[i], property_id, context);
}
return result;

View File

@ -61,6 +61,7 @@ gtk_css_value_shadow_free (GtkCssValue *shadow)
static GtkCssValue *
gtk_css_value_shadow_compute (GtkCssValue *shadow,
guint property_id,
GtkStyleContext *context)
{
GdkRGBA transparent = { 0, 0, 0, 0 };
@ -73,10 +74,10 @@ gtk_css_value_shadow_compute (GtkCssValue *shadow,
FALSE);
_gtk_css_value_unref (fallback);
return gtk_css_shadow_value_new (_gtk_css_value_compute (shadow->hoffset, context),
_gtk_css_value_compute (shadow->voffset, context),
_gtk_css_value_compute (shadow->radius, context),
_gtk_css_value_compute (shadow->spread, context),
return gtk_css_shadow_value_new (_gtk_css_value_compute (shadow->hoffset, property_id, context),
_gtk_css_value_compute (shadow->voffset, property_id, context),
_gtk_css_value_compute (shadow->radius, property_id, context),
_gtk_css_value_compute (shadow->spread, property_id, context),
shadow->inset,
color);
}

View File

@ -34,6 +34,7 @@ gtk_css_value_string_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_string_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);

View File

@ -520,7 +520,7 @@ shadow_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -535,7 +535,7 @@ border_corner_radius_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -561,7 +561,7 @@ css_image_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static void
@ -619,7 +619,7 @@ background_image_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static void
@ -657,7 +657,7 @@ font_size_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -674,7 +674,7 @@ outline_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -722,7 +722,7 @@ compute_border (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -805,7 +805,7 @@ compute_margin (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -823,7 +823,7 @@ compute_padding (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -852,7 +852,7 @@ compute_border_width (GtkCssStyleProperty *property,
border_style == GTK_BORDER_STYLE_HIDDEN)
return _gtk_css_number_value_new (0, GTK_CSS_PX);
else
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -888,7 +888,7 @@ background_size_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
@ -903,7 +903,7 @@ background_position_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_value_compute (specified, context);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
/*** REGISTRATION ***/

View File

@ -35,6 +35,7 @@ gtk_css_value_typed_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_typed_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);

View File

@ -63,12 +63,13 @@ _gtk_css_value_unref (GtkCssValue *value)
GtkCssValue *
_gtk_css_value_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
g_return_val_if_fail (value != NULL, NULL);
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
return value->class->compute (value, context);
return value->class->compute (value, property_id, context);
}
gboolean

View File

@ -43,6 +43,7 @@ struct _GtkCssValueClass {
void (* free) (GtkCssValue *value);
GtkCssValue * (* compute) (GtkCssValue *value,
guint property_id,
GtkStyleContext *context);
gboolean (* equal) (const GtkCssValue *value1,
const GtkCssValue *value2);
@ -63,6 +64,7 @@ GtkCssValue *_gtk_css_value_ref (GtkCssValue
void _gtk_css_value_unref (GtkCssValue *value);
GtkCssValue *_gtk_css_value_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context);
gboolean _gtk_css_value_equal (const GtkCssValue *value1,
const GtkCssValue *value2);

View File

@ -119,6 +119,7 @@ gtk_css_value_symbolic_free (GtkCssValue *value)
static GtkCssValue *
gtk_css_value_symbolic_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
/* for now we expect this to never be called