[gtk+/wip/cssvalue: 51/137] cssvalue: Add _gtk_css_value_equal()



commit e261d6f4872c194c09e71e589739586dfd7dc40e
Author: Benjamin Otte <otte redhat com>
Date:   Tue Mar 27 01:43:12 2012 +0200

    cssvalue: Add _gtk_css_value_equal()
    
    For now, we return FALSE for all default css values, so this is not very
    useful.
    
    I also think of this as an optimization equal, not a guaranteed equal,
    because we don't even have a notion of what "equal" means.
    
    For example, for background-repeat, "repeat, repeat" and "repeat"
    are functionally equivalent. But the cssvalue has no idea that it's used
    for background-repeat.
    As a more complicated example, "repeat, no-repeat" and "repeat" are
    equal to what one sees as long as there's only one image listed
    background-image-source. But once you start transition'ing to an image
    with 2 sources, it's different...

 gtk/gtkcssarrayvalue.c    |   20 ++++++++++++++++++++
 gtk/gtkcssinheritvalue.c  |    8 ++++++++
 gtk/gtkcssinitialvalue.c  |    8 ++++++++
 gtk/gtkcssstyleproperty.c |    2 +-
 gtk/gtkcssvalue.c         |   21 +++++++++++++++++++++
 gtk/gtkcssvalueprivate.h  |    5 +++++
 6 files changed, 63 insertions(+), 1 deletions(-)
---
diff --git a/gtk/gtkcssarrayvalue.c b/gtk/gtkcssarrayvalue.c
index ba919da..922fdfd 100644
--- a/gtk/gtkcssarrayvalue.c
+++ b/gtk/gtkcssarrayvalue.c
@@ -40,6 +40,25 @@ gtk_css_value_array_free (GtkCssValue *value)
   g_slice_free1 (sizeof (GtkCssValue) + sizeof (GtkCssValue *) * (value->n_values - 1), value);
 }
 
+static gboolean
+gtk_css_value_array_equal (const GtkCssValue *value1,
+                           const GtkCssValue *value2)
+{
+  guint i;
+
+  if (value1->n_values != value2->n_values)
+    return FALSE;
+
+  for (i = 0; i < value1->n_values; i++)
+    {
+      if (!_gtk_css_value_equal (value1->values[i],
+                                 value2->values[i]))
+        return FALSE;
+    }
+
+  return TRUE;
+}
+
 static void
 gtk_css_value_array_print (const GtkCssValue *value,
                            GString           *string)
@@ -62,6 +81,7 @@ gtk_css_value_array_print (const GtkCssValue *value,
 
 static const GtkCssValueClass GTK_CSS_VALUE_ARRAY = {
   gtk_css_value_array_free,
+  gtk_css_value_array_equal,
   gtk_css_value_array_print
 };
 
diff --git a/gtk/gtkcssinheritvalue.c b/gtk/gtkcssinheritvalue.c
index 99405bb..427f7ec 100644
--- a/gtk/gtkcssinheritvalue.c
+++ b/gtk/gtkcssinheritvalue.c
@@ -30,6 +30,13 @@ gtk_css_value_inherit_free (GtkCssValue *value)
   g_assert_not_reached ();
 }
 
+static gboolean
+gtk_css_value_inherit_equal (const GtkCssValue *value1,
+                             const GtkCssValue *value2)
+{
+  return TRUE;
+}
+
 static void
 gtk_css_value_inherit_print (const GtkCssValue *value,
                              GString           *string)
@@ -39,6 +46,7 @@ gtk_css_value_inherit_print (const GtkCssValue *value,
 
 static const GtkCssValueClass GTK_CSS_VALUE_INHERIT = {
   gtk_css_value_inherit_free,
+  gtk_css_value_inherit_equal,
   gtk_css_value_inherit_print
 };
 
diff --git a/gtk/gtkcssinitialvalue.c b/gtk/gtkcssinitialvalue.c
index 32fb1c9..73fd38b 100644
--- a/gtk/gtkcssinitialvalue.c
+++ b/gtk/gtkcssinitialvalue.c
@@ -30,6 +30,13 @@ gtk_css_value_initial_free (GtkCssValue *value)
   g_assert_not_reached ();
 }
 
+static gboolean
+gtk_css_value_initial_equal (const GtkCssValue *value1,
+                             const GtkCssValue *value2)
+{
+  return TRUE;
+}
+
 static void
 gtk_css_value_initial_print (const GtkCssValue *value,
                              GString           *string)
@@ -39,6 +46,7 @@ gtk_css_value_initial_print (const GtkCssValue *value,
 
 static const GtkCssValueClass GTK_CSS_VALUE_INITIAL = {
   gtk_css_value_initial_free,
+  gtk_css_value_initial_equal,
   gtk_css_value_initial_print
 };
 
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index 933dbd4..a8bcf2f 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -311,7 +311,7 @@ gtk_css_style_property_real_equal (GtkCssStyleProperty *property,
                                    GtkCssValue         *value1,
                                    GtkCssValue         *value2)
 {
-  return FALSE;
+  return _gtk_css_value_equal (value1, value2);
 }
 
 static void
diff --git a/gtk/gtkcssvalue.c b/gtk/gtkcssvalue.c
index c03f872..be5470c 100644
--- a/gtk/gtkcssvalue.c
+++ b/gtk/gtkcssvalue.c
@@ -54,6 +54,13 @@ gtk_css_value_default_free (GtkCssValue *value)
   g_slice_free (GtkCssValue, value);
 }
 
+static gboolean
+gtk_css_value_default_equal (const GtkCssValue *value1,
+                             const GtkCssValue *value2)
+{
+  return FALSE;
+}
+
 static void
 gtk_css_value_default_print (const GtkCssValue *value,
                              GString           *string)
@@ -67,6 +74,7 @@ gtk_css_value_default_print (const GtkCssValue *value,
 
 static const GtkCssValueClass GTK_CSS_VALUE_DEFAULT = {
   gtk_css_value_default_free,
+  gtk_css_value_default_equal,
   gtk_css_value_default_print
 };
 
@@ -409,6 +417,19 @@ _gtk_css_value_unref (GtkCssValue *value)
   value->class->free (value);
 }
 
+gboolean
+_gtk_css_value_equal (const GtkCssValue *value1,
+                      const GtkCssValue *value2)
+{
+  g_return_val_if_fail (value1 != NULL, FALSE);
+  g_return_val_if_fail (value2 != NULL, FALSE);
+
+  if (value1->class != value2->class)
+    return FALSE;
+
+  return value1->class->equal (value1, value2);
+}
+
 void
 _gtk_css_value_print (const GtkCssValue *value,
                       GString           *string)
diff --git a/gtk/gtkcssvalueprivate.h b/gtk/gtkcssvalueprivate.h
index 90517b5..c726e18 100644
--- a/gtk/gtkcssvalueprivate.h
+++ b/gtk/gtkcssvalueprivate.h
@@ -48,6 +48,8 @@ typedef struct _GtkCssValueClass      GtkCssValueClass;
 struct _GtkCssValueClass {
   void          (* free)                              (GtkCssValue                *value);
 
+  gboolean      (* equal)                             (const GtkCssValue          *value1,
+                                                       const GtkCssValue          *value2);
   void          (* print)                             (const GtkCssValue          *value,
                                                        GString                    *string);
 };
@@ -61,6 +63,9 @@ GtkCssValue *_gtk_css_value_alloc                     (const GtkCssValueClass
 GtkCssValue *_gtk_css_value_ref                       (GtkCssValue                *value);
 void         _gtk_css_value_unref                     (GtkCssValue                *value);
 
+gboolean     _gtk_css_value_equal                     (const GtkCssValue          *value1,
+                                                       const GtkCssValue          *value2);
+
 void         _gtk_css_value_print                     (const GtkCssValue          *value,
                                                        GString                    *string);
 



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