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:
Benjamin Otte 2012-07-11 06:56:07 +02:00
parent 3f00801e9a
commit 9b953829fb
31 changed files with 355 additions and 275 deletions

View File

@ -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 == &GTK_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)

View File

@ -33,9 +33,6 @@ GtkCssValue * _gtk_css_array_value_parse (GtkCssParser *
GtkCssValue * (* parse_func) (GtkCssParser *),
gboolean allow_none);
GtkCssValue * _gtk_css_array_value_compute (GtkCssValue *value,
GtkCssValue * (* compute_func) (GtkCssValue *, GtkStyleContext *),
GtkStyleContext *context);
GtkCssValue * _gtk_css_array_value_get_nth (const GtkCssValue *value,
guint i);
guint _gtk_css_array_value_get_n_values (const GtkCssValue *value);

View File

@ -40,6 +40,17 @@ gtk_css_value_bg_size_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
GtkCssValue *
gtk_css_value_bg_size_compute (GtkCssValue *value,
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);
}
static gboolean
gtk_css_value_bg_size_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -119,6 +130,7 @@ gtk_css_value_bg_size_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_BG_SIZE = {
gtk_css_value_bg_size_free,
gtk_css_value_bg_size_compute,
gtk_css_value_bg_size_equal,
gtk_css_value_bg_size_transition,
gtk_css_value_bg_size_print
@ -243,16 +255,3 @@ _gtk_css_bg_size_value_compute_size (const GtkCssValue *value,
out_width, out_height);
}
GtkCssValue *
_gtk_css_bg_size_value_compute (GtkCssValue *value,
GtkStyleContext *context)
{
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_BG_SIZE, NULL);
if (value->x == NULL && value->y == NULL)
return _gtk_css_value_ref (value);
return _gtk_css_bg_size_value_new (value->x ? _gtk_css_number_value_compute (value->x, context) : NULL,
value->y ? _gtk_css_number_value_compute (value->y, context) : NULL);
}

View File

@ -36,8 +36,6 @@ void _gtk_css_bg_size_value_compute_size (const GtkCssValue *bg_
double area_height,
double *out_width,
double *out_height);
GtkCssValue * _gtk_css_bg_size_value_compute (GtkCssValue *bg_size,
GtkStyleContext *context);
G_END_DECLS

View File

@ -41,6 +41,35 @@ gtk_css_value_border_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_border_compute (GtkCssValue *value,
GtkStyleContext *context)
{
GtkCssValue *computed;
gboolean changed = FALSE;
guint i;
computed = _gtk_css_border_value_new (NULL, NULL, NULL, NULL);
computed->fill = value->fill;
for (i = 0; i < 4; i++)
{
if (value->values[i])
{
computed->values[i] = _gtk_css_value_compute (value->values[i], context);
changed |= (computed->values[i] != value->values[i]);
}
}
if (!changed)
{
_gtk_css_value_unref (computed);
return _gtk_css_value_ref (value);
}
return computed;
}
static gboolean
gtk_css_value_border_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -99,6 +128,7 @@ gtk_css_value_border_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_BORDER = {
gtk_css_value_border_free,
gtk_css_value_border_compute,
gtk_css_value_border_equal,
gtk_css_value_border_transition,
gtk_css_value_border_print
@ -202,34 +232,3 @@ _gtk_css_border_value_get_left (const GtkCssValue *value)
return value->values[GTK_CSS_LEFT];
}
GtkCssValue *
_gtk_css_border_value_compute (GtkCssValue *value,
GtkStyleContext *context)
{
GtkCssValue *computed;
gboolean changed = FALSE;
guint i;
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_BORDER, NULL);
computed = _gtk_css_border_value_new (NULL, NULL, NULL, NULL);
computed->fill = value->fill;
for (i = 0; i < 4; i++)
{
if (value->values[i])
{
computed->values[i] = _gtk_css_number_value_compute (value->values[i], context);
changed |= (computed->values[i] != value->values[i]);
}
}
if (!changed)
{
_gtk_css_value_unref (computed);
return _gtk_css_value_ref (value);
}
return computed;
}

View File

