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.
This commit is contained in:
Sam Atkins 2025-02-05 12:08:27 +00:00
commit 6a4d80b9b6
Notes: github-actions[bot] 2025-02-06 16:48:31 +00:00
49 changed files with 207 additions and 255 deletions

View file

@ -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());

View file

@ -744,7 +744,7 @@ GC::Ptr<ShadowRoot> Element::shadow_root_for_bindings() const
WebIDL::ExceptionOr<bool> 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<bool> Element::matches(StringView selectors) const
WebIDL::ExceptionOr<DOM::Element const*> 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<String> 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);

View file

@ -52,7 +52,7 @@ static WebIDL::ExceptionOr<Variant<GC::Ptr<Element>, GC::Ref<NodeList>>> 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())

View file

@ -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;