mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +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
Notes:
sideshowbarker
2024-07-16 23:17:55 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/5cdcd135ab Pull-request: https://github.com/SerenityOS/serenity/pull/19406
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)
|
||||
{
|
||||
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)
|
||||
|
@ -611,6 +611,8 @@ bool property_accepts_type(PropertyID property_id, ValueType value_type)
|
|||
property_generator.appendln(" case ValueType::Length:");
|
||||
} else if (type_name == "number") {
|
||||
property_generator.appendln(" case ValueType::Number:");
|
||||
} else if (type_name == "paint") {
|
||||
property_generator.appendln(" case ValueType::Paint:");
|
||||
} else if (type_name == "percentage") {
|
||||
property_generator.appendln(" case ValueType::Percentage:");
|
||||
} 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);
|
||||
}
|
||||
|
||||
// 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>
|
||||
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)))
|
||||
return parsed_value.release_nonnull();
|
||||
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:
|
||||
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 };
|
||||
}
|
||||
|
||||
|
|
|
@ -311,6 +311,7 @@ private:
|
|||
ErrorOr<RefPtr<StyleValue>> parse_ratio_value(TokenStream<ComponentValue>&);
|
||||
ErrorOr<RefPtr<StyleValue>> parse_string_value(ComponentValue const&);
|
||||
ErrorOr<RefPtr<StyleValue>> parse_image_value(ComponentValue const&);
|
||||
ErrorOr<RefPtr<StyleValue>> parse_paint_value(TokenStream<ComponentValue>&);
|
||||
template<typename 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&);
|
||||
|
|
|
@ -737,13 +737,8 @@
|
|||
"affects-layout": false,
|
||||
"inherited": true,
|
||||
"initial": "black",
|
||||
"__comment": "FIXME: Use `paint` as the type, once we have a PaintStyleValue and generic parsing for it.",
|
||||
"valid-types": [
|
||||
"color",
|
||||
"url"
|
||||
],
|
||||
"valid-identifiers": [
|
||||
"none"
|
||||
"paint"
|
||||
]
|
||||
},
|
||||
"fill-opacity": {
|
||||
|
@ -1709,13 +1704,8 @@
|
|||
"affects-layout": false,
|
||||
"inherited": true,
|
||||
"initial": "none",
|
||||
"__comment": "FIXME: Use `paint` as the type, once we have a PaintStyleValue and generic parsing for it.",
|
||||
"valid-types": [
|
||||
"color",
|
||||
"url"
|
||||
],
|
||||
"valid-identifiers": [
|
||||
"none"
|
||||
"paint"
|
||||
]
|
||||
},
|
||||
"stroke-opacity": {
|
||||
|
|
Loading…
Add table
Reference in a new issue