LibWeb: Remove Realm parameter from property_initial_value()

We don't need the Realm to parse a style value.

Fixes #2720
This commit is contained in:
Sam Atkins 2024-12-05 10:58:21 +00:00 committed by Alexander Kalenik
commit 2c3c821305
Notes: github-actions[bot] 2024-12-05 19:00:55 +00:00
7 changed files with 58 additions and 61 deletions

View file

@ -46,7 +46,7 @@ static NonnullRefPtr<CSSStyleValue const> with_keyword_values_resolved(DOM::Elem
switch (value.as_keyword().keyword()) {
case CSS::Keyword::Initial:
case CSS::Keyword::Unset:
return property_initial_value(element.realm(), property_id);
return property_initial_value(property_id);
case CSS::Keyword::Inherit:
return CSS::StyleComputer::get_inherit_value(element.realm(), property_id, &element);
default:

View file

@ -4306,14 +4306,14 @@ RefPtr<CSSStyleValue> Parser::parse_background_value(TokenStream<ComponentValue>
StyleValueVector background_origins;
RefPtr<CSSStyleValue> background_color;
auto initial_background_image = property_initial_value(m_context.realm(), PropertyID::BackgroundImage);
auto initial_background_position = property_initial_value(m_context.realm(), PropertyID::BackgroundPosition);
auto initial_background_size = property_initial_value(m_context.realm(), PropertyID::BackgroundSize);
auto initial_background_repeat = property_initial_value(m_context.realm(), PropertyID::BackgroundRepeat);
auto initial_background_attachment = property_initial_value(m_context.realm(), PropertyID::BackgroundAttachment);
auto initial_background_clip = property_initial_value(m_context.realm(), PropertyID::BackgroundClip);
auto initial_background_origin = property_initial_value(m_context.realm(), PropertyID::BackgroundOrigin);
auto initial_background_color = property_initial_value(m_context.realm(), PropertyID::BackgroundColor);
auto initial_background_image = property_initial_value(PropertyID::BackgroundImage);
auto initial_background_position = property_initial_value(PropertyID::BackgroundPosition);
auto initial_background_size = property_initial_value(PropertyID::BackgroundSize);
auto initial_background_repeat = property_initial_value(PropertyID::BackgroundRepeat);
auto initial_background_attachment = property_initial_value(PropertyID::BackgroundAttachment);
auto initial_background_clip = property_initial_value(PropertyID::BackgroundClip);
auto initial_background_origin = property_initial_value(PropertyID::BackgroundOrigin);
auto initial_background_color = property_initial_value(PropertyID::BackgroundColor);
// Per-layer values
RefPtr<CSSStyleValue> background_image;
@ -4750,11 +4750,11 @@ RefPtr<CSSStyleValue> Parser::parse_border_value(PropertyID property_id, TokenSt
}
if (!border_width)
border_width = property_initial_value(m_context.realm(), width_property);
border_width = property_initial_value(width_property);
if (!border_style)
border_style = property_initial_value(m_context.realm(), style_property);
border_style = property_initial_value(style_property);
if (!border_color)
border_color = property_initial_value(m_context.realm(), color_property);
border_color = property_initial_value(color_property);
transaction.commit();
return ShorthandStyleValue::create(property_id,
@ -4930,9 +4930,9 @@ RefPtr<CSSStyleValue> Parser::parse_columns_value(TokenStream<ComponentValue>& t
}
if (!column_count)
column_count = property_initial_value(m_context.realm(), PropertyID::ColumnCount);
column_count = property_initial_value(PropertyID::ColumnCount);
if (!column_width)
column_width = property_initial_value(m_context.realm(), PropertyID::ColumnWidth);
column_width = property_initial_value(PropertyID::ColumnWidth);
transaction.commit();
return ShorthandStyleValue::create(PropertyID::Columns,
@ -5650,9 +5650,9 @@ RefPtr<CSSStyleValue> Parser::parse_flex_shorthand_value(TokenStream<ComponentVa
}
if (!flex_grow)
flex_grow = property_initial_value(m_context.realm(), PropertyID::FlexGrow);
flex_grow = property_initial_value(PropertyID::FlexGrow);
if (!flex_shrink)
flex_shrink = property_initial_value(m_context.realm(), PropertyID::FlexShrink);
flex_shrink = property_initial_value(PropertyID::FlexShrink);
if (!flex_basis) {
// NOTE: The spec says that flex-basis should be 0 here, but other engines currently use 0%.
// https://github.com/w3c/csswg-drafts/issues/5742
@ -5692,9 +5692,9 @@ RefPtr<CSSStyleValue> Parser::parse_flex_flow_value(TokenStream<ComponentValue>&
}
if (!flex_direction)
flex_direction = property_initial_value(m_context.realm(), PropertyID::FlexDirection);
flex_direction = property_initial_value(PropertyID::FlexDirection);
if (!flex_wrap)
flex_wrap = property_initial_value(m_context.realm(), PropertyID::FlexWrap);
flex_wrap = property_initial_value(PropertyID::FlexWrap);
transaction.commit();
return ShorthandStyleValue::create(PropertyID::FlexFlow,
@ -5815,15 +5815,15 @@ RefPtr<CSSStyleValue> Parser::parse_font_value(TokenStream<ComponentValue>& toke
return nullptr;
if (!font_style)
font_style = property_initial_value(m_context.realm(), PropertyID::FontStyle);
font_style = property_initial_value(PropertyID::FontStyle);
if (!font_variant)
font_variant = property_initial_value(m_context.realm(), PropertyID::FontVariant);
font_variant = property_initial_value(PropertyID::FontVariant);
if (!font_weight)
font_weight = property_initial_value(m_context.realm(), PropertyID::FontWeight);
font_weight = property_initial_value(PropertyID::FontWeight);
if (!font_width)
font_width = property_initial_value(m_context.realm(), PropertyID::FontWidth);
font_width = property_initial_value(PropertyID::FontWidth);
if (!line_height)
line_height = property_initial_value(m_context.realm(), PropertyID::LineHeight);
line_height = property_initial_value(PropertyID::LineHeight);
transaction.commit();
return ShorthandStyleValue::create(PropertyID::Font,
@ -6229,11 +6229,11 @@ RefPtr<CSSStyleValue> Parser::parse_list_style_value(TokenStream<ComponentValue>
}
if (!list_position)
list_position = property_initial_value(m_context.realm(), PropertyID::ListStylePosition);
list_position = property_initial_value(PropertyID::ListStylePosition);
if (!list_image)
list_image = property_initial_value(m_context.realm(), PropertyID::ListStyleImage);
list_image = property_initial_value(PropertyID::ListStyleImage);
if (!list_type)
list_type = property_initial_value(m_context.realm(), PropertyID::ListStyleType);
list_type = property_initial_value(PropertyID::ListStyleType);
transaction.commit();
return ShorthandStyleValue::create(PropertyID::ListStyle,
@ -6463,13 +6463,13 @@ RefPtr<CSSStyleValue> Parser::parse_text_decoration_value(TokenStream<ComponentV
}
if (!decoration_line)
decoration_line = property_initial_value(m_context.realm(), PropertyID::TextDecorationLine);
decoration_line = property_initial_value(PropertyID::TextDecorationLine);
if (!decoration_thickness)
decoration_thickness = property_initial_value(m_context.realm(), PropertyID::TextDecorationThickness);
decoration_thickness = property_initial_value(PropertyID::TextDecorationThickness);
if (!decoration_style)
decoration_style = property_initial_value(m_context.realm(), PropertyID::TextDecorationStyle);
decoration_style = property_initial_value(PropertyID::TextDecorationStyle);
if (!decoration_color)
decoration_color = property_initial_value(m_context.realm(), PropertyID::TextDecorationColor);
decoration_color = property_initial_value(PropertyID::TextDecorationColor);
transaction.commit();
return ShorthandStyleValue::create(PropertyID::TextDecoration,
@ -8239,7 +8239,7 @@ Parser::ParseErrorOr<NonnullRefPtr<CSSStyleValue>> Parser::parse_css_value(Prope
}
for (auto& property : unassigned_properties)
assigned_values.ensure(to_underlying(property)).append(property_initial_value(m_context.realm(), property));
assigned_values.ensure(to_underlying(property)).append(property_initial_value(property));
stream.discard_whitespace();
if (stream.has_next_token())

View file

@ -934,7 +934,7 @@ void StyleComputer::set_all_properties(DOM::Element& element, Optional<CSS::Sele
} else {
style.set_property(
property_id,
property_initial_value(document.realm(), property_id),
property_initial_value(property_id),
StyleProperties::Inherited::No,
important);
}
@ -1103,7 +1103,7 @@ void StyleComputer::collect_animation_into(DOM::Element& element, Optional<CSS::
auto resolved_end_property = resolve_property(end_property.value());
if (resolved_end_property && !resolved_start_property)
resolved_start_property = CSS::property_initial_value(document().realm(), it.key);
resolved_start_property = property_initial_value(it.key);
if (!resolved_start_property || !resolved_end_property)
continue;
@ -1670,12 +1670,12 @@ DOM::Element const* element_to_inherit_style_from(DOM::Element const* element, O
return parent_element;
}
NonnullRefPtr<CSSStyleValue const> StyleComputer::get_inherit_value(JS::Realm& initial_value_context_realm, CSS::PropertyID property_id, DOM::Element const* element, Optional<CSS::Selector::PseudoElement::Type> pseudo_element)
NonnullRefPtr<CSSStyleValue const> StyleComputer::get_inherit_value([[maybe_unused]] JS::Realm& initial_value_context_realm, CSS::PropertyID property_id, DOM::Element const* element, Optional<CSS::Selector::PseudoElement::Type> pseudo_element)
{
auto* parent_element = element_to_inherit_style_from(element, pseudo_element);
if (!parent_element || !parent_element->computed_css_values().has_value())
return property_initial_value(initial_value_context_realm, property_id);
return property_initial_value(property_id);
return parent_element->computed_css_values()->property(property_id);
}
@ -1692,13 +1692,13 @@ void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM
StyleProperties::Inherited::Yes,
Important::No);
} else {
style.set_property(property_id, property_initial_value(document().realm(), property_id));
style.set_property(property_id, property_initial_value(property_id));
}
return;
}
if (value_slot->is_initial()) {
value_slot = property_initial_value(document().realm(), property_id);
value_slot = property_initial_value(property_id);
return;
}
@ -1717,7 +1717,7 @@ void StyleComputer::compute_defaulted_property_value(StyleProperties& style, DOM
style.set_property_inherited(property_id, StyleProperties::Inherited::Yes);
} else {
// and if it is not, this is treated as initial.
value_slot = property_initial_value(document().realm(), property_id);
value_slot = property_initial_value(property_id);
}
}
}

View file

@ -239,7 +239,7 @@ String ShorthandStyleValue::to_string() const
StringBuilder builder;
auto append_if_non_default = [&](PropertyID property_id) {
auto value = longhand(property_id);
if (!value->equals(property_initial_value({}, property_id))) {
if (!value->equals(property_initial_value(property_id))) {
if (!builder.is_empty())
builder.append(' ');
builder.append(value->to_string());