nodeparser: Support color states in border nodes

Test included.
This commit is contained in:
Matthias Clasen 2024-08-02 00:24:20 -04:00
parent 89d449352f
commit a3691d311b
3 changed files with 61 additions and 38 deletions

View File

@ -693,34 +693,6 @@ parse_float4 (GtkCssParser *parser,
return TRUE;
}
static gboolean
parse_colors4 (GtkCssParser *parser,
Context *context,
gpointer out_colors)
{
GdkRGBA colors[4];
int i;
for (i = 0; i < 4 && !gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_EOF); i ++)
{
if (!gdk_rgba_parser_parse (parser, &colors[i]))
return FALSE;
}
if (i == 0)
{
gtk_css_parser_error_syntax (parser, "Expected a color");
return FALSE;
}
for (; i < 4; i++)
{
colors[i] = colors[(i - 1) >> 1];
}
memcpy (out_colors, colors, sizeof (GdkRGBA) * 4);
return TRUE;
}
static gboolean
parse_shadows (GtkCssParser *parser,
Context *context,
@ -1705,6 +1677,34 @@ parse_color2 (GtkCssParser *parser,
return FALSE;
}
static gboolean
parse_colors4 (GtkCssParser *parser,
Context *context,
gpointer out_colors)
{
GdkColor colors[4];
int i;
for (i = 0; i < 4 && !gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_EOF); i ++)
{
if (!parse_color2 (parser, context, &colors[i]))
return FALSE;
}
if (i == 0)
{
gtk_css_parser_error_syntax (parser, "Expected a color");
return FALSE;
}
for (; i < 4; i++)
{
colors[i] = colors[(i - 1) >> 1];
}
memcpy (out_colors, colors, sizeof (GdkColor) * 4);
return TRUE;
}
static GskRenderNode *
parse_color_node (GtkCssParser *parser,
Context *context)
@ -2173,16 +2173,21 @@ parse_border_node (GtkCssParser *parser,
{
GskRoundedRect outline = GSK_ROUNDED_RECT_INIT (0, 0, 50, 50);
float widths[4] = { 1, 1, 1, 1 };
GdkRGBA colors[4] = { GDK_RGBA("000"), GDK_RGBA("000"), GDK_RGBA("000"), GDK_RGBA("000") };
GdkColor colors[4] = {
GDK_COLOR_SRGB (0, 0, 0, 1),
GDK_COLOR_SRGB (0, 0, 0, 1),
GDK_COLOR_SRGB (0, 0, 0, 1),
GDK_COLOR_SRGB (0, 0, 0, 1),
};
const Declaration declarations[] = {
{ "outline", parse_rounded_rect, NULL, &outline },
{ "widths", parse_float4, NULL, &widths },
{ "colors", parse_colors4, NULL, &colors }
{ "colors", parse_colors4, NULL, &colors },
};
parse_declarations (parser, context, declarations, G_N_ELEMENTS (declarations));
return gsk_border_node_new (&outline, widths, colors);
return gsk_border_node_new2 (&outline, widths, colors);
}
static GskRenderNode *
@ -3313,13 +3318,20 @@ printer_init_duplicates_for_node (Printer *printer,
printer_init_check_color_state (printer, gsk_color_node_get_color2 (node)->color_state);
break;
case GSK_BORDER_NODE:
{
const GdkColor *colors = gsk_border_node_get_colors2 (node);
for (int i = 0; i < 4; i++)
printer_init_check_color_state (printer, colors[i].color_state);
}
break;
case GSK_CAIRO_NODE:
case GSK_LINEAR_GRADIENT_NODE:
case GSK_REPEATING_LINEAR_GRADIENT_NODE:
case GSK_RADIAL_GRADIENT_NODE:
case GSK_REPEATING_RADIAL_GRADIENT_NODE:
case GSK_CONIC_GRADIENT_NODE:
case GSK_BORDER_NODE:
case GSK_INSET_SHADOW_NODE:
case GSK_OUTSET_SHADOW_NODE:
/* no children */
@ -4428,18 +4440,18 @@ render_node_print (Printer *p,
case GSK_BORDER_NODE:
{
const GdkRGBA *colors = gsk_border_node_get_colors (node);
const GdkColor *colors = gsk_border_node_get_colors2 (node);
const float *widths = gsk_border_node_get_widths (node);
guint i, n;
start_node (p, "border", node_name);
if (!gdk_rgba_equal (&colors[3], &colors[1]))
if (!gdk_color_equal (&colors[3], &colors[1]))
n = 4;
else if (!gdk_rgba_equal (&colors[2], &colors[0]))
else if (!gdk_color_equal (&colors[2], &colors[0]))
n = 3;
else if (!gdk_rgba_equal (&colors[1], &colors[0]))
else if (!gdk_color_equal (&colors[1], &colors[0]))
n = 2;
else if (!gdk_rgba_equal (&colors[0], &GDK_RGBA("000000")))
else if (!gdk_color_equal (&colors[0], (&(GdkColor) { .color_state = GDK_COLOR_STATE_SRGB, .values = { 0, 0, 0, 1 } })))
n = 1;
else
n = 0;
@ -4452,7 +4464,7 @@ render_node_print (Printer *p,
{
if (i > 0)
g_string_append_c (p->str, ' ');
gdk_rgba_print (&colors[i], p->str);
print_color (p, &colors[i]);
}
g_string_append (p->str, ";\n");
}

View File

@ -3,3 +3,9 @@ border {
widths: 1 1 1 1;
colors: rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1) rgba(213, 208, 204, 1);
}
border {
outline: -1 -1 50 26 / 13;
widths: 2 1 3 1;
colors: color(rec2100-pq 0.2 0.4 0.6) color(srgb 0.8 0.2 0.4 / 1) rgba(0, 0, 0, 1) rgb(200, 100, 50);
}

View File

@ -2,3 +2,8 @@ border {
colors: rgb(213,208,204);
outline: -1 -1 50 26 / 13;
}
border {
colors: color(rec2100-pq 0.2 0.4 0.6) rgb(204,51,102) rgb(0,0,0) rgb(200,100,50);
outline: -1 -1 50 26 / 13;
widths: 2 1 3;
}