Getting colder with our second freeze... it's 3.31.91 release day and string freeze, upload a tarball and lock those strings 🏂

Commit 09f9fd42 authored by Benjamin Otte's avatar Benjamin Otte

css: Fold color value computation into gtksymboliccolor.c

This gets rid of the public function
_gtk_css_rgba_value_compute_from_symbolic().
The fallback is now handled using a switch statement instead of letting
the caller pass the function.
parent 9b4ed662
......@@ -413,10 +413,8 @@ gtk_css_image_linear_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
{
static const GdkRGBA transparent = { 0, 0, 0, 0 };
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
GtkCssImageLinear *copy;
GtkCssValue *fallback;
guint i;
copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
......@@ -424,7 +422,6 @@ gtk_css_image_linear_compute (GtkCssImage *image,
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);
for (i = 0; i < linear->stops->len; i++)
{
......@@ -433,10 +430,7 @@ gtk_css_image_linear_compute (GtkCssImage *image,
stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
scopy = &g_array_index (copy->stops, GtkCssImageLinearColorStop, i);
scopy->color = _gtk_css_rgba_value_compute_from_symbolic (stop->color,
fallback,
context,
FALSE);
scopy->color = _gtk_css_value_compute (stop->color, property_id, context);
if (stop->offset)
scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context);
......@@ -444,8 +438,6 @@ gtk_css_image_linear_compute (GtkCssImage *image,
scopy->offset = NULL;
}
_gtk_css_value_unref (fallback);
return GTK_CSS_IMAGE (copy);
}
......
......@@ -102,41 +102,3 @@ _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
return &rgba->rgba;
}
GtkCssValue *
_gtk_css_rgba_value_compute_from_symbolic (GtkCssValue *symbolic,
GtkCssValue *fallback,
GtkStyleContext *context,
gboolean for_color_property)
{
GtkCssValue *resolved, *current;
g_return_val_if_fail (symbolic != NULL, NULL);
/* The computed value of the ‘currentColor’ keyword is the computed
* value of the ‘color’ property. If the ‘currentColor’ keyword is
* set on the ‘color’ property itself, it is treated as ‘color: inherit’.
*/
if (for_color_property)
{
GtkStyleContext *parent = gtk_style_context_get_parent (context);
if (parent)
current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
else
current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
}
else
{
current = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
}
resolved = _gtk_style_context_resolve_color_value (context, current, symbolic);
if (resolved == NULL)
return _gtk_css_rgba_value_compute_from_symbolic (fallback, NULL, context, for_color_property);
g_assert (resolved->class == &GTK_CSS_VALUE_RGBA);
return resolved;
}
......@@ -28,12 +28,6 @@ G_BEGIN_DECLS
GtkCssValue * _gtk_css_rgba_value_new_from_rgba (const GdkRGBA *rgba);
GtkCssValue * _gtk_css_rgba_value_compute_from_symbolic
(GtkCssValue *symbolic,
GtkCssValue *fallback,
GtkStyleContext *context,
gboolean for_color_property);
const GdkRGBA * _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba);
......
......@@ -64,22 +64,12 @@ gtk_css_value_shadow_compute (GtkCssValue *shadow,
guint property_id,
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, 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);
_gtk_css_value_compute (shadow->color, property_id, context));
}
static gboolean
......
......@@ -185,10 +185,7 @@ color_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
return _gtk_css_rgba_value_compute_from_symbolic (specified,
_gtk_css_style_property_get_initial_value (property),
context,
FALSE);
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static GtkCssValue *
......@@ -196,14 +193,7 @@ color_property_compute (GtkCssStyleProperty *property,
GtkStyleContext *context,
GtkCssValue *specified)
{
GtkCssValue *value;
value = _gtk_css_rgba_value_compute_from_symbolic (specified,
_gtk_css_style_property_get_initial_value (property),
context,
TRUE);
_gtk_css_rgba_value_get_rgba (value);
return value;
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
}
static void
......
......@@ -17,6 +17,8 @@
#include "config.h"
#include "gtkcssrgbavalueprivate.h"
#include "gtkcssstylepropertyprivate.h"
#include "gtkstylepropertyprivate.h"
#include "gtksymboliccolorprivate.h"
#include "gtkstyleproperties.h"
#include "gtkintl.h"
......@@ -117,16 +119,69 @@ gtk_css_value_symbolic_free (GtkCssValue *value)
g_slice_free (GtkSymbolicColor, color);
}
static GtkCssValue *
gtk_css_value_symbolic_get_fallback (guint property_id,
GtkStyleContext *context)
{
static const GdkRGBA transparent = { 0, 0, 0, 0 };
switch (property_id)
{
case GTK_CSS_PROPERTY_BACKGROUND_IMAGE:
case GTK_CSS_PROPERTY_BORDER_IMAGE_SOURCE:
case GTK_CSS_PROPERTY_TEXT_SHADOW:
case GTK_CSS_PROPERTY_ICON_SHADOW:
case GTK_CSS_PROPERTY_BOX_SHADOW:
return _gtk_css_rgba_value_new_from_rgba (&transparent);
case GTK_CSS_PROPERTY_COLOR:
case GTK_CSS_PROPERTY_BACKGROUND_COLOR:
case GTK_CSS_PROPERTY_BORDER_TOP_COLOR:
case GTK_CSS_PROPERTY_BORDER_RIGHT_COLOR:
case GTK_CSS_PROPERTY_BORDER_BOTTOM_COLOR:
case GTK_CSS_PROPERTY_BORDER_LEFT_COLOR:
case GTK_CSS_PROPERTY_OUTLINE_COLOR:
return _gtk_css_value_compute (_gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (property_id)),
property_id,
context);
default:
if (property_id < GTK_CSS_PROPERTY_N_PROPERTIES)
g_warning ("No fallback color defined for property '%s'",
_gtk_style_property_get_name (GTK_STYLE_PROPERTY (_gtk_css_style_property_lookup_by_id (property_id))));
return _gtk_css_rgba_value_new_from_rgba (&transparent);
}
}
static GtkCssValue *
gtk_css_value_symbolic_compute (GtkCssValue *value,
guint property_id,
GtkStyleContext *context)
{
/* for now we expect this to never be called
* because all cases are handled via
* _gtk_css_rgba_value_compute_from_symbolic()
GtkCssValue *resolved, *current;
/* The computed value of the ‘currentColor’ keyword is the computed
* value of the ‘color’ property. If the ‘currentColor’ keyword is
* set on the ‘color’ property itself, it is treated as ‘color: inherit’.
*/
g_return_val_if_reached (_gtk_css_value_ref (value));
if (property_id == GTK_CSS_PROPERTY_COLOR)
{
GtkStyleContext *parent = gtk_style_context_get_parent (context);
if (parent)
current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
else
current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
}
else
{
current = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
}
resolved = _gtk_style_context_resolve_color_value (context, current, value);
if (resolved == NULL)
return gtk_css_value_symbolic_get_fallback (property_id, context);
return resolved;
}
static gboolean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment