mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 21:37:34 +00:00
LibWeb: Add parsing for CSS <paint>
values
This gets rid of a couple of FIXMEs in Properties.json :^)
This commit is contained in:
parent
23aae7c7f3
commit
5cdcd135ab
4 changed files with 44 additions and 22 deletions
|
@ -20,7 +20,7 @@ void generate_bounds_checking_function(JsonObject& properties, SourceGenerator&
|
||||||
|
|
||||||
static bool type_name_is_enum(StringView type_name)
|
static bool type_name_is_enum(StringView type_name)
|
||||||
{
|
{
|
||||||
return !AK::first_is_one_of(type_name, "angle"sv, "color"sv, "custom-ident"sv, "frequency"sv, "image"sv, "integer"sv, "length"sv, "number"sv, "percentage"sv, "ratio"sv, "rect"sv, "resolution"sv, "string"sv, "time"sv, "url"sv);
|
return !AK::first_is_one_of(type_name, "angle"sv, "color"sv, "custom-ident"sv, "frequency"sv, "image"sv, "integer"sv, "length"sv, "number"sv, "paint"sv, "percentage"sv, "ratio"sv, "rect"sv, "resolution"sv, "string"sv, "time"sv, "url"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
@ -611,6 +611,8 @@ bool property_accepts_type(PropertyID property_id, ValueType value_type)
|
||||||
property_generator.appendln(" case ValueType::Length:");
|
property_generator.appendln(" case ValueType::Length:");
|
||||||
} else if (type_name == "number") {
|
} else if (type_name == "number") {
|
||||||
property_generator.appendln(" case ValueType::Number:");
|
property_generator.appendln(" case ValueType::Number:");
|
||||||
|
} else if (type_name == "paint") {
|
||||||
|
property_generator.appendln(" case ValueType::Paint:");
|
||||||
} else if (type_name == "percentage") {
|
} else if (type_name == "percentage") {
|
||||||
property_generator.appendln(" case ValueType::Percentage:");
|
property_generator.appendln(" case ValueType::Percentage:");
|
||||||
} else if (type_name == "ratio") {
|
} else if (type_name == "ratio") {
|
||||||
|
|
|
@ -4652,6 +4652,39 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_image_value(ComponentValue const& comp
|
||||||
return parse_radial_gradient_function(component_value);
|
return parse_radial_gradient_function(component_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://svgwg.org/svg2-draft/painting.html#SpecifyingPaint
|
||||||
|
ErrorOr<RefPtr<StyleValue>> Parser::parse_paint_value(TokenStream<ComponentValue>& tokens)
|
||||||
|
{
|
||||||
|
// `<paint> = none | <color> | <url> [none | <color>]? | context-fill | context-stroke`
|
||||||
|
|
||||||
|
if (tokens.peek_token().is(Token::Type::Ident)) {
|
||||||
|
auto maybe_ident = value_id_from_string(tokens.peek_token().token().ident());
|
||||||
|
if (maybe_ident.has_value()) {
|
||||||
|
// FIXME: Accept `context-fill` and `context-stroke`
|
||||||
|
switch (*maybe_ident) {
|
||||||
|
case ValueID::None:
|
||||||
|
(void)tokens.next_token();
|
||||||
|
return IdentifierStyleValue::create(*maybe_ident);
|
||||||
|
default:
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto color = TRY(parse_color_value(tokens.peek_token()))) {
|
||||||
|
(void)tokens.next_token();
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (auto url = TRY(parse_url_value(tokens.peek_token(), AllowedDataUrlType::Image))) {
|
||||||
|
// FIXME: Accept `[none | <color>]?`
|
||||||
|
(void)tokens.next_token();
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
template<typename ParseFunction>
|
template<typename ParseFunction>
|
||||||
ErrorOr<RefPtr<StyleValue>> Parser::parse_comma_separated_value_list(Vector<ComponentValue> const& component_values, ParseFunction parse_one_value)
|
ErrorOr<RefPtr<StyleValue>> Parser::parse_comma_separated_value_list(Vector<ComponentValue> const& component_values, ParseFunction parse_one_value)
|
||||||
{
|
{
|
||||||
|
@ -7760,15 +7793,6 @@ Parser::ParseErrorOr<NonnullRefPtr<StyleValue>> Parser::parse_css_value(Property
|
||||||
if (auto parsed_value = FIXME_TRY(parse_transform_origin_value(component_values)))
|
if (auto parsed_value = FIXME_TRY(parse_transform_origin_value(component_values)))
|
||||||
return parsed_value.release_nonnull();
|
return parsed_value.release_nonnull();
|
||||||
return ParseError ::SyntaxError;
|
return ParseError ::SyntaxError;
|
||||||
case PropertyID::Fill:
|
|
||||||
case PropertyID::Stroke:
|
|
||||||
if (component_values.size() == 1) {
|
|
||||||
if (auto parsed_url = FIXME_TRY(parse_url_value(component_values.first())))
|
|
||||||
return parsed_url.release_nonnull();
|
|
||||||
}
|
|
||||||
// Allow normal value parsing to continue.
|
|
||||||
// URL is done here to avoid ambiguity with images.
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -8055,6 +8079,11 @@ ErrorOr<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readonl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (auto property = any_property_accepts_type(property_ids, ValueType::Paint); property.has_value()) {
|
||||||
|
if (auto value = TRY(parse_paint_value(tokens)))
|
||||||
|
return PropertyAndValue { *property, value.release_nonnull() };
|
||||||
|
}
|
||||||
|
|
||||||
return PropertyAndValue { property_ids.first(), nullptr };
|
return PropertyAndValue { property_ids.first(), nullptr };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -311,6 +311,7 @@ private:
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_ratio_value(TokenStream<ComponentValue>&);
|
ErrorOr<RefPtr<StyleValue>> parse_ratio_value(TokenStream<ComponentValue>&);
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_string_value(ComponentValue const&);
|
ErrorOr<RefPtr<StyleValue>> parse_string_value(ComponentValue const&);
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_image_value(ComponentValue const&);
|
ErrorOr<RefPtr<StyleValue>> parse_image_value(ComponentValue const&);
|
||||||
|
ErrorOr<RefPtr<StyleValue>> parse_paint_value(TokenStream<ComponentValue>&);
|
||||||
template<typename ParseFunction>
|
template<typename ParseFunction>
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_comma_separated_value_list(Vector<ComponentValue> const&, ParseFunction);
|
ErrorOr<RefPtr<StyleValue>> parse_comma_separated_value_list(Vector<ComponentValue> const&, ParseFunction);
|
||||||
ErrorOr<RefPtr<StyleValue>> parse_simple_comma_separated_value_list(PropertyID, Vector<ComponentValue> const&);
|
ErrorOr<RefPtr<StyleValue>> parse_simple_comma_separated_value_list(PropertyID, Vector<ComponentValue> const&);
|
||||||
|
|
|
@ -737,13 +737,8 @@
|
||||||
"affects-layout": false,
|
"affects-layout": false,
|
||||||
"inherited": true,
|
"inherited": true,
|
||||||
"initial": "black",
|
"initial": "black",
|
||||||
"__comment": "FIXME: Use `paint` as the type, once we have a PaintStyleValue and generic parsing for it.",
|
|
||||||
"valid-types": [
|
"valid-types": [
|
||||||
"color",
|
"paint"
|
||||||
"url"
|
|
||||||
],
|
|
||||||
"valid-identifiers": [
|
|
||||||
"none"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"fill-opacity": {
|
"fill-opacity": {
|
||||||
|
@ -1709,13 +1704,8 @@
|
||||||
"affects-layout": false,
|
"affects-layout": false,
|
||||||
"inherited": true,
|
"inherited": true,
|
||||||
"initial": "none",
|
"initial": "none",
|
||||||
"__comment": "FIXME: Use `paint` as the type, once we have a PaintStyleValue and generic parsing for it.",
|
|
||||||
"valid-types": [
|
"valid-types": [
|
||||||
"color",
|
"paint"
|
||||||
"url"
|
|
||||||
],
|
|
||||||
"valid-identifiers": [
|
|
||||||
"none"
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"stroke-opacity": {
|
"stroke-opacity": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue