cssimageradial: Only allow at "<position>" after other props

Don't allow syntax like
  at top left circle
but follow the spec about requiring the at <position> right before the
comma.

This is porbably because
  circle at 10px 10px
could be interpreted as
  circle 10px at 10px
with the now disallowed syntax, too.

Test included.
This commit is contained in:
Benjamin Otte 2016-02-05 19:01:48 +01:00
parent 982da040b2
commit 0c12601208
5 changed files with 35 additions and 16 deletions

View File

@ -234,7 +234,6 @@ gtk_css_image_radial_parse (GtkCssImage *image,
GtkCssImageRadial *radial = GTK_CSS_IMAGE_RADIAL (image);
gboolean has_shape = FALSE;
gboolean has_size = FALSE;
gboolean has_position = FALSE;
gboolean found_one = FALSE;
guint i;
static struct {
@ -269,13 +268,6 @@ gtk_css_image_radial_parse (GtkCssImage *image,
radial->circle = FALSE;
found_one = has_shape = TRUE;
}
else if (!has_position && _gtk_css_parser_try (parser, "at", TRUE))
{
radial->position = _gtk_css_position_value_parse (parser);
if (!radial->position)
return FALSE;
found_one = has_position = TRUE;
}
else if (!has_size)
{
for (i = 0; i < G_N_ELEMENTS (names); i++)
@ -298,18 +290,30 @@ gtk_css_image_radial_parse (GtkCssImage *image,
}
}
} while (found_one && !(has_shape && has_size && has_position));
} while (found_one && !(has_shape && has_size));
if ((has_shape || has_size || has_position) &&
!_gtk_css_parser_try (parser, ",", TRUE))
if (_gtk_css_parser_try (parser, "at", TRUE))
{
_gtk_css_parser_error (parser, "Expected a comma here");
return FALSE;
radial->position = _gtk_css_position_value_parse (parser);
if (!radial->position)
return FALSE;
if (!_gtk_css_parser_try (parser, ",", TRUE))
{
_gtk_css_parser_error (parser, "Expected a comma here");
return FALSE;
}
}
if (!has_position)
else
{
radial->position = _gtk_css_position_value_new (_gtk_css_number_value_new (50, GTK_CSS_PERCENT), _gtk_css_number_value_new (50, GTK_CSS_PERCENT));
radial->position = _gtk_css_position_value_new (_gtk_css_number_value_new (50, GTK_CSS_PERCENT),
_gtk_css_number_value_new (50, GTK_CSS_PERCENT));
if ((has_shape || has_size) &&
!_gtk_css_parser_try (parser, ",", TRUE))
{
_gtk_css_parser_error (parser, "Expected a comma here");
return FALSE;
}
}
if (!has_size)

View File

@ -410,6 +410,9 @@ test_data = \
radial-background-position-error.css \
radial-background-position-error.errors \
radial-background-position-error.ref.css \
radial-positions.css \
radial-positions.errors \
radial-positions.ref.css \
selector.css \
selector.ref.css \
shadow.css \

View File

@ -0,0 +1,9 @@
a {
background-image: radial-gradient(at left circle, red, blue);
}
b {
background-image: radial-gradient(10px at left circle, red, blue);
}
c {
background-image: radial-gradient(at 10px 10px circle, red, blue);
}

View File

@ -0,0 +1,3 @@
radial-positions.css:2: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
radial-positions.css:5: error: GTK_CSS_PROVIDER_ERROR_SYNTAX
radial-positions.css:8: error: GTK_CSS_PROVIDER_ERROR_SYNTAX