diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp index 61f54cea28e..e501dec6f16 100644 --- a/Libraries/LibWeb/DOM/Element.cpp +++ b/Libraries/LibWeb/DOM/Element.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -567,15 +568,21 @@ CSS::RequiredInvalidationAfterStyleChange Element::recompute_style() CSS::RequiredInvalidationAfterStyleChange Element::recompute_inherited_style() { - // Traversal of the subtree is necessary to update the animated properties inherited from the target element. auto computed_properties = this->computed_properties(); - if (!computed_properties || !layout_node()) + if (!m_cascaded_properties || !computed_properties || !layout_node()) return {}; CSS::RequiredInvalidationAfterStyleChange invalidation; for (auto i = to_underlying(CSS::first_property_id); i <= to_underlying(CSS::last_property_id); ++i) { auto property_id = static_cast(i); + auto const& preabsolutized_value = m_cascaded_properties->property(property_id); + // Update property if it uses relative units as it might have been affected by a change in ancestor element style. + if (preabsolutized_value && preabsolutized_value->is_length() && preabsolutized_value->as_length().length().is_font_relative()) { + auto is_inherited = computed_properties->is_property_inherited(property_id); + computed_properties->set_property(property_id, *preabsolutized_value, is_inherited ? CSS::ComputedProperties::Inherited::Yes : CSS::ComputedProperties::Inherited::No); + invalidation |= CSS::compute_property_invalidation(property_id, preabsolutized_value, preabsolutized_value); + } if (!computed_properties->is_property_inherited(property_id)) continue; RefPtr old_value = computed_properties->maybe_null_property(property_id); diff --git a/Tests/LibWeb/Text/expected/invlidate-properties-with-relative-units-in-inherited-style-update.txt b/Tests/LibWeb/Text/expected/invlidate-properties-with-relative-units-in-inherited-style-update.txt new file mode 100644 index 00000000000..7b0a6d046c9 --- /dev/null +++ b/Tests/LibWeb/Text/expected/invlidate-properties-with-relative-units-in-inherited-style-update.txt @@ -0,0 +1,6 @@ +(before) child.style.width: 192px +(before) child.style.height: 192px +(before) child.style.fontSize: 96px +(after) child.style.width: 600px +(after) child.style.height: 600px +(after) child.style.fontSize: 300px diff --git a/Tests/LibWeb/Text/input/invlidate-properties-with-relative-units-in-inherited-style-update.html b/Tests/LibWeb/Text/input/invlidate-properties-with-relative-units-in-inherited-style-update.html new file mode 100644 index 00000000000..7c111b1e45b --- /dev/null +++ b/Tests/LibWeb/Text/input/invlidate-properties-with-relative-units-in-inherited-style-update.html @@ -0,0 +1,43 @@ + + + + + + +
+

+ Hello! +

+
+ + + +