[gtk/wip/baedert/css-values] cssimage: Add is_computed vfunc



commit 28d31a487e9b6d8e8177a400431c6357c4591cb1
Author: Timm Bäder <mail baedert org>
Date:   Sat Jan 11 14:38:49 2020 +0100

    cssimage: Add is_computed vfunc
    
    Same semantics as the is_computed field of GtkCssValue

 gtk/gtkcssimage.c          | 13 +++++++++++++
 gtk/gtkcssimagecrossfade.c | 17 +++++++++++++++++
 gtk/gtkcssimagefallback.c  | 25 +++++++++++++++++++++++++
 gtk/gtkcssimagelinear.c    | 28 ++++++++++++++++++++++++++++
 gtk/gtkcssimageprivate.h   |  3 +++
 gtk/gtkcssimageradial.c    | 27 +++++++++++++++++++++++++++
 gtk/gtkcssimagevalue.c     |  1 +
 7 files changed, 114 insertions(+)
---
diff --git a/gtk/gtkcssimage.c b/gtk/gtkcssimage.c
index 91507c0af4..5398412876 100644
--- a/gtk/gtkcssimage.c
+++ b/gtk/gtkcssimage.c
@@ -565,3 +565,16 @@ _gtk_css_image_new_parse (GtkCssParser *parser)
   return image;
 }
 
+gboolean
+gtk_css_image_is_computed (GtkCssImage *image)
+{
+  GtkCssImageClass *klass = GTK_CSS_IMAGE_GET_CLASS (image);
+
+  if (!klass->is_computed)
+    return FALSE;
+
+  if (gtk_css_image_is_dynamic (image))
+    return FALSE;
+
+  return klass->is_computed (image);
+}
diff --git a/gtk/gtkcssimagecrossfade.c b/gtk/gtkcssimagecrossfade.c
index 57bc96d386..2d281b26cc 100644
--- a/gtk/gtkcssimagecrossfade.c
+++ b/gtk/gtkcssimagecrossfade.c
@@ -414,6 +414,22 @@ gtk_css_image_cross_fade_dispose (GObject *object)
   G_OBJECT_CLASS (gtk_css_image_cross_fade_parent_class)->dispose (object);
 }
 
+static gboolean
+gtk_css_image_cross_fade_is_computed (GtkCssImage *image)
+{
+  GtkCssImageCrossFade *cross_fade = GTK_CSS_IMAGE_CROSS_FADE (image);
+  guint i;
+
+  for (i = 0; i < cross_fade->images->len; i++)
+    {
+      const CrossFadeEntry *entry = &g_array_index (cross_fade->images, CrossFadeEntry, i);
+      if (!gtk_css_image_is_computed (entry->image))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
 static void
 gtk_css_image_cross_fade_class_init (GtkCssImageCrossFadeClass *klass)
 {
@@ -429,6 +445,7 @@ gtk_css_image_cross_fade_class_init (GtkCssImageCrossFadeClass *klass)
   image_class->get_dynamic_image = gtk_css_image_cross_fade_get_dynamic_image;
   image_class->parse = gtk_css_image_cross_fade_parse;
   image_class->print = gtk_css_image_cross_fade_print;
+  image_class->is_computed = gtk_css_image_cross_fade_is_computed;
 
   object_class->dispose = gtk_css_image_cross_fade_dispose;
 }
diff --git a/gtk/gtkcssimagefallback.c b/gtk/gtkcssimagefallback.c
index 879703b0d9..d922da942b 100644
--- a/gtk/gtkcssimagefallback.c
+++ b/gtk/gtkcssimagefallback.c
@@ -270,6 +270,30 @@ gtk_css_image_fallback_equal (GtkCssImage *image1,
                                fallback2->images[fallback2->used]);
 }
 
+static gboolean
+gtk_css_image_fallback_is_computed (GtkCssImage *image)
+{
+  GtkCssImageFallback *fallback = GTK_CSS_IMAGE_FALLBACK (image);
+
+  if (fallback->used < 0)
+    {
+      guint i;
+
+      if (fallback->color && !fallback->images)
+        return gtk_css_value_is_computed (fallback->color);
+
+      for (i = 0; i < fallback->n_images; i++)
+        {
+          if (!gtk_css_image_is_computed (fallback->images[i]))
+            {
+              return FALSE;
+            }
+        }
+    }
+
+  return TRUE;
+}
+
 static void
 _gtk_css_image_fallback_class_init (GtkCssImageFallbackClass *klass)
 {
@@ -284,6 +308,7 @@ _gtk_css_image_fallback_class_init (GtkCssImageFallbackClass *klass)
   image_class->compute = gtk_css_image_fallback_compute;
   image_class->print = gtk_css_image_fallback_print;
   image_class->equal = gtk_css_image_fallback_equal;
+  image_class->is_computed = gtk_css_image_fallback_is_computed;
 
   object_class->dispose = gtk_css_image_fallback_dispose;
 }
diff --git a/gtk/gtkcssimagelinear.c b/gtk/gtkcssimagelinear.c
index 8ae38a8288..c861d47210 100644
--- a/gtk/gtkcssimagelinear.c
+++ b/gtk/gtkcssimagelinear.c
@@ -688,6 +688,33 @@ gtk_css_image_linear_dispose (GObject *object)
   G_OBJECT_CLASS (_gtk_css_image_linear_parent_class)->dispose (object);
 }
 
