1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 05:08:13 +00:00

LibWeb: Parse CSS background-position property

This is done a bit differently from other properties: using a
TokenStream instead of just a Vector of ComponentValues. The reason for
this is, we can then use call the same function when parsing the
`background` shorthand. Otherwise, we would have to know in advance how
many values to pass down, which basically would involve duplicating the
`background-position` parsing code inside `background`.

The StyleValue is PositionStyleValue, since it represents a
`<position>`: https://www.w3.org/TR/css-values-4/#typedef-position
Unfortunately, background-position's parsing is a bit different from
`<position>`'s, (background-position allows 3-value syntax and
`<position>` doesn't) so we'll need to come back and write a different
parsing function for that later.
This commit is contained in:
Sam Atkins 2021-10-31 16:02:29 +00:00 committed by Andreas Kling
parent 5594a492f0
commit 988a8ed3d8
6 changed files with 260 additions and 2 deletions

View file

@ -343,6 +343,21 @@ static void set_property_expanding_shorthands(StyleProperties& style, CSS::Prope
return;
}
if (property_id == CSS::PropertyID::BackgroundPosition) {
if (value.is_value_list()) {
auto& background_position_list = value.as_value_list().values();
// FIXME: Handle multiple backgrounds.
if (!background_position_list.is_empty()) {
auto& background_position = background_position_list.first();
style.set_property(CSS::PropertyID::BackgroundPosition, background_position);
}
return;
}
style.set_property(CSS::PropertyID::BackgroundPosition, value);
return;
}
if (property_id == CSS::PropertyID::BackgroundRepeat) {
if (value.is_value_list()) {
auto& background_repeat_list = value.as_value_list().values();