mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-25 20:22:18 +03:00
LibWeb: Parse and ignore SVG paint fallback color
This commit is contained in:
parent
439735fd35
commit
109ea418ab
Notes:
sideshowbarker
2024-07-17 04:10:16 +09:00
Author: https://github.com/MacDue Commit: https://github.com/SerenityOS/serenity/commit/109ea418ab Pull-request: https://github.com/SerenityOS/serenity/pull/20263
@ -4249,30 +4249,43 @@ ErrorOr<RefPtr<StyleValue>> Parser::parse_paint_value(TokenStream<ComponentValue
|
||||
{
|
||||
// `<paint> = none | <color> | <url> [none | <color>]? | context-fill | context-stroke`
|
||||
|
||||
if (auto color = TRY(parse_color_value(tokens.peek_token()))) {
|
||||
(void)tokens.next_token();
|
||||
return color;
|
||||
}
|
||||
auto parse_color_or_none = [&]() -> ErrorOr<Optional<RefPtr<StyleValue>>> {
|
||||
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;
|
||||
}
|
||||
|
||||
// NOTE: <color> also accepts identifiers, so we do this identifier check last.
|
||||
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;
|
||||
// NOTE: <color> also accepts identifiers, so we do this identifier check last.
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return OptionalNone {};
|
||||
};
|
||||
|
||||
// FIMXE: Allow context-fill/context-stroke here
|
||||
if (auto color_or_none = TRY(parse_color_or_none()); color_or_none.has_value())
|
||||
return *color_or_none;
|
||||
|
||||
if (auto url = TRY(parse_url_value(tokens.peek_token()))) {
|
||||
(void)tokens.next_token();
|
||||
tokens.skip_whitespace();
|
||||
if (auto color_or_none = TRY(parse_color_or_none()); color_or_none == nullptr) {
|
||||
// Fail to parse if the fallback is invalid, but otherwise ignore it.
|
||||
// FIXME: Use fallback color
|
||||
return nullptr;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
Loading…
Reference in New Issue
Block a user