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

@ -601,7 +601,7 @@ Optional<double> AnimationEffect::transformed_progress() const
RefPtr<CSS::CSSStyleValue const> AnimationEffect::parse_easing_string(StringView value) RefPtr<CSS::CSSStyleValue const> 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()) if (style_value->is_easing())
return style_value; return style_value;
} }

View file

@ -543,7 +543,7 @@ static WebIDL::ExceptionOr<Vector<BaseKeyframe>> process_a_keyframes_argument(JS
if (!property_id.has_value()) if (!property_id.has_value())
continue; 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 // 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()) if (style_value->is_initial())
style_value = CSS::property_initial_value(*property_id); style_value = CSS::property_initial_value(*property_id);
@ -861,7 +861,7 @@ WebIDL::ExceptionOr<void> KeyframeEffect::set_keyframes(Optional<GC::Root<JS::Ob
for (auto [property_id, property_value] : keyframe.parsed_properties()) { for (auto [property_id, property_value] : keyframe.parsed_properties()) {
if (property_value->is_unresolved() && target) if (property_value->is_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) { 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); m_target_properties.set(shorthand_id);
resolved_keyframe.properties.set(shorthand_id, NonnullRefPtr<CSS::CSSStyleValue const> { shorthand_value }); resolved_keyframe.properties.set(shorthand_id, NonnullRefPtr<CSS::CSSStyleValue const> { shorthand_value });

View file

@ -17,7 +17,7 @@ WebIDL::ExceptionOr<Optional<CSS::Selector::PseudoElement>> pseudo_element_parsi
// 2. If value is not null and is an invalid <pseudo-element-selector>, // 2. If value is not null and is an invalid <pseudo-element-selector>,
Optional<CSS::Selector::PseudoElement> pseudo_element; Optional<CSS::Selector::PseudoElement> pseudo_element;
if (value.has_value()) { 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()) { if (!pseudo_element.has_value()) {
// 1. Throw a DOMException with error name "SyntaxError". // 1. Throw a DOMException with error name "SyntaxError".
// 2. Abort. // 2. Abort.

View file

@ -99,7 +99,6 @@ set(SOURCES
CSS/Parser/Helpers.cpp CSS/Parser/Helpers.cpp
CSS/Parser/MediaParsing.cpp CSS/Parser/MediaParsing.cpp
CSS/Parser/Parser.cpp CSS/Parser/Parser.cpp
CSS/Parser/ParsingContext.cpp
CSS/Parser/PropertyParsing.cpp CSS/Parser/PropertyParsing.cpp
CSS/Parser/RuleParsing.cpp CSS/Parser/RuleParsing.cpp
CSS/Parser/SelectorParsing.cpp CSS/Parser/SelectorParsing.cpp

View file

@ -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, // 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 propertys grammar, return true. // and value successfully parses according to that propertys grammar, return true.
if (auto property_id = property_id_from_string(property); property_id.has_value()) { 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; return true;
} }
@ -46,13 +46,13 @@ WebIDL::ExceptionOr<bool> supports(JS::VM& vm, StringView condition_text)
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
// 1. If conditionText, parsed and evaluated as a <supports-condition>, would return true, return true. // 1. If conditionText, parsed and evaluated as a <supports-condition>, 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; return true;
// 2. Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true. // 2. Otherwise, If conditionText, wrapped in parentheses and then parsed and evaluated as a <supports-condition>, would return true, return true.
auto wrapped_condition_text = TRY_OR_THROW_OOM(vm, String::formatted("({})", condition_text)); 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; return true;
// 3. Otherwise, return false. // 3. Otherwise, return false.

View file

@ -139,7 +139,7 @@ void CSSImportRule::fetch()
} }
auto decoded = decoded_or_error.release_value(); 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 importedStylesheets origin-clean flag to parentStylesheets origin-clean flag. // 5. Set importedStylesheets origin-clean flag to parentStylesheets origin-clean flag.
imported_style_sheet->set_origin_clean(parent_style_sheet->is_origin_clean()); imported_style_sheet->set_origin_clean(parent_style_sheet->is_origin_clean());

View file

@ -69,7 +69,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
CSSRule* new_rule = nullptr; CSSRule* new_rule = nullptr;
if (rule.has<StringView>()) { if (rule.has<StringView>()) {
new_rule = parse_css_rule( new_rule = parse_css_rule(
CSS::Parser::ParsingContext { realm() }, CSS::Parser::ParsingParams { realm() },
rule.get<StringView>()); rule.get<StringView>());
} else { } else {
new_rule = rule.get<CSSRule*>(); new_rule = rule.get<CSSRule*>();

View file

@ -131,8 +131,8 @@ WebIDL::ExceptionOr<void> PropertyOwningCSSStyleDeclaration::set_property(String
// 5. Let component value list be the result of parsing value for property property. // 5. Let component value list be the result of parsing value for property property.
auto component_value_list = is<ElementInlineCSSStyleDeclaration>(this) auto component_value_list = is<ElementInlineCSSStyleDeclaration>(this)
? parse_css_value(CSS::Parser::ParsingContext { static_cast<ElementInlineCSSStyleDeclaration&>(*this).element()->document() }, value, property_id) ? parse_css_value(CSS::Parser::ParsingParams { static_cast<ElementInlineCSSStyleDeclaration&>(*this).element()->document() }, value, property_id)
: parse_css_value(CSS::Parser::ParsingContext {}, value, property_id); : parse_css_value(CSS::Parser::ParsingParams {}, value, property_id);
// 6. If component value list is null, then return. // 6. If component value list is null, then return.
if (!component_value_list) if (!component_value_list)
@ -528,7 +528,7 @@ void ElementInlineCSSStyleDeclaration::set_declarations_from_text(StringView css
} }
empty_the_declarations(); 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()); set_the_declarations(style->properties(), style->custom_properties());
} }

View file

@ -129,9 +129,9 @@ void CSSStyleRule::set_selector_text(StringView selector_text)
Optional<SelectorList> parsed_selectors; Optional<SelectorList> parsed_selectors;
if (parent_style_rule()) { 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. // 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 { } 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. // 2. If the algorithm returns a non-null value replace the associated group of selectors with the returned value.

View file

@ -139,7 +139,7 @@ WebIDL::ExceptionOr<unsigned> CSSStyleSheet::insert_rule(StringView rule, unsign
return WebIDL::NotAllowedError::create(realm(), "Can't call insert_rule() on non-modifiable stylesheets."_string); 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. // 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); auto parsed_rule = parse_css_rule(context, rule);
// 4. If parsed rule is a syntax error, return parsed rule. // 4. If parsed rule is a syntax error, return parsed rule.
@ -207,7 +207,7 @@ GC::Ref<WebIDL::Promise> CSSStyleSheet::replace(String text)
HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
// 1. Let rules be the result of running parse a stylesheets contents from text. // 1. Let rules be the result of running parse a stylesheets 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* parsed_stylesheet = parse_css_stylesheet(context, text);
auto& rules = parsed_stylesheet->rules(); auto& rules = parsed_stylesheet->rules();
@ -241,7 +241,7 @@ WebIDL::ExceptionOr<void> CSSStyleSheet::replace_sync(StringView text)
return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-modifiable stylesheets"_string); return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-modifiable stylesheets"_string);
// 2. Let rules be the result of running parse a stylesheets contents from text. // 2. Let rules be the result of running parse a stylesheets 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* parsed_stylesheet = parse_css_stylesheet(context, text);
auto& rules = parsed_stylesheet->rules(); auto& rules = parsed_stylesheet->rules();

View file

@ -62,7 +62,7 @@ void CascadedProperties::resolve_unresolved_properties(GC::Ref<DOM::Element> ele
for (auto& entry : entries) { for (auto& entry : entries) {
if (!entry.property.value->is_unresolved()) if (!entry.property.value->is_unresolved())
continue; 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());
} }
} }
} }

