css: Make color lookup handle dependencies

This commit is contained in:
Benjamin Otte 2012-08-27 17:27:06 +02:00
parent 27fd3fdf81
commit 11d0f9e408
6 changed files with 75 additions and 39 deletions

View File

@ -216,7 +216,7 @@ rgba_value_compute (GtkStyleContext *context,
GValue new_value = G_VALUE_INIT;
GdkRGBA rgba;
if (!_gtk_style_context_resolve_color (context, symbolic, &rgba))
if (!_gtk_style_context_resolve_color (context, symbolic, &rgba, NULL))
rgba = white;
g_value_init (&new_value, GDK_TYPE_RGBA);
@ -290,7 +290,8 @@ color_value_compute (GtkStyleContext *context,
if (_gtk_style_context_resolve_color (context,
g_value_get_boxed (value),
&rgba))
&rgba,
NULL))
{
color.red = rgba.red * 65535. + 0.5;
color.green = rgba.green * 65535. + 0.5;

View File

@ -307,7 +307,7 @@ gtk_gradient_resolve_for_context (GtkGradient *gradient,
stop = &g_array_index (gradient->stops, ColorStop, i);
/* if color resolving fails, assume transparency */
if (!_gtk_style_context_resolve_color (context, stop->color, &rgba))
if (!_gtk_style_context_resolve_color (context, stop->color, &rgba, NULL))
rgba.red = rgba.green = rgba.blue = rgba.alpha = 0.0;
cairo_pattern_add_color_stop_rgba (pattern, stop->offset,

View File

@ -2263,7 +2263,7 @@ _gtk_style_context_peek_style_property (GtkStyleContext *context,
else
g_value_init (&pcache->value, GDK_TYPE_COLOR);
if (_gtk_style_context_resolve_color (context, color, &rgba))
if (_gtk_style_context_resolve_color (context, color, &rgba, NULL))
{
if (G_PARAM_SPEC_VALUE_TYPE (pspec) == GDK_TYPE_RGBA)
g_value_set_boxed (&pcache->value, &rgba);
@ -2677,9 +2677,11 @@ gtk_style_context_color_lookup_func (gpointer contextp,
}
GtkCssValue *
_gtk_style_context_resolve_color_value (GtkStyleContext *context,
GtkCssValue *current,
GtkCssValue *color)
_gtk_style_context_resolve_color_value (GtkStyleContext *context,
GtkCssValue *current,
GtkCssDependencies current_deps,
GtkCssValue *color,
GtkCssDependencies *dependencies)
{
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), FALSE);
g_return_val_if_fail (current != NULL, FALSE);
@ -2687,15 +2689,18 @@ _gtk_style_context_resolve_color_value (GtkStyleContext *context,
return _gtk_symbolic_color_resolve_full ((GtkSymbolicColor *) color,
current,
current_deps,
gtk_style_context_color_lookup_func,
context);
context,
dependencies);
}
gboolean
_gtk_style_context_resolve_color (GtkStyleContext *context,
GtkSymbolicColor *color,
GdkRGBA *result)
_gtk_style_context_resolve_color (GtkStyleContext *context,
GtkSymbolicColor *color,
GdkRGBA *result,
GtkCssDependencies *dependencies)
{
GtkCssValue *val;
@ -2705,8 +2710,10 @@ _gtk_style_context_resolve_color (GtkStyleContext *context,
val = _gtk_symbolic_color_resolve_full (color,
_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR),
GTK_CSS_DEPENDS_ON_COLOR,
gtk_style_context_color_lookup_func,
context);
context,
dependencies);
if (val == NULL)
return FALSE;
@ -2740,7 +2747,7 @@ gtk_style_context_lookup_color (GtkStyleContext *context,
if (sym_color == NULL)
return FALSE;
return _gtk_style_context_resolve_color (context, sym_color, color);
return _gtk_style_context_resolve_color (context, sym_color, color, NULL);
}
/**

View File

@ -44,17 +44,20 @@ void _gtk_style_context_queue_invalidate (GtkStyleContext *c
GtkCssChange change);
gboolean _gtk_style_context_check_region_name (const gchar *str);
gboolean _gtk_style_context_resolve_color (GtkStyleContext *context,
GtkSymbolicColor *color,
GdkRGBA *result);
GtkCssValue * _gtk_style_context_resolve_color_value (GtkStyleContext *context,
GtkCssValue *current,
GtkCssValue *color);
void _gtk_style_context_get_cursor_color (GtkStyleContext *context,
GdkRGBA *primary_color,
GdkRGBA *secondary_color);
gboolean _gtk_style_context_resolve_color (GtkStyleContext *context,
GtkSymbolicColor *color,
GdkRGBA *result,
GtkCssDependencies *dependencies);
GtkCssValue * _gtk_style_context_resolve_color_value (GtkStyleContext *context,
GtkCssValue *current,
GtkCssDependencies current_deps,
GtkCssValue *color,
GtkCssDependencies *dependencies);
void _gtk_style_context_get_cursor_color (GtkStyleContext *context,
GdkRGBA *primary_color,
GdkRGBA *secondary_color);
void _gtk_style_context_stop_animations (GtkStyleContext *context);
void _gtk_style_context_stop_animations (GtkStyleContext *context);
G_END_DECLS

View File

@ -159,8 +159,7 @@ gtk_css_value_symbolic_compute (GtkCssValue *value,
GtkCssDependencies *dependencies)
{
GtkCssValue *resolved, *current;
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
GtkCssDependencies current_deps;
/* The computed value of the currentColor keyword is the computed
* value of the color property. If the currentColor keyword is
@ -171,16 +170,23 @@ gtk_css_value_symbolic_compute (GtkCssValue *value,
GtkStyleContext *parent = gtk_style_context_get_parent (context);
if (parent)
current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
{
current = _gtk_style_context_peek_property (parent, GTK_CSS_PROPERTY_COLOR);
current_deps = GTK_CSS_EQUALS_PARENT;
}
else
current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
{
current = _gtk_css_style_property_get_initial_value (_gtk_css_style_property_lookup_by_id (GTK_CSS_PROPERTY_COLOR));
current_deps = 0;
}
}
else
{
current = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_COLOR);
current_deps = GTK_CSS_DEPENDS_ON_COLOR;
}
resolved = _gtk_style_context_resolve_color_value (context, current, value);
resolved = _gtk_style_context_resolve_color_value (context, current, current_deps, value, dependencies);
if (resolved == NULL)
return gtk_css_value_symbolic_get_fallback (property_id, context);
@ -711,8 +717,10 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
current = _gtk_css_rgba_value_new_from_rgba (&pink);
v =_gtk_symbolic_color_resolve_full (color,
current,
0,
resolve_lookup_color,
props);
props,
NULL);
_gtk_css_value_unref (current);
if (v == NULL)
return FALSE;
@ -725,15 +733,22 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
GtkCssValue *
_gtk_symbolic_color_resolve_full (GtkSymbolicColor *color,
GtkCssValue *current,
GtkCssDependencies current_deps,
GtkSymbolicColorLookupFunc func,
gpointer data)
gpointer data,
GtkCssDependencies *dependencies)
{
GtkCssDependencies unused;
GtkCssValue *value;
g_return_val_if_fail (color != NULL, FALSE);
g_return_val_if_fail (current != NULL, FALSE);
g_return_val_if_fail (func != NULL, FALSE);
if (dependencies == NULL)
dependencies = &unused;
*dependencies = 0;
value = NULL;
switch (color->type)
{
@ -748,7 +763,7 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor *color,
if (!named_color)
return NULL;
return _gtk_symbolic_color_resolve_full (named_color, current, func, data);
return _gtk_symbolic_color_resolve_full (named_color, current, current_deps, func, data, dependencies);
}
break;
@ -757,10 +772,11 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor *color,
GtkCssValue *val;
GdkRGBA shade;
val = _gtk_symbolic_color_resolve_full (color->shade.color, current, func, data);
val = _gtk_symbolic_color_resolve_full (color->shade.color, current, current_deps, func, data, dependencies);
if (val == NULL)
return NULL;
*dependencies = _gtk_css_dependencies_union (*dependencies, 0);
shade = *_gtk_css_rgba_value_get_rgba (val);
_shade_color (&shade, color->shade.factor);
@ -775,10 +791,11 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor *color,
GtkCssValue *val;
GdkRGBA alpha;
val = _gtk_symbolic_color_resolve_full (color->alpha.color, current, func, data);
val = _gtk_symbolic_color_resolve_full (color->alpha.color, current, current_deps, func, data, dependencies);
if (val == NULL)
return NULL;
*dependencies = _gtk_css_dependencies_union (*dependencies, 0);
alpha = *_gtk_css_rgba_value_get_rgba (val);
alpha.alpha = CLAMP (alpha.alpha * color->alpha.factor, 0, 1);
@ -792,20 +809,21 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor *color,
{
GtkCssValue *val;
GdkRGBA color1, color2, res;
GtkCssDependencies dep1, dep2;
val = _gtk_symbolic_color_resolve_full (color->mix.color1, current, func, data);
val = _gtk_symbolic_color_resolve_full (color->mix.color1, current, current_deps, func, data, &dep1);
if (val == NULL)
return NULL;
color1 = *_gtk_css_rgba_value_get_rgba (val);
_gtk_css_value_unref (val);
val = _gtk_symbolic_color_resolve_full (color->mix.color2, current, func, data);
val = _gtk_symbolic_color_resolve_full (color->mix.color2, current, current_deps, func, data, &dep2);
if (val == NULL)
return NULL;
color2 = *_gtk_css_rgba_value_get_rgba (val);
_gtk_css_value_unref (val);
*dependencies = _gtk_css_dependencies_union (dep1, dep2);
res.red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 1);
res.green = CLAMP (color1.green + ((color2.green - color1.green) * color->mix.factor), 0, 1);
res.blue = CLAMP (color1.blue + ((color2.blue - color1.blue) * color->mix.factor), 0, 1);
@ -830,9 +848,14 @@ _gtk_symbolic_color_resolve_full (GtkSymbolicColor *color,
break;
case COLOR_TYPE_CURRENT_COLOR:
if (current)
return _gtk_css_value_ref (current);
{
*dependencies = current_deps;
return _gtk_css_value_ref (current);
}
else
return NULL;
{
return NULL;
}
break;
default:
g_assert_not_reached ();

View File

@ -28,8 +28,10 @@ typedef GtkSymbolicColor * (* GtkSymbolicColorLookupFunc) (gpointer data, const
GtkCssValue * _gtk_symbolic_color_resolve_full (GtkSymbolicColor *color,
GtkCssValue *current,
GtkCssDependencies current_deps,
GtkSymbolicColorLookupFunc func,
gpointer data);
gpointer data,
GtkCssDependencies *dependencies);
GtkSymbolicColor * _gtk_symbolic_color_get_current_color (void);