[gtk+/composite-templates] cssimage: Implement dependencies for images



commit 5b76daeb8182264f231b3f0baff9b19dc4a95f78
Author: Benjamin Otte <otte redhat com>
Date:   Tue Aug 28 15:29:56 2012 +0200

    cssimage: Implement dependencies for images

 gtk/gtkcssimage.c         |   21 ++++++++++++++-------
 gtk/gtkcssimagegradient.c |   10 ++++++----
 gtk/gtkcssimagelinear.c   |   22 +++++++++++++++-------
 gtk/gtkcssimageprivate.h  |    6 ++++--
 gtk/gtkcssimagevalue.c    |    4 +---
 5 files changed, 40 insertions(+), 23 deletions(-)
---
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index e10de72..d990fc7 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -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
diff --git a/gtk/gtkcssimagegradient.c b/gtk/gtkcssimagegradient.c
index 254ebc8..adaee94 100644
--- a/gtk/gtkcssimagegradient.c
+++ b/gtk/gtkcssimagegradient.c
@@ -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);
 }
diff --git a/gtk/gtkcssimagelinear.c b/gtk/gtkcssimagelinear.c
index 998d366..8dee697 100644
--- a/gtk/gtkcssimagelinear.c
+++ b/gtk/gtkcssimagelinear.c
@@ -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);
diff --git a/gtk/gtkcssimageprivate.h b/gtk/gtkcssimageprivate.h
index e14387b..2899ef2 100644
--- a/gtk/gtkcssimageprivate.h
+++ b/gtk/gtkcssimageprivate.h
@@ -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,
diff --git a/gtk/gtkcssimagevalue.c b/gtk/gtkcssimagevalue.c
index e56db9d..c40354f 100644
--- a/gtk/gtkcssimagevalue.c
+++ b/gtk/gtkcssimagevalue.c
@@ -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);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]