View file

@ -81,7 +81,7 @@ GC::Ref<FontFace> FontFace::construct_impl(JS::Realm& realm, String family, Font
Vector<CSS::ParsedFontFace::Source> sources; Vector<CSS::ParsedFontFace::Source> sources;
ByteBuffer buffer; ByteBuffer buffer;
if (auto* string = source.get_pointer<String>()) { if (auto* string = source.get_pointer<String>()) {
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(); sources = parser.parse_as_font_face_src();
if (sources.is_empty()) if (sources.is_empty())
WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid source string"_string)); WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid source string"_string));
@ -206,7 +206,7 @@ GC::Ref<WebIDL::Promise> FontFace::loaded() const
// https://drafts.csswg.org/css-font-loading/#dom-fontface-family // https://drafts.csswg.org/css-font-loading/#dom-fontface-family
WebIDL::ExceptionOr<void> FontFace::set_family(String const& string) WebIDL::ExceptionOr<void> 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) if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.family setter: Invalid font descriptor"_string); return WebIDL::SyntaxError::create(realm(), "FontFace.family setter: Invalid font descriptor"_string);
@ -222,7 +222,7 @@ WebIDL::ExceptionOr<void> FontFace::set_family(String const& string)
// https://drafts.csswg.org/css-font-loading/#dom-fontface-style // https://drafts.csswg.org/css-font-loading/#dom-fontface-style
WebIDL::ExceptionOr<void> FontFace::set_style(String const& string) WebIDL::ExceptionOr<void> 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) if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.style setter: Invalid font descriptor"_string); return WebIDL::SyntaxError::create(realm(), "FontFace.style setter: Invalid font descriptor"_string);
@ -238,7 +238,7 @@ WebIDL::ExceptionOr<void> FontFace::set_style(String const& string)
// https://drafts.csswg.org/css-font-loading/#dom-fontface-weight // https://drafts.csswg.org/css-font-loading/#dom-fontface-weight
WebIDL::ExceptionOr<void> FontFace::set_weight(String const& string) WebIDL::ExceptionOr<void> 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) if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.weight setter: Invalid font descriptor"_string); return WebIDL::SyntaxError::create(realm(), "FontFace.weight setter: Invalid font descriptor"_string);
@ -255,7 +255,7 @@ WebIDL::ExceptionOr<void> FontFace::set_weight(String const& string)
WebIDL::ExceptionOr<void> FontFace::set_stretch(String const& string) WebIDL::ExceptionOr<void> FontFace::set_stretch(String const& string)
{ {
// NOTE: font-stretch is now an alias for font-width // 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) if (!property)
return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid font descriptor"_string); return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid font descriptor"_string);

View file

@ -175,7 +175,7 @@ WebIDL::CallbackType* FontFaceSet::onloadingerror()
static WebIDL::ExceptionOr<GC::Ref<JS::Set>> find_matching_font_faces(JS::Realm& realm, FontFaceSet& font_face_set, String const& font, String const&) static WebIDL::ExceptionOr<GC::Ref<JS::Set>> 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. // 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) if (!property)
return WebIDL::SyntaxError::create(realm, "Unable to parse font"_string); return WebIDL::SyntaxError::create(realm, "Unable to parse font"_string);

View file

@ -45,7 +45,7 @@ void MediaList::set_media_text(StringView text)
m_media.clear(); m_media.clear();
if (text.is_empty()) if (text.is_empty())
return; 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 // https://www.w3.org/TR/cssom-1/#dom-medialist-item
@ -61,7 +61,7 @@ Optional<String> MediaList::item(u32 index) const
void MediaList::append_medium(StringView medium) void MediaList::append_medium(StringView medium)
{ {
// 1. Let m be the result of parsing the given value. // 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. // 2. If m is null, then return.
if (!m) if (!m)
@ -81,7 +81,7 @@ void MediaList::append_medium(StringView medium)
// https://www.w3.org/TR/cssom-1/#dom-medialist-deletemedium // https://www.w3.org/TR/cssom-1/#dom-medialist-deletemedium
void MediaList::delete_medium(StringView medium) 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) if (!m)
return; return;
m_media.remove_all_matching([&](auto& existing) -> bool { m_media.remove_all_matching([&](auto& existing) -> bool {

View file

@ -15,12 +15,12 @@
namespace Web { namespace Web {
CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& context, StringView css, Optional<URL::URL> location) CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingParams const& context, StringView css, Optional<URL::URL> location)
{ {
if (css.is_empty()) { if (css.is_empty()) {
auto rule_list = CSS::CSSRuleList::create_empty(context.realm()); auto rule_list = CSS::CSSRuleList::create_empty(*context.realm);
auto media_list = CSS::MediaList::create(context.realm(), {}); auto media_list = CSS::MediaList::create(*context.realm, {});
auto style_sheet = CSS::CSSStyleSheet::create(context.realm(), rule_list, media_list, location); auto style_sheet = CSS::CSSStyleSheet::create(*context.realm, rule_list, media_list, location);
style_sheet->set_source_text({}); style_sheet->set_source_text({});
return style_sheet; return style_sheet;
} }
@ -30,31 +30,31 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& cont
return style_sheet; 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()) if (css.is_empty())
return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {}); return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {});
return CSS::Parser::Parser::create(context, css).parse_as_style_attribute(element); return CSS::Parser::Parser::create(context, css).parse_as_style_attribute(element);
} }
RefPtr<CSS::CSSStyleValue> parse_css_value(CSS::Parser::ParsingContext const& context, StringView string, CSS::PropertyID property_id) RefPtr<CSS::CSSStyleValue> parse_css_value(CSS::Parser::ParsingParams const& context, StringView string, CSS::PropertyID property_id)
{ {
if (string.is_empty()) if (string.is_empty())
return nullptr; return nullptr;
return CSS::Parser::Parser::create(context, string).parse_as_css_value(property_id); 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(); return CSS::Parser::Parser::create(context, css_text).parse_as_css_rule();
} }
Optional<CSS::SelectorList> parse_selector(CSS::Parser::ParsingContext const& context, StringView selector_text) Optional<CSS::SelectorList> parse_selector(CSS::Parser::ParsingParams const& context, StringView selector_text)
{ {
return CSS::Parser::Parser::create(context, selector_text).parse_as_selector(); return CSS::Parser::Parser::create(context, selector_text).parse_as_selector();
} }
Optional<CSS::SelectorList> parse_selector_for_nested_style_rule(CSS::Parser::ParsingContext const& context, StringView selector_text) Optional<CSS::SelectorList> parse_selector_for_nested_style_rule(CSS::Parser::ParsingParams const& context, StringView selector_text)
{ {
auto parser = CSS::Parser::Parser::create(context, selector_text); auto parser = CSS::Parser::Parser::create(context, selector_text);
@ -65,29 +65,29 @@ Optional<CSS::SelectorList> parse_selector_for_nested_style_rule(CSS::Parser::Pa
return adapt_nested_relative_selector_list(*maybe_selectors); return adapt_nested_relative_selector_list(*maybe_selectors);
} }
Optional<CSS::Selector::PseudoElement> parse_pseudo_element_selector(CSS::Parser::ParsingContext const& context, StringView selector_text) Optional<CSS::Selector::PseudoElement> 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(); return CSS::Parser::Parser::create(context, selector_text).parse_as_pseudo_element_selector();
} }
RefPtr<CSS::MediaQuery> parse_media_query(CSS::Parser::ParsingContext const& context, StringView string) RefPtr<CSS::MediaQuery> parse_media_query(CSS::Parser::ParsingParams const& context, StringView string)
{ {
return CSS::Parser::Parser::create(context, string).parse_as_media_query(); return CSS::Parser::Parser::create(context, string).parse_as_media_query();
} }
Vector<NonnullRefPtr<CSS::MediaQuery>> parse_media_query_list(CSS::Parser::ParsingContext const& context, StringView string) Vector<NonnullRefPtr<CSS::MediaQuery>> parse_media_query_list(CSS::Parser::ParsingParams const& context, StringView string)
{ {
return CSS::Parser::Parser::create(context, string).parse_as_media_query_list(); return CSS::Parser::Parser::create(context, string).parse_as_media_query_list();
} }
RefPtr<CSS::Supports> parse_css_supports(CSS::Parser::ParsingContext const& context, StringView string) RefPtr<CSS::Supports> parse_css_supports(CSS::Parser::ParsingParams const& context, StringView string)
{ {
if (string.is_empty()) if (string.is_empty())
return {}; return {};
return CSS::Parser::Parser::create(context, string).parse_as_supports(); return CSS::Parser::Parser::create(context, string).parse_as_supports();
} }
Optional<CSS::StyleProperty> parse_css_supports_condition(CSS::Parser::ParsingContext const& context, StringView string) Optional<CSS::StyleProperty> parse_css_supports_condition(CSS::Parser::ParsingParams const& context, StringView string)
{ {
if (string.is_empty()) if (string.is_empty())
return {}; return {};

View file

@ -622,9 +622,9 @@ GC::Ptr<CSSMediaRule> Parser::convert_to_media_rule(AtRule const& rule, Nested n
{ {
auto media_query_tokens = TokenStream { rule.prelude }; auto media_query_tokens = TokenStream { rule.prelude };
auto media_query_list = parse_a_media_query_list(media_query_tokens); 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<CSSRule*> child_rules { m_context.realm().heap() }; GC::RootVector<CSSRule*> child_rules { realm().heap() };
for (auto const& child : rule.child_rules_and_lists_of_declarations) { for (auto const& child : rule.child_rules_and_lists_of_declarations) {
child.visit( child.visit(
[&](Rule const& rule) { [&](Rule const& rule) {
@ -637,11 +637,11 @@ GC::Ptr<CSSMediaRule> Parser::convert_to_media_rule(AtRule const& rule, Nested n
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding.");
return; 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); auto rule_list = CSSRuleList::create(realm(), child_rules);
return CSSMediaRule::create(m_context.realm(), media_list, rule_list); return CSSMediaRule::create(realm(), media_list, rule_list);
} }
} }

View file

@ -20,6 +20,7 @@
#include <LibWeb/CSS/PropertyName.h> #include <LibWeb/CSS/PropertyName.h>
#include <LibWeb/CSS/Sizing.h> #include <LibWeb/CSS/Sizing.h>
#include <LibWeb/CSS/StyleComputer.h> #include <LibWeb/CSS/StyleComputer.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Dump.h> #include <LibWeb/Dump.h>
#include <LibWeb/HTML/HTMLImageElement.h> #include <LibWeb/HTML/HTMLImageElement.h>
@ -30,14 +31,51 @@ static void log_parse_error(SourceLocation const& location = SourceLocation::cur
namespace Web::CSS::Parser { 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<JS::Realm&>(document.realm()))
, document(&document)
, url(move(url))
, mode(mode)
{
}
ParsingParams::ParsingParams(DOM::Document const& document, ParsingMode mode)
: realm(const_cast<JS::Realm&>(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); auto tokens = Tokenizer::tokenize(input, encoding);
return Parser { context, move(tokens) }; return Parser { context, move(tokens) };
} }
Parser::Parser(ParsingContext const& context, Vector<Token> tokens) Parser::Parser(ParsingParams const& context, Vector<Token> tokens)
: m_context(context) : m_document(context.document)
, m_realm(context.realm)
, m_url(context.url)
, m_parsing_mode(context.mode)
, m_tokens(move(tokens)) , m_tokens(move(tokens))
, m_token_stream(m_tokens) , m_token_stream(m_tokens)
{ {
@ -84,7 +122,7 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<URL::URL> location)
auto const& style_sheet = parse_a_stylesheet(m_token_stream, {}); auto const& style_sheet = parse_a_stylesheet(m_token_stream, {});
// Interpret all of the resulting top-level qualified rules as style rules, defined below. // Interpret all of the resulting top-level qualified rules as style rules, defined below.
GC::RootVector<CSSRule*> rules(m_context.realm().heap()); GC::RootVector<CSSRule*> rules(realm().heap());
for (auto const& raw_rule : style_sheet.rules) { for (auto const& raw_rule : style_sheet.rules) {
auto rule = convert_to_rule(raw_rule, Nested::No); 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, its a parse error. // If any style rule is invalid, or any at-rule is not recognized or is invalid according to its grammar or context, its a parse error.
@ -96,9 +134,9 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<URL::URL> location)
rules.append(rule); rules.append(rule);
} }
auto rule_list = CSSRuleList::create(m_context.realm(), rules); auto rule_list = CSSRuleList::create(realm(), rules);
auto media_list = MediaList::create(m_context.realm(), {}); auto media_list = MediaList::create(realm(), {});
return CSSStyleSheet::create(m_context.realm(), rule_list, media_list, move(location)); return CSSStyleSheet::create(realm(), rule_list, media_list, move(location));
} }
RefPtr<Supports> Parser::parse_as_supports() RefPtr<Supports> Parser::parse_as_supports()
@ -116,7 +154,7 @@ RefPtr<Supports> Parser::parse_a_supports(TokenStream<T>& tokens)
m_rule_context.take_last(); m_rule_context.take_last();
token_stream.discard_whitespace(); token_stream.discard_whitespace();
if (maybe_condition && !token_stream.has_next_token()) 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 {}; return {};
} }
@ -1413,7 +1451,7 @@ PropertyOwningCSSStyleDeclaration* Parser::convert_to_style_declaration(Vector<D
for (auto const& declaration : declarations) { for (auto const& declaration : declarations) {
extract_property(declaration, dest); extract_property(declaration, dest);
} }
return PropertyOwningCSSStyleDeclaration::create(m_context.realm(), move(properties.properties), move(properties.custom_properties)); return PropertyOwningCSSStyleDeclaration::create(realm(), move(properties.properties), move(properties.custom_properties));
} }
Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& declaration) Optional<StyleProperty> Parser::convert_to_style_property(Declaration const& declaration)
@ -1462,7 +1500,7 @@ Optional<LengthOrCalculated> Parser::parse_source_size_value(TokenStream<Compone
bool Parser::context_allows_quirky_length() const bool Parser::context_allows_quirky_length() const
{ {
if (!m_context.in_quirks_mode()) if (!in_quirks_mode())
return false; return false;
// https://drafts.csswg.org/css-values-4/#deprecated-quirky-length // https://drafts.csswg.org/css-values-4/#deprecated-quirky-length
@ -1600,7 +1638,7 @@ LengthOrCalculated Parser::parse_as_sizes_attribute(DOM::Element const& element,
// If it does not parse correctly, or it does parse correctly but the <media-condition> evaluates to false, continue. // If it does not parse correctly, or it does parse correctly but the <media-condition> evaluates to false, continue.
TokenStream<ComponentValue> token_stream { unparsed_size }; TokenStream<ComponentValue> token_stream { unparsed_size };
auto media_condition = parse_media_condition(token_stream, MediaCondition::AllowOr::Yes); 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)) { if (!media_condition || (context_window && media_condition->evaluate(*context_window) == MatchResult::False)) {
continue; continue;
} }
@ -1693,4 +1731,39 @@ template Vector<ComponentValue> Parser::parse_a_list_of_component_values(TokenSt
template Vector<Vector<ComponentValue>> Parser::parse_a_comma_separated_list_of_component_values(TokenStream<ComponentValue>&); template Vector<Vector<ComponentValue>> Parser::parse_a_comma_separated_list_of_component_values(TokenStream<ComponentValue>&);
template Vector<Vector<ComponentValue>> Parser::parse_a_comma_separated_list_of_component_values(TokenStream<Token>&); template Vector<Vector<ComponentValue>> Parser::parse_a_comma_separated_list_of_component_values(TokenStream<Token>&);
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);
}
} }

View file

@ -1,68 +0,0 @@
/*
* Copyright (c) 2018-2022, Andreas Kling <andreas@ladybird.org>
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/DOM/Document.h>
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<JS::Realm&>(document.realm()))
, m_document(&document)
, m_url(move(url))
, m_mode(mode)
{
}
ParsingContext::ParsingContext(DOM::Document const& document, Mode mode)
: m_realm(const_cast<JS::Realm&>(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();
}
}

View file

@ -1,49 +0,0 @@
/*
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/Realm.h>
#include <LibWeb/DOM/Document.h>
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<JS::Realm> m_realm;
GC::Ptr<DOM::Document const> m_document;
URL::URL m_url;
Mode m_mode { Mode::Normal };
};
}

View file

@ -108,7 +108,7 @@ GC::Ptr<CSSStyleRule> Parser::convert_to_style_rule(QualifiedRule const& qualifi
return {}; return {};
} }
GC::RootVector<CSSRule*> child_rules { m_context.realm().heap() }; GC::RootVector<CSSRule*> child_rules { realm().heap() };
for (auto& child : qualified_rule.child_rules) { for (auto& child : qualified_rule.child_rules) {
child.visit( child.visit(
[&](Rule const& rule) { [&](Rule const& rule) {
@ -129,11 +129,11 @@ GC::Ptr<CSSStyleRule> Parser::convert_to_style_rule(QualifiedRule const& qualifi
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding.");
return; 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)); auto nested_rules = CSSRuleList::create(realm(), move(child_rules));
return CSSStyleRule::create(m_context.realm(), move(selectors), *declaration, *nested_rules); return CSSStyleRule::create(realm(), move(selectors), *declaration, *nested_rules);
} }
GC::Ptr<CSSImportRule> Parser::convert_to_import_rule(AtRule const& rule) GC::Ptr<CSSImportRule> Parser::convert_to_import_rule(AtRule const& rule)
@ -161,7 +161,7 @@ GC::Ptr<CSSImportRule> Parser::convert_to_import_rule(AtRule const& rule)
Optional<URL::URL> url = parse_url_function(tokens); Optional<URL::URL> url = parse_url_function(tokens);
if (!url.has_value() && tokens.next_token().is(Token::Type::String)) 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()) { 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()); 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<CSSImportRule> Parser::convert_to_import_rule(AtRule const& rule)
return {}; return {};
} }
return CSSImportRule::create(url.value(), const_cast<DOM::Document&>(*m_context.document())); return CSSImportRule::create(url.value(), const_cast<DOM::Document&>(*document()));
} }
Optional<FlyString> Parser::parse_layer_name(TokenStream<ComponentValue>& tokens, AllowBlankLayerName allow_blank_layer_name) Optional<FlyString> Parser::parse_layer_name(TokenStream<ComponentValue>& tokens, AllowBlankLayerName allow_blank_layer_name)
@ -247,7 +247,7 @@ GC::Ptr<CSSRule> Parser::convert_to_layer_rule(AtRule const& rule, Nested nested
} }
// Then the rules // Then the rules
GC::RootVector<CSSRule*> child_rules { m_context.realm().heap() }; GC::RootVector<CSSRule*> child_rules { realm().heap() };
for (auto const& child : rule.child_rules_and_lists_of_declarations) { for (auto const& child : rule.child_rules_and_lists_of_declarations) {
child.visit( child.visit(
[&](Rule const& rule) { [&](Rule const& rule) {
@ -260,11 +260,11 @@ GC::Ptr<CSSRule> Parser::convert_to_layer_rule(AtRule const& rule, Nested nested
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding.");
return; 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); auto rule_list = CSSRuleList::create(realm(), child_rules);
return CSSLayerBlockRule::create(m_context.realm(), layer_name, rule_list); return CSSLayerBlockRule::create(realm(), layer_name, rule_list);
} }
// CSSLayerStatementRule // CSSLayerStatementRule
@ -296,7 +296,7 @@ GC::Ptr<CSSRule> Parser::convert_to_layer_rule(AtRule const& rule, Nested nested
return {}; return {};
} }
return CSSLayerStatementRule::create(m_context.realm(), move(layer_names)); return CSSLayerStatementRule::create(realm(), move(layer_names));
} }
GC::Ptr<CSSKeyframesRule> Parser::convert_to_keyframes_rule(AtRule const& rule) GC::Ptr<CSSKeyframesRule> Parser::convert_to_keyframes_rule(AtRule const& rule)
@ -342,7 +342,7 @@ GC::Ptr<CSSKeyframesRule> Parser::convert_to_keyframes_rule(AtRule const& rule)
auto name = name_token.to_string(); auto name = name_token.to_string();
GC::RootVector<CSSRule*> keyframes(m_context.realm().heap()); GC::RootVector<CSSRule*> keyframes(realm().heap());
rule.for_each_as_qualified_rule_list([&](auto& qualified_rule) { rule.for_each_as_qualified_rule_list([&](auto& qualified_rule) {
if (!qualified_rule.child_rules.is_empty()) { if (!qualified_rule.child_rules.is_empty()) {
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @keyframes keyframe rule contains at-rules; discarding them."); dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @keyframes keyframe rule contains at-rules; discarding them.");
@ -390,14 +390,14 @@ GC::Ptr<CSSKeyframesRule> Parser::convert_to_keyframes_rule(AtRule const& rule)
qualified_rule.for_each_as_declaration_list([&](auto const& declaration) { qualified_rule.for_each_as_declaration_list([&](auto const& declaration) {
extract_property(declaration, properties); 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) { 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); 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<CSSNamespaceRule> Parser::convert_to_namespace_rule(AtRule const& rule) GC::Ptr<CSSNamespaceRule> Parser::convert_to_namespace_rule(AtRule const& rule)
@ -444,7 +444,7 @@ GC::Ptr<CSSNamespaceRule> Parser::convert_to_namespace_rule(AtRule const& rule)
return {}; return {};
} }
return CSSNamespaceRule::create(m_context.realm(), prefix, namespace_uri); return CSSNamespaceRule::create(realm(), prefix, namespace_uri);
} }
GC::Ptr<CSSSupportsRule> Parser::convert_to_supports_rule(AtRule const& rule, Nested nested) GC::Ptr<CSSSupportsRule> Parser::convert_to_supports_rule(AtRule const& rule, Nested nested)
@ -469,7 +469,7 @@ GC::Ptr<CSSSupportsRule> Parser::convert_to_supports_rule(AtRule const& rule, Ne
return {}; return {};
} }
GC::RootVector<CSSRule*> child_rules { m_context.realm().heap() }; GC::RootVector<CSSRule*> child_rules { realm().heap() };
for (auto const& child : rule.child_rules_and_lists_of_declarations) { for (auto const& child : rule.child_rules_and_lists_of_declarations) {
child.visit( child.visit(
[&](Rule const& rule) { [&](Rule const& rule) {
@ -482,12 +482,12 @@ GC::Ptr<CSSSupportsRule> Parser::convert_to_supports_rule(AtRule const& rule, Ne
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding."); dbgln_if(CSS_PARSER_DEBUG, "CSSParser: nested declarations invalid; discarding.");
return; 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); auto rule_list = CSSRuleList::create(realm(), child_rules);
return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), rule_list); return CSSSupportsRule::create(realm(), supports.release_nonnull(), rule_list);
} }
GC::Ptr<CSSPropertyRule> Parser::convert_to_property_rule(AtRule const& rule) GC::Ptr<CSSPropertyRule> Parser::convert_to_property_rule(AtRule const& rule)
@ -582,7 +582,7 @@ GC::Ptr<CSSPropertyRule> Parser::convert_to_property_rule(AtRule const& rule)
}); });
if (syntax_maybe.has_value() && inherits_maybe.has_value()) { 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 {}; return {};
} }
@ -976,7 +976,7 @@ GC::Ptr<CSSFontFaceRule> Parser::convert_to_font_face_rule(AtRule const& rule)
unicode_range.empend(0x0u, 0x10FFFFu); 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) });
} }
} }

View file

@ -52,6 +52,7 @@
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h> #include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
#include <LibWeb/CSS/StyleValues/URLStyleValue.h> #include <LibWeb/CSS/StyleValues/URLStyleValue.h>
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h> #include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
#include <LibWeb/DOM/Element.h>
#include <LibWeb/Dump.h> #include <LibWeb/Dump.h>
#include <LibWeb/Infra/CharacterTypes.h> #include <LibWeb/Infra/CharacterTypes.h>
@ -659,7 +660,7 @@ RefPtr<CSSStyleValue> Parser::parse_angle_value(TokenStream<ComponentValue>& tok
// When parsing an SVG attribute, an angle is allowed without a unit. // 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 // FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792
// For now: Convert to an angle in degrees. // 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(); auto numeric_value = tokens.consume_a_token().token().number_value();
return AngleStyleValue::create(Angle::make_degrees(numeric_value)); return AngleStyleValue::create(Angle::make_degrees(numeric_value));
} }
@ -693,7 +694,7 @@ RefPtr<CSSStyleValue> Parser::parse_angle_percentage_value(TokenStream<Component
// When parsing an SVG attribute, an angle is allowed without a unit. // 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 // FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792
// For now: Convert to an angle in degrees. // 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(); auto numeric_value = tokens.consume_a_token().token().number_value();
return AngleStyleValue::create(Angle::make_degrees(numeric_value)); return AngleStyleValue::create(Angle::make_degrees(numeric_value));
} }
@ -805,7 +806,7 @@ RefPtr<CSSStyleValue> Parser::parse_length_value(TokenStream<ComponentValue>& to
// When parsing an SVG attribute, a length is allowed without a unit. // 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 // FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792
// For now: Convert to a length in pixels. // For now: Convert to a length in pixels.
if (m_context.is_parsing_svg_presentation_attribute()) { if (is_parsing_svg_presentation_attribute()) {
transaction.commit(); transaction.commit();
return LengthStyleValue::create(Length::make_px(CSSPixels::nearest_value_for(numeric_value))); return LengthStyleValue::create(Length::make_px(CSSPixels::nearest_value_for(numeric_value)));
} }
@ -852,7 +853,7 @@ RefPtr<CSSStyleValue> Parser::parse_length_percentage_value(TokenStream<Componen
// When parsing an SVG attribute, a length is allowed without a unit. // 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 // FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792
// For now: Convert to a length in pixels. // For now: Convert to a length in pixels.
if (m_context.is_parsing_svg_presentation_attribute()) { if (is_parsing_svg_presentation_attribute()) {
transaction.commit(); transaction.commit();
return LengthStyleValue::create(Length::make_px(CSSPixels::nearest_value_for(numeric_value))); return LengthStyleValue::create(Length::make_px(CSSPixels::nearest_value_for(numeric_value)));
} }
@ -1696,7 +1697,7 @@ RefPtr<CSSStyleValue> Parser::parse_color_value(TokenStream<ComponentValue>& tok
} }
// https://drafts.csswg.org/css-color-4/#quirky-color // 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, <quirky-color> is a type of <color> that is only valid in certain properties:" // "When CSS is being parsed in quirks mode, <quirky-color> is a type of <color> that is only valid in certain properties:"
// (NOTE: List skipped for brevity; quirks data is assigned in Properties.json) // (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, // "It is not valid in properties that include or reference these properties, such as the background shorthand,
@ -2468,7 +2469,7 @@ Optional<URL::URL> Parser::parse_url_function(TokenStream<ComponentValue>& token
auto& component_value = tokens.consume_a_token(); auto& component_value = tokens.consume_a_token();
auto convert_string_to_url = [&](StringView url_string) -> Optional<URL::URL> { auto convert_string_to_url = [&](StringView url_string) -> Optional<URL::URL> {
auto url = m_context.complete_url(url_string); auto url = complete_url(url_string);
if (url.is_valid()) { if (url.is_valid()) {
transaction.commit(); transaction.commit();
return url; return url;
@ -3510,7 +3511,7 @@ RefPtr<StringStyleValue> Parser::parse_opentype_tag_value(TokenStream<ComponentV
return string_value; return string_value;
} }
NonnullRefPtr<CSSStyleValue> Parser::resolve_unresolved_style_value(ParsingContext const& context, DOM::Element& element, Optional<Selector::PseudoElement::Type> pseudo_element, PropertyID property_id, UnresolvedStyleValue const& unresolved) NonnullRefPtr<CSSStyleValue> Parser::resolve_unresolved_style_value(ParsingParams const& context, DOM::Element& element, Optional<Selector::PseudoElement::Type> 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 // 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. // to produce a different CSSStyleValue from it.

View file

@ -307,7 +307,7 @@ static CSSStyleSheet& default_stylesheet(DOM::Document const& document)
static GC::Root<CSSStyleSheet> sheet; static GC::Root<CSSStyleSheet> sheet;
if (!sheet.cell()) { if (!sheet.cell()) {
extern String default_stylesheet_source; 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; return *sheet;
} }
@ -317,7 +317,7 @@ static CSSStyleSheet& quirks_mode_stylesheet(DOM::Document const& document)
static GC::Root<CSSStyleSheet> sheet; static GC::Root<CSSStyleSheet> sheet;
if (!sheet.cell()) { if (!sheet.cell()) {
extern String quirks_mode_stylesheet_source; 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; return *sheet;
} }
@ -327,7 +327,7 @@ static CSSStyleSheet& mathml_stylesheet(DOM::Document const& document)
static GC::Root<CSSStyleSheet> sheet; static GC::Root<CSSStyleSheet> sheet;
if (!sheet.cell()) { if (!sheet.cell()) {
extern String mathml_stylesheet_source; 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; return *sheet;
} }
@ -337,7 +337,7 @@ static CSSStyleSheet& svg_stylesheet(DOM::Document const& document)
static GC::Root<CSSStyleSheet> sheet; static GC::Root<CSSStyleSheet> sheet;
if (!sheet.cell()) { if (!sheet.cell()) {
extern String svg_stylesheet_source; 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; return *sheet;
} }
@ -1009,7 +1009,7 @@ void StyleComputer::set_all_properties(
NonnullRefPtr<CSSStyleValue> property_value = value; NonnullRefPtr<CSSStyleValue> property_value = value;
if (property_value->is_unresolved()) 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()) if (!property_value->is_unresolved())
set_property_expanding_shorthands(cascaded_properties, property_id, property_value, declaration, cascade_origin, important, layer_name); 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; auto property_value = property.value;
if (property.value->is_unresolved()) 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()) if (!property_value->is_unresolved())
set_property_expanding_shorthands(cascaded_properties, property.property_id, property_value, &match->declaration(), cascade_origin, important, layer_name); 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; auto property_value = property.value;
if (property.value->is_unresolved()) 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()) if (!property_value->is_unresolved())
set_property_expanding_shorthands(cascaded_properties, property.property_id, property_value, inline_style, cascade_origin, important, layer_name); 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, Optional<CSS::
if (value->is_revert() || value->is_revert_layer()) if (value->is_revert() || value->is_revert_layer())
return computed_properties.property(it.key); return computed_properties.property(it.key);
if (value->is_unresolved()) 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; return value;
}); });
}; };
@ -2974,7 +2974,7 @@ void StyleComputer::build_rule_cache()
m_style_invalidation_data = make<StyleInvalidationData>(); m_style_invalidation_data = make<StyleInvalidationData>();
if (auto user_style_source = document().page().user_style(); user_style_source.has_value()) { 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(); build_qualified_layer_names_cache();

View file

@ -59,13 +59,13 @@ bool Supports::InParens::evaluate(JS::Realm& realm) const
bool Supports::Declaration::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(); return style_property.has_value();
} }
bool Supports::Selector::evaluate(JS::Realm& realm) const 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(); return style_property.has_value();
} }

View file

@ -1541,7 +1541,7 @@ void Document::obtain_supported_color_schemes()
auto content = element.attribute(HTML::AttributeNames::content); auto content = element.attribute(HTML::AttributeNames::content);
if (element.name().has_value() && element.name()->equals_ignoring_ascii_case("color-scheme"sv) && content.has_value()) { 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. // 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); 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. // 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); auto content = element.attribute(HTML::AttributeNames::content);
if (element.name().has_value() && element.name()->equals_ignoring_ascii_case("theme-color"sv) && content.has_value()) { 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. // 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); auto media = element.attribute(HTML::AttributeNames::media);
if (media.has_value()) { if (media.has_value()) {
auto query = parse_media_query(context, media.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 WebIDL::ExceptionOr<bool> Element::matches(StringView selectors) const
{ {
// 1. Let s be the result of parse a selector from selectors. // 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. // 2. If s is failure, then throw a "SyntaxError" DOMException.
if (!maybe_selectors.has_value()) 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 WebIDL::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors) const
{ {
// 1. Let s be the result of parse a selector from selectors. // 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. // 2. If s is failure, then throw a "SyntaxError" DOMException.
if (!maybe_selectors.has_value()) 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()) if (m_inline_style && m_inline_style->is_updating())
return; return;
if (!m_inline_style) { 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 { } else {
// NOTE: ElementInlineCSSStyleDeclaration::set_css_text should never throw an exception. // NOTE: ElementInlineCSSStyleDeclaration::set_css_text should never throw an exception.
m_inline_style->set_declarations_from_text(*value); 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: // To scope-match a selectors string selectors against a node, run these steps:
// 1. Let s be the result of parse a selector selectors. // 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. // 2. If s is failure, then throw a "SyntaxError" DOMException.
if (!maybe_selectors.has_value()) 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, // 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(). // 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) if (!sheet)
return; return;

View file

@ -947,7 +947,7 @@ WebIDL::ExceptionOr<ParsedMatrix> parse_dom_matrix_init_string(JS::Realm& realm,
// 2. Parse transformList into parsedValue given the grammar for the CSS transform property. // 2. Parse transformList into parsedValue given the grammar for the CSS transform property.
// The result will be a <transform-list>, the keyword none, or failure. // The result will be a <transform-list>, the keyword none, or failure.
// If parsedValue is failure, or any <transform-function> has <length> values without absolute length units, or any keyword other than none is used, then return failure. [CSS3-SYNTAX] [CSS3-TRANSFORMS] // If parsedValue is failure, or any <transform-function> has <length> 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)) 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); return WebIDL::SyntaxError::create(realm, "Failed to parse CSS transform string."_string);
auto parsed_value = CSS::ComputedProperties::transformations_for_style_value(*transform_style_value); auto parsed_value = CSS::ComputedProperties::transformations_for_style_value(*transform_style_value);

View file

@ -35,7 +35,7 @@ public:
// 2. Let parsedValue be the result of parsing the given value with context if non-null. // 2. Let parsedValue be the result of parsing the given value with context if non-null.
// FIXME: Parse a color value // FIXME: Parse a color value
// https://drafts.csswg.org/css-color/#parse-a-css-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()) { if (style_value && style_value->has_color()) {
auto parsedValue = style_value->to_color(OptionalNone()); 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. // 2. Let parsedValue be the result of parsing the given value with context if non-null.
// FIXME: Parse a color value // FIXME: Parse a color value
// https://drafts.csswg.org/css-color/#parse-a-css-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()) { if (style_value && style_value->has_color()) {
auto parsedValue = style_value->to_color(OptionalNone()); auto parsedValue = style_value->to_color(OptionalNone());

View file

@ -47,7 +47,7 @@ public:
// and with system fonts being computed to explicit values. // and with system fonts being computed to explicit values.
// FIXME: with the 'line-height' component forced to 'normal' // FIXME: with the 'line-height' component forced to 'normal'
// FIXME: with the 'font-size' component converted to CSS pixels // 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. // 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. // NOTE: ShorthandStyleValue should be the only valid option here. We implicitly VERIFY this below.

View file

@ -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. // 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. // 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()) { if (style_value && style_value->has_color()) {
auto parsedValue = style_value->to_color(OptionalNone()); auto parsedValue = style_value->to_color(OptionalNone());
@ -944,7 +944,7 @@ void CanvasRenderingContext2D::set_filter(String filter)
} }
auto& realm = static_cast<CanvasRenderingContext2D&>(*this).realm(); auto& realm = static_cast<CanvasRenderingContext2D&>(*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 <filter-value-list>. // 2. Let parsedValue be the result of parsing the given values as a <filter-value-list>.
// If any property-independent style sheet syntax like 'inherit' or 'initial' is present, // If any property-independent style sheet syntax like 'inherit' or 'initial' is present,

View file

@ -9,7 +9,6 @@
#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/ComputedProperties.h> #include <LibWeb/CSS/ComputedProperties.h>
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/Parser/ParsingContext.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h> #include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/HTML/HTMLFontElement.h> #include <LibWeb/HTML/HTMLFontElement.h>
#include <LibWeb/HTML/Parser/HTMLParser.h> #include <LibWeb/HTML/Parser/HTMLParser.h>
@ -136,7 +135,7 @@ void HTMLFontElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties
auto font_size_or_empty = parse_legacy_font_size(value); auto font_size_or_empty = parse_legacy_font_size(value);
if (font_size_or_empty.has_value()) { if (font_size_or_empty.has_value()) {
auto font_size = string_from_keyword(font_size_or_empty.release_value()); auto font_size = string_from_keyword(font_size_or_empty.release_value());
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, font_size, CSS::PropertyID::FontSize)) if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, font_size, CSS::PropertyID::FontSize))
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::FontSize, parsed_value.release_nonnull()); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::FontSize, parsed_value.release_nonnull());
} }
} }

View file

@ -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. // 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)) { 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)); child->get_attribute_value(HTML::AttributeNames::media));
if (!media_query || !element.document().window() || !media_query->evaluate(*element.document().window())) { if (!media_query || !element.document().window() || !media_query->evaluate(*element.document().window())) {
continue; continue;

View file

@ -441,7 +441,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error)); dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error));
} else { } else {
auto const decoded_string = maybe_decoded_string.release_value(); 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) { if (m_loaded_style_sheet) {
Optional<String> location; Optional<String> location;

View file

@ -9,7 +9,6 @@
#include <LibWeb/Bindings/HTMLMetaElementPrototype.h> #include <LibWeb/Bindings/HTMLMetaElementPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/Parser/ParsingContext.h>
#include <LibWeb/CSS/PropertyID.h> #include <LibWeb/CSS/PropertyID.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h> #include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h> #include <LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h>

View file

@ -62,7 +62,7 @@ void HTMLTableCellElement::apply_presentational_hints(GC::Ref<CSS::CascadedPrope
return; return;
} }
if (name == HTML::AttributeNames::valign) { 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()); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
return; return;
} }
@ -74,7 +74,7 @@ void HTMLTableCellElement::apply_presentational_hints(GC::Ref<CSS::CascadedPrope
} else if (value.equals_ignoring_ascii_case("right"sv)) { } else if (value.equals_ignoring_ascii_case("right"sv)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebRight)); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, CSS::CSSKeywordValue::create(CSS::Keyword::LibwebRight));
} else { } 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()); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
} }
return; return;

View file

@ -85,7 +85,7 @@ void HTMLTableElement::apply_presentational_hints(GC::Ref<CSS::CascadedPropertie
if (value.equals_ignoring_ascii_case("center"sv)) { if (value.equals_ignoring_ascii_case("center"sv)) {
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::MarginLeft, CSS::CSSKeywordValue::create(CSS::Keyword::Auto)); cascaded_properties->set_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)); 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()); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Float, parsed_value.release_nonnull());
} }
return; return;

View file

@ -8,7 +8,6 @@
#include <LibWeb/Bindings/Intrinsics.h> #include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/ComputedProperties.h> #include <LibWeb/CSS/ComputedProperties.h>
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/Parser/ParsingContext.h>
#include <LibWeb/CSS/StyleValues/CSSColorValue.h> #include <LibWeb/CSS/StyleValues/CSSColorValue.h>
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.h> #include <LibWeb/CSS/StyleValues/CSSKeywordValue.h>
#include <LibWeb/CSS/StyleValues/ImageStyleValue.h> #include <LibWeb/CSS/StyleValues/ImageStyleValue.h>
@ -68,7 +67,7 @@ void HTMLTableRowElement::apply_presentational_hints(GC::Ref<CSS::CascadedProper
if (auto parsed_value = parse_dimension_value(value)) if (auto parsed_value = parse_dimension_value(value))
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value);
} else if (name == HTML::AttributeNames::valign) { } 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()); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
} }
}); });

View file

@ -341,7 +341,7 @@ descriptor_parser:
// https://html.spec.whatwg.org/multipage/images.html#parse-a-sizes-attribute // 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) 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); return css_parser.parse_as_sizes_attribute(element, img);
} }

View file

@ -1218,7 +1218,7 @@ GC::Ref<CSS::CSSStyleDeclaration> Window::get_computed_style(DOM::Element& eleme
// 3. If pseudoElt is provided, is not the empty string, and starts with a colon, then: // 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(':')) { if (pseudo_element.has_value() && pseudo_element.value().starts_with(':')) {
// 1. Parse pseudoElt as a <pseudo-element-selector>, and let type be the result. // 1. Parse pseudoElt as a <pseudo-element-selector>, 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. // 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 // FIXME: We can't pass a null element to ResolvedCSSStyleDeclaration
@ -1261,7 +1261,7 @@ GC::Ref<CSS::CSSStyleDeclaration> Window::get_computed_style(DOM::Element& eleme
WebIDL::ExceptionOr<GC::Ref<CSS::MediaQueryList>> Window::match_media(String const& query) WebIDL::ExceptionOr<GC::Ref<CSS::MediaQueryList>> Window::match_media(String const& query)
{ {
// 1. Let parsed media query list be the result of parsing 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. // 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<CSS::MediaQueryList>(associated_document(), move(parsed_media_query_list)); auto media_query_list = realm().create<CSS::MediaQueryList>(associated_document(), move(parsed_media_query_list));

View file

@ -319,7 +319,7 @@ void IntersectionObserver::queue_entry(Badge<DOM::Document>, GC::Ref<Intersectio
Optional<Vector<CSS::LengthPercentage>> IntersectionObserver::parse_a_margin(JS::Realm& realm, String margin_string) Optional<Vector<CSS::LengthPercentage>> IntersectionObserver::parse_a_margin(JS::Realm& realm, String margin_string)
{ {
// 1. Parse a list of component values marginString, storing the result as tokens. // 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. // 2. Remove all whitespace tokens from tokens.
tokens.remove_all_matching([](auto componentValue) { return componentValue.is(CSS::Parser::Token::Type::Whitespace); }); tokens.remove_all_matching([](auto componentValue) { return componentValue.is(CSS::Parser::Token::Type::Whitespace); });

View file

@ -43,7 +43,7 @@ bool SVGCircleElement::is_presentational_hint(FlyString const& name) const
void SVGCircleElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const void SVGCircleElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
{ {
Base::apply_presentational_hints(cascaded_properties); 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); auto cx_attribute = attribute(SVG::AttributeNames::cx);
if (auto cx_value = parse_css_value(parsing_context, cx_attribute.value_or(String {}), CSS::PropertyID::Cx)) if (auto cx_value = parse_css_value(parsing_context, cx_attribute.value_or(String {}), CSS::PropertyID::Cx))

View file

@ -65,7 +65,7 @@ bool SVGForeignObjectElement::is_presentational_hint(FlyString const& name) cons
void SVGForeignObjectElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const void SVGForeignObjectElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
{ {
Base::apply_presentational_hints(cascaded_properties); 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)) 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()); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, width_value.release_nonnull());

View file

@ -177,7 +177,7 @@ bool SVGGraphicsElement::is_presentational_hint(FlyString const& name) const
void SVGGraphicsElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const void SVGGraphicsElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> 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_each_attribute([&](auto& name, auto& value) {
for (auto property : attribute_style_properties) { for (auto property : attribute_style_properties) {
if (!name.equals_ignoring_ascii_case(property.name)) if (!name.equals_ignoring_ascii_case(property.name))

View file

@ -49,7 +49,7 @@ GC::Ptr<Layout::Node> SVGSVGElement::create_layout_node(GC::Ref<CSS::ComputedPro
RefPtr<CSS::CSSStyleValue> SVGSVGElement::width_style_value_from_attribute() const RefPtr<CSS::CSSStyleValue> 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); auto width_attribute = attribute(SVG::AttributeNames::width);
if (auto width_value = parse_css_value(parsing_context, width_attribute.value_or(String {}), CSS::PropertyID::Width)) { if (auto width_value = parse_css_value(parsing_context, width_attribute.value_or(String {}), CSS::PropertyID::Width)) {
return width_value.release_nonnull(); return width_value.release_nonnull();
@ -65,7 +65,7 @@ RefPtr<CSS::CSSStyleValue> SVGSVGElement::width_style_value_from_attribute() con
RefPtr<CSS::CSSStyleValue> SVGSVGElement::height_style_value_from_attribute() const RefPtr<CSS::CSSStyleValue> 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); auto height_attribute = attribute(SVG::AttributeNames::height);
if (auto height_value = parse_css_value(parsing_context, height_attribute.value_or(String {}), CSS::PropertyID::Height)) { if (auto height_value = parse_css_value(parsing_context, height_attribute.value_or(String {}), CSS::PropertyID::Height)) {
return height_value.release_nonnull(); 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<CSS::CascadedProperties> cascaded_properties) const void SVGSVGElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
{ {
Base::apply_presentational_hints(cascaded_properties); 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); auto x_attribute = attribute(SVG::AttributeNames::x);
if (auto x_value = parse_css_value(parsing_context, x_attribute.value_or(String {}), CSS::PropertyID::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<double> height; Optional<double> height;
auto width_attribute = get_attribute_value(SVG::AttributeNames::width); 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 (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()) if (width_value->is_length() && width_value->as_length().length().is_absolute())
width = width_value->as_length().length().absolute_length_to_px().to_double(); width = width_value->as_length().length().absolute_length_to_px().to_double();

View file

@ -42,9 +42,9 @@ bool SVGStopElement::is_presentational_hint(FlyString const& name) const
void SVGStopElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const void SVGStopElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
{ {
CSS::Parser::ParsingContext parsing_context { document() }; CSS::Parser::ParsingParams parsing_context { document() };
for_each_attribute([&](auto& name, auto& value) { 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 (name.equals_ignoring_ascii_case("stop-color"sv)) {
if (auto stop_color = parse_css_value(parsing_context, value, CSS::PropertyID::StopColor)) { 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()); cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::StopColor, stop_color.release_nonnull());

View file

@ -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" // FIXME: There's got to be a better way to do this "correctly"
auto& vm = Web::Bindings::main_thread_vm(); 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; return 0;
} }

View file

@ -672,7 +672,7 @@ NonnullRefPtr<CSSStyleValue> property_initial_value(PropertyID property_id)
// This ensures the shorthands will always be able to get the initial values of their longhands. // 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). // 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) { switch (property_id) {
)~~~"); )~~~");
@ -691,7 +691,7 @@ NonnullRefPtr<CSSStyleValue> property_initial_value(PropertyID property_id)
member_generator.append( member_generator.append(
R"~~~( case PropertyID::@name:titlecase@: 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()); VERIFY(!parsed_value.is_null());
auto initial_value = parsed_value.release_nonnull(); auto initial_value = parsed_value.release_nonnull();
initial_values[to_underlying(PropertyID::@name:titlecase@)] = initial_value; initial_values[to_underlying(PropertyID::@name:titlecase@)] = initial_value;

View file

@ -7,7 +7,6 @@ source_set("Parser") {
"Helpers.cpp", "Helpers.cpp",
"MediaParsing.cpp", "MediaParsing.cpp",
"Parser.cpp", "Parser.cpp",
"ParsingContext.cpp",
"PropertyParsing.cpp", "PropertyParsing.cpp",
"RuleParsing.cpp", "RuleParsing.cpp",
"SelectorParsing.cpp", "SelectorParsing.cpp",