From f17e151b8d7a04efc2670cf516dbec9999fee79a Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 4 Apr 2025 15:40:01 +0100 Subject: [PATCH] LibWeb/CSS: Remove redundant font-face src parsing code We now always parse this as a descriptor. --- Libraries/LibWeb/CSS/Parser/Parser.cpp | 5 - Libraries/LibWeb/CSS/Parser/Parser.h | 5 - Libraries/LibWeb/CSS/Parser/RuleParsing.cpp | 106 -------------------- 3 files changed, 116 deletions(-) diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index c277f906592..811f8999c63 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1617,11 +1617,6 @@ bool Parser::context_allows_quirky_length() const return unitless_length_allowed; } -Vector Parser::parse_as_font_face_src() -{ - return parse_font_face_src(m_token_stream); -} - Vector Parser::parse_as_list_of_component_values() { return parse_a_list_of_component_values(m_token_stream); diff --git a/Libraries/LibWeb/CSS/Parser/Parser.h b/Libraries/LibWeb/CSS/Parser/Parser.h index 8d4f32f93d1..d118e6697f3 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.h +++ b/Libraries/LibWeb/CSS/Parser/Parser.h @@ -123,8 +123,6 @@ public: Optional parse_as_component_value(); - Vector parse_as_font_face_src(); - Vector parse_as_list_of_component_values(); static NonnullRefPtr resolve_unresolved_style_value(ParsingParams const&, DOM::Element&, Optional, PropertyID, UnresolvedStyleValue const&); @@ -226,9 +224,6 @@ private: OwnPtr parse_general_enclosed(TokenStream&, MatchResult); - template - Vector parse_font_face_src(TokenStream&); - enum class AllowBlankLayerName { No, Yes, diff --git a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp index cce79fb7b3d..055f2303c94 100644 --- a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp @@ -590,112 +590,6 @@ GC::Ptr Parser::convert_to_property_rule(AtRule const& rule) return {}; } -template -Vector Parser::parse_font_face_src(TokenStream& component_values) -{ - Vector supported_sources; - - auto list_of_source_token_lists = parse_a_comma_separated_list_of_component_values(component_values); - for (auto const& source_token_list : list_of_source_token_lists) { - TokenStream source_tokens { source_token_list }; - source_tokens.discard_whitespace(); - - // [ format()]? - // FIXME: Implement optional tech() function from CSS-Fonts-4. - if (auto maybe_url = parse_url_function(source_tokens); maybe_url.has_value()) { - auto url = maybe_url.release_value(); - if (!url.is_valid()) { - continue; - } - - Optional format; - - source_tokens.discard_whitespace(); - if (!source_tokens.has_next_token()) { - supported_sources.empend(move(url), format); - continue; - } - - auto const& maybe_function = source_tokens.consume_a_token(); - if (!maybe_function.is_function()) { - dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (token after `url()` that isn't a function: {}); discarding.", maybe_function.to_debug_string()); - return {}; - } - - auto const& function = maybe_function.function(); - if (function.name.equals_ignoring_ascii_case("format"sv)) { - auto context_guard = push_temporary_value_parsing_context(FunctionContext { function.name }); - - TokenStream format_tokens { function.value }; - format_tokens.discard_whitespace(); - auto const& format_name_token = format_tokens.consume_a_token(); - FlyString format_name; - if (format_name_token.is(Token::Type::Ident)) { - format_name = format_name_token.token().ident(); - } else if (format_name_token.is(Token::Type::String)) { - format_name = format_name_token.token().string(); - } else { - dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (`format()` parameter not an ident or string; is: {}); discarding.", format_name_token.to_debug_string()); - return {}; - } - - if (!font_format_is_supported(format_name)) { - dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src format({}) not supported; skipping.", format_name); - continue; - } - - format = move(format_name); - } else { - dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (unrecognized function token `{}`); discarding.", function.name); - return {}; - } - - source_tokens.discard_whitespace(); - if (source_tokens.has_next_token()) { - dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (extra token `{}`); discarding.", source_tokens.next_token().to_debug_string()); - return {}; - } - - supported_sources.empend(move(url), format); - continue; - } - - auto const& first = source_tokens.consume_a_token(); - if (first.is_function("local"sv)) { - // local() - if (first.function().value.is_empty()) { - dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (`local()` syntax is invalid: no arguments); discarding."); - return {}; - } - - TokenStream function_tokens { first.function().value }; - function_tokens.discard_whitespace(); - auto font_family = parse_family_name_value(function_tokens); - function_tokens.discard_whitespace(); - if (!font_family || function_tokens.has_next_token()) { - dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (`local()` syntax is invalid: `{}`); discarding.", first.function().original_source_text()); - return {}; - } - - if (font_family->is_string()) - supported_sources.empend(font_family->as_string().string_value(), Optional {}); - else if (font_family->is_custom_ident()) - supported_sources.empend(font_family->as_custom_ident().custom_ident(), Optional {}); - else - VERIFY_NOT_REACHED(); - - continue; - } - - dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @font-face src invalid (failed to parse url from: {}); discarding.", first.to_debug_string()); - return {}; - } - - return supported_sources; -} -template Vector Parser::parse_font_face_src(TokenStream& component_values); -template Vector Parser::parse_font_face_src(TokenStream& component_values); - GC::Ptr Parser::convert_to_font_face_rule(AtRule const& rule) { // https://drafts.csswg.org/css-fonts/#font-face-rule