css: Fix oversights in handling of used values

Some of the properties where currentcolor might make a difference
between computed and used value are arrays, so we need to be able
to resolve arrays of values. Change things around to make resolve
a GtkCssValue vfunc and turn the existing resolve() implementations
into implementations of that vfunc.

Fixes: #6814
This commit is contained in:
Matthias Clasen 2024-06-28 21:16:15 -04:00
parent d998d703ff
commit 89020892a8
44 changed files with 212 additions and 122 deletions

View File

@ -789,9 +789,7 @@ gtk_style_context_resolve_color (GtkStyleContext *context,
if (gtk_css_node_get_parent (priv->cssnode))
ctx.parent_style = gtk_css_node_get_style (gtk_css_node_get_parent (priv->cssnode));
val = gtk_css_color_value_resolve (color,
&ctx,
_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
val = gtk_css_value_resolve (color, &ctx, _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR));
if (val == NULL)
return FALSE;

View File

@ -724,10 +724,10 @@ update_links_cb (GtkAboutDialog *about)
GSList *l;
style = gtk_css_node_get_style (about->link_node);
link_color = *gtk_css_color_value_get_rgba (style->core->color);
link_color = *gtk_css_color_value_get_rgba (style->used->color);
style = gtk_css_node_get_style (about->visited_link_node);
visited_link_color = *gtk_css_color_value_get_rgba (style->core->color);
visited_link_color = *gtk_css_color_value_get_rgba (style->used->color);
for (l = about->link_tags; l != NULL; l = l->next)
{

View File

@ -74,6 +74,40 @@ gtk_css_value_array_compute (GtkCssValue *value,
return result;
}
static GtkCssValue *
gtk_css_value_array_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current)
{
GtkCssValue *result;
GtkCssValue *i_value;
guint i, j;
result = NULL;
for (i = 0; i < value->n_values; i++)
{
i_value = gtk_css_value_resolve (value->values[i], context, current);
if (result == NULL &&
i_value != value->values[i])
{
result = _gtk_css_array_value_new_from_array (value->values, value->n_values);
for (j = 0; j < i; j++)
gtk_css_value_ref (result->values[j]);
}
if (result != NULL)
result->values[i] = i_value;
else
gtk_css_value_unref (i_value);
}
if (result == NULL)
return gtk_css_value_ref (value);
return result;
}
static gboolean
gtk_css_value_array_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -364,6 +398,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
"GtkCssArrayValue",
gtk_css_value_array_free,
gtk_css_value_array_compute,
gtk_css_value_array_resolve,
gtk_css_value_array_equal,
gtk_css_value_array_transition,
gtk_css_value_array_is_dynamic,
@ -398,6 +433,7 @@ _gtk_css_array_value_new_from_array (GtkCssValue **values,
result->is_computed = TRUE;
result->contains_variables = FALSE;
result->contains_current_color = FALSE;
for (i = 0; i < n_values; i ++)
{
if (!gtk_css_value_is_computed (values[i]))
@ -406,7 +442,10 @@ _gtk_css_array_value_new_from_array (GtkCssValue **values,
if (gtk_css_value_contains_variables (values[i]))
result->contains_variables = TRUE;
if (!result->is_computed && result->contains_variables)
if (gtk_css_value_contains_current_color (values[i]))
result->contains_current_color = TRUE;
if (!result->is_computed && result->contains_variables && result->contains_current_color)
break;
}
@ -468,5 +507,3 @@ _gtk_css_array_value_get_n_values (const GtkCssValue *value)
return value->n_values;
}

View File

@ -37,6 +37,5 @@ GtkCssValue * _gtk_css_array_value_get_nth (GtkCssValue *
guint i);
guint _gtk_css_array_value_get_n_values (const GtkCssValue *value) G_GNUC_PURE;
G_END_DECLS

View File

@ -154,6 +154,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_BG_SIZE = {
"GtkCssBgSizeValue",
gtk_css_value_bg_size_free,
gtk_css_value_bg_size_compute,
NULL,
gtk_css_value_bg_size_equal,
gtk_css_value_bg_size_transition,
NULL,

View File

@ -141,6 +141,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_BORDER = {
"GtkCssBorderValue",
gtk_css_value_border_free,
gtk_css_value_border_compute,
NULL,
gtk_css_value_border_equal,
gtk_css_value_border_transition,
NULL,

View File

@ -46,6 +46,9 @@ static GtkCssValue * gtk_css_color_value_new_color_mix (GtkCssColorSpace
GtkCssValue *color2,
float percentage1,
float percentage2);
static GtkCssValue * gtk_css_color_value_resolve (GtkCssValue *color,
GtkCssComputeContext *context,
GtkCssValue *current);
typedef enum {
COLOR_TYPE_COLOR,
@ -193,13 +196,21 @@ gtk_css_value_color_compute (GtkCssValue *value,
guint property_id,
GtkCssComputeContext *context)
{
GtkCssValue *resolved;
GtkCssValue *computed;
resolved = gtk_css_color_value_resolve (value, context, NULL);
if (resolved == NULL)
computed = gtk_css_color_value_resolve (value, context, NULL);
if (computed == NULL)
return gtk_css_value_color_get_fallback (property_id, context);
return resolved;
return computed;
}
static GtkCssValue *
gtk_css_value_color_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current)
{
return gtk_css_color_value_resolve (value, context, current);
}
static gboolean
@ -512,6 +523,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_COLOR = {
"GtkCssColorValue",
gtk_css_value_color_free,
gtk_css_value_color_compute,
gtk_css_value_color_resolve,
gtk_css_value_color_equal,
gtk_css_value_color_transition,
NULL,
@ -798,7 +810,7 @@ gtk_css_color_value_do_resolve (GtkCssValue *color,
* to fully resolve color values that contain currentcolor
* references
*/
GtkCssValue *
static GtkCssValue *
gtk_css_color_value_resolve (GtkCssValue *color,
GtkCssComputeContext *context,
GtkCssValue *current)

View File

@ -33,10 +33,6 @@ GtkCssValue * gtk_css_color_value_new_name (const char *name) G
gboolean gtk_css_color_value_can_parse (GtkCssParser *parser);
GtkCssValue * gtk_css_color_value_parse (GtkCssParser *parser);
GtkCssValue * gtk_css_color_value_resolve (GtkCssValue *color,
GtkCssComputeContext *context,
GtkCssValue *current);
const GdkRGBA * gtk_css_color_value_get_rgba (const GtkCssValue *color) G_GNUC_CONST;
GtkCssValue * gtk_css_color_value_new_color (GtkCssColorSpace color_space,

View File

@ -100,6 +100,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_CORNER = {
"GtkCssCornerValue",
gtk_css_value_corner_free,
gtk_css_value_corner_compute,
NULL,
gtk_css_value_corner_equal,
gtk_css_value_corner_transition,
NULL,

View File

@ -136,6 +136,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_EASE = {
"GtkCssEaseValue",
gtk_css_value_ease_free,
gtk_css_value_ease_compute,
NULL,
gtk_css_value_ease_equal,
gtk_css_value_ease_transition,
NULL,

View File

@ -77,6 +77,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_BORDER_STYLE = {
"GtkCssBorderStyleValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -135,6 +136,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_BLEND_MODE = {
"GtkCssBlendModeValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -288,6 +290,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_SIZE = {
"GtkCssFontSizeValue",
gtk_css_value_enum_free,
gtk_css_value_font_size_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -345,6 +348,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_STYLE = {
"GtkCssFontStyleValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -442,6 +446,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
"GtkCssFontWeightValue",
gtk_css_value_enum_free,
gtk_css_value_font_weight_compute,
NULL,
gtk_css_value_enum_equal,
NULL,
NULL,
@ -492,6 +497,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_STRETCH = {
"GtkCssFontStretchValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -549,6 +555,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_TEXT_DECORATION_STYLE = {
"GtkCssTextDecorationStyleValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -600,6 +607,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_AREA = {
"GtkCssAreaValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -657,6 +665,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_DIRECTION = {
"GtkCssDirectionValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -718,6 +727,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_PLAY_STATE = {
"GtkCssPlayStateValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -774,6 +784,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FILL_MODE = {
"GtkCssFillModeValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -832,6 +843,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_ICON_STYLE = {
"GtkCssIconStyleValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -889,6 +901,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_KERNING = {
"GtkCssFontKerningValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -946,6 +959,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_POSITION = {
"GtkCssFontVariationPositionValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -1003,6 +1017,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_CAPS = {
"GtkCssFontVariantCapsValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -1064,6 +1079,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_ALTERNATE = {
"GtkCssFontVariantAlternateValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,
@ -1172,6 +1188,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_TEXT_DECORATION_LINE = {
"GtkCssTextDecorationLine",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_flags_equal,
gtk_css_value_enum_transition,
NULL,
@ -1271,6 +1288,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_LIGATURE = {
"GtkCssFontVariantLigatureValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_flags_equal,
gtk_css_value_enum_transition,
NULL,
@ -1379,6 +1397,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_NUMERIC = {
"GtkCssFontVariantNumbericValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_flags_equal,
gtk_css_value_enum_transition,
NULL,
@ -1484,6 +1503,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIANT_EAST_ASIAN = {
"GtkCssFontVariantEastAsianValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_flags_equal,
gtk_css_value_enum_transition,
NULL,
@ -1573,6 +1593,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_TEXT_TRANSFORM = {
"GtkCssTextTransformValue",
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
NULL,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
NULL,

View File

@ -710,6 +710,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FILTER = {
"GtkCssFilterValue",
gtk_css_value_filter_free,
gtk_css_value_filter_compute,
NULL,
gtk_css_value_filter_equal,
gtk_css_value_filter_transition,
NULL,

View File

@ -156,6 +156,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_FEATURES = {
"GtkCssFontFeaturesValue",
gtk_css_value_font_features_free,
gtk_css_value_font_features_compute,
NULL,
gtk_css_value_font_features_equal,
gtk_css_value_font_features_transition,
NULL,

View File

@ -157,6 +157,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_FONT_VARIATIONS = {
"GtkCssFontVariationsValue",
gtk_css_value_font_variations_free,
gtk_css_value_font_variations_compute,
NULL,
gtk_css_value_font_variations_equal,
gtk_css_value_font_variations_transition,
NULL,

View File

@ -586,7 +586,7 @@ gtk_css_image_conic_resolve (GtkCssImage *image,
else
resolved->color_stops[i].offset = NULL;
resolved->color_stops[i].color = gtk_css_color_value_resolve (self->color_stops[i].color, context, current_color);
resolved->color_stops[i].color = gtk_css_value_resolve (self->color_stops[i].color, context, current_color);
}
return GTK_CSS_IMAGE (resolved);

View File

@ -340,7 +340,7 @@ gtk_css_image_fallback_resolve (GtkCssImage *image,
GtkCssValue *resolved_color = NULL;
if (fallback->color)
resolved_color = gtk_css_color_value_resolve (fallback->color, context, current_color);
resolved_color = gtk_css_value_resolve (fallback->color, context, current_color);
/* image($color) that didn't change */
if (resolved_color && !fallback->images && resolved_color == fallback->color)

View File

@ -240,7 +240,7 @@ gtk_css_image_icon_theme_resolve (GtkCssImage *image,
copy->scale = icon_theme->scale;
for (guint i = 0; i < 4; i++)
copy->colors[i] = gtk_css_color_value_resolve (icon_theme->colors[i], context, current);
copy->colors[i] = gtk_css_value_resolve (icon_theme->colors[i], context, current);
return GTK_CSS_IMAGE (copy);
}

View File

@ -787,7 +787,7 @@ gtk_css_image_linear_resolve (GtkCssImage *image,
const GtkCssImageLinearColorStop *stop = &linear->color_stops[i];
GtkCssImageLinearColorStop *scopy = &copy->color_stops[i];
scopy->color = gtk_css_color_value_resolve (stop->color, context, current_color);
scopy->color = gtk_css_value_resolve (stop->color, context, current_color);
if (stop->offset)
scopy->offset = gtk_css_value_ref (stop->offset);

View File

@ -794,7 +794,7 @@ gtk_css_image_radial_resolve (GtkCssImage *image,
const GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
GtkCssImageRadialColorStop *scopy = &copy->color_stops[i];
scopy->color = gtk_css_color_value_resolve (stop->color, context, current_color);
scopy->color = gtk_css_value_resolve (stop->color, context, current_color);
if (stop->offset)
scopy->offset = gtk_css_value_ref (stop->offset);

View File

@ -323,8 +323,8 @@ gtk_css_image_recolor_resolve (GtkCssImage *image,
img = g_object_new (GTK_TYPE_CSS_IMAGE_RECOLOR, NULL);
img->palette = gtk_css_palette_value_resolve (recolor->palette, context, current_color);
img->color = gtk_css_color_value_resolve (recolor->color, context, current_color);
img->palette = gtk_css_value_resolve (recolor->palette, context, current_color);
img->color = gtk_css_value_resolve (recolor->color, context, current_color);
img->file = g_object_ref (recolor->file);
if (recolor->texture)
img->texture = g_object_ref (recolor->texture);

View File

@ -56,6 +56,17 @@ gtk_css_value_image_compute (GtkCssValue *value,
return _gtk_css_image_value_new (computed);
}
static GtkCssValue *
gtk_css_value_image_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color)
{
if (!gtk_css_value_contains_current_color (value))
return gtk_css_value_ref (value);
return _gtk_css_image_value_new (gtk_css_image_resolve (_gtk_css_image_value_get_image (value), context, current_color));
}
static gboolean
gtk_css_value_image_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -124,6 +135,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_IMAGE = {
"GtkCssImageValue",
gtk_css_value_image_free,
gtk_css_value_image_compute,
gtk_css_value_image_resolve,
gtk_css_value_image_equal,
gtk_css_value_image_transition,
gtk_css_value_image_is_dynamic,
@ -155,14 +167,3 @@ _gtk_css_image_value_get_image (const GtkCssValue *value)
return value->image;
}
GtkCssValue *
gtk_css_image_value_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color)
{
if (!gtk_css_value_contains_current_color (value))
return gtk_css_value_ref (value);
return _gtk_css_image_value_new (gtk_css_image_resolve (_gtk_css_image_value_get_image (value), context, current_color));
}

View File

@ -28,10 +28,6 @@ GtkCssValue * _gtk_css_image_value_new (GtkCssImage *image);
GtkCssImage * _gtk_css_image_value_get_image (const GtkCssValue *image);
GtkCssValue * gtk_css_image_value_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color);
G_END_DECLS

View File

@ -77,6 +77,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
"GtkCssInheritValue",
gtk_css_value_inherit_free,
gtk_css_value_inherit_compute,
NULL,
gtk_css_value_inherit_equal,
gtk_css_value_inherit_transition,
NULL,

View File

@ -101,6 +101,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
"GtkCssInitialValue",
gtk_css_value_initial_free,
gtk_css_value_initial_compute,
NULL,
gtk_css_value_initial_equal,
gtk_css_value_initial_transition,
NULL,

View File

@ -107,6 +107,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_LINE_HEIGHT = {
"GtkCssLineHeightValue",
gtk_css_value_line_height_free,
gtk_css_value_line_height_compute,
NULL,
gtk_css_value_line_height_equal,
gtk_css_value_line_height_transition,
NULL,

View File

@ -605,6 +605,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_NUMBER = {
"GtkCssNumberValue",
gtk_css_value_number_free,
gtk_css_value_number_compute,
NULL,
gtk_css_value_number_equal,
gtk_css_value_number_transition,
NULL,

View File

@ -134,6 +134,26 @@ gtk_css_value_palette_compute (GtkCssValue *specified,
return result;
}
static GtkCssValue *
gtk_css_value_palette_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color)
{
GtkCssValue *result;
if (!gtk_css_value_contains_current_color (value))
return gtk_css_value_ref (value);
result = gtk_css_palette_value_new_sized (value->n_colors);
for (guint i = 0; i < value->n_colors; i++)
{
result->color_names[i] = g_strdup (value->color_names[i]);
result->color_values[i] = gtk_css_value_resolve (value->color_values[i], context, current_color);
}
return result;
}
static gboolean
gtk_css_value_palette_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -243,6 +263,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_PALETTE = {
"GtkCssPaletteValue",
gtk_css_value_palette_free,
gtk_css_value_palette_compute,
gtk_css_value_palette_resolve,
gtk_css_value_palette_equal,
gtk_css_value_palette_transition,
NULL,
@ -353,23 +374,3 @@ gtk_css_palette_value_get_color (GtkCssValue *value,
return NULL;
}
GtkCssValue *
gtk_css_palette_value_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color)
{
GtkCssValue *result;
if (!gtk_css_value_contains_current_color (value))
return gtk_css_value_ref (value);
result = gtk_css_palette_value_new_sized (value->n_colors);
for (guint i = 0; i < value->n_colors; i++)
{
result->color_names[i] = g_strdup (value->color_names[i]);
result->color_values[i] = gtk_css_color_value_resolve (value->color_values[i], context, current_color);
}
return result;
}

View File

@ -33,9 +33,5 @@ GtkCssValue * gtk_css_palette_value_parse (GtkCssParser *pa
GtkCssValue * gtk_css_palette_value_get_color (GtkCssValue *value,
const char *color_name);
GtkCssValue * gtk_css_palette_value_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color);
G_END_DECLS

View File

@ -150,6 +150,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_POSITION = {
"GtkCssPositionValue",
gtk_css_value_position_free,
gtk_css_value_position_compute,
NULL,
gtk_css_value_position_equal,
gtk_css_value_position_transition,
NULL,

View File

@ -362,6 +362,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_REFERENCE = {
"GtkCssReferenceValue",
gtk_css_value_reference_free,
gtk_css_value_reference_compute,
NULL,
gtk_css_value_reference_equal,
gtk_css_value_reference_transition,
NULL,

View File

@ -114,6 +114,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_BACKGROUND_REPEAT = {
"GtkCssBackgroundRepeatValue",
gtk_css_value_repeat_free,
gtk_css_value_repeat_compute,
NULL,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
NULL,
@ -125,6 +126,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_BORDER_REPEAT = {
"GtkCssBorderRepeatValue",
gtk_css_value_repeat_free,
gtk_css_value_repeat_compute,
NULL,
gtk_css_value_repeat_equal,
gtk_css_value_repeat_transition,
NULL,

View File

@ -138,6 +138,34 @@ gtk_css_value_shadow_compute (GtkCssValue *value,
return gtk_css_shadow_value_new (shadows, value->n_shadows, value->is_filter);
}
static GtkCssValue *
gtk_css_value_shadow_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color)
{
guint i;
ShadowValue *shadows;
if (!gtk_css_value_contains_current_color (value))
return gtk_css_value_ref (value);
shadows = g_alloca (sizeof (ShadowValue) * value->n_shadows);
for (i = 0; i < value->n_shadows; i++)
{
const ShadowValue *shadow = &value->shadows[i];
shadows[i].hoffset = gtk_css_value_ref (shadow->hoffset);
shadows[i].voffset = gtk_css_value_ref (shadow->voffset);
shadows[i].radius = gtk_css_value_ref (shadow->radius);
shadows[i].spread = gtk_css_value_ref (shadow->spread);
shadows[i].color = gtk_css_value_resolve (shadow->color, context, current_color);
shadows[i].inset = shadow->inset;
}
return gtk_css_shadow_value_new (shadows, value->n_shadows, value->is_filter);
}
static gboolean
gtk_css_value_shadow_equal (const GtkCssValue *value1,
const GtkCssValue *value2)
@ -279,11 +307,12 @@ static const GtkCssValueClass GTK_CSS_VALUE_SHADOW = {
"GtkCssShadowValue",
gtk_css_value_shadow_free,
gtk_css_value_shadow_compute,
gtk_css_value_shadow_resolve,
gtk_css_value_shadow_equal,
gtk_css_value_shadow_transition,
NULL,
NULL,
gtk_css_value_shadow_print
gtk_css_value_shadow_print,
};
static GtkCssValue shadow_none_singleton = { &GTK_CSS_VALUE_SHADOW, 1, 1, 0, 0, 0, 0 };
@ -748,31 +777,3 @@ gtk_css_shadow_value_pop_snapshot (const GtkCssValue *value,
if (!gtk_css_shadow_value_is_clear (value))
gtk_snapshot_pop (snapshot);
}
GtkCssValue *
gtk_css_shadow_value_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color)
{
guint i;
ShadowValue *shadows;
if (!gtk_css_value_contains_current_color (value))
return gtk_css_value_ref (value);
shadows = g_alloca (sizeof (ShadowValue) * value->n_shadows);
for (i = 0; i < value->n_shadows; i++)
{
const ShadowValue *shadow = &value->shadows[i];
shadows[i].hoffset = gtk_css_value_ref (shadow->hoffset);
shadows[i].voffset = gtk_css_value_ref (shadow->voffset);
shadows[i].radius = gtk_css_value_ref (shadow->radius);
shadows[i].spread = gtk_css_value_ref (shadow->spread);
shadows[i].color = gtk_css_color_value_resolve (shadow->color, context, current_color);
shadows[i].inset = shadow->inset;
}
return gtk_css_shadow_value_new (shadows, value->n_shadows, value->is_filter);
}

View File

@ -56,9 +56,5 @@ gboolean gtk_css_shadow_value_push_snapshot (const GtkCssValue
void gtk_css_shadow_value_pop_snapshot (const GtkCssValue *value,
GtkSnapshot *snapshot);
GtkCssValue * gtk_css_shadow_value_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current_color);
G_END_DECLS

View File

@ -119,6 +119,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_STRING = {
"GtkCssStringValue",
gtk_css_value_string_free,
gtk_css_value_string_compute,
NULL,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
NULL,
@ -130,6 +131,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_IDENT = {
"GtkCssIdentValue",
gtk_css_value_string_free,
gtk_css_value_string_compute,
NULL,
gtk_css_value_string_equal,
gtk_css_value_string_transition,
NULL,

View File

@ -1017,7 +1017,7 @@ gtk_css_style_resolve_used_value (GtkCssStyle *style,
else
current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
used = gtk_css_color_value_resolve (value, context, current);
used = gtk_css_value_resolve (value, context, current);
}
break;
@ -1030,23 +1030,14 @@ gtk_css_style_resolve_used_value (GtkCssStyle *style,
case GTK_CSS_PROPERTY_OUTLINE_COLOR:
case GTK_CSS_PROPERTY_CARET_COLOR:
case GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR:
used = gtk_css_color_value_resolve (value, context, style->used->color);
break;
case GTK_CSS_PROPERTY_BOX_SHADOW:
case GTK_CSS_PROPERTY_TEXT_SHADOW:
case GTK_CSS_PROPERTY_ICON_SHADOW:
used = gtk_css_shadow_value_resolve (value, context, style->used->color);
break;
case GTK_CSS_PROPERTY_ICON_PALETTE:
used = gtk_css_palette_value_resolve (value, context, style->used->color);
break;
case GTK_CSS_PROPERTY_BACKGROUND_IMAGE:
case GTK_CSS_PROPERTY_ICON_SOURCE:
case GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE:
used = gtk_css_image_value_resolve (value, context, style->used->color);
used = gtk_css_value_resolve (value, context, style->used->color);
break;
default:

View File

@ -788,6 +788,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_TRANSFORM = {
"GtkCssTransformValue",
gtk_css_value_transform_free,
gtk_css_value_transform_compute,
NULL,
gtk_css_value_transform_equal,
gtk_css_value_transform_transition,
NULL,

View File

@ -79,6 +79,7 @@ static const GtkCssValueClass GTK_CSS_VALUE_UNSET = {
"GtkCssUnsetValue",
gtk_css_value_unset_free,
gtk_css_value_unset_compute,
NULL,
gtk_css_value_unset_equal,
gtk_css_value_unset_transition,
NULL,

View File

@ -196,11 +196,8 @@ void
* gtk_css_value_compute:
* @value: the value to compute from
* @property_id: the ID of the property to compute
* @provider: Style provider for looking up extra information
* @style: Style to compute for
* @parent_style: parent style to use for inherited values
* @variables: an additional set of variables to use along with @style
* @shorthands: (nullable): Already computed values for shorthands
* @context: the context containing the style provider, style
* parent style and variables that might be used during computation
*
* Converts the specified @value into the computed value for the CSS
* property given by @property_id using the information in @context.
@ -224,6 +221,29 @@ gtk_css_value_compute (GtkCssValue *value,
return value->class->compute (value, property_id, context);
}
/**
* gtk_css_value_resolve:
* @value: the value to resolve
* @context: the context containing the style provider, style
* parent style and variables that might be used during computation
* @current: the value to use for currentcolor
*
* Converts the computed @value into the used value, by replacing
* currentcolor with @current.
*
* Returns: the used value
*/
GtkCssValue *
gtk_css_value_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current)
{
if (!value->class->resolve)
return gtk_css_value_ref (value);
return value->class->resolve (value, context, current);
}
gboolean
gtk_css_value_equal (const GtkCssValue *value1,
const GtkCssValue *value2)

View File

@ -57,6 +57,9 @@ struct _GtkCssValueClass {
GtkCssValue * (* compute) (GtkCssValue *value,
guint property_id,
GtkCssComputeContext *context);
GtkCssValue * (* resolve) (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current);
gboolean (* equal) (const GtkCssValue *value1,
const GtkCssValue *value2);
GtkCssValue * (* transition) (GtkCssValue *start,
@ -82,6 +85,9 @@ void (gtk_css_value_unref) (GtkCssValue
GtkCssValue * gtk_css_value_compute (GtkCssValue *value,
guint property_id,
GtkCssComputeContext *context) G_GNUC_PURE;
GtkCssValue * gtk_css_value_resolve (GtkCssValue *value,
GtkCssComputeContext *context,
GtkCssValue *current) G_GNUC_PURE;
gboolean gtk_css_value_equal (const GtkCssValue *value1,
const GtkCssValue *value2) G_GNUC_PURE;
gboolean gtk_css_value_equal0 (const GtkCssValue *value1,

View File

@ -873,7 +873,7 @@ gtk_label_update_layout_attributes (GtkLabel *self,
g_slist_free (attributes);
}
link_color = gtk_css_color_value_get_rgba (style->core->color);
link_color = gtk_css_color_value_get_rgba (style->used->color);
attr = pango_attr_foreground_new (CLAMP (link_color->red * 65535. + 0.5, 0, 65535),
CLAMP (link_color->green * 65535. + 0.5, 0, 65535),

View File

@ -415,7 +415,7 @@ get_shadow_width (GtkWidget *widget,
GtkCssNode *css_node = gtk_widget_get_css_node (widget);
const GtkCssStyle *style = gtk_css_node_get_style (css_node);
gtk_css_shadow_value_get_extents (style->background->box_shadow, shadow_width);
gtk_css_shadow_value_get_extents (style->used->box_shadow, shadow_width);
shadow_width->left = MAX (shadow_width->left, resize_handle_size);
shadow_width->top = MAX (shadow_width->top, resize_handle_size);

View File

@ -507,7 +507,7 @@ create_popup_layout (GtkPopover *popover)
compute_surface_pointing_to (popover, &rect);
style = gtk_css_node_get_style (gtk_widget_get_css_node (GTK_WIDGET (priv->contents_widget)));
gtk_css_shadow_value_get_extents (style->background->box_shadow, &shadow_width);
gtk_css_shadow_value_get_extents (style->used->box_shadow, &shadow_width);
switch (priv->position)
{
@ -1274,7 +1274,7 @@ gtk_popover_get_gap_coords (GtkPopover *popover,
border_right = gtk_css_number_value_get (style->border->border_right_width, 100);
border_bottom = gtk_css_number_value_get (style->border->border_bottom_width, 100);
gtk_css_shadow_value_get_extents (style->background->box_shadow, &shadow_width);
gtk_css_shadow_value_get_extents (style->used->box_shadow, &shadow_width);
if (pos == GTK_POS_BOTTOM)
{
@ -1448,7 +1448,7 @@ gtk_popover_update_shape (GtkPopover *popover)
content_css_node =
gtk_widget_get_css_node (GTK_WIDGET (priv->contents_widget));
style = gtk_css_node_get_style (content_css_node);
gtk_css_shadow_value_get_extents (style->background->box_shadow, &shadow_width);
gtk_css_shadow_value_get_extents (style->used->box_shadow, &shadow_width);
input_rect.x = shadow_width.left;
input_rect.y = shadow_width.top;
@ -1515,7 +1515,7 @@ gtk_popover_measure (GtkWidget *widget,
for_size -= tail_height;
style = gtk_css_node_get_style (gtk_widget_get_css_node (GTK_WIDGET (priv->contents_widget)));
gtk_css_shadow_value_get_extents (style->background->box_shadow, &shadow_width);
gtk_css_shadow_value_get_extents (style->used->box_shadow, &shadow_width);
gtk_widget_measure (priv->contents_widget,
orientation, for_size,
@ -1558,7 +1558,7 @@ gtk_popover_size_allocate (GtkWidget *widget,
GtkBorder shadow_width;
style = gtk_css_node_get_style (gtk_widget_get_css_node (GTK_WIDGET (priv->contents_widget)));
gtk_css_shadow_value_get_extents (style->background->box_shadow, &shadow_width);
gtk_css_shadow_value_get_extents (style->used->box_shadow, &shadow_width);
switch (priv->final_position)
{

View File

@ -54,7 +54,7 @@ static gboolean
gtk_border_image_init (GtkBorderImage *image,
GtkCssStyle *style)
{
image->source = _gtk_css_image_value_get_image (style->border->border_image_source);
image->source = _gtk_css_image_value_get_image (style->used->border_image_source);
if (image->source == NULL)
return FALSE;

View File

@ -4046,7 +4046,7 @@ get_shadow_width (GtkWindow *window,
style = gtk_css_node_get_style (gtk_widget_get_css_node (GTK_WIDGET (window)));
/* Calculate the size of the drop shadows ... */
gtk_css_shadow_value_get_extents (style->background->box_shadow, shadow_width);
gtk_css_shadow_value_get_extents (style->used->box_shadow, shadow_width);
shadow_width->left = MAX (shadow_width->left, RESIZE_HANDLE_SIZE);
shadow_width->top = MAX (shadow_width->top, RESIZE_HANDLE_SIZE);