[gtk+] css: Make color lookup handle dependencies
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] css: Make color lookup handle dependencies
- Date: Tue, 28 Aug 2012 13:47:57 +0000 (UTC)
commit 11d0f9e408eaa403fd56715188d0f1b78bbaa1a4
Author: Benjamin Otte <otte redhat com>
Date: Mon Aug 27 17:27:06 2012 +0200
css: Make color lookup handle dependencies
gtk/gtkcssstylefuncs.c | 5 ++-
gtk/gtkgradient.c | 2 +-
gtk/gtkstylecontext.c | 27 +++++++++++++-------
gtk/gtkstylecontextprivate.h | 25 +++++++++++--------
gtk/gtksymboliccolor.c | 53 +++++++++++++++++++++++++++++-----------
gtk/gtksymboliccolorprivate.h | 4 ++-
6 files changed, 76 insertions(+), 40 deletions(-)
---
diff --git a/gtk/gtkcssstylefuncs.c b/gtk/gtkcssstylefuncs.c
index 9db3510..1d5d6ae 100644
--- a/gtk/gtkcssstylefuncs.c
+++ b/gtk/gtkcssstylefuncs.c
@@ -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;
diff --git a/gtk/gtkgradient.c b/gtk/gtkgradient.c
index ffbadc8..9743654 100644
--- a/gtk/gtkgradient.c
+++ b/gtk/gtkgradient.c
@@ -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,
diff --git a/gtk/gtkstylecontext.c b/gtk/gtkstylecontext.c
index 7163b81..0b3cf04 100644
--- a/gtk/gtkstylecontext.c
+++ b/gtk/gtkstylecontext.c
@@ -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);
}
/**
diff --git a/gtk/gtkstylecontextprivate.h b/gtk/gtkstylecontextprivate.h
index 9642793..1c950b9 100644
--- a/gtk/gtkstylecontextprivate.h
+++ b/gtk/gtkstylecontextprivate.h
@@ -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);
-
-void _gtk_style_context_stop_animations (GtkStyleContext *context);
+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);
G_END_DECLS
diff --git a/gtk/gtksymboliccolor.c b/gtk/gtksymboliccolor.c
index 9fcfd49..a96f9f5 100644
--- a/gtk/gtksymboliccolor.c
+++ b/gtk/gtksymboliccolor.c
@@ -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 ();
diff --git a/gtk/gtksymboliccolorprivate.h b/gtk/gtksymboliccolorprivate.h
index 03b3b32..fb1f6b7 100644
--- a/gtk/gtksymboliccolorprivate.h
+++ b/gtk/gtksymboliccolorprivate.h
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]