+static gboolean
+gtk_css_image_linear_is_computed (GtkCssImage *image)
+{
+  GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
+  guint i;
+  gboolean computed = TRUE;
+
+  for (i = 0; i < linear->n_stops; i ++)
+    {
+      const GtkCssImageLinearColorStop *stop = &linear->color_stops[i];
+
+      if (stop->offset && !gtk_css_value_is_computed (stop->offset))
+        {
+          computed = FALSE;
+          break;
+        }
+
+      if (!gtk_css_value_is_computed (stop->color))
+        {
+          computed = FALSE;
+          break;
+        }
+    }
+
+  return computed;
+}
+
 static void
 _gtk_css_image_linear_class_init (GtkCssImageLinearClass *klass)
 {
@@ -700,6 +727,7 @@ _gtk_css_image_linear_class_init (GtkCssImageLinearClass *klass)
   image_class->compute = gtk_css_image_linear_compute;
   image_class->equal = gtk_css_image_linear_equal;
   image_class->transition = gtk_css_image_linear_transition;
+  image_class->is_computed = gtk_css_image_linear_is_computed;
 
   object_class->dispose = gtk_css_image_linear_dispose;
 }
diff --git a/gtk/gtkcssimageprivate.h b/gtk/gtkcssimageprivate.h
index f39d73ae8d..b467112e6e 100644
--- a/gtk/gtkcssimageprivate.h
+++ b/gtk/gtkcssimageprivate.h
@@ -89,6 +89,7 @@ struct _GtkCssImageClass
   /* print to CSS */
   void         (* print)                           (GtkCssImage                *image,
                                                     GString                    *string);
+  gboolean     (* is_computed)                     (GtkCssImage                *image);
 };
 
 GType          _gtk_css_image_get_type             (void) G_GNUC_CONST;
@@ -139,6 +140,8 @@ cairo_surface_t *
                                                     cairo_surface_t            *target,
                                                     int                         surface_width,
                                                     int                         surface_height);
+gboolean       gtk_css_image_is_computed           (GtkCssImage                *image);
+
 
 G_END_DECLS
 
diff --git a/gtk/gtkcssimageradial.c b/gtk/gtkcssimageradial.c
index 29778e0a85..934e5150f9 100644
--- a/gtk/gtkcssimageradial.c
+++ b/gtk/gtkcssimageradial.c
@@ -744,6 +744,32 @@ gtk_css_image_radial_dispose (GObject *object)
   G_OBJECT_CLASS (_gtk_css_image_radial_parent_class)->dispose (object);
 }
 
+static gboolean
+gtk_css_image_radial_is_computed (GtkCssImage *image)
+{
+  GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image);
+  guint i;
+  gboolean computed = TRUE;
+
+  for (i = 0; i < radial->n_stops; i ++)
+    {
+      const GtkCssImageRadialColorStop *stop = &radial->color_stops[i];
+
+      if (stop->offset && !gtk_css_value_is_computed (stop->offset))
+        {
+          computed = FALSE;
+          break;
+        }
+
+      if (!gtk_css_value_is_computed (stop->color))
+        {
+          computed = FALSE;
+          break;
+        }
+    }
+
+  return computed;
+}
 static void
 _gtk_css_image_radial_class_init (GtkCssImageRadialClass *klass)
 {
@@ -756,6 +782,7 @@ _gtk_css_image_radial_class_init (GtkCssImageRadialClass *klass)
   image_class->compute = gtk_css_image_radial_compute;
   image_class->transition = gtk_css_image_radial_transition;
   image_class->equal = gtk_css_image_radial_equal;
+  image_class->is_computed = gtk_css_image_radial_is_computed;
 
   object_class->dispose = gtk_css_image_radial_dispose;
 }
diff --git a/gtk/gtkcssimagevalue.c b/gtk/gtkcssimagevalue.c
index addbe928be..ceeba6cafc 100644
--- a/gtk/gtkcssimagevalue.c
+++ b/gtk/gtkcssimagevalue.c
@@ -144,6 +144,7 @@ _gtk_css_image_value_new (GtkCssImage *image)
 
   value = _gtk_css_value_new (GtkCssValue, &GTK_CSS_VALUE_IMAGE);
   value->image = image;
+  value->is_computed = gtk_css_image_is_computed (image);
 
   return value;
 }


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