From 6a4d80b9b6500d53e00794a850eba89d7d4f6725 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Wed, 5 Feb 2025 12:08:27 +0000 Subject: [PATCH] LibWeb/CSS: Integrate ParsingContext into the Parser This is not really a context, but more of a set of parameters for creating a Parser. So, treat it as such: Rename it to ParsingParams, and store its values and methods directly in the Parser instead of keeping the ParsingContext around. This has a nice side-effect of not including DOM/Document.h everywhere that needs a Parser. --- .../LibWeb/Animations/AnimationEffect.cpp | 2 +- .../LibWeb/Animations/KeyframeEffect.cpp | 4 +- .../Animations/PseudoElementParsing.cpp | 2 +- Libraries/LibWeb/CMakeLists.txt | 1 - Libraries/LibWeb/CSS/CSS.cpp | 6 +- Libraries/LibWeb/CSS/CSSImportRule.cpp | 2 +- Libraries/LibWeb/CSS/CSSRuleList.cpp | 2 +- Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp | 6 +- Libraries/LibWeb/CSS/CSSStyleRule.cpp | 4 +- Libraries/LibWeb/CSS/CSSStyleSheet.cpp | 6 +- Libraries/LibWeb/CSS/CascadedProperties.cpp | 2 +- Libraries/LibWeb/CSS/FontFace.cpp | 10 +- Libraries/LibWeb/CSS/FontFaceSet.cpp | 2 +- Libraries/LibWeb/CSS/MediaList.cpp | 6 +- Libraries/LibWeb/CSS/Parser/Helpers.cpp | 28 +++--- Libraries/LibWeb/CSS/Parser/MediaParsing.cpp | 10 +- Libraries/LibWeb/CSS/Parser/Parser.cpp | 95 ++++++++++++++++--- .../LibWeb/CSS/Parser/ParsingContext.cpp | 68 ------------- Libraries/LibWeb/CSS/Parser/ParsingContext.h | 49 ---------- Libraries/LibWeb/CSS/Parser/RuleParsing.cpp | 44 ++++----- Libraries/LibWeb/CSS/Parser/ValueParsing.cpp | 15 +-- Libraries/LibWeb/CSS/StyleComputer.cpp | 18 ++-- Libraries/LibWeb/CSS/Supports.cpp | 4 +- Libraries/LibWeb/DOM/Document.cpp | 4 +- Libraries/LibWeb/DOM/Element.cpp | 6 +- Libraries/LibWeb/DOM/ParentNode.cpp | 2 +- Libraries/LibWeb/DOM/StyleElementUtils.cpp | 2 +- .../LibWeb/Geometry/DOMMatrixReadOnly.cpp | 2 +- .../HTML/Canvas/CanvasFillStrokeStyles.h | 4 +- .../HTML/Canvas/CanvasTextDrawingStyles.h | 2 +- .../LibWeb/HTML/CanvasRenderingContext2D.cpp | 4 +- Libraries/LibWeb/HTML/HTMLFontElement.cpp | 3 +- Libraries/LibWeb/HTML/HTMLImageElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLMetaElement.cpp | 1 - .../LibWeb/HTML/HTMLTableCellElement.cpp | 4 +- Libraries/LibWeb/HTML/HTMLTableElement.cpp | 2 +- Libraries/LibWeb/HTML/HTMLTableRowElement.cpp | 3 +- Libraries/LibWeb/HTML/SourceSet.cpp | 2 +- Libraries/LibWeb/HTML/Window.cpp | 4 +- .../IntersectionObserver.cpp | 2 +- Libraries/LibWeb/SVG/SVGCircleElement.cpp | 2 +- .../LibWeb/SVG/SVGForeignObjectElement.cpp | 2 +- Libraries/LibWeb/SVG/SVGGraphicsElement.cpp | 2 +- Libraries/LibWeb/SVG/SVGSVGElement.cpp | 8 +- Libraries/LibWeb/SVG/SVGStopElement.cpp | 4 +- Meta/Lagom/Fuzzers/FuzzCSSParser.cpp | 2 +- .../LibWeb/GenerateCSSPropertyID.cpp | 4 +- .../Libraries/LibWeb/CSS/Parser/BUILD.gn | 1 - 49 files changed, 207 insertions(+), 255 deletions(-) delete mode 100644 Libraries/LibWeb/CSS/Parser/ParsingContext.cpp delete mode 100644 Libraries/LibWeb/CSS/Parser/ParsingContext.h diff --git a/Libraries/LibWeb/Animations/AnimationEffect.cpp b/Libraries/LibWeb/Animations/AnimationEffect.cpp index 4c97a850fa..772e7480cb 100644 --- a/Libraries/LibWeb/Animations/AnimationEffect.cpp +++ b/Libraries/LibWeb/Animations/AnimationEffect.cpp @@ -601,7 +601,7 @@ Optional AnimationEffect::transformed_progress() const RefPtr AnimationEffect::parse_easing_string(StringView value) { - if (auto style_value = parse_css_value(CSS::Parser::ParsingContext(), value, CSS::PropertyID::AnimationTimingFunction)) { + if (auto style_value = parse_css_value(CSS::Parser::ParsingParams(), value, CSS::PropertyID::AnimationTimingFunction)) { if (style_value->is_easing()) return style_value; } diff --git a/Libraries/LibWeb/Animations/KeyframeEffect.cpp b/Libraries/LibWeb/Animations/KeyframeEffect.cpp index d9d187bfc1..ceb6c23726 100644 --- a/Libraries/LibWeb/Animations/KeyframeEffect.cpp +++ b/Libraries/LibWeb/Animations/KeyframeEffect.cpp @@ -543,7 +543,7 @@ static WebIDL::ExceptionOr> process_a_keyframes_argument(JS if (!property_id.has_value()) continue; - if (auto style_value = parse_css_value(CSS::Parser::ParsingContext(), value_string, *property_id)) { + if (auto style_value = parse_css_value(CSS::Parser::ParsingParams(), value_string, *property_id)) { // Handle 'initial' here so we don't have to get the default value of the property every frame in StyleComputer if (style_value->is_initial()) style_value = CSS::property_initial_value(*property_id); @@ -861,7 +861,7 @@ WebIDL::ExceptionOr KeyframeEffect::set_keyframes(Optionalis_unresolved() && target) - property_value = CSS::Parser::Parser::resolve_unresolved_style_value(CSS::Parser::ParsingContext { target->document() }, *target, pseudo_element_type(), property_id, property_value->as_unresolved()); + property_value = CSS::Parser::Parser::resolve_unresolved_style_value(CSS::Parser::ParsingParams { target->document() }, *target, pseudo_element_type(), property_id, property_value->as_unresolved()); CSS::StyleComputer::for_each_property_expanding_shorthands(property_id, property_value, CSS::StyleComputer::AllowUnresolved::Yes, [&](CSS::PropertyID shorthand_id, CSS::CSSStyleValue const& shorthand_value) { m_target_properties.set(shorthand_id); resolved_keyframe.properties.set(shorthand_id, NonnullRefPtr { shorthand_value }); diff --git a/Libraries/LibWeb/Animations/PseudoElementParsing.cpp b/Libraries/LibWeb/Animations/PseudoElementParsing.cpp index 5607c85a40..347e0582e3 100644 --- a/Libraries/LibWeb/Animations/PseudoElementParsing.cpp +++ b/Libraries/LibWeb/Animations/PseudoElementParsing.cpp @@ -17,7 +17,7 @@ WebIDL::ExceptionOr> pseudo_element_parsi // 2. If value is not null and is an invalid , Optional pseudo_element; if (value.has_value()) { - pseudo_element = parse_pseudo_element_selector(CSS::Parser::ParsingContext { realm }, *value); + pseudo_element = parse_pseudo_element_selector(CSS::Parser::ParsingParams { realm }, *value); if (!pseudo_element.has_value()) { // 1. Throw a DOMException with error name "SyntaxError". // 2. Abort. diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt index 9f599ec4f9..aef0b95325 100644 --- a/Libraries/LibWeb/CMakeLists.txt +++ b/Libraries/LibWeb/CMakeLists.txt @@ -99,7 +99,6 @@ set(SOURCES CSS/Parser/Helpers.cpp CSS/Parser/MediaParsing.cpp CSS/Parser/Parser.cpp - CSS/Parser/ParsingContext.cpp CSS/Parser/PropertyParsing.cpp CSS/Parser/RuleParsing.cpp CSS/Parser/SelectorParsing.cpp diff --git a/Libraries/LibWeb/CSS/CSS.cpp b/Libraries/LibWeb/CSS/CSS.cpp index ef10d4353b..ded5789db4 100644 --- a/Libraries/LibWeb/CSS/CSS.cpp +++ b/Libraries/LibWeb/CSS/CSS.cpp @@ -27,7 +27,7 @@ bool supports(JS::VM&, StringView property, StringView value) // 1. If property is an ASCII case-insensitive match for any defined CSS property that the UA supports, // and value successfully parses according to that property’s grammar, return true. if (auto property_id = property_id_from_string(property); property_id.has_value()) { - if (parse_css_value(Parser::ParsingContext {}, value, property_id.value())) + if (parse_css_value(Parser::ParsingParams {}, value, property_id.value())) return true; } @@ -46,13 +46,13 @@ WebIDL::ExceptionOr supports(JS::VM& vm, StringView condition_text) auto& realm = *vm.current_realm(); // 1. If conditionText, parsed and evaluated as a , would return true, return true. - if (auto supports = parse_css_supports(Parser::ParsingContext { realm }, condition_text); supports && supports->matches()) + if (auto supports = parse_css_supports(Parser::ParsingParams { realm }, condition_text); supports && supports->matches()) return true; // 2. Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a , would return true, return true. auto wrapped_condition_text = TRY_OR_THROW_OOM(vm, String::formatted("({})", condition_text)); - if (auto supports = parse_css_supports(Parser::ParsingContext { realm }, wrapped_condition_text); supports && supports->matches()) + if (auto supports = parse_css_supports(Parser::ParsingParams { realm }, wrapped_condition_text); supports && supports->matches()) return true; // 3. Otherwise, return false. diff --git a/Libraries/LibWeb/CSS/CSSImportRule.cpp b/Libraries/LibWeb/CSS/CSSImportRule.cpp index 37a0967620..e3340cd796 100644 --- a/Libraries/LibWeb/CSS/CSSImportRule.cpp +++ b/Libraries/LibWeb/CSS/CSSImportRule.cpp @@ -139,7 +139,7 @@ void CSSImportRule::fetch() } auto decoded = decoded_or_error.release_value(); - auto* imported_style_sheet = parse_css_stylesheet(Parser::ParsingContext(*strong_this->m_document, strong_this->url()), decoded, strong_this->url()); + auto* imported_style_sheet = parse_css_stylesheet(Parser::ParsingParams(*strong_this->m_document, strong_this->url()), decoded, strong_this->url()); // 5. Set importedStylesheet’s origin-clean flag to parentStylesheet’s origin-clean flag. imported_style_sheet->set_origin_clean(parent_style_sheet->is_origin_clean()); diff --git a/Libraries/LibWeb/CSS/CSSRuleList.cpp b/Libraries/LibWeb/CSS/CSSRuleList.cpp index 86ba4eb298..3685755da3 100644 --- a/Libraries/LibWeb/CSS/CSSRuleList.cpp +++ b/Libraries/LibWeb/CSS/CSSRuleList.cpp @@ -69,7 +69,7 @@ WebIDL::ExceptionOr CSSRuleList::insert_a_css_rule(Variant()) { new_rule = parse_css_rule( - CSS::Parser::ParsingContext { realm() }, + CSS::Parser::ParsingParams { realm() }, rule.get()); } else { new_rule = rule.get(); diff --git a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index 8012796cd3..fa199042c2 100644 --- a/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -131,8 +131,8 @@ WebIDL::ExceptionOr PropertyOwningCSSStyleDeclaration::set_property(String // 5. Let component value list be the result of parsing value for property property. auto component_value_list = is(this) - ? parse_css_value(CSS::Parser::ParsingContext { static_cast(*this).element()->document() }, value, property_id) - : parse_css_value(CSS::Parser::ParsingContext {}, value, property_id); + ? parse_css_value(CSS::Parser::ParsingParams { static_cast(*this).element()->document() }, value, property_id) + : parse_css_value(CSS::Parser::ParsingParams {}, value, property_id); // 6. If component value list is null, then return. if (!component_value_list) @@ -528,7 +528,7 @@ void ElementInlineCSSStyleDeclaration::set_declarations_from_text(StringView css } empty_the_declarations(); - auto style = parse_css_style_attribute(CSS::Parser::ParsingContext(m_element->document()), css_text, *m_element.ptr()); + auto style = parse_css_style_attribute(CSS::Parser::ParsingParams(m_element->document()), css_text, *m_element.ptr()); set_the_declarations(style->properties(), style->custom_properties()); } diff --git a/Libraries/LibWeb/CSS/CSSStyleRule.cpp b/Libraries/LibWeb/CSS/CSSStyleRule.cpp index 17298b73bb..ee568cc70f 100644 --- a/Libraries/LibWeb/CSS/CSSStyleRule.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleRule.cpp @@ -129,9 +129,9 @@ void CSSStyleRule::set_selector_text(StringView selector_text) Optional parsed_selectors; if (parent_style_rule()) { // AD-HOC: If we're a nested style rule, then we need to parse the selector as relative and then adapt it with implicit &s. - parsed_selectors = parse_selector_for_nested_style_rule(Parser::ParsingContext { realm() }, selector_text); + parsed_selectors = parse_selector_for_nested_style_rule(Parser::ParsingParams { realm() }, selector_text); } else { - parsed_selectors = parse_selector(Parser::ParsingContext { realm() }, selector_text); + parsed_selectors = parse_selector(Parser::ParsingParams { realm() }, selector_text); } // 2. If the algorithm returns a non-null value replace the associated group of selectors with the returned value. diff --git a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index d7b8097593..a91b9b6675 100644 --- a/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -139,7 +139,7 @@ WebIDL::ExceptionOr CSSStyleSheet::insert_rule(StringView rule, unsign return WebIDL::NotAllowedError::create(realm(), "Can't call insert_rule() on non-modifiable stylesheets."_string); // 3. Let parsed rule be the return value of invoking parse a rule with rule. - auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingContext { (*m_owning_documents_or_shadow_roots.begin())->document() } : Parser::ParsingContext { realm() }; + auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingParams { (*m_owning_documents_or_shadow_roots.begin())->document() } : Parser::ParsingParams { realm() }; auto parsed_rule = parse_css_rule(context, rule); // 4. If parsed rule is a syntax error, return parsed rule. @@ -207,7 +207,7 @@ GC::Ref CSSStyleSheet::replace(String text) HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 1. Let rules be the result of running parse a stylesheet’s contents from text. - auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingContext { (*m_owning_documents_or_shadow_roots.begin())->document() } : CSS::Parser::ParsingContext { realm }; + auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingParams { (*m_owning_documents_or_shadow_roots.begin())->document() } : CSS::Parser::ParsingParams { realm }; auto* parsed_stylesheet = parse_css_stylesheet(context, text); auto& rules = parsed_stylesheet->rules(); @@ -241,7 +241,7 @@ WebIDL::ExceptionOr CSSStyleSheet::replace_sync(StringView text) return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-modifiable stylesheets"_string); // 2. Let rules be the result of running parse a stylesheet’s contents from text. - auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingContext { (*m_owning_documents_or_shadow_roots.begin())->document() } : CSS::Parser::ParsingContext { realm() }; + auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingParams { (*m_owning_documents_or_shadow_roots.begin())->document() } : CSS::Parser::ParsingParams { realm() }; auto* parsed_stylesheet = parse_css_stylesheet(context, text); auto& rules = parsed_stylesheet->rules(); diff --git a/Libraries/LibWeb/CSS/CascadedProperties.cpp b/Libraries/LibWeb/CSS/CascadedProperties.cpp index 66e4495983..67aa583739 100644 --- a/Libraries/LibWeb/CSS/CascadedProperties.cpp +++ b/Libraries/LibWeb/CSS/CascadedProperties.cpp @@ -62,7 +62,7 @@ void CascadedProperties::resolve_unresolved_properties(GC::Ref ele for (auto& entry : entries) { if (!entry.property.value->is_unresolved()) continue; - entry.property.value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { element->document() }, element, pseudo_element, property_id, entry.property.value->as_unresolved()); + entry.property.value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { element->document() }, element, pseudo_element, property_id, entry.property.value->as_unresolved()); } } } diff --git a/Libraries/LibWeb/CSS/FontFace.cpp b/Libraries/LibWeb/CSS/FontFace.cpp index 6ec07b9e0f..a4f1836ce3 100644 --- a/Libraries/LibWeb/CSS/FontFace.cpp +++ b/Libraries/LibWeb/CSS/FontFace.cpp @@ -81,7 +81,7 @@ GC::Ref FontFace::construct_impl(JS::Realm& realm, String family, Font Vector sources; ByteBuffer buffer; if (auto* string = source.get_pointer()) { - auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm, base_url), *string); + auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingParams(realm, base_url), *string); sources = parser.parse_as_font_face_src(); if (sources.is_empty()) WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid source string"_string)); @@ -206,7 +206,7 @@ GC::Ref FontFace::loaded() const // https://drafts.csswg.org/css-font-loading/#dom-fontface-family WebIDL::ExceptionOr FontFace::set_family(String const& string) { - auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontFamily); + auto property = parse_css_value(Parser::ParsingParams(), string, CSS::PropertyID::FontFamily); if (!property) return WebIDL::SyntaxError::create(realm(), "FontFace.family setter: Invalid font descriptor"_string); @@ -222,7 +222,7 @@ WebIDL::ExceptionOr FontFace::set_family(String const& string) // https://drafts.csswg.org/css-font-loading/#dom-fontface-style WebIDL::ExceptionOr FontFace::set_style(String const& string) { - auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontStyle); + auto property = parse_css_value(Parser::ParsingParams(), string, CSS::PropertyID::FontStyle); if (!property) return WebIDL::SyntaxError::create(realm(), "FontFace.style setter: Invalid font descriptor"_string); @@ -238,7 +238,7 @@ WebIDL::ExceptionOr FontFace::set_style(String const& string) // https://drafts.csswg.org/css-font-loading/#dom-fontface-weight WebIDL::ExceptionOr FontFace::set_weight(String const& string) { - auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontWeight); + auto property = parse_css_value(Parser::ParsingParams(), string, CSS::PropertyID::FontWeight); if (!property) return WebIDL::SyntaxError::create(realm(), "FontFace.weight setter: Invalid font descriptor"_string); @@ -255,7 +255,7 @@ WebIDL::ExceptionOr FontFace::set_weight(String const& string) WebIDL::ExceptionOr FontFace::set_stretch(String const& string) { // NOTE: font-stretch is now an alias for font-width - auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontWidth); + auto property = parse_css_value(Parser::ParsingParams(), string, CSS::PropertyID::FontWidth); if (!property) return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid font descriptor"_string); diff --git a/Libraries/LibWeb/CSS/FontFaceSet.cpp b/Libraries/LibWeb/CSS/FontFaceSet.cpp index 10363a17e1..f8f7c5be25 100644 --- a/Libraries/LibWeb/CSS/FontFaceSet.cpp +++ b/Libraries/LibWeb/CSS/FontFaceSet.cpp @@ -175,7 +175,7 @@ WebIDL::CallbackType* FontFaceSet::onloadingerror() static WebIDL::ExceptionOr> find_matching_font_faces(JS::Realm& realm, FontFaceSet& font_face_set, String const& font, String const&) { // 1. Parse font using the CSS value syntax of the font property. If a syntax error occurs, return a syntax error. - auto property = parse_css_value(CSS::Parser::ParsingContext(), font, PropertyID::Font); + auto property = parse_css_value(CSS::Parser::ParsingParams(), font, PropertyID::Font); if (!property) return WebIDL::SyntaxError::create(realm, "Unable to parse font"_string); diff --git a/Libraries/LibWeb/CSS/MediaList.cpp b/Libraries/LibWeb/CSS/MediaList.cpp index 25c4e8b0b0..394b44f2fa 100644 --- a/Libraries/LibWeb/CSS/MediaList.cpp +++ b/Libraries/LibWeb/CSS/MediaList.cpp @@ -45,7 +45,7 @@ void MediaList::set_media_text(StringView text) m_media.clear(); if (text.is_empty()) return; - m_media = parse_media_query_list(Parser::ParsingContext { realm() }, text); + m_media = parse_media_query_list(Parser::ParsingParams { realm() }, text); } // https://www.w3.org/TR/cssom-1/#dom-medialist-item @@ -61,7 +61,7 @@ Optional MediaList::item(u32 index) const void MediaList::append_medium(StringView medium) { // 1. Let m be the result of parsing the given value. - auto m = parse_media_query(Parser::ParsingContext { realm() }, medium); + auto m = parse_media_query(Parser::ParsingParams { realm() }, medium); // 2. If m is null, then return. if (!m) @@ -81,7 +81,7 @@ void MediaList::append_medium(StringView medium) // https://www.w3.org/TR/cssom-1/#dom-medialist-deletemedium void MediaList::delete_medium(StringView medium) { - auto m = parse_media_query(Parser::ParsingContext { realm() }, medium); + auto m = parse_media_query(Parser::ParsingParams { realm() }, medium); if (!m) return; m_media.remove_all_matching([&](auto& existing) -> bool { diff --git a/Libraries/LibWeb/CSS/Parser/Helpers.cpp b/Libraries/LibWeb/CSS/Parser/Helpers.cpp index ebd84000d0..9478d33139 100644 --- a/Libraries/LibWeb/CSS/Parser/Helpers.cpp +++ b/Libraries/LibWeb/CSS/Parser/Helpers.cpp @@ -15,12 +15,12 @@ namespace Web { -CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& context, StringView css, Optional location) +CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const& context, StringView css, Optional location) { if (css.is_empty()) { - auto rule_list = CSS::CSSRuleList::create_empty(context.realm()); - auto media_list = CSS::MediaList::create(context.realm(), {}); - auto style_sheet = CSS::CSSStyleSheet::create(context.realm(), rule_list, media_list, location); + auto rule_list = CSS::CSSRuleList::create_empty(*context.realm); + auto media_list = CSS::MediaList::create(*context.realm, {}); + auto style_sheet = CSS::CSSStyleSheet::create(*context.realm, rule_list, media_list, location); style_sheet->set_source_text({}); return style_sheet; } @@ -30,31 +30,31 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& cont return style_sheet; } -CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingContext const& context, StringView css, DOM::Element& element) +CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingParams const& context, StringView css, DOM::Element& element) { if (css.is_empty()) return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {}); return CSS::Parser::Parser::create(context, css).parse_as_style_attribute(element); } -RefPtr parse_css_value(CSS::Parser::ParsingContext const& context, StringView string, CSS::PropertyID property_id) +RefPtr parse_css_value(CSS::Parser::ParsingParams const& context, StringView string, CSS::PropertyID property_id) { if (string.is_empty()) return nullptr; return CSS::Parser::Parser::create(context, string).parse_as_css_value(property_id); } -CSS::CSSRule* parse_css_rule(CSS::Parser::ParsingContext const& context, StringView css_text) +CSS::CSSRule* parse_css_rule(CSS::Parser::ParsingParams const& context, StringView css_text) { return CSS::Parser::Parser::create(context, css_text).parse_as_css_rule(); } -Optional parse_selector(CSS::Parser::ParsingContext const& context, StringView selector_text) +Optional parse_selector(CSS::Parser::ParsingParams const& context, StringView selector_text) { return CSS::Parser::Parser::create(context, selector_text).parse_as_selector(); } -Optional parse_selector_for_nested_style_rule(CSS::Parser::ParsingContext const& context, StringView selector_text) +Optional parse_selector_for_nested_style_rule(CSS::Parser::ParsingParams const& context, StringView selector_text) { auto parser = CSS::Parser::Parser::create(context, selector_text); @@ -65,29 +65,29 @@ Optional parse_selector_for_nested_style_rule(CSS::Parser::Pa return adapt_nested_relative_selector_list(*maybe_selectors); } -Optional parse_pseudo_element_selector(CSS::Parser::ParsingContext const& context, StringView selector_text) +Optional parse_pseudo_element_selector(CSS::Parser::ParsingParams const& context, StringView selector_text) { return CSS::Parser::Parser::create(context, selector_text).parse_as_pseudo_element_selector(); } -RefPtr parse_media_query(CSS::Parser::ParsingContext const& context, StringView string) +RefPtr parse_media_query(CSS::Parser::ParsingParams const& context, StringView string) { return CSS::Parser::Parser::create(context, string).parse_as_media_query(); } -Vector> parse_media_query_list(CSS::Parser::ParsingContext const& context, StringView string) +Vector> parse_media_query_list(CSS::Parser::ParsingParams const& context, StringView string) { return CSS::Parser::Parser::create(context, string).parse_as_media_query_list(); } -RefPtr parse_css_supports(CSS::Parser::ParsingContext const& context, StringView string) +RefPtr parse_css_supports(CSS::Parser::ParsingParams const& context, StringView string) { if (string.is_empty()) return {}; return CSS::Parser::Parser::create(context, string).parse_as_supports(); } -Optional parse_css_supports_condition(CSS::Parser::ParsingContext const& context, StringView string) +Optional parse_css_supports_condition(CSS::Parser::ParsingParams const& context, StringView string) { if (string.is_empty()) return {}; diff --git a/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp b/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp index 611e42c795..b4633ead95 100644 --- a/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/MediaParsing.cpp @@ -622,9 +622,9 @@ GC::Ptr Parser::convert_to_media_rule(AtRule const& rule, Nested n { auto media_query_tokens = TokenStream { rule.prelude }; auto media_query_list = parse_a_media_query_list(media_query_tokens); - auto media_list = MediaList::create(m_context.realm(), move(media_query_list)); + auto media_list = MediaList::create(realm(), move(media_query_list)); - GC::RootVector child_rules { m_context.realm().heap() }; + GC::RootVector child_rules { realm().heap() }; for (auto const& child : rule.child_rules_and_lists_of_declarations) { child.visit( [&](Rule const& rule) { @@ -637,11 +637,11 @@ GC::Ptr Parser::convert_to_media_rule(AtRule const& rule, Nested n dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); return; } - child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration)); + child_rules.append(CSSNestedDeclarations::create(realm(), *declaration)); }); } - auto rule_list = CSSRuleList::create(m_context.realm(), child_rules); - return CSSMediaRule::create(m_context.realm(), media_list, rule_list); + auto rule_list = CSSRuleList::create(realm(), child_rules); + return CSSMediaRule::create(realm(), media_list, rule_list); } } diff --git a/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Libraries/LibWeb/CSS/Parser/Parser.cpp index 7b16548e2b..accd1ffbd2 100644 --- a/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -30,14 +31,51 @@ static void log_parse_error(SourceLocation const& location = SourceLocation::cur namespace Web::CSS::Parser { -Parser Parser::create(ParsingContext const& context, StringView input, StringView encoding) +ParsingParams::ParsingParams(ParsingMode mode) + : mode(mode) +{ +} + +ParsingParams::ParsingParams(JS::Realm& realm, ParsingMode mode) + : realm(realm) + , mode(mode) +{ +} + +ParsingParams::ParsingParams(JS::Realm& realm, URL::URL url, ParsingMode mode) + : realm(realm) + , url(move(url)) + , mode(mode) +{ +} + +ParsingParams::ParsingParams(DOM::Document const& document, URL::URL url, ParsingMode mode) + : realm(const_cast(document.realm())) + , document(&document) + , url(move(url)) + , mode(mode) +{ +} + +ParsingParams::ParsingParams(DOM::Document const& document, ParsingMode mode) + : realm(const_cast(document.realm())) + , document(&document) + , url(document.url()) + , mode(mode) +{ +} + +Parser Parser::create(ParsingParams const& context, StringView input, StringView encoding) { auto tokens = Tokenizer::tokenize(input, encoding); return Parser { context, move(tokens) }; } -Parser::Parser(ParsingContext const& context, Vector tokens) - : m_context(context) +Parser::Parser(ParsingParams const& context, Vector tokens) + : m_document(context.document) + , m_realm(context.realm) + , m_url(context.url) + , m_parsing_mode(context.mode) , m_tokens(move(tokens)) , m_token_stream(m_tokens) { @@ -84,7 +122,7 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional location) auto const& style_sheet = parse_a_stylesheet(m_token_stream, {}); // Interpret all of the resulting top-level qualified rules as style rules, defined below. - GC::RootVector rules(m_context.realm().heap()); + GC::RootVector rules(realm().heap()); for (auto const& raw_rule : style_sheet.rules) { auto rule = convert_to_rule(raw_rule, Nested::No); // If any style rule is invalid, or any at-rule is not recognized or is invalid according to its grammar or context, it’s a parse error. @@ -96,9 +134,9 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional location) rules.append(rule); } - auto rule_list = CSSRuleList::create(m_context.realm(), rules); - auto media_list = MediaList::create(m_context.realm(), {}); - return CSSStyleSheet::create(m_context.realm(), rule_list, media_list, move(location)); + auto rule_list = CSSRuleList::create(realm(), rules); + auto media_list = MediaList::create(realm(), {}); + return CSSStyleSheet::create(realm(), rule_list, media_list, move(location)); } RefPtr Parser::parse_as_supports() @@ -116,7 +154,7 @@ RefPtr Parser::parse_a_supports(TokenStream& tokens) m_rule_context.take_last(); token_stream.discard_whitespace(); if (maybe_condition && !token_stream.has_next_token()) - return Supports::create(m_context.realm(), maybe_condition.release_nonnull()); + return Supports::create(realm(), maybe_condition.release_nonnull()); return {}; } @@ -1413,7 +1451,7 @@ PropertyOwningCSSStyleDeclaration* Parser::convert_to_style_declaration(Vector Parser::convert_to_style_property(Declaration const& declaration) @@ -1462,7 +1500,7 @@ Optional Parser::parse_source_size_value(TokenStream evaluates to false, continue. TokenStream token_stream { unparsed_size }; auto media_condition = parse_media_condition(token_stream, MediaCondition::AllowOr::Yes); - auto const* context_window = m_context.window(); + auto const* context_window = window(); if (!media_condition || (context_window && media_condition->evaluate(*context_window) == MatchResult::False)) { continue; } @@ -1693,4 +1731,39 @@ template Vector Parser::parse_a_list_of_component_values(TokenSt template Vector> Parser::parse_a_comma_separated_list_of_component_values(TokenStream&); template Vector> Parser::parse_a_comma_separated_list_of_component_values(TokenStream&); +DOM::Document const* Parser::document() const +{ + return m_document; +} + +HTML::Window const* Parser::window() const +{ + if (!m_document) + return nullptr; + return m_document->window(); +} + +JS::Realm& Parser::realm() const +{ + VERIFY(m_realm); + return *m_realm; +} + +bool Parser::in_quirks_mode() const +{ + return m_document ? m_document->in_quirks_mode() : false; +} + +bool Parser::is_parsing_svg_presentation_attribute() const +{ + return m_parsing_mode == ParsingMode::SVGPresentationAttribute; +} + +// https://www.w3.org/TR/css-values-4/#relative-urls +// FIXME: URLs shouldn't be completed during parsing, but when used. +URL::URL Parser::complete_url(StringView relative_url) const +{ + return m_url.complete_url(relative_url); +} + } diff --git a/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp b/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp deleted file mode 100644 index 3831508cea..0000000000 --- a/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (c) 2018-2022, Andreas Kling - * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021-2023, Sam Atkins - * Copyright (c) 2021, Tobias Christiansen - * Copyright (c) 2022, MacDue - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#include -#include - -namespace Web::CSS::Parser { - -ParsingContext::ParsingContext(Mode mode) - : m_mode(mode) -{ -} - -ParsingContext::ParsingContext(JS::Realm& realm, Mode mode) - : m_realm(realm) - , m_mode(mode) -{ -} - -ParsingContext::ParsingContext(JS::Realm& realm, URL::URL url, Mode mode) - : m_realm(realm) - , m_url(move(url)) - , m_mode(mode) -{ -} - -ParsingContext::ParsingContext(DOM::Document const& document, URL::URL url, Mode mode) - : m_realm(const_cast(document.realm())) - , m_document(&document) - , m_url(move(url)) - , m_mode(mode) -{ -} - -ParsingContext::ParsingContext(DOM::Document const& document, Mode mode) - : m_realm(const_cast(document.realm())) - , m_document(&document) - , m_url(document.url()) - , m_mode(mode) -{ -} - -bool ParsingContext::in_quirks_mode() const -{ - return m_document ? m_document->in_quirks_mode() : false; -} - -// https://www.w3.org/TR/css-values-4/#relative-urls -URL::URL ParsingContext::complete_url(StringView relative_url) const -{ - return m_url.complete_url(relative_url); -} - -HTML::Window const* ParsingContext::window() const -{ - if (!m_document) - return nullptr; - return m_document->window(); -} - -} diff --git a/Libraries/LibWeb/CSS/Parser/ParsingContext.h b/Libraries/LibWeb/CSS/Parser/ParsingContext.h deleted file mode 100644 index 9923825f08..0000000000 --- a/Libraries/LibWeb/CSS/Parser/ParsingContext.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2020-2021, the SerenityOS developers. - * Copyright (c) 2021-2024, Sam Atkins - * - * SPDX-License-Identifier: BSD-2-Clause - */ - -#pragma once - -#include -#include - -namespace Web::CSS::Parser { - -class ParsingContext { -public: - enum class Mode { - Normal, - SVGPresentationAttribute, // See https://svgwg.org/svg2-draft/types.html#presentation-attribute-css-value - }; - - explicit ParsingContext(Mode = Mode::Normal); - explicit ParsingContext(JS::Realm&, Mode = Mode::Normal); - explicit ParsingContext(JS::Realm&, URL::URL, Mode = Mode::Normal); - explicit ParsingContext(DOM::Document const&, Mode = Mode::Normal); - explicit ParsingContext(DOM::Document const&, URL::URL, Mode = Mode::Normal); - - Mode mode() const { return m_mode; } - bool is_parsing_svg_presentation_attribute() const { return m_mode == Mode::SVGPresentationAttribute; } - - bool in_quirks_mode() const; - DOM::Document const* document() const { return m_document; } - HTML::Window const* window() const; - URL::URL complete_url(StringView) const; - - JS::Realm& realm() const - { - VERIFY(m_realm); - return *m_realm; - } - -private: - GC::Ptr m_realm; - GC::Ptr m_document; - URL::URL m_url; - Mode m_mode { Mode::Normal }; -}; - -} diff --git a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp index 1c3c057326..6a669113d0 100644 --- a/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp @@ -108,7 +108,7 @@ GC::Ptr Parser::convert_to_style_rule(QualifiedRule const& qualifi return {}; } - GC::RootVector child_rules { m_context.realm().heap() }; + GC::RootVector child_rules { realm().heap() }; for (auto& child : qualified_rule.child_rules) { child.visit( [&](Rule const& rule) { @@ -129,11 +129,11 @@ GC::Ptr Parser::convert_to_style_rule(QualifiedRule const& qualifi dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); return; } - child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration)); + child_rules.append(CSSNestedDeclarations::create(realm(), *declaration)); }); } - auto nested_rules = CSSRuleList::create(m_context.realm(), move(child_rules)); - return CSSStyleRule::create(m_context.realm(), move(selectors), *declaration, *nested_rules); + auto nested_rules = CSSRuleList::create(realm(), move(child_rules)); + return CSSStyleRule::create(realm(), move(selectors), *declaration, *nested_rules); } GC::Ptr Parser::convert_to_import_rule(AtRule const& rule) @@ -161,7 +161,7 @@ GC::Ptr Parser::convert_to_import_rule(AtRule const& rule) Optional url = parse_url_function(tokens); if (!url.has_value() && tokens.next_token().is(Token::Type::String)) - url = m_context.complete_url(tokens.consume_a_token().token().string()); + url = complete_url(tokens.consume_a_token().token().string()); if (!url.has_value()) { dbgln_if(CSS_PARSER_DEBUG, "Failed to parse @import rule: Unable to parse `{}` as URL.", tokens.next_token().to_debug_string()); @@ -178,7 +178,7 @@ GC::Ptr Parser::convert_to_import_rule(AtRule const& rule) return {}; } - return CSSImportRule::create(url.value(), const_cast(*m_context.document())); + return CSSImportRule::create(url.value(), const_cast(*document())); } Optional Parser::parse_layer_name(TokenStream& tokens, AllowBlankLayerName allow_blank_layer_name) @@ -247,7 +247,7 @@ GC::Ptr Parser::convert_to_layer_rule(AtRule const& rule, Nested nested } // Then the rules - GC::RootVector child_rules { m_context.realm().heap() }; + GC::RootVector child_rules { realm().heap() }; for (auto const& child : rule.child_rules_and_lists_of_declarations) { child.visit( [&](Rule const& rule) { @@ -260,11 +260,11 @@ GC::Ptr Parser::convert_to_layer_rule(AtRule const& rule, Nested nested dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); return; } - child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration)); + child_rules.append(CSSNestedDeclarations::create(realm(), *declaration)); }); } - auto rule_list = CSSRuleList::create(m_context.realm(), child_rules); - return CSSLayerBlockRule::create(m_context.realm(), layer_name, rule_list); + auto rule_list = CSSRuleList::create(realm(), child_rules); + return CSSLayerBlockRule::create(realm(), layer_name, rule_list); } // CSSLayerStatementRule @@ -296,7 +296,7 @@ GC::Ptr Parser::convert_to_layer_rule(AtRule const& rule, Nested nested return {}; } - return CSSLayerStatementRule::create(m_context.realm(), move(layer_names)); + return CSSLayerStatementRule::create(realm(), move(layer_names)); } GC::Ptr Parser::convert_to_keyframes_rule(AtRule const& rule) @@ -342,7 +342,7 @@ GC::Ptr Parser::convert_to_keyframes_rule(AtRule const& rule) auto name = name_token.to_string(); - GC::RootVector keyframes(m_context.realm().heap()); + GC::RootVector keyframes(realm().heap()); rule.for_each_as_qualified_rule_list([&](auto& qualified_rule) { if (!qualified_rule.child_rules.is_empty()) { dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @keyframes keyframe rule contains at-rules; discarding them."); @@ -390,14 +390,14 @@ GC::Ptr Parser::convert_to_keyframes_rule(AtRule const& rule) qualified_rule.for_each_as_declaration_list([&](auto const& declaration) { extract_property(declaration, properties); }); - auto style = PropertyOwningCSSStyleDeclaration::create(m_context.realm(), move(properties.properties), move(properties.custom_properties)); + auto style = PropertyOwningCSSStyleDeclaration::create(realm(), move(properties.properties), move(properties.custom_properties)); for (auto& selector : selectors) { - auto keyframe_rule = CSSKeyframeRule::create(m_context.realm(), selector, *style); + auto keyframe_rule = CSSKeyframeRule::create(realm(), selector, *style); keyframes.append(keyframe_rule); } }); - return CSSKeyframesRule::create(m_context.realm(), name, CSSRuleList::create(m_context.realm(), move(keyframes))); + return CSSKeyframesRule::create(realm(), name, CSSRuleList::create(realm(), move(keyframes))); } GC::Ptr Parser::convert_to_namespace_rule(AtRule const& rule) @@ -444,7 +444,7 @@ GC::Ptr Parser::convert_to_namespace_rule(AtRule const& rule) return {}; } - return CSSNamespaceRule::create(m_context.realm(), prefix, namespace_uri); + return CSSNamespaceRule::create(realm(), prefix, namespace_uri); } GC::Ptr Parser::convert_to_supports_rule(AtRule const& rule, Nested nested) @@ -469,7 +469,7 @@ GC::Ptr Parser::convert_to_supports_rule(AtRule const& rule, Ne return {}; } - GC::RootVector child_rules { m_context.realm().heap() }; + GC::RootVector child_rules { realm().heap() }; for (auto const& child : rule.child_rules_and_lists_of_declarations) { child.visit( [&](Rule const& rule) { @@ -482,12 +482,12 @@ GC::Ptr Parser::convert_to_supports_rule(AtRule const& rule, Ne dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); return; } - child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration)); + child_rules.append(CSSNestedDeclarations::create(realm(), *declaration)); }); } - auto rule_list = CSSRuleList::create(m_context.realm(), child_rules); - return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), rule_list); + auto rule_list = CSSRuleList::create(realm(), child_rules); + return CSSSupportsRule::create(realm(), supports.release_nonnull(), rule_list); } GC::Ptr Parser::convert_to_property_rule(AtRule const& rule) @@ -582,7 +582,7 @@ GC::Ptr Parser::convert_to_property_rule(AtRule const& rule) }); if (syntax_maybe.has_value() && inherits_maybe.has_value()) { - return CSSPropertyRule::create(m_context.realm(), name, syntax_maybe.value(), inherits_maybe.value(), std::move(initial_value_maybe)); + return CSSPropertyRule::create(realm(), name, syntax_maybe.value(), inherits_maybe.value(), std::move(initial_value_maybe)); } return {}; } @@ -976,7 +976,7 @@ GC::Ptr Parser::convert_to_font_face_rule(AtRule const& rule) unicode_range.empend(0x0u, 0x10FFFFu); } - return CSSFontFaceRule::create(m_context.realm(), ParsedFontFace { font_family.release_value(), move(weight), move(slope), move(width), move(src), move(unicode_range), move(ascent_override), move(descent_override), move(line_gap_override), font_display, move(font_named_instance), move(language_override), move(font_feature_settings), move(font_variation_settings) }); + return CSSFontFaceRule::create(realm(), ParsedFontFace { font_family.release_value(), move(weight), move(slope), move(width), move(src), move(unicode_range), move(ascent_override), move(descent_override), move(line_gap_override), font_display, move(font_named_instance), move(language_override), move(font_feature_settings), move(font_variation_settings) }); } } diff --git a/Libraries/LibWeb/CSS/Parser/ValueParsing.cpp b/Libraries/LibWeb/CSS/Parser/ValueParsing.cpp index b30d84b04d..2e24636aa3 100644 --- a/Libraries/LibWeb/CSS/Parser/ValueParsing.cpp +++ b/Libraries/LibWeb/CSS/Parser/ValueParsing.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -659,7 +660,7 @@ RefPtr Parser::parse_angle_value(TokenStream& tok // When parsing an SVG attribute, an angle is allowed without a unit. // FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792 // For now: Convert to an angle in degrees. - if (tokens.next_token().is(Token::Type::Number) && m_context.is_parsing_svg_presentation_attribute()) { + if (tokens.next_token().is(Token::Type::Number) && is_parsing_svg_presentation_attribute()) { auto numeric_value = tokens.consume_a_token().token().number_value(); return AngleStyleValue::create(Angle::make_degrees(numeric_value)); } @@ -693,7 +694,7 @@ RefPtr Parser::parse_angle_percentage_value(TokenStream Parser::parse_length_value(TokenStream& to // When parsing an SVG attribute, a length is allowed without a unit. // FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792 // For now: Convert to a length in pixels. - if (m_context.is_parsing_svg_presentation_attribute()) { + if (is_parsing_svg_presentation_attribute()) { transaction.commit(); return LengthStyleValue::create(Length::make_px(CSSPixels::nearest_value_for(numeric_value))); } @@ -852,7 +853,7 @@ RefPtr Parser::parse_length_percentage_value(TokenStream Parser::parse_color_value(TokenStream& tok } // https://drafts.csswg.org/css-color-4/#quirky-color - if (m_context.in_quirks_mode()) { + if (in_quirks_mode()) { // "When CSS is being parsed in quirks mode, is a type of that is only valid in certain properties:" // (NOTE: List skipped for brevity; quirks data is assigned in Properties.json) // "It is not valid in properties that include or reference these properties, such as the background shorthand, @@ -2468,7 +2469,7 @@ Optional Parser::parse_url_function(TokenStream& token auto& component_value = tokens.consume_a_token(); auto convert_string_to_url = [&](StringView url_string) -> Optional { - auto url = m_context.complete_url(url_string); + auto url = complete_url(url_string); if (url.is_valid()) { transaction.commit(); return url; @@ -3510,7 +3511,7 @@ RefPtr Parser::parse_opentype_tag_value(TokenStream Parser::resolve_unresolved_style_value(ParsingContext const& context, DOM::Element& element, Optional pseudo_element, PropertyID property_id, UnresolvedStyleValue const& unresolved) +NonnullRefPtr Parser::resolve_unresolved_style_value(ParsingParams const& context, DOM::Element& element, Optional pseudo_element, PropertyID property_id, UnresolvedStyleValue const& unresolved) { // Unresolved always contains a var() or attr(), unless it is a custom property's value, in which case we shouldn't be trying // to produce a different CSSStyleValue from it. diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index d8d7179c9b..eca04ed3e5 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -307,7 +307,7 @@ static CSSStyleSheet& default_stylesheet(DOM::Document const& document) static GC::Root sheet; if (!sheet.cell()) { extern String default_stylesheet_source; - sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document), default_stylesheet_source)); + sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document), default_stylesheet_source)); } return *sheet; } @@ -317,7 +317,7 @@ static CSSStyleSheet& quirks_mode_stylesheet(DOM::Document const& document) static GC::Root sheet; if (!sheet.cell()) { extern String quirks_mode_stylesheet_source; - sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document), quirks_mode_stylesheet_source)); + sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document), quirks_mode_stylesheet_source)); } return *sheet; } @@ -327,7 +327,7 @@ static CSSStyleSheet& mathml_stylesheet(DOM::Document const& document) static GC::Root sheet; if (!sheet.cell()) { extern String mathml_stylesheet_source; - sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document), mathml_stylesheet_source)); + sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document), mathml_stylesheet_source)); } return *sheet; } @@ -337,7 +337,7 @@ static CSSStyleSheet& svg_stylesheet(DOM::Document const& document) static GC::Root sheet; if (!sheet.cell()) { extern String svg_stylesheet_source; - sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document), svg_stylesheet_source)); + sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document), svg_stylesheet_source)); } return *sheet; } @@ -1009,7 +1009,7 @@ void StyleComputer::set_all_properties( NonnullRefPtr property_value = value; if (property_value->is_unresolved()) - property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { document }, element, pseudo_element, property_id, property_value->as_unresolved()); + property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { document }, element, pseudo_element, property_id, property_value->as_unresolved()); if (!property_value->is_unresolved()) set_property_expanding_shorthands(cascaded_properties, property_id, property_value, declaration, cascade_origin, important, layer_name); @@ -1038,7 +1038,7 @@ void StyleComputer::cascade_declarations( auto property_value = property.value; if (property.value->is_unresolved()) - property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { document() }, element, pseudo_element, property.property_id, property.value->as_unresolved()); + property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { document() }, element, pseudo_element, property.property_id, property.value->as_unresolved()); if (!property_value->is_unresolved()) set_property_expanding_shorthands(cascaded_properties, property.property_id, property_value, &match->declaration(), cascade_origin, important, layer_name); } @@ -1057,7 +1057,7 @@ void StyleComputer::cascade_declarations( auto property_value = property.value; if (property.value->is_unresolved()) - property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { document() }, element, pseudo_element, property.property_id, property.value->as_unresolved()); + property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { document() }, element, pseudo_element, property.property_id, property.value->as_unresolved()); if (!property_value->is_unresolved()) set_property_expanding_shorthands(cascaded_properties, property.property_id, property_value, inline_style, cascade_origin, important, layer_name); } @@ -1157,7 +1157,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optionalis_revert() || value->is_revert_layer()) return computed_properties.property(it.key); if (value->is_unresolved()) - return Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { element.document() }, element, pseudo_element, it.key, value->as_unresolved()); + return Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { element.document() }, element, pseudo_element, it.key, value->as_unresolved()); return value; }); }; @@ -2974,7 +2974,7 @@ void StyleComputer::build_rule_cache() m_style_invalidation_data = make(); if (auto user_style_source = document().page().user_style(); user_style_source.has_value()) { - m_user_style_sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document()), user_style_source.value())); + m_user_style_sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document()), user_style_source.value())); } build_qualified_layer_names_cache(); diff --git a/Libraries/LibWeb/CSS/Supports.cpp b/Libraries/LibWeb/CSS/Supports.cpp index 07478d4c34..5f97ada429 100644 --- a/Libraries/LibWeb/CSS/Supports.cpp +++ b/Libraries/LibWeb/CSS/Supports.cpp @@ -59,13 +59,13 @@ bool Supports::InParens::evaluate(JS::Realm& realm) const bool Supports::Declaration::evaluate(JS::Realm& realm) const { - auto style_property = parse_css_supports_condition(Parser::ParsingContext { realm }, declaration); + auto style_property = parse_css_supports_condition(Parser::ParsingParams { realm }, declaration); return style_property.has_value(); } bool Supports::Selector::evaluate(JS::Realm& realm) const { - auto style_property = parse_selector(Parser::ParsingContext { realm }, selector); + auto style_property = parse_selector(Parser::ParsingParams { realm }, selector); return style_property.has_value(); } diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 6c82c15846..d70bddfc4c 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -1541,7 +1541,7 @@ void Document::obtain_supported_color_schemes() auto content = element.attribute(HTML::AttributeNames::content); if (element.name().has_value() && element.name()->equals_ignoring_ascii_case("color-scheme"sv) && content.has_value()) { // 1. Let parsed be the result of parsing a list of component values given the value of element's content attribute. - auto context = CSS::Parser::ParsingContext { document() }; + auto context = CSS::Parser::ParsingParams { document() }; auto parsed = parse_css_value(context, content.value(), CSS::PropertyID::ColorScheme); // 2. If parsed is a valid CSS 'color-scheme' property value, then return parsed. @@ -1572,7 +1572,7 @@ void Document::obtain_theme_color() auto content = element.attribute(HTML::AttributeNames::content); if (element.name().has_value() && element.name()->equals_ignoring_ascii_case("theme-color"sv) && content.has_value()) { // 1. If element has a media attribute and the value of element's media attribute does not match the environment, then continue. - auto context = CSS::Parser::ParsingContext { document() }; + auto context = CSS::Parser::ParsingParams { document() }; auto media = element.attribute(HTML::AttributeNames::media); if (media.has_value()) { auto query = parse_media_query(context, media.value()); diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 5e85ef5265..0750d7d7ad 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -744,7 +744,7 @@ GC::Ptr Element::shadow_root_for_bindings() const WebIDL::ExceptionOr Element::matches(StringView selectors) const { // 1. Let s be the result of parse a selector from selectors. - auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(document()), selectors); + auto maybe_selectors = parse_selector(CSS::Parser::ParsingParams(document()), selectors); // 2. If s is failure, then throw a "SyntaxError" DOMException. if (!maybe_selectors.has_value()) @@ -764,7 +764,7 @@ WebIDL::ExceptionOr Element::matches(StringView selectors) const WebIDL::ExceptionOr Element::closest(StringView selectors) const { // 1. Let s be the result of parse a selector from selectors. - auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext(document()), selectors); + auto maybe_selectors = parse_selector(CSS::Parser::ParsingParams(document()), selectors); // 2. If s is failure, then throw a "SyntaxError" DOMException. if (!maybe_selectors.has_value()) @@ -3273,7 +3273,7 @@ void Element::attribute_changed(FlyString const& local_name, Optional co if (m_inline_style && m_inline_style->is_updating()) return; if (!m_inline_style) { - m_inline_style = parse_css_style_attribute(CSS::Parser::ParsingContext(document()), *value, *this); + m_inline_style = parse_css_style_attribute(CSS::Parser::ParsingParams(document()), *value, *this); } else { // NOTE: ElementInlineCSSStyleDeclaration::set_css_text should never throw an exception. m_inline_style->set_declarations_from_text(*value); diff --git a/Libraries/LibWeb/DOM/ParentNode.cpp b/Libraries/LibWeb/DOM/ParentNode.cpp index 250c652d52..2a44bc4029 100644 --- a/Libraries/LibWeb/DOM/ParentNode.cpp +++ b/Libraries/LibWeb/DOM/ParentNode.cpp @@ -52,7 +52,7 @@ static WebIDL::ExceptionOr, GC::Ref>> scope_m { // To scope-match a selectors string selectors against a node, run these steps: // 1. Let s be the result of parse a selector selectors. - auto maybe_selectors = parse_selector(CSS::Parser::ParsingContext { node.document() }, selector_text); + auto maybe_selectors = parse_selector(CSS::Parser::ParsingParams { node.document() }, selector_text); // 2. If s is failure, then throw a "SyntaxError" DOMException. if (!maybe_selectors.has_value()) diff --git a/Libraries/LibWeb/DOM/StyleElementUtils.cpp b/Libraries/LibWeb/DOM/StyleElementUtils.cpp index ba251894bd..6e030bb8a4 100644 --- a/Libraries/LibWeb/DOM/StyleElementUtils.cpp +++ b/Libraries/LibWeb/DOM/StyleElementUtils.cpp @@ -54,7 +54,7 @@ void StyleElementUtils::update_a_style_block(DOM::Element& style_element) // FIXME: This is a bit awkward, as the spec doesn't actually tell us when to parse the CSS text, // so we just do it here and pass the parsed sheet to create_a_css_style_sheet(). - auto* sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(style_element.document()), style_element.text_content().value_or(String {})); + auto* sheet = parse_css_stylesheet(CSS::Parser::ParsingParams(style_element.document()), style_element.text_content().value_or(String {})); if (!sheet) return; diff --git a/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp b/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp index ed58afc5da..9738ecae04 100644 --- a/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp +++ b/Libraries/LibWeb/Geometry/DOMMatrixReadOnly.cpp @@ -947,7 +947,7 @@ WebIDL::ExceptionOr parse_dom_matrix_init_string(JS::Realm& realm, // 2. Parse transformList into parsedValue given the grammar for the CSS transform property. // The result will be a , the keyword none, or failure. // If parsedValue is failure, or any has values without absolute length units, or any keyword other than none is used, then return failure. [CSS3-SYNTAX] [CSS3-TRANSFORMS] - auto transform_style_value = parse_css_value(CSS::Parser::ParsingContext {}, transform_list, CSS::PropertyID::Transform); + auto transform_style_value = parse_css_value(CSS::Parser::ParsingParams {}, transform_list, CSS::PropertyID::Transform); if (!transform_style_value || (transform_style_value->is_keyword() && transform_style_value->to_keyword() != CSS::Keyword::None)) return WebIDL::SyntaxError::create(realm, "Failed to parse CSS transform string."_string); auto parsed_value = CSS::ComputedProperties::transformations_for_style_value(*transform_style_value); diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h b/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h index bfd426585e..07a2f0199b 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h +++ b/Libraries/LibWeb/HTML/Canvas/CanvasFillStrokeStyles.h @@ -35,7 +35,7 @@ public: // 2. Let parsedValue be the result of parsing the given value with context if non-null. // FIXME: Parse a color value // https://drafts.csswg.org/css-color/#parse-a-css-color-value - auto style_value = parse_css_value(CSS::Parser::ParsingContext(), string, CSS::PropertyID::Color); + auto style_value = parse_css_value(CSS::Parser::ParsingParams(), string, CSS::PropertyID::Color); if (style_value && style_value->has_color()) { auto parsedValue = style_value->to_color(OptionalNone()); @@ -74,7 +74,7 @@ public: // 2. Let parsedValue be the result of parsing the given value with context if non-null. // FIXME: Parse a color value // https://drafts.csswg.org/css-color/#parse-a-css-color-value - auto style_value = parse_css_value(CSS::Parser::ParsingContext(), string, CSS::PropertyID::Color); + auto style_value = parse_css_value(CSS::Parser::ParsingParams(), string, CSS::PropertyID::Color); if (style_value && style_value->has_color()) { auto parsedValue = style_value->to_color(OptionalNone()); diff --git a/Libraries/LibWeb/HTML/Canvas/CanvasTextDrawingStyles.h b/Libraries/LibWeb/HTML/Canvas/CanvasTextDrawingStyles.h index 75fb7e9d87..c7d46e84db 100644 --- a/Libraries/LibWeb/HTML/Canvas/CanvasTextDrawingStyles.h +++ b/Libraries/LibWeb/HTML/Canvas/CanvasTextDrawingStyles.h @@ -47,7 +47,7 @@ public: // and with system fonts being computed to explicit values. // FIXME: with the 'line-height' component forced to 'normal' // FIXME: with the 'font-size' component converted to CSS pixels - auto font_style_value_result = parse_css_value(CSS::Parser::ParsingContext {}, font, CSS::PropertyID::Font); + auto font_style_value_result = parse_css_value(CSS::Parser::ParsingParams {}, font, CSS::PropertyID::Font); // If the new value is syntactically incorrect (including using property-independent style sheet syntax like 'inherit' or 'initial'), then it must be ignored, without assigning a new font value. // NOTE: ShorthandStyleValue should be the only valid option here. We implicitly VERIFY this below. diff --git a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp index b5b54ba719..4ec7d1eb8b 100644 --- a/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp +++ b/Libraries/LibWeb/HTML/CanvasRenderingContext2D.cpp @@ -863,7 +863,7 @@ void CanvasRenderingContext2D::set_shadow_color(String color) // 1. Let context be this's canvas attribute's value, if that is an element; otherwise null. // 2. Let parsedValue be the result of parsing the given value with context if non-null. - auto style_value = parse_css_value(CSS::Parser::ParsingContext(), color, CSS::PropertyID::Color); + auto style_value = parse_css_value(CSS::Parser::ParsingParams(), color, CSS::PropertyID::Color); if (style_value && style_value->has_color()) { auto parsedValue = style_value->to_color(OptionalNone()); @@ -944,7 +944,7 @@ void CanvasRenderingContext2D::set_filter(String filter) } auto& realm = static_cast(*this).realm(); - auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), filter); + auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingParams(realm), filter); // 2. Let parsedValue be the result of parsing the given values as a . // If any property-independent style sheet syntax like 'inherit' or 'initial' is present, diff --git a/Libraries/LibWeb/HTML/HTMLFontElement.cpp b/Libraries/LibWeb/HTML/HTMLFontElement.cpp index 9048f497f7..6da8a15c87 100644 --- a/Libraries/LibWeb/HTML/HTMLFontElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLFontElement.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include @@ -136,7 +135,7 @@ void HTMLFontElement::apply_presentational_hints(GC::Refset_property_from_presentational_hint(CSS::PropertyID::FontSize, parsed_value.release_nonnull()); } } diff --git a/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 2364956286..53487f393a 100644 --- a/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -1130,7 +1130,7 @@ static void update_the_source_set(DOM::Element& element) // 6. If child has a media attribute, and its value does not match the environment, continue to the next child. if (child->has_attribute(HTML::AttributeNames::media)) { - auto media_query = parse_media_query(CSS::Parser::ParsingContext { element.document() }, + auto media_query = parse_media_query(CSS::Parser::ParsingParams { element.document() }, child->get_attribute_value(HTML::AttributeNames::media)); if (!media_query || !element.document().window() || !media_query->evaluate(*element.document().window())) { continue; diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 00305f87a1..3ced52f28d 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -441,7 +441,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); } else { auto const decoded_string = maybe_decoded_string.release_value(); - m_loaded_style_sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(document(), *response.url()), decoded_string); + m_loaded_style_sheet = parse_css_stylesheet(CSS::Parser::ParsingParams(document(), *response.url()), decoded_string); if (m_loaded_style_sheet) { Optional location; diff --git a/Libraries/LibWeb/HTML/HTMLMetaElement.cpp b/Libraries/LibWeb/HTML/HTMLMetaElement.cpp index ef145e6f5e..4d64b730b9 100644 --- a/Libraries/LibWeb/HTML/HTMLMetaElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLMetaElement.cpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include #include diff --git a/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp b/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp index c3e2c7f59c..b866d78469 100644 --- a/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLTableCellElement.cpp @@ -62,7 +62,7 @@ void HTMLTableCellElement::apply_presentational_hints(GC::Refset_property_from_presentational_hint(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull()); return; } @@ -74,7 +74,7 @@ void HTMLTableCellElement::apply_presentational_hints(GC::Refset_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebRight)); } else { - if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::TextAlign)) + if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::TextAlign)) cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, parsed_value.release_nonnull()); } return; diff --git a/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Libraries/LibWeb/HTML/HTMLTableElement.cpp index 9423e2f850..a685aad9a6 100644 --- a/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -85,7 +85,7 @@ void HTMLTableElement::apply_presentational_hints(GC::Refset_property_from_presentational_hint(CSS::PropertyID::MarginLeft, CSS::CSSKeywordValue::create(CSS::Keyword::Auto)); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginRight, CSS::CSSKeywordValue::create(CSS::Keyword::Auto)); - } else if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::Float)) { + } else if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::Float)) { cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Float, parsed_value.release_nonnull()); } return; diff --git a/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp index 5bf2abfcac..fcdb8bcbe9 100644 --- a/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include @@ -68,7 +67,7 @@ void HTMLTableRowElement::apply_presentational_hints(GC::Refset_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value); } else if (name == HTML::AttributeNames::valign) { - if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::VerticalAlign)) + if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::VerticalAlign)) cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull()); } }); diff --git a/Libraries/LibWeb/HTML/SourceSet.cpp b/Libraries/LibWeb/HTML/SourceSet.cpp index 9c1ce6a2c5..570908df43 100644 --- a/Libraries/LibWeb/HTML/SourceSet.cpp +++ b/Libraries/LibWeb/HTML/SourceSet.cpp @@ -341,7 +341,7 @@ descriptor_parser: // https://html.spec.whatwg.org/multipage/images.html#parse-a-sizes-attribute CSS::LengthOrCalculated parse_a_sizes_attribute(DOM::Element const& element, StringView sizes, HTML::HTMLImageElement const* img) { - auto css_parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext { element.document() }, sizes); + auto css_parser = CSS::Parser::Parser::create(CSS::Parser::ParsingParams { element.document() }, sizes); return css_parser.parse_as_sizes_attribute(element, img); } diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp index e5973e553c..c49b53d6d4 100644 --- a/Libraries/LibWeb/HTML/Window.cpp +++ b/Libraries/LibWeb/HTML/Window.cpp @@ -1218,7 +1218,7 @@ GC::Ref Window::get_computed_style(DOM::Element& eleme // 3. If pseudoElt is provided, is not the empty string, and starts with a colon, then: if (pseudo_element.has_value() && pseudo_element.value().starts_with(':')) { // 1. Parse pseudoElt as a , and let type be the result. - auto type = parse_pseudo_element_selector(CSS::Parser::ParsingContext(associated_document()), pseudo_element.value()); + auto type = parse_pseudo_element_selector(CSS::Parser::ParsingParams(associated_document()), pseudo_element.value()); // 2. If type is failure, or is an ::slotted() or ::part() pseudo-element, let obj be null. // FIXME: We can't pass a null element to ResolvedCSSStyleDeclaration @@ -1261,7 +1261,7 @@ GC::Ref Window::get_computed_style(DOM::Element& eleme WebIDL::ExceptionOr> Window::match_media(String const& query) { // 1. Let parsed media query list be the result of parsing query. - auto parsed_media_query_list = parse_media_query_list(CSS::Parser::ParsingContext(associated_document()), query); + auto parsed_media_query_list = parse_media_query_list(CSS::Parser::ParsingParams(associated_document()), query); // 2. Return a new MediaQueryList object, with this's associated Document as the document, with parsed media query list as its associated media query list. auto media_query_list = realm().create(associated_document(), move(parsed_media_query_list)); diff --git a/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp index 1b24c2fc36..90b329b5a6 100644 --- a/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp +++ b/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp @@ -319,7 +319,7 @@ void IntersectionObserver::queue_entry(Badge, GC::Ref> IntersectionObserver::parse_a_margin(JS::Realm& realm, String margin_string) { // 1. Parse a list of component values marginString, storing the result as tokens. - auto tokens = CSS::Parser::Parser::create(CSS::Parser::ParsingContext { realm }, margin_string).parse_as_list_of_component_values(); + auto tokens = CSS::Parser::Parser::create(CSS::Parser::ParsingParams { realm }, margin_string).parse_as_list_of_component_values(); // 2. Remove all whitespace tokens from tokens. tokens.remove_all_matching([](auto componentValue) { return componentValue.is(CSS::Parser::Token::Type::Whitespace); }); diff --git a/Libraries/LibWeb/SVG/SVGCircleElement.cpp b/Libraries/LibWeb/SVG/SVGCircleElement.cpp index daeccaafc5..381a0a4746 100644 --- a/Libraries/LibWeb/SVG/SVGCircleElement.cpp +++ b/Libraries/LibWeb/SVG/SVGCircleElement.cpp @@ -43,7 +43,7 @@ bool SVGCircleElement::is_presentational_hint(FlyString const& name) const void SVGCircleElement::apply_presentational_hints(GC::Ref cascaded_properties) const { Base::apply_presentational_hints(cascaded_properties); - auto parsing_context = CSS::Parser::ParsingContext { document(), CSS::Parser::ParsingContext::Mode::SVGPresentationAttribute }; + auto parsing_context = CSS::Parser::ParsingParams { document(), CSS::Parser::ParsingMode::SVGPresentationAttribute }; auto cx_attribute = attribute(SVG::AttributeNames::cx); if (auto cx_value = parse_css_value(parsing_context, cx_attribute.value_or(String {}), CSS::PropertyID::Cx)) diff --git a/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp b/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp index 80e7b5449e..2d84023be5 100644 --- a/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp +++ b/Libraries/LibWeb/SVG/SVGForeignObjectElement.cpp @@ -65,7 +65,7 @@ bool SVGForeignObjectElement::is_presentational_hint(FlyString const& name) cons void SVGForeignObjectElement::apply_presentational_hints(GC::Ref cascaded_properties) const { Base::apply_presentational_hints(cascaded_properties); - auto parsing_context = CSS::Parser::ParsingContext { document() }; + auto parsing_context = CSS::Parser::ParsingParams { document() }; if (auto width_value = parse_css_value(parsing_context, get_attribute_value(Web::HTML::AttributeNames::width), CSS::PropertyID::Width)) cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, width_value.release_nonnull()); diff --git a/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp b/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp index 367e23cdcd..8d9e5d2738 100644 --- a/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp +++ b/Libraries/LibWeb/SVG/SVGGraphicsElement.cpp @@ -177,7 +177,7 @@ bool SVGGraphicsElement::is_presentational_hint(FlyString const& name) const void SVGGraphicsElement::apply_presentational_hints(GC::Ref cascaded_properties) const { - CSS::Parser::ParsingContext parsing_context { document(), CSS::Parser::ParsingContext::Mode::SVGPresentationAttribute }; + CSS::Parser::ParsingParams parsing_context { document(), CSS::Parser::ParsingMode::SVGPresentationAttribute }; for_each_attribute([&](auto& name, auto& value) { for (auto property : attribute_style_properties) { if (!name.equals_ignoring_ascii_case(property.name)) diff --git a/Libraries/LibWeb/SVG/SVGSVGElement.cpp b/Libraries/LibWeb/SVG/SVGSVGElement.cpp index d66bfd2255..894580cc63 100644 --- a/Libraries/LibWeb/SVG/SVGSVGElement.cpp +++ b/Libraries/LibWeb/SVG/SVGSVGElement.cpp @@ -49,7 +49,7 @@ GC::Ptr SVGSVGElement::create_layout_node(GC::Ref SVGSVGElement::width_style_value_from_attribute() const { - auto parsing_context = CSS::Parser::ParsingContext { document(), CSS::Parser::ParsingContext::Mode::SVGPresentationAttribute }; + auto parsing_context = CSS::Parser::ParsingParams { document(), CSS::Parser::ParsingMode::SVGPresentationAttribute }; auto width_attribute = attribute(SVG::AttributeNames::width); if (auto width_value = parse_css_value(parsing_context, width_attribute.value_or(String {}), CSS::PropertyID::Width)) { return width_value.release_nonnull(); @@ -65,7 +65,7 @@ RefPtr SVGSVGElement::width_style_value_from_attribute() con RefPtr SVGSVGElement::height_style_value_from_attribute() const { - auto parsing_context = CSS::Parser::ParsingContext { document(), CSS::Parser::ParsingContext::Mode::SVGPresentationAttribute }; + auto parsing_context = CSS::Parser::ParsingParams { document(), CSS::Parser::ParsingMode::SVGPresentationAttribute }; auto height_attribute = attribute(SVG::AttributeNames::height); if (auto height_value = parse_css_value(parsing_context, height_attribute.value_or(String {}), CSS::PropertyID::Height)) { return height_value.release_nonnull(); @@ -96,7 +96,7 @@ bool SVGSVGElement::is_presentational_hint(FlyString const& name) const void SVGSVGElement::apply_presentational_hints(GC::Ref cascaded_properties) const { Base::apply_presentational_hints(cascaded_properties); - auto parsing_context = CSS::Parser::ParsingContext { document(), CSS::Parser::ParsingContext::Mode::SVGPresentationAttribute }; + auto parsing_context = CSS::Parser::ParsingParams { document(), CSS::Parser::ParsingMode::SVGPresentationAttribute }; auto x_attribute = attribute(SVG::AttributeNames::x); if (auto x_value = parse_css_value(parsing_context, x_attribute.value_or(String {}), CSS::PropertyID::X)) { @@ -147,7 +147,7 @@ void SVGSVGElement::update_fallback_view_box_for_svg_as_image() Optional height; auto width_attribute = get_attribute_value(SVG::AttributeNames::width); - auto parsing_context = CSS::Parser::ParsingContext { document() }; + auto parsing_context = CSS::Parser::ParsingParams { document() }; if (auto width_value = parse_css_value(parsing_context, width_attribute, CSS::PropertyID::Width)) { if (width_value->is_length() && width_value->as_length().length().is_absolute()) width = width_value->as_length().length().absolute_length_to_px().to_double(); diff --git a/Libraries/LibWeb/SVG/SVGStopElement.cpp b/Libraries/LibWeb/SVG/SVGStopElement.cpp index 52d5cc48b0..1725f53bf8 100644 --- a/Libraries/LibWeb/SVG/SVGStopElement.cpp +++ b/Libraries/LibWeb/SVG/SVGStopElement.cpp @@ -42,9 +42,9 @@ bool SVGStopElement::is_presentational_hint(FlyString const& name) const void SVGStopElement::apply_presentational_hints(GC::Ref cascaded_properties) const { - CSS::Parser::ParsingContext parsing_context { document() }; + CSS::Parser::ParsingParams parsing_context { document() }; for_each_attribute([&](auto& name, auto& value) { - CSS::Parser::ParsingContext parsing_context { document() }; + CSS::Parser::ParsingParams parsing_context { document() }; if (name.equals_ignoring_ascii_case("stop-color"sv)) { if (auto stop_color = parse_css_value(parsing_context, value, CSS::PropertyID::StopColor)) { cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::StopColor, stop_color.release_nonnull()); diff --git a/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp b/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp index 9b9dce4591..d24c631184 100644 --- a/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp +++ b/Meta/Lagom/Fuzzers/FuzzCSSParser.cpp @@ -28,6 +28,6 @@ extern "C" int LLVMFuzzerTestOneInput(uint8_t const* data, size_t size) // FIXME: There's got to be a better way to do this "correctly" auto& vm = Web::Bindings::main_thread_vm(); - (void)Web::parse_css_stylesheet(Web::CSS::Parser::ParsingContext(*vm.current_realm()), { data, size }); + (void)Web::parse_css_stylesheet(Web::CSS::Parser::ParsingParams(*vm.current_realm()), { data, size }); return 0; } diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp index 197298e1a2..4ab4d19e0d 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/GenerateCSSPropertyID.cpp @@ -672,7 +672,7 @@ NonnullRefPtr property_initial_value(PropertyID property_id) // This ensures the shorthands will always be able to get the initial values of their longhands. // This also now allows a longhand have its own longhand (like background-position-x). - Parser::ParsingContext parsing_context; + Parser::ParsingParams parsing_params; switch (property_id) { )~~~"); @@ -691,7 +691,7 @@ NonnullRefPtr property_initial_value(PropertyID property_id) member_generator.append( R"~~~( case PropertyID::@name:titlecase@: { - auto parsed_value = parse_css_value(parsing_context, "@initial_value_string@"sv, PropertyID::@name:titlecase@); + auto parsed_value = parse_css_value(parsing_params, "@initial_value_string@"sv, PropertyID::@name:titlecase@); VERIFY(!parsed_value.is_null()); auto initial_value = parsed_value.release_nonnull(); initial_values[to_underlying(PropertyID::@name:titlecase@)] = initial_value; diff --git a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/Parser/BUILD.gn b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/Parser/BUILD.gn index 910dc33184..428fa55e5f 100644 --- a/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/Parser/BUILD.gn +++ b/Meta/gn/secondary/Userland/Libraries/LibWeb/CSS/Parser/BUILD.gn @@ -7,7 +7,6 @@ source_set("Parser") { "Helpers.cpp", "MediaParsing.cpp", "Parser.cpp", - "ParsingContext.cpp", "PropertyParsing.cpp", "RuleParsing.cpp", "SelectorParsing.cpp",