mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 13:19:05 +00:00
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:
parent
30ba7e334e
commit
6a4d80b9b6
Notes:
github-actions[bot]
2025-02-06 16:48:31 +00:00
Author: https://github.com/AtkinsSJ
Commit: 6a4d80b9b6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3464
Reviewed-by: https://github.com/ADKaster
49 changed files with 207 additions and 255 deletions
|
@ -27,7 +27,7 @@ bool supports(JS::VM&, StringView property, StringView value)
|
|||
// 1. If property is an ASCII case-insensitive match for any defined CSS property that the UA supports,
|
||||
// and value successfully parses according to that property’s grammar, return true.
|
||||
if (auto property_id = property_id_from_string(property); property_id.has_value()) {
|
||||
if (parse_css_value(Parser::ParsingContext {}, value, property_id.value()))
|
||||
if (parse_css_value(Parser::ParsingParams {}, value, property_id.value()))
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -46,13 +46,13 @@ WebIDL::ExceptionOr<bool> supports(JS::VM& vm, StringView condition_text)
|
|||
auto& realm = *vm.current_realm();
|
||||
|
||||
// 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;
|
||||
|
||||
// 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));
|
||||
|
||||
if (auto supports = parse_css_supports(Parser::ParsingContext { realm }, wrapped_condition_text); supports && supports->matches())
|
||||
if (auto supports = parse_css_supports(Parser::ParsingParams { realm }, wrapped_condition_text); supports && supports->matches())
|
||||
return true;
|
||||
|
||||
// 3. Otherwise, return false.
|
||||
|
|
|
@ -139,7 +139,7 @@ void CSSImportRule::fetch()
|
|||
}
|
||||
auto decoded = decoded_or_error.release_value();
|
||||
|
||||
auto* imported_style_sheet = parse_css_stylesheet(Parser::ParsingContext(*strong_this->m_document, strong_this->url()), decoded, strong_this->url());
|
||||
auto* imported_style_sheet = parse_css_stylesheet(Parser::ParsingParams(*strong_this->m_document, strong_this->url()), decoded, strong_this->url());
|
||||
|
||||
// 5. Set importedStylesheet’s origin-clean flag to parentStylesheet’s origin-clean flag.
|
||||
imported_style_sheet->set_origin_clean(parent_style_sheet->is_origin_clean());
|
||||
|
|
|
@ -69,7 +69,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
|
|||
CSSRule* new_rule = nullptr;
|
||||
if (rule.has<StringView>()) {
|
||||
new_rule = parse_css_rule(
|
||||
CSS::Parser::ParsingContext { realm() },
|
||||
CSS::Parser::ParsingParams { realm() },
|
||||
rule.get<StringView>());
|
||||
} else {
|
||||
new_rule = rule.get<CSSRule*>();
|
||||
|
|
|
@ -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.
|
||||
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::ParsingContext {}, value, property_id);
|
||||
? parse_css_value(CSS::Parser::ParsingParams { static_cast<ElementInlineCSSStyleDeclaration&>(*this).element()->document() }, value, property_id)
|
||||
: parse_css_value(CSS::Parser::ParsingParams {}, value, property_id);
|
||||
|
||||
// 6. If component value list is null, then return.
|
||||
if (!component_value_list)
|
||||
|
@ -528,7 +528,7 @@ void ElementInlineCSSStyleDeclaration::set_declarations_from_text(StringView css
|
|||
}
|
||||
|
||||
empty_the_declarations();
|
||||
auto style = parse_css_style_attribute(CSS::Parser::ParsingContext(m_element->document()), css_text, *m_element.ptr());
|
||||
auto style = parse_css_style_attribute(CSS::Parser::ParsingParams(m_element->document()), css_text, *m_element.ptr());
|
||||
set_the_declarations(style->properties(), style->custom_properties());
|
||||
}
|
||||
|
||||
|
|
|
@ -129,9 +129,9 @@ void CSSStyleRule::set_selector_text(StringView selector_text)
|
|||
Optional<SelectorList> parsed_selectors;
|
||||
if (parent_style_rule()) {
|
||||
// AD-HOC: If we're a nested style rule, then we need to parse the selector as relative and then adapt it with implicit &s.
|
||||
parsed_selectors = parse_selector_for_nested_style_rule(Parser::ParsingContext { realm() }, selector_text);
|
||||
parsed_selectors = parse_selector_for_nested_style_rule(Parser::ParsingParams { realm() }, selector_text);
|
||||
} else {
|
||||
parsed_selectors = parse_selector(Parser::ParsingContext { realm() }, selector_text);
|
||||
parsed_selectors = parse_selector(Parser::ParsingParams { realm() }, selector_text);
|
||||
}
|
||||
|
||||
// 2. If the algorithm returns a non-null value replace the associated group of selectors with the returned value.
|
||||
|
|
|
@ -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);
|
||||
|
||||
// 3. Let parsed rule be the return value of invoking parse a rule with rule.
|
||||
auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingContext { (*m_owning_documents_or_shadow_roots.begin())->document() } : Parser::ParsingContext { realm() };
|
||||
auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingParams { (*m_owning_documents_or_shadow_roots.begin())->document() } : Parser::ParsingParams { realm() };
|
||||
auto parsed_rule = parse_css_rule(context, rule);
|
||||
|
||||
// 4. If parsed rule is a syntax error, return parsed rule.
|
||||
|
@ -207,7 +207,7 @@ GC::Ref<WebIDL::Promise> CSSStyleSheet::replace(String text)
|
|||
HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes };
|
||||
|
||||
// 1. Let rules be the result of running parse a stylesheet’s contents from text.
|
||||
auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingContext { (*m_owning_documents_or_shadow_roots.begin())->document() } : CSS::Parser::ParsingContext { realm };
|
||||
auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingParams { (*m_owning_documents_or_shadow_roots.begin())->document() } : CSS::Parser::ParsingParams { realm };
|
||||
auto* parsed_stylesheet = parse_css_stylesheet(context, text);
|
||||
auto& rules = parsed_stylesheet->rules();
|
||||
|
||||
|
@ -241,7 +241,7 @@ WebIDL::ExceptionOr<void> CSSStyleSheet::replace_sync(StringView text)
|
|||
return WebIDL::NotAllowedError::create(realm(), "Can't call replaceSync() on non-modifiable stylesheets"_string);
|
||||
|
||||
// 2. Let rules be the result of running parse a stylesheet’s contents from text.
|
||||
auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingContext { (*m_owning_documents_or_shadow_roots.begin())->document() } : CSS::Parser::ParsingContext { realm() };
|
||||
auto context = !m_owning_documents_or_shadow_roots.is_empty() ? Parser::ParsingParams { (*m_owning_documents_or_shadow_roots.begin())->document() } : CSS::Parser::ParsingParams { realm() };
|
||||
auto* parsed_stylesheet = parse_css_stylesheet(context, text);
|
||||
auto& rules = parsed_stylesheet->rules();
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ void CascadedProperties::resolve_unresolved_properties(GC::Ref<DOM::Element> ele
|
|||
for (auto& entry : entries) {
|
||||
if (!entry.property.value->is_unresolved())
|
||||
continue;
|
||||
entry.property.value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { element->document() }, element, pseudo_element, property_id, entry.property.value->as_unresolved());
|
||||
entry.property.value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { element->document() }, element, pseudo_element, property_id, entry.property.value->as_unresolved());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ GC::Ref<FontFace> FontFace::construct_impl(JS::Realm& realm, String family, Font
|
|||
Vector<CSS::ParsedFontFace::Source> sources;
|
||||
ByteBuffer buffer;
|
||||
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();
|
||||
if (sources.is_empty())
|
||||
WebIDL::reject_promise(realm, promise, WebIDL::SyntaxError::create(realm, "FontFace constructor: Invalid source string"_string));
|
||||
|
@ -206,7 +206,7 @@ GC::Ref<WebIDL::Promise> FontFace::loaded() const
|
|||
// https://drafts.csswg.org/css-font-loading/#dom-fontface-family
|
||||
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)
|
||||
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
|
||||
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)
|
||||
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
|
||||
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)
|
||||
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)
|
||||
{
|
||||
// NOTE: font-stretch is now an alias for font-width
|
||||
auto property = parse_css_value(Parser::ParsingContext(), string, CSS::PropertyID::FontWidth);
|
||||
auto property = parse_css_value(Parser::ParsingParams(), string, CSS::PropertyID::FontWidth);
|
||||
if (!property)
|
||||
return WebIDL::SyntaxError::create(realm(), "FontFace.stretch setter: Invalid font descriptor"_string);
|
||||
|
||||
|
|
|
@ -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&)
|
||||
{
|
||||
// 1. Parse font using the CSS value syntax of the font property. If a syntax error occurs, return a syntax error.
|
||||
auto property = parse_css_value(CSS::Parser::ParsingContext(), font, PropertyID::Font);
|
||||
auto property = parse_css_value(CSS::Parser::ParsingParams(), font, PropertyID::Font);
|
||||
if (!property)
|
||||
return WebIDL::SyntaxError::create(realm, "Unable to parse font"_string);
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ void MediaList::set_media_text(StringView text)
|
|||
m_media.clear();
|
||||
if (text.is_empty())
|
||||
return;
|
||||
m_media = parse_media_query_list(Parser::ParsingContext { realm() }, text);
|
||||
m_media = parse_media_query_list(Parser::ParsingParams { realm() }, text);
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/cssom-1/#dom-medialist-item
|
||||
|
@ -61,7 +61,7 @@ Optional<String> MediaList::item(u32 index) const
|
|||
void MediaList::append_medium(StringView medium)
|
||||
{
|
||||
// 1. Let m be the result of parsing the given value.
|
||||
auto m = parse_media_query(Parser::ParsingContext { realm() }, medium);
|
||||
auto m = parse_media_query(Parser::ParsingParams { realm() }, medium);
|
||||
|
||||
// 2. If m is null, then return.
|
||||
if (!m)
|
||||
|
@ -81,7 +81,7 @@ void MediaList::append_medium(StringView medium)
|
|||
// https://www.w3.org/TR/cssom-1/#dom-medialist-deletemedium
|
||||
void MediaList::delete_medium(StringView medium)
|
||||
{
|
||||
auto m = parse_media_query(Parser::ParsingContext { realm() }, medium);
|
||||
auto m = parse_media_query(Parser::ParsingParams { realm() }, medium);
|
||||
if (!m)
|
||||
return;
|
||||
m_media.remove_all_matching([&](auto& existing) -> bool {
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
|
||||
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()) {
|
||||
auto rule_list = CSS::CSSRuleList::create_empty(context.realm());
|
||||
auto media_list = CSS::MediaList::create(context.realm(), {});
|
||||
auto style_sheet = CSS::CSSStyleSheet::create(context.realm(), rule_list, media_list, location);
|
||||
auto rule_list = CSS::CSSRuleList::create_empty(*context.realm);
|
||||
auto media_list = CSS::MediaList::create(*context.realm, {});
|
||||
auto style_sheet = CSS::CSSStyleSheet::create(*context.realm, rule_list, media_list, location);
|
||||
style_sheet->set_source_text({});
|
||||
return style_sheet;
|
||||
}
|
||||
|
@ -30,31 +30,31 @@ CSS::CSSStyleSheet* parse_css_stylesheet(CSS::Parser::ParsingContext const& cont
|
|||
return style_sheet;
|
||||
}
|
||||
|
||||
CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingContext const& context, StringView css, DOM::Element& element)
|
||||
CSS::ElementInlineCSSStyleDeclaration* parse_css_style_attribute(CSS::Parser::ParsingParams const& context, StringView css, DOM::Element& element)
|
||||
{
|
||||
if (css.is_empty())
|
||||
return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {});
|
||||
return CSS::Parser::Parser::create(context, css).parse_as_style_attribute(element);
|
||||
}
|
||||
|
||||
RefPtr<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())
|
||||
return nullptr;
|
||||
return CSS::Parser::Parser::create(context, string).parse_as_css_value(property_id);
|
||||
}
|
||||
|
||||
CSS::CSSRule* parse_css_rule(CSS::Parser::ParsingContext const& context, StringView css_text)
|
||||
CSS::CSSRule* parse_css_rule(CSS::Parser::ParsingParams const& context, StringView css_text)
|
||||
{
|
||||
return CSS::Parser::Parser::create(context, css_text).parse_as_css_rule();
|
||||
}
|
||||
|
||||
Optional<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();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
@ -65,29 +65,29 @@ Optional<CSS::SelectorList> parse_selector_for_nested_style_rule(CSS::Parser::Pa
|
|||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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())
|
||||
return {};
|
||||
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())
|
||||
return {};
|
||||
|
|
|
@ -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_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) {
|
||||
child.visit(
|
||||
[&](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.");
|
||||
return;
|
||||
}
|
||||
child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration));
|
||||
child_rules.append(CSSNestedDeclarations::create(realm(), *declaration));
|
||||
});
|
||||
}
|
||||
auto rule_list = CSSRuleList::create(m_context.realm(), child_rules);
|
||||
return CSSMediaRule::create(m_context.realm(), media_list, rule_list);
|
||||
auto rule_list = CSSRuleList::create(realm(), child_rules);
|
||||
return CSSMediaRule::create(realm(), media_list, rule_list);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include <LibWeb/CSS/PropertyName.h>
|
||||
#include <LibWeb/CSS/Sizing.h>
|
||||
#include <LibWeb/CSS/StyleComputer.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||
|
||||
|
@ -30,14 +31,51 @@ static void log_parse_error(SourceLocation const& location = SourceLocation::cur
|
|||
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
Parser Parser::create(ParsingContext const& context, StringView input, StringView encoding)
|
||||
ParsingParams::ParsingParams(ParsingMode mode)
|
||||
: mode(mode)
|
||||
{
|
||||
}
|
||||
|
||||
ParsingParams::ParsingParams(JS::Realm& realm, ParsingMode mode)
|
||||
: realm(realm)
|
||||
, mode(mode)
|
||||
{
|
||||
}
|
||||
|
||||
ParsingParams::ParsingParams(JS::Realm& realm, URL::URL url, ParsingMode mode)
|
||||
: realm(realm)
|
||||
, url(move(url))
|
||||
, mode(mode)
|
||||
{
|
||||
}
|
||||
|
||||
ParsingParams::ParsingParams(DOM::Document const& document, URL::URL url, ParsingMode mode)
|
||||
: realm(const_cast<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);
|
||||
return Parser { context, move(tokens) };
|
||||
}
|
||||
|
||||
Parser::Parser(ParsingContext const& context, Vector<Token> tokens)
|
||||
: m_context(context)
|
||||
Parser::Parser(ParsingParams const& context, Vector<Token> tokens)
|
||||
: m_document(context.document)
|
||||
, m_realm(context.realm)
|
||||
, m_url(context.url)
|
||||
, m_parsing_mode(context.mode)
|
||||
, m_tokens(move(tokens))
|
||||
, m_token_stream(m_tokens)
|
||||
{
|
||||
|
@ -84,7 +122,7 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<URL::URL> location)
|
|||
auto const& style_sheet = parse_a_stylesheet(m_token_stream, {});
|
||||
|
||||
// Interpret all of the resulting top-level qualified rules as style rules, defined below.
|
||||
GC::RootVector<CSSRule*> rules(m_context.realm().heap());
|
||||
GC::RootVector<CSSRule*> rules(realm().heap());
|
||||
for (auto const& raw_rule : style_sheet.rules) {
|
||||
auto rule = convert_to_rule(raw_rule, Nested::No);
|
||||
// If any style rule is invalid, or any at-rule is not recognized or is invalid according to its grammar or context, it’s a parse error.
|
||||
|
@ -96,9 +134,9 @@ CSSStyleSheet* Parser::parse_as_css_stylesheet(Optional<URL::URL> location)
|
|||
rules.append(rule);
|
||||
}
|
||||
|
||||
auto rule_list = CSSRuleList::create(m_context.realm(), rules);
|
||||
auto media_list = MediaList::create(m_context.realm(), {});
|
||||
return CSSStyleSheet::create(m_context.realm(), rule_list, media_list, move(location));
|
||||
auto rule_list = CSSRuleList::create(realm(), rules);
|
||||
auto media_list = MediaList::create(realm(), {});
|
||||
return CSSStyleSheet::create(realm(), rule_list, media_list, move(location));
|
||||
}
|
||||
|
||||
RefPtr<Supports> Parser::parse_as_supports()
|
||||
|
@ -116,7 +154,7 @@ RefPtr<Supports> Parser::parse_a_supports(TokenStream<T>& tokens)
|
|||
m_rule_context.take_last();
|
||||
token_stream.discard_whitespace();
|
||||
if (maybe_condition && !token_stream.has_next_token())
|
||||
return Supports::create(m_context.realm(), maybe_condition.release_nonnull());
|
||||
return Supports::create(realm(), maybe_condition.release_nonnull());
|
||||
|
||||
return {};
|
||||
}
|
||||
|
@ -1413,7 +1451,7 @@ PropertyOwningCSSStyleDeclaration* Parser::convert_to_style_declaration(Vector<D
|
|||
for (auto const& declaration : declarations) {
|
||||
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)
|
||||
|
@ -1462,7 +1500,7 @@ Optional<LengthOrCalculated> Parser::parse_source_size_value(TokenStream<Compone
|
|||
|
||||
bool Parser::context_allows_quirky_length() const
|
||||
{
|
||||
if (!m_context.in_quirks_mode())
|
||||
if (!in_quirks_mode())
|
||||
return false;
|
||||
|
||||
// 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.
|
||||
TokenStream<ComponentValue> token_stream { unparsed_size };
|
||||
auto media_condition = parse_media_condition(token_stream, MediaCondition::AllowOr::Yes);
|
||||
auto const* context_window = m_context.window();
|
||||
auto const* context_window = window();
|
||||
if (!media_condition || (context_window && media_condition->evaluate(*context_window) == MatchResult::False)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -1693,4 +1731,39 @@ template Vector<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<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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
|
@ -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 };
|
||||
};
|
||||
|
||||
}
|
|
@ -108,7 +108,7 @@ GC::Ptr<CSSStyleRule> Parser::convert_to_style_rule(QualifiedRule const& qualifi
|
|||
return {};
|
||||
}
|
||||
|
||||
GC::RootVector<CSSRule*> child_rules { m_context.realm().heap() };
|
||||
GC::RootVector<CSSRule*> child_rules { realm().heap() };
|
||||
for (auto& child : qualified_rule.child_rules) {
|
||||
child.visit(
|
||||
[&](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.");
|
||||
return;
|
||||
}
|
||||
child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration));
|
||||
child_rules.append(CSSNestedDeclarations::create(realm(), *declaration));
|
||||
});
|
||||
}
|
||||
auto nested_rules = CSSRuleList::create(m_context.realm(), move(child_rules));
|
||||
return CSSStyleRule::create(m_context.realm(), move(selectors), *declaration, *nested_rules);
|
||||
auto nested_rules = CSSRuleList::create(realm(), move(child_rules));
|
||||
return CSSStyleRule::create(realm(), move(selectors), *declaration, *nested_rules);
|
||||
}
|
||||
|
||||
GC::Ptr<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);
|
||||
if (!url.has_value() && tokens.next_token().is(Token::Type::String))
|
||||
url = m_context.complete_url(tokens.consume_a_token().token().string());
|
||||
url = complete_url(tokens.consume_a_token().token().string());
|
||||
|
||||
if (!url.has_value()) {
|
||||
dbgln_if(CSS_PARSER_DEBUG, "Failed to parse @import rule: Unable to parse `{}` as URL.", tokens.next_token().to_debug_string());
|
||||
|
@ -178,7 +178,7 @@ GC::Ptr<CSSImportRule> Parser::convert_to_import_rule(AtRule const& rule)
|
|||
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)
|
||||
|
@ -247,7 +247,7 @@ GC::Ptr<CSSRule> Parser::convert_to_layer_rule(AtRule const& rule, Nested nested
|
|||
}
|
||||
|
||||
// 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) {
|
||||
child.visit(
|
||||
[&](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.");
|
||||
return;
|
||||
}
|
||||
child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration));
|
||||
child_rules.append(CSSNestedDeclarations::create(realm(), *declaration));
|
||||
});
|
||||
}
|
||||
auto rule_list = CSSRuleList::create(m_context.realm(), child_rules);
|
||||
return CSSLayerBlockRule::create(m_context.realm(), layer_name, rule_list);
|
||||
auto rule_list = CSSRuleList::create(realm(), child_rules);
|
||||
return CSSLayerBlockRule::create(realm(), layer_name, rule_list);
|
||||
}
|
||||
|
||||
// CSSLayerStatementRule
|
||||
|
@ -296,7 +296,7 @@ GC::Ptr<CSSRule> Parser::convert_to_layer_rule(AtRule const& rule, Nested nested
|
|||
return {};
|
||||
}
|
||||
|
||||
return CSSLayerStatementRule::create(m_context.realm(), move(layer_names));
|
||||
return CSSLayerStatementRule::create(realm(), move(layer_names));
|
||||
}
|
||||
|
||||
GC::Ptr<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();
|
||||
|
||||
GC::RootVector<CSSRule*> keyframes(m_context.realm().heap());
|
||||
GC::RootVector<CSSRule*> keyframes(realm().heap());
|
||||
rule.for_each_as_qualified_rule_list([&](auto& qualified_rule) {
|
||||
if (!qualified_rule.child_rules.is_empty()) {
|
||||
dbgln_if(CSS_PARSER_DEBUG, "CSSParser: @keyframes keyframe rule contains at-rules; discarding them.");
|
||||
|
@ -390,14 +390,14 @@ GC::Ptr<CSSKeyframesRule> Parser::convert_to_keyframes_rule(AtRule const& rule)
|
|||
qualified_rule.for_each_as_declaration_list([&](auto const& declaration) {
|
||||
extract_property(declaration, properties);
|
||||
});
|
||||
auto style = PropertyOwningCSSStyleDeclaration::create(m_context.realm(), move(properties.properties), move(properties.custom_properties));
|
||||
auto style = PropertyOwningCSSStyleDeclaration::create(realm(), move(properties.properties), move(properties.custom_properties));
|
||||
for (auto& selector : selectors) {
|
||||
auto keyframe_rule = CSSKeyframeRule::create(m_context.realm(), selector, *style);
|
||||
auto keyframe_rule = CSSKeyframeRule::create(realm(), selector, *style);
|
||||
keyframes.append(keyframe_rule);
|
||||
}
|
||||
});
|
||||
|
||||
return CSSKeyframesRule::create(m_context.realm(), name, CSSRuleList::create(m_context.realm(), move(keyframes)));
|
||||
return CSSKeyframesRule::create(realm(), name, CSSRuleList::create(realm(), move(keyframes)));
|
||||
}
|
||||
|
||||
GC::Ptr<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 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)
|
||||
|
@ -469,7 +469,7 @@ GC::Ptr<CSSSupportsRule> Parser::convert_to_supports_rule(AtRule const& rule, Ne
|
|||
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) {
|
||||
child.visit(
|
||||
[&](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.");
|
||||
return;
|
||||
}
|
||||
child_rules.append(CSSNestedDeclarations::create(m_context.realm(), *declaration));
|
||||
child_rules.append(CSSNestedDeclarations::create(realm(), *declaration));
|
||||
});
|
||||
}
|
||||
|
||||
auto rule_list = CSSRuleList::create(m_context.realm(), child_rules);
|
||||
return CSSSupportsRule::create(m_context.realm(), supports.release_nonnull(), rule_list);
|
||||
auto rule_list = CSSRuleList::create(realm(), child_rules);
|
||||
return CSSSupportsRule::create(realm(), supports.release_nonnull(), rule_list);
|
||||
}
|
||||
|
||||
GC::Ptr<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()) {
|
||||
return CSSPropertyRule::create(m_context.realm(), name, syntax_maybe.value(), inherits_maybe.value(), std::move(initial_value_maybe));
|
||||
return CSSPropertyRule::create(realm(), name, syntax_maybe.value(), inherits_maybe.value(), std::move(initial_value_maybe));
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
@ -976,7 +976,7 @@ GC::Ptr<CSSFontFaceRule> Parser::convert_to_font_face_rule(AtRule const& rule)
|
|||
unicode_range.empend(0x0u, 0x10FFFFu);
|
||||
}
|
||||
|
||||
return CSSFontFaceRule::create(m_context.realm(), ParsedFontFace { font_family.release_value(), move(weight), move(slope), move(width), move(src), move(unicode_range), move(ascent_override), move(descent_override), move(line_gap_override), font_display, move(font_named_instance), move(language_override), move(font_feature_settings), move(font_variation_settings) });
|
||||
return CSSFontFaceRule::create(realm(), ParsedFontFace { font_family.release_value(), move(weight), move(slope), move(width), move(src), move(unicode_range), move(ascent_override), move(descent_override), move(line_gap_override), font_display, move(font_named_instance), move(language_override), move(font_feature_settings), move(font_variation_settings) });
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -52,6 +52,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
||||
#include <LibWeb/DOM/Element.h>
|
||||
#include <LibWeb/Dump.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.
|
||||
// FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792
|
||||
// For now: Convert to an angle in degrees.
|
||||
if (tokens.next_token().is(Token::Type::Number) && m_context.is_parsing_svg_presentation_attribute()) {
|
||||
if (tokens.next_token().is(Token::Type::Number) && is_parsing_svg_presentation_attribute()) {
|
||||
auto numeric_value = tokens.consume_a_token().token().number_value();
|
||||
return AngleStyleValue::create(Angle::make_degrees(numeric_value));
|
||||
}
|
||||
|
@ -693,7 +694,7 @@ RefPtr<CSSStyleValue> Parser::parse_angle_percentage_value(TokenStream<Component
|
|||
// When parsing an SVG attribute, an angle is allowed without a unit.
|
||||
// FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792
|
||||
// For now: Convert to an angle in degrees.
|
||||
if (tokens.next_token().is(Token::Type::Number) && m_context.is_parsing_svg_presentation_attribute()) {
|
||||
if (tokens.next_token().is(Token::Type::Number) && is_parsing_svg_presentation_attribute()) {
|
||||
auto numeric_value = tokens.consume_a_token().token().number_value();
|
||||
return AngleStyleValue::create(Angle::make_degrees(numeric_value));
|
||||
}
|
||||
|
@ -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.
|
||||
// FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792
|
||||
// For now: Convert to a length in pixels.
|
||||
if (m_context.is_parsing_svg_presentation_attribute()) {
|
||||
if (is_parsing_svg_presentation_attribute()) {
|
||||
transaction.commit();
|
||||
return LengthStyleValue::create(Length::make_px(CSSPixels::nearest_value_for(numeric_value)));
|
||||
}
|
||||
|
@ -852,7 +853,7 @@ RefPtr<CSSStyleValue> Parser::parse_length_percentage_value(TokenStream<Componen
|
|||
// When parsing an SVG attribute, a length is allowed without a unit.
|
||||
// FIXME: How should these numbers be interpreted? https://github.com/w3c/svgwg/issues/792
|
||||
// For now: Convert to a length in pixels.
|
||||
if (m_context.is_parsing_svg_presentation_attribute()) {
|
||||
if (is_parsing_svg_presentation_attribute()) {
|
||||
transaction.commit();
|
||||
return LengthStyleValue::create(Length::make_px(CSSPixels::nearest_value_for(numeric_value)));
|
||||
}
|
||||
|
@ -1696,7 +1697,7 @@ RefPtr<CSSStyleValue> Parser::parse_color_value(TokenStream<ComponentValue>& tok
|
|||
}
|
||||
|
||||
// https://drafts.csswg.org/css-color-4/#quirky-color
|
||||
if (m_context.in_quirks_mode()) {
|
||||
if (in_quirks_mode()) {
|
||||
// "When CSS is being parsed in quirks mode, <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)
|
||||
// "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 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()) {
|
||||
transaction.commit();
|
||||
return url;
|
||||
|
@ -3510,7 +3511,7 @@ RefPtr<StringStyleValue> Parser::parse_opentype_tag_value(TokenStream<ComponentV
|
|||
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
|
||||
// to produce a different CSSStyleValue from it.
|
||||
|
|
|
@ -307,7 +307,7 @@ static CSSStyleSheet& default_stylesheet(DOM::Document const& document)
|
|||
static GC::Root<CSSStyleSheet> sheet;
|
||||
if (!sheet.cell()) {
|
||||
extern String default_stylesheet_source;
|
||||
sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document), default_stylesheet_source));
|
||||
sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document), default_stylesheet_source));
|
||||
}
|
||||
return *sheet;
|
||||
}
|
||||
|
@ -317,7 +317,7 @@ static CSSStyleSheet& quirks_mode_stylesheet(DOM::Document const& document)
|
|||
static GC::Root<CSSStyleSheet> sheet;
|
||||
if (!sheet.cell()) {
|
||||
extern String quirks_mode_stylesheet_source;
|
||||
sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document), quirks_mode_stylesheet_source));
|
||||
sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document), quirks_mode_stylesheet_source));
|
||||
}
|
||||
return *sheet;
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ static CSSStyleSheet& mathml_stylesheet(DOM::Document const& document)
|
|||
static GC::Root<CSSStyleSheet> sheet;
|
||||
if (!sheet.cell()) {
|
||||
extern String mathml_stylesheet_source;
|
||||
sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document), mathml_stylesheet_source));
|
||||
sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document), mathml_stylesheet_source));
|
||||
}
|
||||
return *sheet;
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ static CSSStyleSheet& svg_stylesheet(DOM::Document const& document)
|
|||
static GC::Root<CSSStyleSheet> sheet;
|
||||
if (!sheet.cell()) {
|
||||
extern String svg_stylesheet_source;
|
||||
sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingContext(document), svg_stylesheet_source));
|
||||
sheet = GC::make_root(parse_css_stylesheet(CSS::Parser::ParsingParams(document), svg_stylesheet_source));
|
||||
}
|
||||
return *sheet;
|
||||
}
|
||||
|
@ -1009,7 +1009,7 @@ void StyleComputer::set_all_properties(
|
|||
|
||||
NonnullRefPtr<CSSStyleValue> property_value = value;
|
||||
if (property_value->is_unresolved())
|
||||
property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { document }, element, pseudo_element, property_id, property_value->as_unresolved());
|
||||
property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { document }, element, pseudo_element, property_id, property_value->as_unresolved());
|
||||
if (!property_value->is_unresolved())
|
||||
set_property_expanding_shorthands(cascaded_properties, property_id, property_value, declaration, cascade_origin, important, layer_name);
|
||||
|
||||
|
@ -1038,7 +1038,7 @@ void StyleComputer::cascade_declarations(
|
|||
|
||||
auto property_value = property.value;
|
||||
if (property.value->is_unresolved())
|
||||
property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { document() }, element, pseudo_element, property.property_id, property.value->as_unresolved());
|
||||
property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { document() }, element, pseudo_element, property.property_id, property.value->as_unresolved());
|
||||
if (!property_value->is_unresolved())
|
||||
set_property_expanding_shorthands(cascaded_properties, property.property_id, property_value, &match->declaration(), cascade_origin, important, layer_name);
|
||||
}
|
||||
|
@ -1057,7 +1057,7 @@ void StyleComputer::cascade_declarations(
|
|||
|
||||
auto property_value = property.value;
|
||||
if (property.value->is_unresolved())
|
||||
property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { document() }, element, pseudo_element, property.property_id, property.value->as_unresolved());
|
||||
property_value = Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { document() }, element, pseudo_element, property.property_id, property.value->as_unresolved());
|
||||
if (!property_value->is_unresolved())
|
||||
set_property_expanding_shorthands(cascaded_properties, property.property_id, property_value, inline_style, cascade_origin, important, layer_name);
|
||||
}
|
||||
|
@ -1157,7 +1157,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
|
|||
if (value->is_revert() || value->is_revert_layer())
|
||||
return computed_properties.property(it.key);
|
||||
if (value->is_unresolved())
|
||||
return Parser::Parser::resolve_unresolved_style_value(Parser::ParsingContext { element.document() }, element, pseudo_element, it.key, value->as_unresolved());
|
||||
return Parser::Parser::resolve_unresolved_style_value(Parser::ParsingParams { element.document() }, element, pseudo_element, it.key, value->as_unresolved());
|
||||
return value;
|
||||
});
|
||||
};
|
||||
|
@ -2974,7 +2974,7 @@ void StyleComputer::build_rule_cache()
|
|||
m_style_invalidation_data = make<StyleInvalidationData>();
|
||||
|
||||
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();
|
||||
|
|
|
@ -59,13 +59,13 @@ bool Supports::InParens::evaluate(JS::Realm& realm) const
|
|||
|
||||
bool Supports::Declaration::evaluate(JS::Realm& realm) const
|
||||
{
|
||||
auto style_property = parse_css_supports_condition(Parser::ParsingContext { realm }, declaration);
|
||||
auto style_property = parse_css_supports_condition(Parser::ParsingParams { realm }, declaration);
|
||||
return style_property.has_value();
|
||||
}
|
||||
|
||||
bool Supports::Selector::evaluate(JS::Realm& realm) const
|
||||
{
|
||||
auto style_property = parse_selector(Parser::ParsingContext { realm }, selector);
|
||||
auto style_property = parse_selector(Parser::ParsingParams { realm }, selector);
|
||||
return style_property.has_value();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue