[gtk+/wip/css: 64/97] css: Feed sections to CSS lookup code
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 64/97] css: Feed sections to CSS lookup code
- Date: Mon, 2 Jan 2012 14:58:51 +0000 (UTC)
commit c5128263120d2f0b505404dea5ddad5e60fd1f15
Author: Benjamin Otte <otte redhat com>
Date: Sun Jan 1 23:16:35 2012 +0100
css: Feed sections to CSS lookup code
gtk/gtkcsslookup.c | 38 +++++++++++++++++----------
gtk/gtkcsslookupprivate.h | 2 +
gtk/gtkcssprovider.c | 2 +-
gtk/gtkcssshorthandpropertyimpl.c | 50 +++++++++++++-----------------------
gtk/gtkstyleproperties.c | 2 +-
5 files changed, 46 insertions(+), 48 deletions(-)
---
diff --git a/gtk/gtkcsslookup.c b/gtk/gtkcsslookup.c
index 3e21304..c3e6a73 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 19001d8..79e5578 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 04f9493..1052728 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 38d3033..023a38f 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 bef1fbf..0431905 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);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]