From 823dd11b674f93ea5d5eb74f81ba4e3826942683 Mon Sep 17 00:00:00 2001 From: Callum Law Date: Mon, 27 Oct 2025 01:18:52 +1300 Subject: [PATCH] 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. --- Libraries/LibWeb/CSS/ComputedProperties.cpp | 9 ++++++- Libraries/LibWeb/CSS/ComputedProperties.h | 1 + Libraries/LibWeb/CSS/StyleComputer.cpp | 29 ++++++++------------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Libraries/LibWeb/CSS/ComputedProperties.cpp b/Libraries/LibWeb/CSS/ComputedProperties.cpp index d414caf71a9..cf4547e4812 100644 --- a/Libraries/LibWeb/CSS/ComputedProperties.cpp +++ b/Libraries/LibWeb/CSS/ComputedProperties.cpp @@ -118,11 +118,18 @@ void ComputedProperties::set_property(PropertyID id, NonnullRefPtr= 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_inherited(id, inherited); } +void ComputedProperties::set_property_without_modifying_flags(PropertyID id, NonnullRefPtr 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) { VERIFY(id >= first_longhand_property_id && id <= last_longhand_property_id); diff --git a/Libraries/LibWeb/CSS/ComputedProperties.h b/Libraries/LibWeb/CSS/ComputedProperties.h index 0afa1b5ea93..577d5001d38 100644 --- a/Libraries/LibWeb/CSS/ComputedProperties.h +++ b/Libraries/LibWeb/CSS/ComputedProperties.h @@ -60,6 +60,7 @@ public: void set_animated_property_inherited(PropertyID, Inherited); void set_property(PropertyID, NonnullRefPtr value, Inherited = Inherited::No, Important = Important::No); + void set_property_without_modifying_flags(PropertyID, NonnullRefPtr value); void set_animated_property(PropertyID, NonnullRefPtr value, Inherited = Inherited::No); void remove_animated_property(PropertyID); enum class WithAnimationsApplied { diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp index cce9a5c035c..f758cb71b5f 100644 --- a/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1959,33 +1959,29 @@ void StyleComputer::compute_font(ComputedProperties& style, Optionalcomputed_properties()->font_weight() : InitialValues::font_weight(); auto const& font_weight_specified_value = style.property(PropertyID::FontWeight, ComputedProperties::WithAnimationsApplied::No); - style.set_property( + style.set_property_without_modifying_flags( PropertyID::FontWeight, - 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); + compute_font_weight(font_weight_specified_value, inherited_font_weight, font_computation_context)); auto const& font_width_specified_value = style.property(PropertyID::FontWidth, ComputedProperties::WithAnimationsApplied::No); - style.set_property( + style.set_property_without_modifying_flags( PropertyID::FontWidth, - compute_font_width(font_width_specified_value, font_computation_context), - style.is_property_inherited(PropertyID::FontWidth) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No); + compute_font_width(font_width_specified_value, font_computation_context)); auto const& font_style_specified_value = style.property(PropertyID::FontStyle, ComputedProperties::WithAnimationsApplied::No); - style.set_property( + style.set_property_without_modifying_flags( PropertyID::FontStyle, - compute_font_style(font_style_specified_value, font_computation_context), - style.is_property_inherited(PropertyID::FontStyle) ? ComputedProperties::Inherited::Yes : ComputedProperties::Inherited::No); + compute_font_style(font_style_specified_value, font_computation_context)); auto const& font_family = style.property(CSS::PropertyID::FontFamily); @@ -2014,10 +2010,9 @@ void StyleComputer::compute_font(ComputedProperties& style, Optional(abstract_element->element())) { const_cast(*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) { 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(property_id, computed_value, is_inherited); + style.set_property_without_modifying_flags(property_id, computed_value); }); style.set_display_before_box_type_transformation(style.display());