css: Add gtk_css_number_value_can_parse()

Use it instead of _gtk_css_parser_has_number().

We need that once we introduce calc() support.
This commit is contained in:
Benjamin Otte 2016-02-12 06:45:06 +01:00
parent b246d55472
commit a52ecd2be6
11 changed files with 28 additions and 21 deletions

View File

@ -194,7 +194,7 @@ _gtk_css_bg_size_value_parse (GtkCssParser *parser)
if (_gtk_css_parser_try (parser, "auto", TRUE)) if (_gtk_css_parser_try (parser, "auto", TRUE))
y = NULL; y = NULL;
else if (!_gtk_css_parser_has_number (parser)) else if (!gtk_css_number_value_can_parse (parser))
y = NULL; y = NULL;
else else
{ {

View File

@ -174,7 +174,7 @@ _gtk_css_border_value_parse (GtkCssParser *parser,
if (allow_auto && _gtk_css_parser_try (parser, "auto", TRUE)) if (allow_auto && _gtk_css_parser_try (parser, "auto", TRUE))
continue; continue;
if (!_gtk_css_parser_has_number (parser)) if (!gtk_css_number_value_can_parse (parser))
break; break;
result->values[i] = _gtk_css_number_value_parse (parser, flags); result->values[i] = _gtk_css_number_value_parse (parser, flags);

View File

@ -132,7 +132,7 @@ _gtk_css_corner_value_parse (GtkCssParser *parser)
if (x == NULL) if (x == NULL)
return NULL; return NULL;
if (!_gtk_css_parser_has_number (parser)) if (!gtk_css_number_value_can_parse (parser))
y = _gtk_css_value_ref (x); y = _gtk_css_value_ref (x);
else else
{ {

View File

@ -163,7 +163,7 @@ gtk_css_image_cross_fade_parse (GtkCssImage *image,
return FALSE; return FALSE;
} }
if (_gtk_css_parser_has_number (parser)) if (gtk_css_number_value_can_parse (parser))
{ {
GtkCssValue *number; GtkCssValue *number;

View File

@ -310,7 +310,7 @@ gtk_css_image_linear_parse (GtkCssImage *image,
return FALSE; return FALSE;
} }
} }
else if (_gtk_css_parser_has_number (parser)) else if (gtk_css_number_value_can_parse (parser))
{ {
linear->angle = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_ANGLE); linear->angle = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_ANGLE);
if (linear->angle == NULL) if (linear->angle == NULL)
@ -332,7 +332,7 @@ gtk_css_image_linear_parse (GtkCssImage *image,
if (stop.color == NULL) if (stop.color == NULL)
return FALSE; return FALSE;
if (_gtk_css_parser_has_number (parser)) if (gtk_css_number_value_can_parse (parser))
{ {
stop.offset = _gtk_css_number_value_parse (parser, stop.offset = _gtk_css_number_value_parse (parser,
GTK_CSS_PARSE_PERCENT GTK_CSS_PARSE_PERCENT

View File

@ -282,9 +282,9 @@ gtk_css_image_radial_parse (GtkCssImage *image,
if (!has_size) if (!has_size)
{ {
if (_gtk_css_parser_has_number (parser)) if (gtk_css_number_value_can_parse (parser))
radial->sizes[0] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH | GTK_CSS_PARSE_PERCENT); radial->sizes[0] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH | GTK_CSS_PARSE_PERCENT);
if (_gtk_css_parser_has_number (parser)) if (gtk_css_number_value_can_parse (parser))
radial->sizes[1] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH | GTK_CSS_PARSE_PERCENT); radial->sizes[1] = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH | GTK_CSS_PARSE_PERCENT);
found_one = has_size = radial->sizes[0] != NULL; found_one = has_size = radial->sizes[0] != NULL;
} }
@ -357,7 +357,7 @@ gtk_css_image_radial_parse (GtkCssImage *image,
if (stop.color == NULL) if (stop.color == NULL)
return FALSE; return FALSE;
if (_gtk_css_parser_has_number (parser)) if (gtk_css_number_value_can_parse (parser))
{ {
stop.offset = _gtk_css_number_value_parse (parser, stop.offset = _gtk_css_number_value_parse (parser,
GTK_CSS_PARSE_PERCENT GTK_CSS_PARSE_PERCENT

View File

@ -48,6 +48,12 @@ _gtk_css_number_value_new (double value,
return gtk_css_dimension_value_new (value, unit); return gtk_css_dimension_value_new (value, unit);
} }
gboolean
gtk_css_number_value_can_parse (GtkCssParser *parser)
{
return _gtk_css_parser_has_number (parser);
}
GtkCssValue * GtkCssValue *
_gtk_css_number_value_parse (GtkCssParser *parser, _gtk_css_number_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags) GtkCssNumberParseFlags flags)

View File

@ -49,6 +49,7 @@ struct _GtkCssNumberValueClass {
GtkCssValue * _gtk_css_number_value_new (double value, GtkCssValue * _gtk_css_number_value_new (double value,
GtkCssUnit unit); GtkCssUnit unit);
gboolean gtk_css_number_value_can_parse (GtkCssParser *parser);
GtkCssValue * _gtk_css_number_value_parse (GtkCssParser *parser, GtkCssValue * _gtk_css_number_value_parse (GtkCssParser *parser,
GtkCssNumberParseFlags flags); GtkCssNumberParseFlags flags);

View File

@ -210,7 +210,7 @@ position_value_parse (GtkCssParser *parser, gboolean try)
} }
if (names[first].name == NULL) if (names[first].name == NULL)
{ {
if (_gtk_css_parser_has_number (parser)) if (gtk_css_number_value_can_parse (parser))
{ {
missing = &y; missing = &y;
x = _gtk_css_number_value_parse (parser, x = _gtk_css_number_value_parse (parser,
@ -239,7 +239,7 @@ position_value_parse (GtkCssParser *parser, gboolean try)
if (names[second].name == NULL) if (names[second].name == NULL)
{ {
if (_gtk_css_parser_has_number (parser)) if (gtk_css_number_value_can_parse (parser))
{ {
if (missing != &y) if (missing != &y)
{ {

View File

@ -215,7 +215,7 @@ _gtk_css_shadow_value_parse (GtkCssParser *parser,
do do
{ {
if (values[HOFFSET] == NULL && if (values[HOFFSET] == NULL &&
_gtk_css_parser_has_number (parser)) gtk_css_number_value_can_parse (parser))
{ {
values[HOFFSET] = _gtk_css_number_value_parse (parser, values[HOFFSET] = _gtk_css_number_value_parse (parser,
GTK_CSS_PARSE_LENGTH GTK_CSS_PARSE_LENGTH
@ -229,7 +229,7 @@ _gtk_css_shadow_value_parse (GtkCssParser *parser,
if (values[VOFFSET] == NULL) if (values[VOFFSET] == NULL)
goto fail; goto fail;
if (_gtk_css_parser_has_number (parser)) if (gtk_css_number_value_can_parse (parser))
{ {
values[RADIUS] = _gtk_css_number_value_parse (parser, values[RADIUS] = _gtk_css_number_value_parse (parser,
GTK_CSS_PARSE_LENGTH GTK_CSS_PARSE_LENGTH
@ -241,7 +241,7 @@ _gtk_css_shadow_value_parse (GtkCssParser *parser,
else else
values[RADIUS] = _gtk_css_number_value_new (0.0, GTK_CSS_PX); values[RADIUS] = _gtk_css_number_value_new (0.0, GTK_CSS_PX);
if (box_shadow_mode && _gtk_css_parser_has_number (parser)) if (box_shadow_mode && gtk_css_number_value_can_parse (parser))
{ {
values[SPREAD] = _gtk_css_number_value_parse (parser, values[SPREAD] = _gtk_css_number_value_parse (parser,
GTK_CSS_PARSE_LENGTH GTK_CSS_PARSE_LENGTH

View File

@ -68,7 +68,7 @@ parse_four_numbers (GtkCssShorthandProperty *shorthand,
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
if (!_gtk_css_parser_has_number (parser)) if (!gtk_css_number_value_can_parse (parser))
break; break;
values[i] = _gtk_css_number_value_parse (parser, flags); values[i] = _gtk_css_number_value_parse (parser, flags);
@ -138,7 +138,7 @@ parse_border_radius (GtkCssShorthandProperty *shorthand,
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
if (!_gtk_css_parser_has_number (parser)) if (!gtk_css_number_value_can_parse (parser))
break; break;
x[i] = _gtk_css_number_value_parse (parser, x[i] = _gtk_css_number_value_parse (parser,
GTK_CSS_POSITIVE_ONLY GTK_CSS_POSITIVE_ONLY
@ -165,7 +165,7 @@ parse_border_radius (GtkCssShorthandProperty *shorthand,
{ {
for (i = 0; i < 4; i++) for (i = 0; i < 4; i++)
{ {
if (!_gtk_css_parser_has_number (parser)) if (!gtk_css_number_value_can_parse (parser))
break; break;
y[i] = _gtk_css_number_value_parse (parser, y[i] = _gtk_css_number_value_parse (parser,
GTK_CSS_POSITIVE_ONLY GTK_CSS_POSITIVE_ONLY
@ -335,7 +335,7 @@ parse_border_side (GtkCssShorthandProperty *shorthand,
do do
{ {
if (values[0] == NULL && if (values[0] == NULL &&
_gtk_css_parser_has_number (parser)) gtk_css_number_value_can_parse (parser))
{ {
values[0] = _gtk_css_number_value_parse (parser, values[0] = _gtk_css_number_value_parse (parser,
GTK_CSS_POSITIVE_ONLY GTK_CSS_POSITIVE_ONLY
@ -377,7 +377,7 @@ parse_border (GtkCssShorthandProperty *shorthand,
do do
{ {
if (values[0] == NULL && if (values[0] == NULL &&
_gtk_css_parser_has_number (parser)) gtk_css_number_value_can_parse (parser))
{ {
values[0] = _gtk_css_number_value_parse (parser, values[0] = _gtk_css_number_value_parse (parser,
GTK_CSS_POSITIVE_ONLY GTK_CSS_POSITIVE_ONLY
@ -620,7 +620,7 @@ parse_one_transition (GtkCssShorthandProperty *shorthand,
{ {
/* the image part */ /* the image part */
if (values[2] == NULL && if (values[2] == NULL &&
_gtk_css_parser_has_number (parser) && !_gtk_css_parser_begins_with (parser, '-')) gtk_css_number_value_can_parse (parser) && !_gtk_css_parser_begins_with (parser, '-'))
{ {
GtkCssValue *number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_TIME); GtkCssValue *number = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_TIME);
@ -725,7 +725,7 @@ parse_one_animation (GtkCssShorthandProperty *shorthand,
values[1] = _gtk_css_number_value_new (HUGE_VAL, GTK_CSS_NUMBER); values[1] = _gtk_css_number_value_new (HUGE_VAL, GTK_CSS_NUMBER);
} }
else if ((values[1] == NULL || values[3] == NULL) && else if ((values[1] == NULL || values[3] == NULL) &&
_gtk_css_parser_has_number (parser)) gtk_css_number_value_can_parse (parser))
{ {
GtkCssValue *value; GtkCssValue *value;