1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 05:07:34 +00:00

LibWeb: Handle StyleValueList for background-image

Also removed the string-parsing code I'd accidentally missed removing
before. Oops!
This commit is contained in:
Sam Atkins 2021-08-10 16:20:30 +01:00 committed by Andreas Kling
parent 6f9263de04
commit 75450d2250
3 changed files with 40 additions and 35 deletions

View file

@ -1761,16 +1761,17 @@ static inline bool is_background_repeat(StyleValue const& value)
}
}
static inline bool is_background_image(StyleValue const& value)
{
if (value.is_image())
return true;
if (value.to_identifier() == ValueID::None)
return true;
return false;
}
RefPtr<StyleValue> Parser::parse_background_value(ParsingContext const& context, Vector<StyleComponentValueRule> const& component_values)
{
auto is_background_image = [](StyleValue const& value) -> bool {
if (value.is_image())
return true;
if (value.to_identifier() == ValueID::None)
return true;
return false;
};
RefPtr<StyleValue> background_color;
RefPtr<StyleValue> background_image;
RefPtr<StyleValue> repeat_x;
@ -1849,6 +1850,23 @@ RefPtr<StyleValue> Parser::parse_background_value(ParsingContext const& context,
return BackgroundStyleValue::create(background_color.release_nonnull(), background_image.release_nonnull(), repeat_x.release_nonnull(), repeat_y.release_nonnull());
}
RefPtr<StyleValue> Parser::parse_background_image_value(ParsingContext const& context, Vector<StyleComponentValueRule> const& component_values)
{
if (component_values.size() == 1) {
auto maybe_value = parse_css_value(context, PropertyID::BackgroundImage, component_values.first());
if (!maybe_value)
return nullptr;
auto value = maybe_value.release_nonnull();
if (is_background_image(*value))
return value;
return nullptr;
}
// FIXME: Handle multiple sets of comma-separated values.
dbgln("CSS Parser does not yet support multiple comma-separated values for background-image.");
return nullptr;
}
RefPtr<StyleValue> Parser::parse_background_repeat_value(ParsingContext const& context, Vector<StyleComponentValueRule> const& component_values)
{
auto is_directional_repeat = [](StyleValue const& value) -> bool {
@ -2697,6 +2715,10 @@ RefPtr<StyleValue> Parser::parse_css_value(PropertyID property_id, TokenStream<S
if (auto parsed_value = parse_background_value(m_context, component_values))
return parsed_value;
break;
case PropertyID::BackgroundImage:
if (auto parsed_value = parse_background_image_value(m_context, component_values))
return parsed_value;
break;
case PropertyID::BackgroundRepeat:
if (auto parsed_value = parse_background_repeat_value(m_context, component_values))
return parsed_value;