[gtk+/wip/css: 83/97] styleproperty: Let parse_value() initialize the value
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/css: 83/97] styleproperty: Let parse_value() initialize the value
- Date: Mon, 2 Jan 2012 15:00:26 +0000 (UTC)
commit ecf1bb33c3f1a56510035869940fa088db35b485
Author: Benjamin Otte <otte redhat com>
Date: Mon Jan 2 10:06:47 2012 +0100
styleproperty: Let parse_value() initialize the value
... and document that behavior.
gtk/gtkcssprovider.c | 1 -
gtk/gtkcssshorthandproperty.c | 1 -
gtk/gtkcssstyleproperty.c | 21 +++++++++++++++------
gtk/gtkstyleproperty.c | 19 +++++++++++++++++++
4 files changed, 34 insertions(+), 8 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 03b3dbf..2077a6b 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -2353,7 +2353,6 @@ parse_declaration (GtkCssScanner *scanner,
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_VALUE);
val = property_value_new (scanner->section);
- g_value_init (&val->value, _gtk_style_property_get_value_type (property));
if (_gtk_style_property_parse_value (property,
&val->value,
diff --git a/gtk/gtkcssshorthandproperty.c b/gtk/gtkcssshorthandproperty.c
index 2c6906b..8258c00 100644
--- a/gtk/gtkcssshorthandproperty.c
+++ b/gtk/gtkcssshorthandproperty.c
@@ -153,7 +153,6 @@ gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
g_value_set_enum (val, GTK_CSS_INITIAL);
}
- g_value_unset (value);
g_value_init (value, G_TYPE_VALUE_ARRAY);
g_value_set_boxed (value, array);
return TRUE;
diff --git a/gtk/gtkcssstyleproperty.c b/gtk/gtkcssstyleproperty.c
index b7c7afe..6232373 100644
--- a/gtk/gtkcssstyleproperty.c
+++ b/gtk/gtkcssstyleproperty.c
@@ -324,12 +324,13 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
GtkCssParser *parser,
GFile *base)
{
+ gboolean success;
+
if (_gtk_css_parser_try (parser, "initial", TRUE))
{
/* the initial value can be explicitly specified with the
* âinitialâ keyword which all properties accept.
*/
- g_value_unset (value);
g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
g_value_set_enum (value, GTK_CSS_INITIAL);
return TRUE;
@@ -342,7 +343,6 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
* strengthen inherited values in the cascade, and it can
* also be used on properties that are not normally inherited.
*/
- g_value_unset (value);
g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
g_value_set_enum (value, GTK_CSS_INHERIT);
return TRUE;
@@ -351,22 +351,31 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
{
GError *error = NULL;
char *value_str;
- gboolean success;
value_str = _gtk_css_parser_read_value (parser);
if (value_str == NULL)
return FALSE;
+ g_value_init (value, _gtk_style_property_get_value_type (property));
success = (*property->property_parse_func) (value_str, value, &error);
g_free (value_str);
+ if (!success)
+ g_value_unset (value);
return success;
}
- else if (property->parse_func)
- return (* property->parse_func) (parser, base, value);
+
+ g_value_init (value, _gtk_style_property_get_value_type (property));
+ if (property->parse_func)
+ success = (* property->parse_func) (parser, base, value);
else
- return _gtk_css_style_parse_value (value, parser, base);
+ success = _gtk_css_style_parse_value (value, parser, base);
+
+ if (!success)
+ g_value_unset (value);
+
+ return success;
}
static void
diff --git a/gtk/gtkstyleproperty.c b/gtk/gtkstyleproperty.c
index 472d26a..83dc19b 100644
--- a/gtk/gtkstyleproperty.c
+++ b/gtk/gtkstyleproperty.c
@@ -379,6 +379,25 @@ border_corner_radius_value_print (const GValue *value,
/*** API ***/
+/**
+ * _gtk_style_property_parse_value:
+ * @property: the property
+ * @value: an uninitialized value
+ * @parser: the parser to parse from
+ * @base: the base file for @aprser
+ *
+ * Tries to parse the given @property from the given @parser into
+ * @value. The type that @value will be assigned is dependant on
+ * the parser and no assumptions must be made about it. If the
+ * parsing fails, %FALSE will be returned and @value will be
+ * left uninitialized.
+ *
+ * Only if @property is a #GtkCssShorthandProperty, the @value will
+ * always contain a #GValueArray with the values to be used for
+ * the subproperties.
+ *
+ * Returns: %TRUE on success
+ **/
gboolean
_gtk_style_property_parse_value (GtkStyleProperty *property,
GValue *value,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]