diff options
author | Robert Staudinger <robsta@gnome.org> | 2009-06-19 16:25:44 +0200 |
---|---|---|
committer | Robert Staudinger <robsta@gnome.org> | 2009-06-19 16:25:44 +0200 |
commit | ecc970ef96f1f73c90984385206411194edbacb7 (patch) | |
tree | 849b4db10864d961ff7245f4930753462ab75fa3 | |
parent | 9f1d1e88a13eb787b8ccd21d1616942553ea1f17 (diff) |
[style] Better tracking of property origin in debug mode.
-rw-r--r-- | ccss-doc/tmpl/ccss-unused.sgml | 18 | ||||
-rw-r--r-- | ccss-doc/tmpl/property.sgml | 1 | ||||
-rw-r--r-- | ccss/ccss-property.c | 30 | ||||
-rw-r--r-- | ccss/ccss-property.h | 7 | ||||
-rw-r--r-- | ccss/ccss-selector.c | 27 | ||||
-rw-r--r-- | ccss/ccss-selector.h | 4 | ||||
-rw-r--r-- | ccss/ccss-style-priv.h | 11 | ||||
-rw-r--r-- | ccss/ccss-style.c | 65 | ||||
-rw-r--r-- | ccss/ccss-stylesheet.c | 9 |
9 files changed, 158 insertions, 14 deletions
diff --git a/ccss-doc/tmpl/ccss-unused.sgml b/ccss-doc/tmpl/ccss-unused.sgml index 6abb5a6..02f3f65 100644 --- a/ccss-doc/tmpl/ccss-unused.sgml +++ b/ccss-doc/tmpl/ccss-unused.sgml @@ -280,6 +280,24 @@ ccss_selector_group_t @Returns: +<!-- ##### FUNCTION ccss_style_set_property_selector ##### --> +<para> + +</para> + +@self: +@property: +@selector: + +<!-- ##### FUNCTION ccss_style_set_property_selector_string ##### --> +<para> + +</para> + +@self: +@property: +@selector: + <!-- ##### FUNCTION ccss_stylesheet_create_from_buffer ##### --> <para> diff --git a/ccss-doc/tmpl/property.sgml b/ccss-doc/tmpl/property.sgml index f1a6998..f3990bf 100644 --- a/ccss-doc/tmpl/property.sgml +++ b/ccss-doc/tmpl/property.sgml @@ -26,6 +26,7 @@ ccss_property_t @CCSS_PROPERTY_STATE_NONE: @CCSS_PROPERTY_STATE_INHERIT: @CCSS_PROPERTY_STATE_SET: +@CCSS_PROPERTY_STATE_ERROR_OVERFLOW: <!-- ##### ENUM ccss_property_type_t ##### --> <para> diff --git a/ccss/ccss-property.c b/ccss/ccss-property.c index 951188c..4f87e36 100644 --- a/ccss/ccss-property.c +++ b/ccss/ccss-property.c @@ -73,3 +73,33 @@ ccss_property_parse_state (CRTerm const **value) return CCSS_PROPERTY_STATE_SET; } +static const struct { + ccss_property_state_t property_state; + char const *name; +} _property_state_map[] = { + { CCSS_PROPERTY_STATE_INVALID, "invalid" }, + { CCSS_PROPERTY_STATE_NONE, "none" }, + { CCSS_PROPERTY_STATE_INHERIT, "inherit" }, + { CCSS_PROPERTY_STATE_SET, "set" }, + { CCSS_PROPERTY_STATE_ERROR_OVERFLOW, "<invalid>" } +}; + +/** + * ccss_property_state_serialize: + * @self: a #ccss_property_state_t. + * + * Convert a property state into a readable string. + * + * Returns: textual representation of @self. + **/ +const char * +ccss_property_state_serialize (ccss_property_state_t self) +{ + for (unsigned int i = 0; i < CCSS_PROPERTY_STATE_ERROR_OVERFLOW; i++) { + if (self == _property_state_map[i].property_state) { + return _property_state_map[i].name; + } + } + + return NULL; +} diff --git a/ccss/ccss-property.h b/ccss/ccss-property.h index 7a2b4cb..caecb6f 100644 --- a/ccss/ccss-property.h +++ b/ccss/ccss-property.h @@ -39,6 +39,7 @@ struct ccss_style_; * @CCSS_PROPERTY_STATE_NONE: property set to `none', switched off. * @CCSS_PROPERTY_STATE_INHERIT: inherit property from container. * @CCSS_PROPERTY_STATE_SET: property is valid and set. + * @CCSS_PROPERTY_STATE_ERROR_OVERFLOW: error state, used for bounds checking. * * This enum must be embedded as first field in every property implementation. * @@ -48,9 +49,13 @@ typedef enum { CCSS_PROPERTY_STATE_INVALID = 0, CCSS_PROPERTY_STATE_NONE, CCSS_PROPERTY_STATE_INHERIT, - CCSS_PROPERTY_STATE_SET + CCSS_PROPERTY_STATE_SET, + CCSS_PROPERTY_STATE_ERROR_OVERFLOW } ccss_property_state_t; +const char * +ccss_property_state_serialize (ccss_property_state_t self); + /** * ccss_property_type_t: * @CCSS_PROPERTY_TYPE_DOUBLE: property represented by a floating point number. diff --git a/ccss/ccss-selector.c b/ccss/ccss-selector.c index ce26ae7..1716a10 100644 --- a/ccss/ccss-selector.c +++ b/ccss/ccss-selector.c @@ -1018,14 +1018,10 @@ ccss_selector_apply (ccss_selector_t const *self, g_hash_table_insert (style->properties, key, value); #ifdef CCSS_DEBUG -{ /* Track where the property comes from. */ - GString *selector = g_string_new (NULL); - ccss_selector_serialize_selector (self, selector); - /* Hash takes ownership. */ - g_hash_table_insert (style->selectors, value, selector->str); - g_string_free (selector, FALSE); -} + ccss_style_set_property_selector (style, + (ccss_property_base_t const *) value, + self); #endif } @@ -1045,6 +1041,23 @@ ccss_selector_apply (ccss_selector_t const *self, } void +ccss_selector_serialize_specificity (ccss_selector_t const *self, + GString *specificity) +{ + g_return_if_fail (self); + g_return_if_fail (specificity); + + g_string_append_printf (specificity, "%d,%d,%d,%d,%d,%d,%d", + self->importance, + self->precedence, + self->a, + self->b, + self->c, + self->d, + self->e); +} + +void ccss_selector_serialize_selector (ccss_selector_t const *self, GString *selector) { diff --git a/ccss/ccss-selector.h b/ccss/ccss-selector.h index 6fb0323..3338e6d 100644 --- a/ccss/ccss-selector.h +++ b/ccss/ccss-selector.h @@ -124,6 +124,10 @@ ccss_selector_apply (ccss_selector_t const *self, ccss_style_t *style); void +ccss_selector_serialize_specificity (ccss_selector_t const *self, + GString *specificity); + +void ccss_selector_serialize_selector (ccss_selector_t const *self, GString *selector); diff --git a/ccss/ccss-style-priv.h b/ccss/ccss-style-priv.h index d0b249f..bd98fe6 100644 --- a/ccss/ccss-style-priv.h +++ b/ccss/ccss-style-priv.h @@ -25,6 +25,7 @@ #include <glib.h> #include <ccss/ccss-macros.h> #include <ccss/ccss-property.h> +#include <ccss/ccss-selector.h> #include <ccss/ccss-style.h> #include <ccss/ccss-stylesheet.h> @@ -48,6 +49,16 @@ struct ccss_style_ { ccss_style_t * ccss_style_create (void); +void +ccss_style_set_property_selector (ccss_style_t *self, + ccss_property_base_t const *property, + ccss_selector_t const *selector); + +void +ccss_style_set_property_selector_string (ccss_style_t *self, + ccss_property_base_t const *property, + char const *selector); + CCSS_END_DECLS #endif /* CCSS_STYLE_PRIV_H */ diff --git a/ccss/ccss-style.c b/ccss/ccss-style.c index 86da309..fc24f79 100644 --- a/ccss/ccss-style.c +++ b/ccss/ccss-style.c @@ -23,7 +23,6 @@ #include <string.h> #include <glib.h> #include "ccss-property-generic.h" -#include "ccss-selector.h" #include "ccss-style-priv.h" #include "config.h" @@ -197,7 +196,7 @@ ccss_style_get_property (ccss_style_t const *self, * ccss_style_set_property: * @self: a #ccss_style_t. * @property_name: name of the property. - * @value: location to store the raw property pointer. + * @value: the property to insert into the style. * * Insert custom property. This is for custom property implementations only. **/ @@ -216,6 +215,68 @@ ccss_style_set_property (ccss_style_t *self, } /** + * @self: a #ccss_style_t. + * @property: the property. + * @selector: the selector that caused @property to be applied to this style. + * + * Track which selector caused assignment of a property to a style. This is for + * debugging purpose only, when serialising @self the properties will be + * annotated with selector information. + **/ +void +ccss_style_set_property_selector (ccss_style_t *self, + ccss_property_base_t const *property, + ccss_selector_t const *selector) +{ +#ifdef CCSS_DEBUG + GString *annotation; + + g_return_if_fail (self); + g_return_if_fail (property); + g_return_if_fail (selector); + + annotation = g_string_new ("'"); + ccss_selector_serialize_selector (selector, annotation); + g_string_append (annotation, "'"); + + g_string_append_printf (annotation, ", '%s'", + ccss_property_state_serialize (property->state)); + + g_string_append (annotation, ", "); + ccss_selector_serialize_specificity (selector, annotation); + + /* Hash takes ownership. */ + g_hash_table_insert (self->selectors, (gpointer) property, annotation->str); + g_string_free (annotation, FALSE); +#endif +} + +/** + * @self: a #ccss_style_t. + * @property: the property. + * @selector: the selector that caused @property to be applied to this style. + * + * Track which selector caused assignment of a property to a style. This is for + * debugging purpose only, when serialising @self the properties will be + * annotated with selector information. + * + * See: #ccss_style_set_property_selector + **/ +void +ccss_style_set_property_selector_string (ccss_style_t *self, + ccss_property_base_t const *property, + char const *selector) +{ +#ifdef CCSS_DEBUG + g_return_if_fail (self); + g_return_if_fail (property); + g_return_if_fail (selector); + + g_hash_table_insert (self->selectors, (gpointer) property, g_strdup (selector)); +#endif +} + +/** * ccss_style_interpret_property: * @self: a #ccss_style_t. * @property_name: name of the property. diff --git a/ccss/ccss-stylesheet.c b/ccss/ccss-stylesheet.c index a1c848b..9216bd9 100644 --- a/ccss/ccss-stylesheet.c +++ b/ccss/ccss-stylesheet.c @@ -372,10 +372,11 @@ inherit_container_style (ccss_style_t const *container_style, g_hash_table_lookup (container_style->selectors, property); if (selector) { - g_hash_table_insert (style->selectors, - (gpointer) property, - g_strdup (selector)); - } + ccss_style_set_property_selector_string (style, + property, + g_strdup (selector)); + + } } #endif } |