diff options
author | Benjamin Otte <otte@redhat.com> | 2012-01-01 23:16:35 +0100 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2012-01-09 18:37:53 +0100 |
commit | 30eb26087c8b8ac3562c9370a07d3a389cd7a8e1 (patch) | |
tree | 4d41fc8674e0756daea97cb5bdb44bd9032a23d2 /gtk | |
parent | 79a171de0a592dcacdcd2151229ec77733441f15 (diff) | |
download | gtk+-30eb26087c8b8ac3562c9370a07d3a389cd7a8e1.tar.gz |
css: Feed sections to CSS lookup code
Diffstat (limited to 'gtk')
-rw-r--r-- | gtk/gtkcsslookup.c | 38 | ||||
-rw-r--r-- | gtk/gtkcsslookupprivate.h | 2 | ||||
-rw-r--r-- | gtk/gtkcssprovider.c | 2 | ||||
-rw-r--r-- | gtk/gtkcssshorthandpropertyimpl.c | 50 | ||||
-rw-r--r-- | gtk/gtkstyleproperties.c | 2 |
5 files changed, 46 insertions, 48 deletions
diff --git a/gtk/gtkcsslookup.c b/gtk/gtkcsslookup.c index 3e21304187..c3e6a7316f 100644 --- a/gtk/gtkcsslookup.c +++ b/gtk/gtkcsslookup.c @@ -26,9 +26,14 @@ #include "gtkcssstylepropertyprivate.h" #include "gtkstylepropertiesprivate.h" +typedef struct { + GtkCssSection *section; + const GValue *value; +} GtkCssLookupValue; + struct _GtkCssLookup { - GtkBitmask *missing; - const GValue *values[1]; + GtkBitmask *missing; + GtkCssLookupValue values[1]; }; GtkCssLookup * @@ -37,7 +42,7 @@ _gtk_css_lookup_new (void) GtkCssLookup *lookup; guint n = _gtk_css_style_property_get_n_properties (); - lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (const GValue *) * n); + lookup = g_malloc0 (sizeof (GtkCssLookup) + sizeof (GtkCssLookupValue) * n); lookup->missing = _gtk_bitmask_new (); _gtk_bitmask_invert_range (lookup->missing, 0, n); @@ -67,30 +72,35 @@ _gtk_css_lookup_is_missing (const GtkCssLookup *lookup, { g_return_val_if_fail (lookup != NULL, FALSE); - return lookup->values[id] == NULL; + return lookup->values[id].value == NULL; } /** * _gtk_css_lookup_set: * @lookup: the lookup * @id: id of the property to set, see _gtk_style_property_get_id() + * @section: (allow-none): The @section the value was defined in or %NULL * @value: the "cascading value" to use * * Sets the @value for a given @id. No value may have been set for @id * before. See _gtk_css_lookup_is_missing(). This function is used to - * set the "winning declaration" of a lookup. + * set the "winning declaration" of a lookup. Note that for performance + * reasons @value and @section are not copied. It is your responsibility + * to ensure they are kept alive until _gtk_css_lookup_free() is called. **/ void -_gtk_css_lookup_set (GtkCssLookup *lookup, - guint id, - const GValue *value) +_gtk_css_lookup_set (GtkCssLookup *lookup, + guint id, + GtkCssSection *section, + const GValue *value) { g_return_if_fail (lookup != NULL); g_return_if_fail (_gtk_bitmask_get (lookup->missing, id)); g_return_if_fail (value != NULL); _gtk_bitmask_set (lookup->missing, id, FALSE); - lookup->values[id] = value; + lookup->values[id].value = value; + lookup->values[id].section = section; } /** @@ -130,20 +140,20 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup, * by following this pseudo-algorithm: * 1) Identify all declarations that apply to the element */ - if (lookup->values[i] != NULL) + if (lookup->values[i].value != NULL) { /* 2) If the cascading process (described below) yields a winning * declaration and the value of the winning declaration is not * ‘initial’ or ‘inherit’, the value of the winning declaration * becomes the specified value. */ - if (!G_VALUE_HOLDS (lookup->values[i], GTK_TYPE_CSS_SPECIAL_VALUE)) + if (!G_VALUE_HOLDS (lookup->values[i].value, GTK_TYPE_CSS_SPECIAL_VALUE)) { - result = lookup->values[i]; + result = lookup->values[i].value; } else { - switch (g_value_get_enum (lookup->values[i])) + switch (g_value_get_enum (lookup->values[i].value)) { case GTK_CSS_INHERIT: /* 3) if the value of the winning declaration is ‘inherit’, @@ -159,7 +169,7 @@ _gtk_css_lookup_resolve (GtkCssLookup *lookup, break; default: /* This is part of (2) above */ - result = lookup->values[i]; + result = lookup->values[i].value; break; } } diff --git a/gtk/gtkcsslookupprivate.h b/gtk/gtkcsslookupprivate.h index 19001d8cee..79e5578686 100644 --- a/gtk/gtkcsslookupprivate.h +++ b/gtk/gtkcsslookupprivate.h @@ -22,6 +22,7 @@ #include <glib-object.h> #include "gtk/gtkbitmaskprivate.h" +#include "gtk/gtkcsssection.h" #include "gtk/gtkstylecontext.h" #include "gtk/gtkstyleproperties.h" @@ -38,6 +39,7 @@ gboolean _gtk_css_lookup_is_missing (const GtkCssLoo guint id); void _gtk_css_lookup_set (GtkCssLookup *lookup, guint id, + GtkCssSection *section, const GValue *value); GtkStyleProperties * _gtk_css_lookup_resolve (GtkCssLookup *lookup, GtkStyleContext *context); diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c index f24ef0d098..102708697f 100644 --- a/gtk/gtkcssprovider.c +++ b/gtk/gtkcssprovider.c @@ -1560,7 +1560,7 @@ gtk_css_style_provider_lookup (GtkStyleProviderPrivate *provider, if (!_gtk_css_lookup_is_missing (lookup, id)) continue; - _gtk_css_lookup_set (lookup, id, &value->value); + _gtk_css_lookup_set (lookup, id, value->section, &value->value); } } } diff --git a/gtk/gtkcssshorthandpropertyimpl.c b/gtk/gtkcssshorthandpropertyimpl.c index 38d303323d..023a38fb4b 100644 --- a/gtk/gtkcssshorthandpropertyimpl.c +++ b/gtk/gtkcssshorthandpropertyimpl.c @@ -618,7 +618,8 @@ pack_border_color (GValue *value, } static void -_gtk_css_shorthand_property_register (GParamSpec *pspec, +_gtk_css_shorthand_property_register (const char *name, + GType value_type, const char **subproperties, GtkStyleUnpackFunc unpack_func, GtkStylePackFunc pack_func, @@ -630,12 +631,11 @@ _gtk_css_shorthand_property_register (GParamSpec *pspec, g_return_if_fail (unpack_func != NULL); node = g_object_new (GTK_TYPE_CSS_SHORTHAND_PROPERTY, - "name", pspec->name, - "value-type", pspec->value_type, + "name", name, + "value-type", value_type, "subproperties", subproperties, NULL); - node->pspec = pspec; node->pack_func = pack_func; node->unpack_func = unpack_func; node->parse_func = parse_func; @@ -653,58 +653,44 @@ _gtk_css_shorthand_property_init_properties (void) const char *border_color_subproperties[] = { "border-top-color", "border-right-color", "border-bottom-color", "border-left-color", NULL }; const char *border_image_subproperties[] = { "border-image-source", "border-image-slice", "border-image-width", "border-image-repeat", NULL }; - _gtk_css_shorthand_property_register (g_param_spec_boxed ("font", - "Font Description", - "Font Description", - PANGO_TYPE_FONT_DESCRIPTION, 0), + _gtk_css_shorthand_property_register ("font", + PANGO_TYPE_FONT_DESCRIPTION, font_subproperties, unpack_font_description, pack_font_description, NULL); - _gtk_css_shorthand_property_register (g_param_spec_boxed ("margin", - "Margin", - "Margin", - GTK_TYPE_BORDER, 0), + _gtk_css_shorthand_property_register ("margin", + GTK_TYPE_BORDER, margin_subproperties, unpack_margin, pack_margin, NULL); - _gtk_css_shorthand_property_register (g_param_spec_boxed ("padding", - "Padding", - "Padding", - GTK_TYPE_BORDER, 0), + _gtk_css_shorthand_property_register ("padding", + GTK_TYPE_BORDER, padding_subproperties, unpack_padding, pack_padding, NULL); - _gtk_css_shorthand_property_register (g_param_spec_boxed ("border-width", - "Border width", - "Border width, in pixels", - GTK_TYPE_BORDER, 0), + _gtk_css_shorthand_property_register ("border-width", + GTK_TYPE_BORDER, border_width_subproperties, unpack_border_width, pack_border_width, NULL); - _gtk_css_shorthand_property_register (g_param_spec_int ("border-radius", - "Border radius", - "Border radius, in pixels", - 0, G_MAXINT, 0, 0), + _gtk_css_shorthand_property_register ("border-radius", + G_TYPE_INT, border_radius_subproperties, unpack_border_radius, pack_border_radius, border_radius_value_parse); - _gtk_css_shorthand_property_register (g_param_spec_boxed ("border-color", - "Border color", - "Border color", - GDK_TYPE_RGBA, 0), + _gtk_css_shorthand_property_register ("border-color", + GDK_TYPE_RGBA, border_color_subproperties, unpack_border_color, pack_border_color, border_color_shorthand_value_parse); - _gtk_css_shorthand_property_register (g_param_spec_boxed ("border-image", - "Border Image", - "Border Image", - GTK_TYPE_BORDER_IMAGE, 0), + _gtk_css_shorthand_property_register ("border-image", + GTK_TYPE_BORDER_IMAGE, border_image_subproperties, _gtk_border_image_unpack, _gtk_border_image_pack, diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c index bef1fbfc48..0431905b1d 100644 --- a/gtk/gtkstyleproperties.c +++ b/gtk/gtkstyleproperties.c @@ -341,7 +341,7 @@ gtk_style_properties_provider_lookup (GtkStyleProviderPrivate *provider, if (value == NULL) continue; - _gtk_css_lookup_set (lookup, id, value); + _gtk_css_lookup_set (lookup, id, NULL, value); } } |