LibWeb: Add ComputedProperties::set_property_without_modifying_flags

There are a few places in style computation where we want to update the
value of a property without modifying the inherited or important flags.

Previously we would look up these flags and pass them to the normal
`set_property` method but this is unnecessary and was easy to forget to
do.
This commit is contained in:
Callum Law 2025-10-27 01:18:52 +13:00 committed by Sam Atkins
parent 84762021b8
commit 823dd11b67
Notes: github-actions[bot] 2025-10-27 09:53:13 +00:00
3 changed files with 20 additions and 19 deletions

View file

@ -118,11 +118,18 @@ void ComputedProperties::set_property(PropertyID id, NonnullRefPtr<StyleValue co
{ {
VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id); VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id);
m_property_values[to_underlying(id) - to_underlying(first_longhand_property_id)] = move(value); set_property_without_modifying_flags(id, move(value));
set_property_important(id, important); set_property_important(id, important);
set_property_inherited(id, inherited); set_property_inherited(id, inherited);
} }
void ComputedProperties::set_property_without_modifying_flags(PropertyID id, NonnullRefPtr<StyleValue const> value)
{
VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id);
m_property_values[to_underlying(id) - to_underlying(first_longhand_property_id)] = move(value);
}
void ComputedProperties::revert_property(PropertyID id, ComputedProperties const& style_for_revert) void ComputedProperties::revert_property(PropertyID id, ComputedProperties const& style_for_revert)
{ {
VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id); VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id);

View file

@ -60,6 +60,7 @@ public:
void set_animated_property_inherited(PropertyID, Inherited); void set_animated_property_inherited(PropertyID, Inherited);
void set_property(PropertyID, NonnullRefPtr<StyleValue const> value, Inherited = Inherited::No, Important = Important::No); void set_property(PropertyID, NonnullRefPtr<StyleValue const> value, Inherited = Inherited::No, Important = Important::No);
void set_property_without_modifying_flags(PropertyID, NonnullRefPtr<StyleValue const> value);
void set_animated_property(PropertyID, NonnullRefPtr<StyleValue const> value, Inherited = Inherited::No); void set_animated_property(PropertyID, NonnullRefPtr<StyleValue const> value, Inherited = Inherited::No);
void remove_animated_property(PropertyID); void remove_animated_property(PropertyID);
enum class WithAnimationsApplied { enum class WithAnimationsApplied {

View file

@ -1959,33 +1959,29 @@ void StyleComputer::compute_font(ComputedProperties& style, Optional<DOM::Abstra
auto const& font_size_specified_value = style.property(PropertyID::FontSize, ComputedProperties::WithAnimationsApplied::No); auto const& font_size_specified_value = style.property(PropertyID::FontSize, ComputedProperties::WithAnimationsApplied::No);
style.set_property( style.set_property_without_modifying_flags(
PropertyID::FontSize, PropertyID::FontSize,
compute_font_size(font_size_specified_value, style.math_depth(), inherited_font_size, inherited_math_depth, font_computation_context), compute_font_size(font_size_specified_value, style.math_depth(), inherited_font_size, inherited_math_depth, font_computation_context));
style.is_property_inherited(PropertyID::FontSize) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
auto inherited_font_weight = inheritance_parent_has_computed_properties ? inheritance_parent->computed_properties()->font_weight() : InitialValues::font_weight(); auto inherited_font_weight = inheritance_parent_has_computed_properties ? inheritance_parent->computed_properties()->font_weight() : InitialValues::font_weight();
auto const& font_weight_specified_value = style.property(PropertyID::FontWeight, ComputedProperties::WithAnimationsApplied::No); auto const& font_weight_specified_value = style.property(PropertyID::FontWeight, ComputedProperties::WithAnimationsApplied::No);
style.set_property( style.set_property_without_modifying_flags(
PropertyID::FontWeight, PropertyID::FontWeight,
compute_font_weight(font_weight_specified_value, inherited_font_weight, font_computation_context), compute_font_weight(font_weight_specified_value, inherited_font_weight, font_computation_context));
style.is_property_inherited(PropertyID::FontWeight) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
auto const& font_width_specified_value = style.property(PropertyID::FontWidth, ComputedProperties::WithAnimationsApplied::No); auto const& font_width_specified_value = style.property(PropertyID::FontWidth, ComputedProperties::WithAnimationsApplied::No);
style.set_property( style.set_property_without_modifying_flags(
PropertyID::FontWidth, PropertyID::FontWidth,
compute_font_width(font_width_specified_value, font_computation_context), compute_font_width(font_width_specified_value, font_computation_context));
style.is_property_inherited(PropertyID::FontWidth) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
auto const& font_style_specified_value = style.property(PropertyID::FontStyle, ComputedProperties::WithAnimationsApplied::No); auto const& font_style_specified_value = style.property(PropertyID::FontStyle, ComputedProperties::WithAnimationsApplied::No);
style.set_property( style.set_property_without_modifying_flags(
PropertyID::FontStyle, PropertyID::FontStyle,
compute_font_style(font_style_specified_value, font_computation_context), compute_font_style(font_style_specified_value, font_computation_context));
style.is_property_inherited(PropertyID::FontStyle) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
auto const& font_family = style.property(CSS::PropertyID::FontFamily); auto const& font_family = style.property(CSS::PropertyID::FontFamily);
@ -2014,10 +2010,9 @@ void StyleComputer::compute_font(ComputedProperties& style, Optional<DOM::Abstra
auto const& line_height_specified_value = style.property(CSS::PropertyID::LineHeight, ComputedProperties::WithAnimationsApplied::No); auto const& line_height_specified_value = style.property(CSS::PropertyID::LineHeight, ComputedProperties::WithAnimationsApplied::No);
style.set_property( style.set_property_without_modifying_flags(
PropertyID::LineHeight, PropertyID::LineHeight,
compute_line_height(line_height_specified_value, line_height_computation_context), compute_line_height(line_height_specified_value, line_height_computation_context));
style.is_property_inherited(PropertyID::LineHeight) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No);
if (abstract_element.has_value() && is<HTML::HTMLHtmlElement>(abstract_element->element())) { if (abstract_element.has_value() && is<HTML::HTMLHtmlElement>(abstract_element->element())) {
const_cast<StyleComputer&>(*this).m_root_element_font_metrics = calculate_root_element_font_metrics(style); const_cast<StyleComputer&>(*this).m_root_element_font_metrics = calculate_root_element_font_metrics(style);
@ -2096,9 +2091,7 @@ void StyleComputer::compute_property_values(ComputedProperties& style, Optional<
style.for_each_property([&](PropertyID property_id, auto& specified_value) { style.for_each_property([&](PropertyID property_id, auto& specified_value) {
auto const& computed_value = compute_value_of_property(property_id, specified_value, get_property_specified_value, computation_context, m_document->page().client().device_pixels_per_css_pixel()); auto const& computed_value = compute_value_of_property(property_id, specified_value, get_property_specified_value, computation_context, m_document->page().client().device_pixels_per_css_pixel());
auto const& is_inherited = style.is_property_inherited(property_id) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No; style.set_property_without_modifying_flags(property_id, computed_value);
style.set_property(property_id, computed_value, is_inherited);
}); });
style.set_display_before_box_type_transformation(style.display()); style.set_display_before_box_type_transformation(style.display());