@ -40,9 +40,6 @@ GtkCssValue * _gtk_css_border_value_get_right (const GtkCssValue *val
GtkCssValue * _gtk_css_border_value_get_bottom (const GtkCssValue *value);
GtkCssValue * _gtk_css_border_value_get_left (const GtkCssValue *value);
GtkCssValue * _gtk_css_border_value_compute (GtkCssValue *border,
GtkStyleContext *context);
G_END_DECLS

View File

@ -36,6 +36,24 @@ gtk_css_value_corner_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_corner_compute (GtkCssValue *corner,
GtkStyleContext *context)
{
GtkCssValue *x, *y;
x = _gtk_css_value_compute (corner->x, context);
y = _gtk_css_value_compute (corner->y, context);
if (x == corner->x && y == corner->y)
{
_gtk_css_value_unref (x);
_gtk_css_value_unref (y);
return _gtk_css_value_ref (corner);
}
return _gtk_css_corner_value_new (x, y);
}
static gboolean
gtk_css_value_corner_equal (const GtkCssValue *corner1,
const GtkCssValue *corner2)
@ -78,6 +96,7 @@ gtk_css_value_corner_print (const GtkCssValue *corner,
static const GtkCssValueClass GTK_CSS_VALUE_CORNER = {
gtk_css_value_corner_free,
gtk_css_value_corner_compute,
gtk_css_value_corner_equal,
gtk_css_value_corner_transition,
gtk_css_value_corner_print
@ -148,23 +167,3 @@ _gtk_css_corner_value_get_y (const GtkCssValue *corner,
return _gtk_css_number_value_get (corner->y, one_hundred_percent);
}
GtkCssValue *
_gtk_css_corner_value_compute (GtkCssValue *corner,
GtkStyleContext *context)
{
GtkCssValue *x, *y;
g_return_val_if_fail (corner->class == &GTK_CSS_VALUE_CORNER, NULL);
x = _gtk_css_number_value_compute (corner->x, context);
y = _gtk_css_number_value_compute (corner->y, context);
if (x == corner->x && y == corner->y)
{
_gtk_css_value_unref (x);
_gtk_css_value_unref (y);
return _gtk_css_value_ref (corner);
}
return _gtk_css_corner_value_new (x, y);
}

View File

@ -33,8 +33,6 @@ double _gtk_css_corner_value_get_x (const GtkCssValue *cor
double one_hundred_percent);
double _gtk_css_corner_value_get_y (const GtkCssValue *corner,
double one_hundred_percent);
GtkCssValue * _gtk_css_corner_value_compute (GtkCssValue *corner,
GtkStyleContext *context);
G_END_DECLS

View File

@ -49,6 +49,13 @@ gtk_css_value_ease_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_ease_compute (GtkCssValue *value,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_ease_equal (const GtkCssValue *ease1,
const GtkCssValue *ease2)
@ -125,6 +132,7 @@ gtk_css_value_ease_print (const GtkCssValue *ease,
static const GtkCssValueClass GTK_CSS_VALUE_EASE = {
gtk_css_value_ease_free,
gtk_css_value_ease_compute,
gtk_css_value_ease_equal,
gtk_css_value_ease_transition,
gtk_css_value_ease_print

View File

@ -34,6 +34,13 @@ gtk_css_value_engine_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_engine_compute (GtkCssValue *value,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_engine_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -67,6 +74,7 @@ gtk_css_value_engine_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_ENGINE = {
gtk_css_value_engine_free,
gtk_css_value_engine_compute,
gtk_css_value_engine_equal,
gtk_css_value_engine_transition,
gtk_css_value_engine_print

View File

@ -35,6 +35,13 @@ gtk_css_value_enum_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_enum_compute (GtkCssValue *value,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_enum_equal (const GtkCssValue *enum1,
const GtkCssValue *enum2)
@ -61,6 +68,7 @@ gtk_css_value_enum_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_BORDER_STYLE = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@ -115,6 +123,7 @@ _gtk_css_border_style_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_STYLE = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@ -162,6 +171,7 @@ _gtk_css_font_style_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@ -208,6 +218,7 @@ _gtk_css_font_variant_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
@ -275,6 +286,7 @@ _gtk_css_font_weight_value_get (const GtkCssValue *value)
static const GtkCssValueClass GTK_CSS_VALUE_AREA = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print

View File

@ -421,7 +421,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_number_value_compute (linear->angle, context);
copy->angle = _gtk_css_value_compute (linear->angle, 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 +438,7 @@ gtk_css_image_linear_compute (GtkCssImage *image,
FALSE);
if (stop->offset)
scopy->offset = _gtk_css_number_value_compute (stop->offset, context);
scopy->offset = _gtk_css_value_compute (stop->offset, context);
else
scopy->offset = NULL;
}

View File

@ -33,6 +33,28 @@ gtk_css_value_image_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_image_compute (GtkCssValue *value,
GtkStyleContext *context)
{
GtkCssImage *image, *computed;
image = _gtk_css_image_value_get_image (value);
if (image == NULL)
return _gtk_css_value_ref (value);
computed = _gtk_css_image_compute (image, context);
if (computed == image)
{
g_object_unref (computed);
return _gtk_css_value_ref (value);
}
return _gtk_css_image_value_new (computed);
}
static gboolean
gtk_css_value_image_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -66,6 +88,7 @@ gtk_css_value_image_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
gtk_css_value_image_free,
gtk_css_value_image_compute,
gtk_css_value_image_equal,
gtk_css_value_image_transition,
gtk_css_value_image_print

View File

@ -30,6 +30,14 @@ gtk_css_value_inherit_free (GtkCssValue *value)
g_assert_not_reached ();
}
static GtkCssValue *
gtk_css_value_inherit_compute (GtkCssValue *value,
GtkStyleContext *context)
{
/* This value should be caught further up */
g_return_val_if_reached (_gtk_css_value_ref (value));
}
static gboolean
gtk_css_value_inherit_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -54,6 +62,7 @@ gtk_css_value_inherit_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
gtk_css_value_inherit_free,
gtk_css_value_inherit_compute,
gtk_css_value_inherit_equal,
gtk_css_value_inherit_transition,
gtk_css_value_inherit_print

View File

@ -30,6 +30,14 @@ gtk_css_value_initial_free (GtkCssValue *value)
g_assert_not_reached ();
}
static GtkCssValue *
gtk_css_value_initial_compute (GtkCssValue *value,
GtkStyleContext *context)
{
/* This value should be caught further up */
g_return_val_if_reached (_gtk_css_value_ref (value));
}
static gboolean
gtk_css_value_initial_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -54,6 +62,7 @@ gtk_css_value_initial_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
gtk_css_value_initial_free,
gtk_css_value_initial_compute,
gtk_css_value_initial_equal,
gtk_css_value_initial_transition,
gtk_css_value_initial_print

View File

@ -33,6 +33,65 @@ gtk_css_value_number_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_number_compute (GtkCssValue *number,
GtkStyleContext *context)
{
switch (number->unit)
{
default:
g_assert_not_reached();
/* fall through */
case GTK_CSS_PERCENT:
case GTK_CSS_NUMBER:
case GTK_CSS_PX:
case GTK_CSS_DEG:
case GTK_CSS_S:
return _gtk_css_value_ref (number);
case GTK_CSS_PT:
return _gtk_css_number_value_new (number->value * 96.0 / 72.0,
GTK_CSS_PX);
case GTK_CSS_PC:
return _gtk_css_number_value_new (number->value * 96.0 / 72.0 * 12.0,
GTK_CSS_PX);
break;
case GTK_CSS_IN:
return _gtk_css_number_value_new (number->value * 96.0,
GTK_CSS_PX);
break;
case GTK_CSS_CM:
return _gtk_css_number_value_new (number->value * 96.0 * 0.39370078740157477,
GTK_CSS_PX);
break;
case GTK_CSS_MM:
return _gtk_css_number_value_new (number->value * 96.0 * 0.039370078740157477,
GTK_CSS_PX);
break;
case GTK_CSS_EM:
return _gtk_css_number_value_new (number->value *
_gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100),
GTK_CSS_PX);
break;
case GTK_CSS_EX:
/* for now we pretend ex is half of em */
return _gtk_css_number_value_new (number->value * 0.5 *
_gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100),
GTK_CSS_PX);
case GTK_CSS_RAD:
return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI),
GTK_CSS_DEG);
case GTK_CSS_GRAD:
return _gtk_css_number_value_new (number->value * 360.0 / 400.0,
GTK_CSS_DEG);
case GTK_CSS_TURN:
return _gtk_css_number_value_new (number->value * 360.0,
GTK_CSS_DEG);
case GTK_CSS_MS:
return _gtk_css_number_value_new (number->value / 1000.0,
GTK_CSS_S);
}
}
static gboolean
gtk_css_value_number_equal (const GtkCssValue *number1,
const GtkCssValue *number2)
@ -88,6 +147,7 @@ gtk_css_value_number_print (const GtkCssValue *number,
static const GtkCssValueClass GTK_CSS_VALUE_NUMBER = {
gtk_css_value_number_free,
gtk_css_value_number_compute,
gtk_css_value_number_equal,
gtk_css_value_number_transition,
gtk_css_value_number_print
@ -148,64 +208,3 @@ _gtk_css_number_value_get (const GtkCssValue *number,
return number->value;
}
GtkCssValue *
_gtk_css_number_value_compute (GtkCssValue *number,
GtkStyleContext *context)
{
g_return_val_if_fail (number->class == &GTK_CSS_VALUE_NUMBER, NULL);
switch (number->unit)
{
default:
g_assert_not_reached();
/* fall through */
case GTK_CSS_PERCENT:
case GTK_CSS_NUMBER:
case GTK_CSS_PX:
case GTK_CSS_DEG:
case GTK_CSS_S:
return _gtk_css_value_ref (number);
case GTK_CSS_PT:
return _gtk_css_number_value_new (number->value * 96.0 / 72.0,
GTK_CSS_PX);
case GTK_CSS_PC:
return _gtk_css_number_value_new (number->value * 96.0 / 72.0 * 12.0,
GTK_CSS_PX);
break;
case GTK_CSS_IN:
return _gtk_css_number_value_new (number->value * 96.0,
GTK_CSS_PX);
break;
case GTK_CSS_CM:
return _gtk_css_number_value_new (number->value * 96.0 * 0.39370078740157477,
GTK_CSS_PX);
break;
case GTK_CSS_MM:
return _gtk_css_number_value_new (number->value * 96.0 * 0.039370078740157477,
GTK_CSS_PX);
break;
case GTK_CSS_EM:
return _gtk_css_number_value_new (number->value *
_gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100),
GTK_CSS_PX);
break;
case GTK_CSS_EX:
/* for now we pretend ex is half of em */
return _gtk_css_number_value_new (number->value * 0.5 *
_gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_FONT_SIZE), 100),
GTK_CSS_PX);
case GTK_CSS_RAD:
return _gtk_css_number_value_new (number->value * 360.0 / (2 * G_PI),
GTK_CSS_DEG);
case GTK_CSS_GRAD:
return _gtk_css_number_value_new (number->value * 360.0 / 400.0,
GTK_CSS_DEG);
case GTK_CSS_TURN:
return _gtk_css_number_value_new (number->value * 360.0,
GTK_CSS_DEG);
case GTK_CSS_MS:
return _gtk_css_number_value_new (number->value / 1000.0,
GTK_CSS_S);
}
}

View File

@ -45,8 +45,6 @@ GtkCssValue * _gtk_css_number_value_parse (GtkCssParser *par
GtkCssUnit _gtk_css_number_value_get_unit (const GtkCssValue *value);
double _gtk_css_number_value_get (const GtkCssValue *number,
double one_hundred_percent);
GtkCssValue * _gtk_css_number_value_compute (GtkCssValue *number,
GtkStyleContext *context);
G_END_DECLS

View File

@ -36,6 +36,24 @@ gtk_css_value_position_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_position_compute (GtkCssValue *position,
GtkStyleContext *context)
{
GtkCssValue *x, *y;
x = _gtk_css_value_compute (position->x, context);
y = _gtk_css_value_compute (position->y, context);
if (x == position->x && y == position->y)
{
_gtk_css_value_unref (x);
_gtk_css_value_unref (y);
return _gtk_css_value_ref (position);
}
return _gtk_css_position_value_new (x, y);
}
static gboolean
gtk_css_value_position_equal (const GtkCssValue *position1,
const GtkCssValue *position2)
@ -129,6 +147,7 @@ done:
static const GtkCssValueClass GTK_CSS_VALUE_POSITION = {
gtk_css_value_position_free,
gtk_css_value_position_compute,
gtk_css_value_position_equal,
gtk_css_value_position_transition,
gtk_css_value_position_print
@ -270,23 +289,3 @@ _gtk_css_position_value_get_y (const GtkCssValue *position,
return _gtk_css_number_value_get (position->y, one_hundred_percent);
}
GtkCssValue *
_gtk_css_position_value_compute (GtkCssValue *position,
GtkStyleContext *context)
{
GtkCssValue *x, *y;
g_return_val_if_fail (position->class == &GTK_CSS_VALUE_POSITION, NULL);
x = _gtk_css_number_value_compute (position->x, context);
y = _gtk_css_number_value_compute (position->y, context);
if (x == position->x && y == position->y)
{
_gtk_css_value_unref (x);
_gtk_css_value_unref (y);
return _gtk_css_value_ref (position);
}
return _gtk_css_position_value_new (x, y);
}

View File

@ -33,8 +33,6 @@ double _gtk_css_position_value_get_x (const GtkCssValue *p
double one_hundred_percent);
double _gtk_css_position_value_get_y (const GtkCssValue *position,
double one_hundred_percent);
GtkCssValue * _gtk_css_position_value_compute (GtkCssValue *position,
GtkStyleContext *context);
G_END_DECLS

View File

@ -33,6 +33,13 @@ gtk_css_value_repeat_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_repeat_compute (GtkCssValue *value,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_repeat_equal (const GtkCssValue *repeat1,
const GtkCssValue *repeat2)
@ -103,6 +110,7 @@ gtk_css_value_border_repeat_print (const GtkCssValue *repeat,
static const GtkCssValueClass GTK_CSS_VALUE_BACKGROUND_REPEAT = {
gtk_css_value_repeat_free,
gtk_css_value_repeat_compute,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
gtk_css_value_background_repeat_print
@ -110,6 +118,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_BACKGROUND_REPEAT = {
static const GtkCssValueClass GTK_CSS_VALUE_BORDER_REPEAT = {
gtk_css_value_repeat_free,
gtk_css_value_repeat_compute,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
gtk_css_value_border_repeat_print

View File

@ -34,6 +34,13 @@ gtk_css_value_rgba_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_rgba_compute (GtkCssValue *value,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_rgba_equal (const GtkCssValue *rgba1,
const GtkCssValue *rgba2)
@ -68,6 +75,7 @@ gtk_css_value_rgba_print (const GtkCssValue *rgba,
static const GtkCssValueClass GTK_CSS_VALUE_RGBA = {
gtk_css_value_rgba_free,
gtk_css_value_rgba_compute,
gtk_css_value_rgba_equal,
gtk_css_value_rgba_transition,
gtk_css_value_rgba_print

View File

@ -47,6 +47,25 @@ gtk_css_value_shadows_free (GtkCssValue *value)
g_slice_free1 (sizeof (GtkCssValue) + sizeof (GtkCssValue *) * (value->len - 1), value);
}
static GtkCssValue *
gtk_css_value_shadows_compute (GtkCssValue *value,
GtkStyleContext *context)
{
GtkCssValue *result;
guint i;
if (value->len == 0)
return _gtk_css_value_ref (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);
}
return result;
}
static gboolean
gtk_css_value_shadows_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -132,6 +151,7 @@ gtk_css_value_shadows_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_SHADOWS = {
gtk_css_value_shadows_free,
gtk_css_value_shadows_compute,
gtk_css_value_shadows_equal,
gtk_css_value_shadows_transition,
gtk_css_value_shadows_print
@ -190,27 +210,6 @@ _gtk_css_shadows_value_parse (GtkCssParser *parser)
return result;
}
GtkCssValue *
_gtk_css_shadows_value_compute (GtkCssValue *value,
GtkStyleContext *context)
{
GtkCssValue *result;
guint i;
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_SHADOWS, NULL);
if (value->len == 0)
return _gtk_css_value_ref (value);
result = gtk_css_shadows_value_new (value->values, value->len);
for (i = 0; i < value->len; i++)
{
result->values[i] = _gtk_css_shadow_value_compute (value->values[i], context);
}
return result;
}
void
_gtk_css_shadows_value_paint_layout (const GtkCssValue *shadows,
cairo_t *cr,

View File

@ -33,9 +33,6 @@ G_BEGIN_DECLS
GtkCssValue * _gtk_css_shadows_value_new_none (void);
GtkCssValue * _gtk_css_shadows_value_parse (GtkCssParser *parser);
GtkCssValue * _gtk_css_shadows_value_compute (GtkCssValue *shadows,
GtkStyleContext *context);
void _gtk_css_shadows_value_paint_layout (const GtkCssValue *shadows,
cairo_t *cr,
PangoLayout *layout);

View File

@ -59,6 +59,28 @@ gtk_css_value_shadow_free (GtkCssValue *shadow)
g_slice_free (GtkCssValue, shadow);
}
static GtkCssValue *
gtk_css_value_shadow_compute (GtkCssValue *shadow,
GtkStyleContext *context)
{
GdkRGBA transparent = { 0, 0, 0, 0 };
GtkCssValue *color, *fallback;
fallback = _gtk_css_symbolic_value_new_take_symbolic_color (gtk_symbolic_color_new_literal (&transparent));
color = _gtk_css_rgba_value_compute_from_symbolic (shadow->color,
fallback,
context,
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),
shadow->inset,
color);
}
static gboolean
gtk_css_value_shadow_equal (const GtkCssValue *shadow1,
const GtkCssValue *shadow2)
@ -117,6 +139,7 @@ gtk_css_value_shadow_print (const GtkCssValue *shadow,
static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
gtk_css_value_shadow_free,
gtk_css_value_shadow_compute,
gtk_css_value_shadow_equal,
gtk_css_value_shadow_transition,
gtk_css_value_shadow_print
@ -268,28 +291,6 @@ fail:
return NULL;
}
GtkCssValue *
_gtk_css_shadow_value_compute (GtkCssValue *shadow,
GtkStyleContext *context)
{
GdkRGBA transparent = { 0, 0, 0, 0 };
GtkCssValue *color, *fallback;
fallback = _gtk_css_symbolic_value_new_take_symbolic_color (gtk_symbolic_color_new_literal (&transparent));
color = _gtk_css_rgba_value_compute_from_symbolic (shadow->color,
fallback,
context,
FALSE);
_gtk_css_value_unref (fallback);
return gtk_css_shadow_value_new (_gtk_css_number_value_compute (shadow->hoffset, context),
_gtk_css_number_value_compute (shadow->voffset, context),
_gtk_css_number_value_compute (shadow->radius, context),
_gtk_css_number_value_compute (shadow->spread, context),
shadow->inset,
color);
}
void
_gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
cairo_t *cr,

View File

@ -34,9 +34,6 @@ GtkCssValue * _gtk_css_shadow_value_new_for_transition (GtkCssValue
GtkCssValue * _gtk_css_shadow_value_parse (GtkCssParser *parser);
GtkCssValue * _gtk_css_shadow_value_compute (GtkCssValue *shadow,
GtkStyleContext *context);
void _gtk_css_shadow_value_paint_layout (const GtkCssValue *shadow,
cairo_t *cr,
PangoLayout *layout);

View File

@ -32,6 +32,13 @@ gtk_css_value_string_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_string_compute (GtkCssValue *value,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_string_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -130,6 +137,7 @@ gtk_css_value_ident_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
gtk_css_value_string_free,
gtk_css_value_string_compute,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
gtk_css_value_string_print
@ -137,6 +145,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
gtk_css_value_string_free,
gtk_css_value_string_compute,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
gtk_css_value_ident_print

View File

@ -520,7 +520,7 @@ shadow_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_shadows_value_compute (specified, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -535,7 +535,7 @@ border_corner_radius_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_corner_value_compute (specified, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -561,22 +561,7 @@ css_image_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
GtkCssImage *image, *computed;
image = _gtk_css_image_value_get_image (specified);
if (image == NULL)
return _gtk_css_value_ref (specified);
computed = _gtk_css_image_compute (image, context);
if (computed == image)
{
g_object_unref (computed);
return _gtk_css_value_ref (specified);
}
return _gtk_css_image_value_new (computed);
return _gtk_css_value_compute (specified, context);
}
static void
@ -629,19 +614,12 @@ background_image_value_parse (GtkCssStyleProperty *property,
return _gtk_css_array_value_parse (parser, background_image_value_parse_one, FALSE);
}
static GtkCssValue *
background_image_value_compute_one (GtkCssValue *value,
GtkStyleContext *context)
{
return css_image_value_compute (NULL, context, value);
}
static GtkCssValue *
background_image_value_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_array_value_compute (specified, background_image_value_compute_one, context);
return _gtk_css_value_compute (specified, context);
}
static void
@ -679,7 +657,7 @@ font_size_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_number_value_compute (specified, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -696,7 +674,7 @@ outline_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_number_value_compute (specified, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -744,7 +722,7 @@ compute_border (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_border_value_compute (specified, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -827,7 +805,7 @@ compute_margin (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_number_value_compute (specified, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -845,7 +823,7 @@ compute_padding (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_number_value_compute (specified, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -874,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_number_value_compute (specified, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -910,7 +888,7 @@ background_size_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_array_value_compute (specified, _gtk_css_bg_size_value_compute, context);
return _gtk_css_value_compute (specified, context);
}
static GtkCssValue *
@ -925,7 +903,7 @@ background_position_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_array_value_compute (specified, _gtk_css_position_value_compute, context);
return _gtk_css_value_compute (specified, context);
}
/*** REGISTRATION ***/

View File

@ -33,6 +33,13 @@ gtk_css_value_typed_free (GtkCssValue *value)
g_slice_free (GtkCssValue, value);
}
static GtkCssValue *
gtk_css_value_typed_compute (GtkCssValue *value,
GtkStyleContext *context)
{
return _gtk_css_value_ref (value);
}
static gboolean
gtk_css_value_typed_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -57,6 +64,7 @@ gtk_css_value_typed_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_TYPED = {
gtk_css_value_typed_free,
gtk_css_value_typed_compute,
gtk_css_value_typed_equal,
gtk_css_value_typed_transition,
gtk_css_value_typed_print

View File

@ -61,6 +61,16 @@ _gtk_css_value_unref (GtkCssValue *value)
value->class->free (value);
}
GtkCssValue *
_gtk_css_value_compute (GtkCssValue *value,
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);
}
gboolean
_gtk_css_value_equal (const GtkCssValue *value1,
const GtkCssValue *value2)

View File

@ -23,6 +23,7 @@
#include <glib-object.h>
#include "gtkcsstypesprivate.h"
#include "gtksymboliccolor.h"
#include "gtktypes.h"
G_BEGIN_DECLS
@ -41,6 +42,8 @@ typedef struct _GtkCssValueClass GtkCssValueClass;
struct _GtkCssValueClass {
void (* free) (GtkCssValue *value);
GtkCssValue * (* compute) (GtkCssValue *value,
GtkStyleContext *context);
gboolean (* equal) (const GtkCssValue *value1,
const GtkCssValue *value2);
GtkCssValue * (* transition) (GtkCssValue *start,
@ -59,6 +62,8 @@ GtkCssValue *_gtk_css_value_alloc (const GtkCssValueClass
GtkCssValue *_gtk_css_value_ref (GtkCssValue *value);
void _gtk_css_value_unref (GtkCssValue *value);
GtkCssValue *_gtk_css_value_compute (GtkCssValue *value,
GtkStyleContext *context);
gboolean _gtk_css_value_equal (const GtkCssValue *value1,
const GtkCssValue *value2);
gboolean _gtk_css_value_equal0 (const GtkCssValue *value1,

View File

@ -117,6 +117,17 @@ gtk_css_value_symbolic_free (GtkCssValue *value)
g_slice_free (GtkSymbolicColor, color);
}
static GtkCssValue *
gtk_css_value_symbolic_compute (GtkCssValue *value,
GtkStyleContext *context)
{
/* for now we expect this to never be called
* because all cases are handled via
* _gtk_css_rgba_value_compute_from_symbolic()
*/
g_return_val_if_reached (_gtk_css_value_ref (value));
}
static gboolean
gtk_css_value_symbolic_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -180,6 +191,7 @@ gtk_css_value_symbolic_print (const GtkCssValue *value,
static const GtkCssValueClass GTK_CSS_VALUE_SYMBOLIC = {
gtk_css_value_symbolic_free,
gtk_css_value_symbolic_compute,
gtk_css_value_symbolic_equal,
gtk_css_value_symbolic_transition,
gtk_css_value_symbolic_print