styleproperty: Let parse_value() initialize the value

... and document that behavior.
This commit is contained in:
Benjamin Otte 2012-01-02 10:06:47 +01:00
parent 70af2cb2e3
commit 2d46618e08
4 changed files with 34 additions and 8 deletions

View File

@ -2353,7 +2353,6 @@ parse_declaration (GtkCssScanner *scanner,
gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_VALUE); gtk_css_scanner_push_section (scanner, GTK_CSS_SECTION_VALUE);
val = property_value_new (scanner->section); 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, if (_gtk_style_property_parse_value (property,
&val->value, &val->value,

View File

@ -153,7 +153,6 @@ gtk_css_shorthand_property_parse_value (GtkStyleProperty *property,
g_value_set_enum (val, GTK_CSS_INITIAL); g_value_set_enum (val, GTK_CSS_INITIAL);
} }
g_value_unset (value);
g_value_init (value, G_TYPE_VALUE_ARRAY); g_value_init (value, G_TYPE_VALUE_ARRAY);
g_value_set_boxed (value, array); g_value_set_boxed (value, array);
return TRUE; return TRUE;

View File

@ -324,12 +324,13 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
GtkCssParser *parser, GtkCssParser *parser,
GFile *base) GFile *base)
{ {
gboolean success;
if (_gtk_css_parser_try (parser, "initial", TRUE)) if (_gtk_css_parser_try (parser, "initial", TRUE))
{ {
/* the initial value can be explicitly specified with the /* the initial value can be explicitly specified with the
* initial keyword which all properties accept. * initial keyword which all properties accept.
*/ */
g_value_unset (value);
g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE); g_value_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
g_value_set_enum (value, GTK_CSS_INITIAL); g_value_set_enum (value, GTK_CSS_INITIAL);
return TRUE; return TRUE;
@ -342,7 +343,6 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
* strengthen inherited values in the cascade, and it can * strengthen inherited values in the cascade, and it can
* also be used on properties that are not normally inherited. * 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_init (value, GTK_TYPE_CSS_SPECIAL_VALUE);
g_value_set_enum (value, GTK_CSS_INHERIT); g_value_set_enum (value, GTK_CSS_INHERIT);
return TRUE; return TRUE;
@ -351,22 +351,31 @@ gtk_css_style_property_parse_value (GtkStyleProperty *property,
{ {
GError *error = NULL; GError *error = NULL;
char *value_str; char *value_str;
gboolean success;
value_str = _gtk_css_parser_read_value (parser); value_str = _gtk_css_parser_read_value (parser);
if (value_str == NULL) if (value_str == NULL)
return FALSE; return FALSE;
g_value_init (value, _gtk_style_property_get_value_type (property));
success = (*property->property_parse_func) (value_str, value, &error); success = (*property->property_parse_func) (value_str, value, &error);
g_free (value_str); g_free (value_str);
if (!success)
g_value_unset (value);
return success; 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 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 static void

View File

@ -379,6 +379,25 @@ border_corner_radius_value_print (const GValue *value,
/*** API ***/ /*** 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 gboolean
_gtk_style_property_parse_value (GtkStyleProperty *property, _gtk_style_property_parse_value (GtkStyleProperty *property,
GValue *value, GValue *value,