LibWeb: Stop passing Realm unnecessarily to parse CSS properties

Also use the parse_css_value() helper in cases where we previously
constructed a Parser manually.
This commit is contained in:
Sam Atkins 2024-12-05 11:52:43 +00:00 committed by Alexander Kalenik
commit bc77f84359
Notes: github-actions[bot] 2024-12-05 19:00:42 +00:00
11 changed files with 20 additions and 46 deletions

View file

@ -26,19 +26,16 @@ public:
void set_fill_style(FillOrStrokeStyleVariant style)
{
auto& realm = static_cast<IncludingClass&>(*this).realm();
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-fillstyle
style.visit(
// 1. If the given value is a string, then:
[&](String const& string) {
// 1. Let context be this's canvas attribute's value, if that is an element; otherwise null.
auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), string);
// 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 = parser.parse_as_css_value(CSS::PropertyID::Color);
auto style_value = parse_css_value(CSS::Parser::ParsingContext(), string, CSS::PropertyID::Color);
if (style_value && style_value->has_color()) {
auto parsedValue = style_value->to_color(OptionalNone());
@ -67,20 +64,17 @@ public:
void set_stroke_style(FillOrStrokeStyleVariant style)
{
auto& realm = static_cast<IncludingClass&>(*this).realm();
// https://html.spec.whatwg.org/multipage/canvas.html#dom-context-2d-strokestyle
style.visit(
// 1. If the given value is a string, then:
[&](String const& string) {
// 1. Let context be this's canvas attribute's value, if that is an element; otherwise null.
auto parser = CSS::Parser::Parser::create(CSS::Parser::ParsingContext(realm), string);
// 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 = parser.parse_as_css_value(CSS::PropertyID::Color);
auto style_value = parse_css_value(CSS::Parser::ParsingContext(), string, CSS::PropertyID::Color);
if (style_value && style_value->has_color()) {
auto parsedValue = style_value->to_color(OptionalNone());

View file

@ -43,8 +43,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 parsing_context = CSS::Parser::ParsingContext { reinterpret_cast<IncludingClass&>(*this).realm() };
auto font_style_value_result = parse_css_value(parsing_context, font, CSS::PropertyID::Font);
auto font_style_value_result = parse_css_value(CSS::Parser::ParsingContext {}, 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.