mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-06 00:30:08 +00:00
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.
This commit is contained in:
parent
9b4ed66218
commit
09f9fd42b4
@ -413,10 +413,8 @@ gtk_css_image_linear_compute (GtkCssImage *image,
|
|||||||
guint property_id,
|
guint property_id,
|
||||||
GtkStyleContext *context)
|
GtkStyleContext *context)
|
||||||
{
|
{
|
||||||
static const GdkRGBA transparent = { 0, 0, 0, 0 };
|
|
||||||
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
|
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
|
||||||
GtkCssImageLinear *copy;
|
GtkCssImageLinear *copy;
|
||||||
GtkCssValue *fallback;
|
|
||||||
guint i;
|
guint i;
|
||||||
|
|
||||||
copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
|
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);
|
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);
|
g_array_set_size (copy->stops, linear->stops->len);
|
||||||
for (i = 0; i < linear->stops->len; i++)
|
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);
|
stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
|
||||||
scopy = &g_array_index (copy->stops, GtkCssImageLinearColorStop, i);
|
scopy = &g_array_index (copy->stops, GtkCssImageLinearColorStop, i);
|
||||||
|
|
||||||
scopy->color = _gtk_css_rgba_value_compute_from_symbolic (stop->color,
|
scopy->color = _gtk_css_value_compute (stop->color, property_id, context);
|
||||||
fallback,
|
|
||||||
context,
|
|
||||||
FALSE);
|
|
||||||
|
|
||||||
if (stop->offset)
|
if (stop->offset)
|
||||||
scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context);
|
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;
|
scopy->offset = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
_gtk_css_value_unref (fallback);
|
|
||||||
|
|
||||||
return GTK_CSS_IMAGE (copy);
|
return GTK_CSS_IMAGE (copy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,41 +102,3 @@ _gtk_css_rgba_value_get_rgba (const GtkCssValue *rgba)
|
|||||||
|
|
||||||
return &rgba->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 == >K_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_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);
|
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,
|
guint property_id,
|
||||||
GtkStyleContext *context)
|
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),
|
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->voffset, property_id, context),
|
||||||
_gtk_css_value_compute (shadow->radius, property_id, context),
|
_gtk_css_value_compute (shadow->radius, property_id, context),
|
||||||
_gtk_css_value_compute (shadow->spread, property_id, context),
|
_gtk_css_value_compute (shadow->spread, property_id, context),
|
||||||
shadow->inset,
|
shadow->inset,
|
||||||
color);
|
_gtk_css_value_compute (shadow->color, property_id, context));
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
|
@ -185,10 +185,7 @@ color_compute (GtkCssStyleProperty *property,
|
|||||||
GtkStyleContext *context,
|
GtkStyleContext *context,
|
||||||
GtkCssValue *specified)
|
GtkCssValue *specified)
|
||||||
{
|
{
|
||||||
return _gtk_css_rgba_value_compute_from_symbolic (specified,
|
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
|
||||||
_gtk_css_style_property_get_initial_value (property),
|
|
||||||
context,
|
|
||||||
FALSE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static GtkCssValue *
|
static GtkCssValue *
|
||||||
@ -196,14 +193,7 @@ color_property_compute (GtkCssStyleProperty *property,
|
|||||||
GtkStyleContext *context,
|
GtkStyleContext *context,
|
||||||
GtkCssValue *specified)
|
GtkCssValue *specified)
|
||||||
{
|
{
|
||||||
GtkCssValue *value;
|
return _gtk_css_value_compute (specified, _gtk_css_style_property_get_id (property), context);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -17,6 +17,8 @@
|
|||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "gtkcssrgbavalueprivate.h"
|
#include "gtkcssrgbavalueprivate.h"
|
||||||
|
#include "gtkcssstylepropertyprivate.h"
|
||||||
|
#include "gtkstylepropertyprivate.h"
|
||||||
#include "gtksymboliccolorprivate.h"
|
#include "gtksymboliccolorprivate.h"
|
||||||
#include "gtkstyleproperties.h"
|
#include "gtkstyleproperties.h"
|
||||||
#include "gtkintl.h"
|
#include "gtkintl.h"
|
||||||
@ -117,16 +119,69 @@ gtk_css_value_symbolic_free (GtkCssValue *value)
|
|||||||
g_slice_free (GtkSymbolicColor, color);
|
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 *
|
static GtkCssValue *
|
||||||
gtk_css_value_symbolic_compute (GtkCssValue *value,
|
gtk_css_value_symbolic_compute (GtkCssValue *value,
|
||||||
guint property_id,
|
guint property_id,
|
||||||
GtkStyleContext *context)
|
GtkStyleContext *context)
|
||||||
{
|
{
|
||||||
/* for now we expect this to never be called
|
GtkCssValue *resolved, *current;
|
||||||
* because all cases are handled via
|
|
||||||
* _gtk_css_rgba_value_compute_from_symbolic()
|
/* 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
|
static gboolean
|
||||||
|
Loading…
Reference in New Issue
Block a user