cssimage: Implement dependencies for images

This commit is contained in:
Benjamin Otte 2012-08-28 15:29:56 +02:00
parent 3a65fbfc13
commit e1a1432bd3
5 changed files with 40 additions and 23 deletions

View File

@ -57,9 +57,10 @@ gtk_css_image_real_get_aspect_ratio (GtkCssImage *image)
}
static GtkCssImage *
gtk_css_image_real_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
gtk_css_image_real_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context,
GtkCssDependencies *dependencies)
{
return g_object_ref (image);
}
@ -115,18 +116,24 @@ _gtk_css_image_get_aspect_ratio (GtkCssImage *image)
}
GtkCssImage *
_gtk_css_image_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
_gtk_css_image_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context,
GtkCssDependencies *dependencies)
{
GtkCssDependencies unused;
GtkCssImageClass *klass;
g_return_val_if_fail (GTK_IS_CSS_IMAGE (image), NULL);
g_return_val_if_fail (GTK_IS_STYLE_CONTEXT (context), NULL);
if (dependencies == NULL)
dependencies = &unused;
*dependencies = 0;
klass = GTK_CSS_IMAGE_GET_CLASS (image);
return klass->compute (image, property_id, context);
return klass->compute (image, property_id, context, dependencies);
}
void

View File

@ -23,13 +23,15 @@
#include "gtkcssprovider.h"
#include "gtksymboliccolorprivate.h"
#include "gtkstylepropertiesprivate.h"
G_DEFINE_TYPE (GtkCssImageGradient, _gtk_css_image_gradient, GTK_TYPE_CSS_IMAGE)
static GtkCssImage *
gtk_css_image_gradient_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
gtk_css_image_gradient_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context,
GtkCssDependencies *dependencies)
{
GtkCssImageGradient *gradient = GTK_CSS_IMAGE_GRADIENT (image);
GtkCssImageGradient *copy;
@ -39,7 +41,7 @@ gtk_css_image_gradient_compute (GtkCssImage *image,
copy = g_object_new (GTK_TYPE_CSS_IMAGE_GRADIENT, NULL);
copy->gradient = gtk_gradient_ref (gradient->gradient);
copy->pattern = gtk_gradient_resolve_for_context (copy->gradient, context);
copy->pattern = _gtk_gradient_resolve_full (copy->gradient, context, dependencies);
return GTK_CSS_IMAGE (copy);
}

View File

@ -409,9 +409,10 @@ gtk_css_image_linear_print (GtkCssImage *image,
}
static GtkCssImage *
gtk_css_image_linear_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context)
gtk_css_image_linear_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context,
GtkCssDependencies *dependencies)
{
GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
GtkCssImageLinear *copy;
@ -420,22 +421,29 @@ gtk_css_image_linear_compute (GtkCssImage *image,
copy = g_object_new (GTK_TYPE_CSS_IMAGE_LINEAR, NULL);
copy->repeating = linear->repeating;
copy->angle = _gtk_css_value_compute (linear->angle, property_id, context, NULL);
copy->angle = _gtk_css_value_compute (linear->angle, property_id, context, dependencies);
g_array_set_size (copy->stops, linear->stops->len);
for (i = 0; i < linear->stops->len; i++)
{
GtkCssImageLinearColorStop *stop, *scopy;
GtkCssDependencies child_deps;
stop = &g_array_index (linear->stops, GtkCssImageLinearColorStop, i);
scopy = &g_array_index (copy->stops, GtkCssImageLinearColorStop, i);
scopy->color = _gtk_css_value_compute (stop->color, property_id, context, NULL);
scopy->color = _gtk_css_value_compute (stop->color, property_id, context, &child_deps);
*dependencies = _gtk_css_dependencies_union (*dependencies, child_deps);
if (stop->offset)
scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context, NULL);
{
scopy->offset = _gtk_css_value_compute (stop->offset, property_id, context, &child_deps);
*dependencies = _gtk_css_dependencies_union (*dependencies, child_deps);
}
else
scopy->offset = NULL;
{
scopy->offset = NULL;
}
}
return GTK_CSS_IMAGE (copy);

View File

@ -57,7 +57,8 @@ struct _GtkCssImageClass
/* create "computed value" in CSS terms, returns a new reference */
GtkCssImage *(* compute) (GtkCssImage *image,
guint property_id,
GtkStyleContext *context);
GtkStyleContext *context,
GtkCssDependencies *dependencies);
/* draw to 0,0 with the given width and height */
void (* draw) (GtkCssImage *image,
@ -83,7 +84,8 @@ double _gtk_css_image_get_aspect_ratio (GtkCssImage *image);
GtkCssImage * _gtk_css_image_compute (GtkCssImage *image,
guint property_id,
GtkStyleContext *context);
GtkStyleContext *context,
GtkCssDependencies *dependencies);
void _gtk_css_image_draw (GtkCssImage *image,
cairo_t *cr,

View File

@ -46,7 +46,7 @@ gtk_css_value_image_compute (GtkCssValue *value,
if (image == NULL)
return _gtk_css_value_ref (value);
computed = _gtk_css_image_compute (image, property_id, context);
computed = _gtk_css_image_compute (image, property_id, context, dependencies);
if (computed == image)
{
@ -54,8 +54,6 @@ gtk_css_value_image_compute (GtkCssValue *value,
return _gtk_css_value_ref (value);
}
*dependencies = GTK_CSS_DEPENDS_ON_EVERYTHING;
return _gtk_css_image_value_new (computed);
}