mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-09 17:49:40 +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
|
@ -35,7 +35,7 @@ public:
|
|||
// 2. Let parsedValue be the result of parsing the given value with context if non-null.
|
||||
// FIXME: Parse a color value
|
||||
// https://drafts.csswg.org/css-color/#parse-a-css-color-value
|
||||
auto style_value = parse_css_value(CSS::Parser::ParsingContext(), string, CSS::PropertyID::Color);
|
||||
auto style_value = parse_css_value(CSS::Parser::ParsingParams(), string, CSS::PropertyID::Color);
|
||||
if (style_value && style_value->has_color()) {
|
||||
auto parsedValue = style_value->to_color(OptionalNone());
|
||||
|
||||
|
@ -74,7 +74,7 @@ public:
|
|||
// 2. Let parsedValue be the result of parsing the given value with context if non-null.
|
||||
// FIXME: Parse a color value
|
||||
// https://drafts.csswg.org/css-color/#parse-a-css-color-value
|
||||
auto style_value = parse_css_value(CSS::Parser::ParsingContext(), string, CSS::PropertyID::Color);
|
||||
auto style_value = parse_css_value(CSS::Parser::ParsingParams(), string, CSS::PropertyID::Color);
|
||||
if (style_value && style_value->has_color()) {
|
||||
auto parsedValue = style_value->to_color(OptionalNone());
|
||||
|
||||
|
|
|
@ -47,7 +47,7 @@ public:
|
|||
// and with system fonts being computed to explicit values.
|
||||
// FIXME: with the 'line-height' component forced to 'normal'
|
||||
// FIXME: with the 'font-size' component converted to CSS pixels
|
||||
auto font_style_value_result = parse_css_value(CSS::Parser::ParsingContext {}, font, CSS::PropertyID::Font);
|
||||
auto font_style_value_result = parse_css_value(CSS::Parser::ParsingParams {}, font, CSS::PropertyID::Font);
|
||||
|
||||
// If the new value is syntactically incorrect (including using property-independent style sheet syntax like 'inherit' or 'initial'), then it must be ignored, without assigning a new font value.
|
||||
// NOTE: ShorthandStyleValue should be the only valid option here. We implicitly VERIFY this below.
|
||||
|
|
|
@ -863,7 +863,7 @@ void CanvasRenderingContext2D::set_shadow_color(String color)
|
|||
// 1. Let context be this's canvas attribute's value, if that is an element; otherwise null.
|
||||
|
||||
// 2. Let parsedValue be the result of parsing the given value with context if non-null.
|
||||
auto style_value = parse_css_value(CSS::Parser::ParsingContext(), color, CSS::PropertyID::Color);
|
||||
auto style_value = parse_css_value(CSS::Parser::ParsingParams(), color, CSS::PropertyID::Color);
|
||||
if (style_value && style_value->has_color()) {
|
||||
auto parsedValue = style_value->to_color(OptionalNone());
|
||||
|
||||
|
@ -944,7 +944,7 @@ void CanvasRenderingContext2D::set_filter(String filter)
|
|||
}
|
||||
|
||||
auto& realm = static_cast<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>.
|
||||
// If any property-independent style sheet syntax like 'inherit' or 'initial' is present,
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/ComputedProperties.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/Parser/ParsingContext.h>
|
||||
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
|
||||
#include <LibWeb/HTML/HTMLFontElement.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);
|
||||
if (font_size_or_empty.has_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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1130,7 +1130,7 @@ static void update_the_source_set(DOM::Element& element)
|
|||
|
||||
// 6. If child has a media attribute, and its value does not match the environment, continue to the next child.
|
||||
if (child->has_attribute(HTML::AttributeNames::media)) {
|
||||
auto media_query = parse_media_query(CSS::Parser::ParsingContext { element.document() },
|
||||
auto media_query = parse_media_query(CSS::Parser::ParsingParams { element.document() },
|
||||
child->get_attribute_value(HTML::AttributeNames::media));
|
||||
if (!media_query || !element.document().window() || !media_query->evaluate(*element.document().window())) {
|
||||
continue;
|
||||
|
|
|
@ -441,7 +441,7 @@ void HTMLLinkElement::process_stylesheet_resource(bool success, Fetch::Infrastru
|
|||
dispatch_event(*DOM::Event::create(realm(), HTML::EventNames::error));
|
||||
} else {
|
||||
auto const decoded_string = maybe_decoded_string.release_value();
|
||||
m_loaded_style_sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(document(), *response.url()), decoded_string);
|
||||
m_loaded_style_sheet = parse_css_stylesheet(CSS::Parser::ParsingParams(document(), *response.url()), decoded_string);
|
||||
|
||||
if (m_loaded_style_sheet) {
|
||||
Optional<String> location;
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
#include <LibWeb/Bindings/HTMLMetaElementPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/Parser/ParsingContext.h>
|
||||
#include <LibWeb/CSS/PropertyID.h>
|
||||
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ColorSchemeStyleValue.h>
|
||||
|
|
|
@ -62,7 +62,7 @@ void HTMLTableCellElement::apply_presentational_hints(GC::Ref<CSS::CascadedPrope
|
|||
return;
|
||||
}
|
||||
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());
|
||||
return;
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ void HTMLTableCellElement::apply_presentational_hints(GC::Ref<CSS::CascadedPrope
|
|||
} 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));
|
||||
} else {
|
||||
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::TextAlign))
|
||||
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::TextAlign))
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::TextAlign, parsed_value.release_nonnull());
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -85,7 +85,7 @@ void HTMLTableElement::apply_presentational_hints(GC::Ref<CSS::CascadedPropertie
|
|||
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::MarginRight, CSS::CSSKeywordValue::create(CSS::Keyword::Auto));
|
||||
} else if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::Float)) {
|
||||
} else if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::Float)) {
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Float, parsed_value.release_nonnull());
|
||||
}
|
||||
return;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/ComputedProperties.h>
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/CSS/Parser/ParsingContext.h>
|
||||
#include <LibWeb/CSS/StyleValues/CSSColorValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/CSSKeywordValue.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))
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, *parsed_value);
|
||||
} else if (name == HTML::AttributeNames::valign) {
|
||||
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingContext { document() }, value, CSS::PropertyID::VerticalAlign))
|
||||
if (auto parsed_value = parse_css_value(CSS::Parser::ParsingParams { document() }, value, CSS::PropertyID::VerticalAlign))
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::VerticalAlign, parsed_value.release_nonnull());
|
||||
}
|
||||
});
|
||||
|
|
|
@ -341,7 +341,7 @@ descriptor_parser:
|
|||
// https://html.spec.whatwg.org/multipage/images.html#parse-a-sizes-attribute
|
||||
CSS::LengthOrCalculated parse_a_sizes_attribute(DOM::Element const& element, StringView sizes, HTML::HTMLImageElement const* img)
|
||||
{
|
||||
auto css_parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext { element.document() }, sizes);
|
||||
auto css_parser = CSS::Parser::Parser::create(CSS::Parser::ParsingParams { element.document() }, sizes);
|
||||
return css_parser.parse_as_sizes_attribute(element, img);
|
||||
}
|
||||
|
||||
|
|
|
@ -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:
|
||||
if (pseudo_element.has_value() && pseudo_element.value().starts_with(':')) {
|
||||
// 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.
|
||||
// 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)
|
||||
{
|
||||
// 1. Let parsed media query list be the result of parsing query.
|
||||
auto parsed_media_query_list = parse_media_query_list(CSS::Parser::ParsingContext(associated_document()), query);
|
||||
auto parsed_media_query_list = parse_media_query_list(CSS::Parser::ParsingParams(associated_document()), query);
|
||||
|
||||
// 2. Return a new MediaQueryList object, with this's associated Document as the document, with parsed media query list as its associated media query list.
|
||||
auto media_query_list = realm().create<CSS::MediaQueryList>(associated_document(), move(parsed_media_query_list));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue