[gtk+/parser] css: Refactor code to do property lookups earlier



commit ab24e7b73b93c51f9a84da03260f29e3303db128
Author: Benjamin Otte <otte redhat com>
Date:   Mon May 16 23:37:29 2011 +0200

    css: Refactor code to do property lookups earlier
    
    We want to ook up the property in the CSS parser, so we can do fancy
    things with it. We currently don't but we want to later.

 gtk/gtkcssprovider.c            |   20 ++++------
 gtk/gtkstyleproperties.c        |   80 +++++++++++++++++++++++----------------
 gtk/gtkstylepropertiesprivate.h |   11 ++++-
 3 files changed, 63 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index eba21d1..2e3af1b 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -33,6 +33,7 @@
 #include "gtksymboliccolor.h"
 #include "gtkstyleprovider.h"
 #include "gtkstylecontextprivate.h"
+#include "gtkstylepropertiesprivate.h"
 #include "gtkbindings.h"
 #include "gtkmarshalers.h"
 #include "gtkprivate.h"
@@ -1130,20 +1131,15 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
 
       while (g_hash_table_iter_next (&iter, &key, &value))
         {
-          gchar *prop = key;
+          GParamSpec *pspec;
 
-          /* Properties starting with '-' may be both widget style properties
-           * or custom properties from the theming engine, so check whether
-           * the type is registered or not.
-           */
-          if (prop[0] == '-' &&
-              !gtk_style_properties_lookup_property (prop, NULL, NULL))
+          if (!gtk_style_properties_lookup_property (key, NULL, &pspec))
             continue;
 
-          gtk_style_properties_set_property (props,
-                                             key,
-                                             _gtk_css_selector_get_state_flags (info->selector),
-                                             value);
+          _gtk_style_properties_set_property_by_pspec (props,
+                                                       pspec,
+                                                       _gtk_css_selector_get_state_flags (info->selector),
+                                                       value);
         }
     }
 
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
index aeabb95..27e7392 100644
--- a/gtk/gtkstyleproperties.c
+++ b/gtk/gtkstyleproperties.c
@@ -602,66 +602,43 @@ gtk_style_properties_lookup_color (GtkStyleProperties *props,
   return g_hash_table_lookup (priv->color_map, name);
 }
 
-/**
- * gtk_style_properties_set_property:
- * @props: a #GtkStyleProperties
- * @property: styling property to set
- * @state: state to set the value for
- * @value: new value for the property
- *
- * Sets a styling property in @props.
- *
- * Since: 3.0
- **/
 void
-gtk_style_properties_set_property (GtkStyleProperties *props,
-                                   const gchar        *property,
-                                   GtkStateFlags       state,
-                                   const GValue       *value)
+_gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
+                                             GParamSpec         *pspec,
+                                             GtkStateFlags       state,
+                                             const GValue       *value)
 {
   GtkStylePropertiesPrivate *priv;
-  PropertyNode *node;
   PropertyData *prop;
   GType value_type;
   GValue *val;
 
-  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
-  g_return_if_fail (property != NULL);
-  g_return_if_fail (value != NULL);
-
   value_type = G_VALUE_TYPE (value);
-  node = property_node_lookup (property);
 
-  if (!node)
-    {
-      g_warning ("Style property \"%s\" is not registered", property);
-      return;
-    }
-
-  if (node->pspec->value_type == GDK_TYPE_RGBA ||
-      node->pspec->value_type == GDK_TYPE_COLOR)
+  if (pspec->value_type == GDK_TYPE_RGBA ||
+      pspec->value_type == GDK_TYPE_COLOR)
     {
       /* Allow GtkSymbolicColor as well */
       g_return_if_fail (value_type == GDK_TYPE_RGBA ||
                         value_type == GDK_TYPE_COLOR ||
                         value_type == GTK_TYPE_SYMBOLIC_COLOR);
     }
-  else if (node->pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN)
+  else if (pspec->value_type == CAIRO_GOBJECT_TYPE_PATTERN)
     {
       /* Allow GtkGradient as a substitute */
       g_return_if_fail (value_type == CAIRO_GOBJECT_TYPE_PATTERN ||
                         value_type == GTK_TYPE_GRADIENT);
     }
   else
-    g_return_if_fail (node->pspec->value_type == value_type);
+    g_return_if_fail (pspec->value_type == value_type);
 
   priv = props->priv;
-  prop = g_hash_table_lookup (priv->properties, node->pspec);
+  prop = g_hash_table_lookup (priv->properties, pspec);
 
   if (!prop)
     {
       prop = property_data_new ();
-      g_hash_table_insert (priv->properties, node->pspec, prop);
+      g_hash_table_insert (priv->properties, pspec, prop);
     }
 
   val = property_data_get_value (prop, state);
@@ -680,6 +657,43 @@ gtk_style_properties_set_property (GtkStyleProperties *props,
 }
 
 /**
+ * gtk_style_properties_set_property:
+ * @props: a #GtkStyleProperties
+ * @property: styling property to set
+ * @state: state to set the value for
+ * @value: new value for the property
+ *
+ * Sets a styling property in @props.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_set_property (GtkStyleProperties *props,
+                                   const gchar        *property,
+                                   GtkStateFlags       state,
+                                   const GValue       *value)
+{
+  PropertyNode *node;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+  g_return_if_fail (property != NULL);
+  g_return_if_fail (value != NULL);
+
+  node = property_node_lookup (property);
+
+  if (!node)
+    {
+      g_warning ("Style property \"%s\" is not registered", property);
+      return;
+    }
+
+  _gtk_style_properties_set_property_by_pspec (props,
+                                               node->pspec,
+                                               state,
+                                               value);
+}
+
+/**
  * gtk_style_properties_set_valist:
  * @props: a #GtkStyleProperties
  * @state: state to set the values for
diff --git a/gtk/gtkstylepropertiesprivate.h b/gtk/gtkstylepropertiesprivate.h
index 91dc72f..f4cea2d 100644
--- a/gtk/gtkstylepropertiesprivate.h
+++ b/gtk/gtkstylepropertiesprivate.h
@@ -24,9 +24,14 @@
 
 G_BEGIN_DECLS
 
-const GValue * _gtk_style_properties_peek_property (GtkStyleProperties *props,
-                                                    const gchar        *prop_name,
-                                                    GtkStateFlags       state);
+const GValue * _gtk_style_properties_peek_property         (GtkStyleProperties *props,
+                                                            const gchar        *prop_name,
+                                                            GtkStateFlags       state);
+
+void           _gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
+                                                            GParamSpec         *pspec,
+                                                            GtkStateFlags       state,
+                                                            const GValue       *value);
 
 G_END_DECLS
 



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