cssvalue: Handle dependencies for typed values

This commit is contained in:
Benjamin Otte 2012-08-27 17:52:02 +02:00
parent 11d0f9e408
commit 3cf6db8b1a
3 changed files with 29 additions and 18 deletions

View File

@ -53,7 +53,8 @@ typedef gboolean (* GtkStyleParseFunc) (GtkCssParser
typedef void (* GtkStylePrintFunc) (const GValue *value,
GString *string);
typedef GtkCssValue * (* GtkStyleComputeFunc) (GtkStyleContext *context,
GtkCssValue *specified);
GtkCssValue *specified,
GtkCssDependencies *dependencies);
static void
register_conversion_function (GType type,
@ -202,8 +203,9 @@ rgba_value_print (const GValue *value,
}
static GtkCssValue *
rgba_value_compute (GtkStyleContext *context,
GtkCssValue *specified)
rgba_value_compute (GtkStyleContext *context,
GtkCssValue *specified,
GtkCssDependencies *dependencies)
{
GdkRGBA white = { 1, 1, 1, 1 };
const GValue *value;
@ -216,7 +218,7 @@ rgba_value_compute (GtkStyleContext *context,
GValue new_value = G_VALUE_INIT;
GdkRGBA rgba;
if (!_gtk_style_context_resolve_color (context, symbolic, &rgba, NULL))
if (!_gtk_style_context_resolve_color (context, symbolic, &rgba, dependencies))
rgba = white;
g_value_init (&new_value, GDK_TYPE_RGBA);
@ -275,8 +277,9 @@ color_value_print (const GValue *value,
}
static GtkCssValue *
color_value_compute (GtkStyleContext *context,
GtkCssValue *specified)
color_value_compute (GtkStyleContext *context,
GtkCssValue *specified,
GtkCssDependencies *dependencies)
{
GdkRGBA rgba;
GdkColor color = { 0, 65535, 65535, 65535 };
@ -291,7 +294,7 @@ color_value_compute (GtkStyleContext *context,
if (_gtk_style_context_resolve_color (context,
g_value_get_boxed (value),
&rgba,
NULL))
dependencies))
{
color.red = rgba.red * 65535. + 0.5;
color.green = rgba.green * 65535. + 0.5;
@ -816,8 +819,9 @@ pattern_value_print (const GValue *value,
}
static GtkCssValue *
pattern_value_compute (GtkStyleContext *context,
GtkCssValue *specified)
pattern_value_compute (GtkStyleContext *context,
GtkCssValue *specified,
GtkCssDependencies *dependencies)
{
const GValue *value = _gtk_css_typed_value_get (specified);
@ -826,6 +830,8 @@ pattern_value_compute (GtkStyleContext *context,
GValue new_value = G_VALUE_INIT;
cairo_pattern_t *gradient;
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
gradient = gtk_gradient_resolve_for_context (g_value_get_boxed (value), context);
g_value_init (&new_value, CAIRO_GOBJECT_TYPE_PATTERN);
@ -1081,23 +1087,29 @@ _gtk_css_style_print_value (const GValue *value,
/**
* _gtk_css_style_compute_value:
* @computed: (out): a value to be filled with the result
* @context: the context to use for computing the value
* @target_type: Type the resulting value should have
* @specified: the value to use for the computation
* @dependencies: (out): Value initialized with 0 to take the dependencies
* of the returned value
*
* Converts the @specified value into the @computed value using the
* information in @context. The values must have matching types, ie
* @specified must be a result of a call to
* _gtk_css_style_parse_value() with the same type as @computed.
*
* Returns: the resulting value
**/
GtkCssValue *
_gtk_css_style_compute_value (GtkStyleContext *context,
GType target_type,
GtkCssValue *specified)
_gtk_css_style_compute_value (GtkStyleContext *context,
GType target_type,
GtkCssValue *specified,
GtkCssDependencies *dependencies)
{
GtkStyleComputeFunc func;
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
g_return_val_if_fail (*dependencies == 0, NULL);
gtk_css_style_funcs_init ();
@ -1108,7 +1120,7 @@ _gtk_css_style_compute_value (GtkStyleContext *context,
GSIZE_TO_POINTER (g_type_fundamental (target_type)));
if (func)
return func (context, specified);
return func (context, specified, dependencies);
else
return _gtk_css_value_ref (specified);
}

View File

@ -30,7 +30,8 @@ void _gtk_css_style_print_value (const GValue
GString *string);
GtkCssValue * _gtk_css_style_compute_value (GtkStyleContext *context,
GType target_type,
GtkCssValue *specified);
GtkCssValue *specified,
GtkCssDependencies *dependencies);
G_END_DECLS

View File

@ -42,9 +42,7 @@ gtk_css_value_typed_compute (GtkCssValue *value,
{
GtkCssCustomProperty *custom = GTK_CSS_CUSTOM_PROPERTY (_gtk_css_style_property_lookup_by_id (property_id));
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
return _gtk_css_style_compute_value (context, custom->pspec->value_type, value);
return _gtk_css_style_compute_value (context, custom->pspec->value_type, value, dependencies);
}
static gboolean