mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-11-17 23:10:22 +00:00
styleproperty: Let parse_value() initialize the value
... and document that behavior.
This commit is contained in:
parent
70af2cb2e3
commit
2d46618e08
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user