Truly independent web browser
LibWeb: Update descendants when custom properties stop animating
Callum Lawab2d300d415b
diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cppindex c87f891169e..5d15909bec4 100644--- a/Libraries/LibWeb/CSS/StyleComputer.cpp+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp@@ -906,10 +906,11 @@ void StyleComputer::invalidate_animated_custom_property_readers(Layout::BegunReaauto& style_engine = element.document().style_computer().style_engine();style_engine.record_derived_element_style_input_change(element.style_node_id(), StyleEngine::PublishedStyle | StyleEngine::RecomputeStyle);- auto any_animated_custom_property_inherits = [&] {- if (animated_values.is_empty())- return true;- for (auto const& [name, value] : animated_values) {+ if (abstract_element.pseudo_element().has_value())+ return;++ auto any_custom_property_inherits = [&](auto const& values) {+ for (auto const& [name, value] : values) {auto registration = m_document->get_registered_custom_property(name);if (!registration.has_value() || registration->inherit)return true;@@ -917,8 +918,12 @@ void StyleComputer::invalidate_animated_custom_property_readers(Layout::BegunReareturn false;};// What the element hands down moved too. Its descendants take the moved environment as they take one a style- // reaction moved: only those that read a name whose value moved compute again.- if (!abstract_element.pseudo_element().has_value() && any_animated_custom_property_inherits())+ // reaction moved: only those that read a name whose value moved compute again. Include names from the previous+ // animation overlay, since an inheriting property may have stopped animating while non-inheriting ones remain.+ bool const new_values_inherit = any_custom_property_inherits(animated_values);+ bool const old_values_inherit = old_data && old_data->is_animation_overlay_for(abstract_element)+ && any_custom_property_inherits(old_data->own_values());+ if (new_values_inherit || old_values_inherit)move_custom_property_environment_below_animated_element(read, element, move(old_data));}diff --git a/Tests/LibWeb/Text/expected/css/animated-custom-property-partial-cancellation.txt b/Tests/LibWeb/Text/expected/css/animated-custom-property-partial-cancellation.txtnew file mode 100644index 00000000000..eb4fd90b725--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/animated-custom-property-partial-cancellation.txt@@ -0,0 +1,6 @@+plain before cancellation: 40px+plain after cancellation: 10px+plain remaining animation: 0.5+recompute before cancellation: 40px+recompute after cancellation: 10px+recompute remaining animation: 0.5diff --git a/Tests/LibWeb/Text/input/css/animated-custom-property-partial-cancellation.html b/Tests/LibWeb/Text/input/css/animated-custom-property-partial-cancellation.htmlnew file mode 100644index 00000000000..f830d03afc0--- /dev/null+++ b/Tests/LibWeb/Text/input/css/animated-custom-property-partial-cancellation.html@@ -0,0 +1,40 @@+<!doctype html>+<script src="../include.js"></script>+<style>+ @property --inherited {+ syntax: "<length>";+ inherits: true;+ initial-value: 10px;+ }+ @property --local {+ syntax: "<number>";+ inherits: false;+ initial-value: 0;+ }+ .recompute {+ opacity: var(--local);+ }+ .reader {+ width: var(--inherited);+ }+</style>+<div id="plain"><div class="reader"></div></div>+<div id="recompute" class="recompute"><div class="reader"></div></div>+<script>+ test(() => {+ for (const id of ["plain", "recompute"]) {+ const target = document.getElementById(id);+ const reader = target.firstElementChild;+ const inherited = target.animate({ "--inherited": ["20px", "60px"] }, 1000);+ const local = target.animate({ "--local": [0, 1] }, 1000);+ for (const animation of [inherited, local]) {+ animation.pause();+ animation.currentTime = 500;+ }+ println(`${id} before cancellation: ${getComputedStyle(reader).width}`);+ inherited.cancel();+ println(`${id} after cancellation: ${getComputedStyle(reader).width}`);+ println(`${id} remaining animation: ${getComputedStyle(target).getPropertyValue("--local")}`);+ }+ });+</script>