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.
This commit is contained in:
Benjamin Otte 2011-05-16 23:37:29 +02:00
parent 82399bf457
commit c1dc3e9372
3 changed files with 73 additions and 58 deletions

View File

@ -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);
}
}

View File

@ -602,6 +602,60 @@ gtk_style_properties_lookup_color (GtkStyleProperties *props,
return g_hash_table_lookup (priv->color_map, name);
}
void
_gtk_style_properties_set_property_by_pspec (GtkStyleProperties *props,
GParamSpec *pspec,
GtkStateFlags state,
const GValue *value)
{
GtkStylePropertiesPrivate *priv;
PropertyData *prop;
GType value_type;
GValue *val;
value_type = G_VALUE_TYPE (value);
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 (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 (pspec->value_type == value_type);
priv = props->priv;
prop = g_hash_table_lookup (priv->properties, pspec);
if (!prop)
{
prop = property_data_new ();
g_hash_table_insert (priv->properties, pspec, prop);
}
val = property_data_get_value (prop, state);
if (G_VALUE_TYPE (val) == value_type)
g_value_reset (val);
else
{
if (G_IS_VALUE (val))
g_value_unset (val);
g_value_init (val, value_type);
}
g_value_copy (value, val);
}
/**
* gtk_style_properties_set_property:
* @props: a #GtkStyleProperties
@ -619,17 +673,12 @@ gtk_style_properties_set_property (GtkStyleProperties *props,
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)
@ -638,45 +687,10 @@ gtk_style_properties_set_property (GtkStyleProperties *props,
return;
}
if (node->pspec->value_type == GDK_TYPE_RGBA ||
node->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)
{
/* 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);
priv = props->priv;
prop = g_hash_table_lookup (priv->properties, node->pspec);
if (!prop)
{
prop = property_data_new ();
g_hash_table_insert (priv->properties, node->pspec, prop);
}
val = property_data_get_value (prop, state);
if (G_VALUE_TYPE (val) == value_type)
g_value_reset (val);
else
{
if (G_IS_VALUE (val))
g_value_unset (val);
g_value_init (val, value_type);
}
g_value_copy (value, val);
_gtk_style_properties_set_property_by_pspec (props,
node->pspec,
state,
value);
}
/**

View File

@ -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