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

LibWeb: Add RatioStyleValue and parsing

This commit is contained in:
Sam Atkins 2023-06-06 15:42:43 +01:00 committed by Andreas Kling
parent b9f9d87bd0
commit 5e3da93f1a
8 changed files with 88 additions and 2 deletions

View file

@ -72,6 +72,7 @@
#include <LibWeb/CSS/StyleValues/PlaceContentStyleValue.h>
#include <LibWeb/CSS/StyleValues/PositionStyleValue.h>
#include <LibWeb/CSS/StyleValues/RadialGradientStyleValue.h>
#include <LibWeb/CSS/StyleValues/RatioStyleValue.h>
#include <LibWeb/CSS/StyleValues/RectStyleValue.h>
#include <LibWeb/CSS/StyleValues/ResolutionStyleValue.h>
#include <LibWeb/CSS/StyleValues/ShadowStyleValue.h>
@ -4387,6 +4388,13 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_color_value(ComponentValue const& comp
return nullptr;
}
ErrorOr<RefPtr<StyleValue>> Parser::parse_ratio_value(TokenStream<ComponentValue>& tokens)
{
if (auto ratio = parse_ratio(tokens); ratio.has_value())
return RatioStyleValue::create(ratio.release_value());
return nullptr;
}
ErrorOr<RefPtr<StyleValue>> Parser::parse_string_value(ComponentValue const& component_value)
{
if (component_value.is(Token::Type::String))
@ -7626,6 +7634,11 @@ ErrorOr<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readonl
}
}
if (auto property = any_property_accepts_type(property_ids, ValueType::Ratio); property.has_value()) {
if (auto maybe_ratio = TRY(parse_ratio_value(tokens)))
return PropertyAndValue { *property, maybe_ratio };
}
auto property_accepting_integer = any_property_accepts_type(property_ids, ValueType::Integer);
auto property_accepting_number = any_property_accepts_type(property_ids, ValueType::Number);
bool property_accepts_numeric = property_accepting_integer.has_value() || property_accepting_number.has_value();