Skip to content

Truly independent web browser

LibWeb: Avoid redundant restyles after sampling custom properties

Callum Lawad3cbe01ebbf
diff --git a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
index 984ab249881..36cac2969c0 100644
--- a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
+++ b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.cpp
@@ -352,6 +352,7 @@ void ComputedStyleWorkingSet::install_animated_overlay(Badge<StyleComputer>, Com
void ComputedStyleWorkingSet::clear_animated_properties(Badge<StyleComputer>)
{
m_animated_custom_properties.clear();
+ m_animated_custom_properties_trigger_restyle = true;
if (!m_animated_properties)
return;
diff --git a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.h b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.h
index 0bc0e68da06..17fd9f47837 100644
--- a/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.h
+++ b/Libraries/LibWeb/CSS/ComputedStyleWorkingSet.h
@@ -95,6 +95,8 @@ public:
void set_animated_custom_property(Badge<StyleComputer>, Utf16FlyString name, NonnullRefPtr<StyleValue const> value);
void clear_animated_properties(Badge<StyleComputer>);
OrderedHashMap<Utf16FlyString, NonnullRefPtr<StyleValue const>> const& animated_custom_properties() const { return m_animated_custom_properties; }
+ bool animated_custom_properties_trigger_restyle() const { return m_animated_custom_properties_trigger_restyle; }
+ void set_animated_custom_properties_trigger_restyle(Badge<StyleComputer>, bool value) { m_animated_custom_properties_trigger_restyle = value; }
StyleValue const& property(PropertyID, WithAnimationsApplied = WithAnimationsApplied::Yes) const;
StyleValueFFI::StyleValueData const* effective_property_data(PropertyID, WithAnimationsApplied = WithAnimationsApplied::Yes) const;
@@ -162,6 +164,7 @@ private:
RefPtr<AnimatedProperties> m_animated_properties;
bool m_had_animated_post_compute_adjustment_property { false };
OrderedHashMap<Utf16FlyString, NonnullRefPtr<StyleValue const>> m_animated_custom_properties;
+ bool m_animated_custom_properties_trigger_restyle { true };
mutable RefPtr<Gfx::FontCascadeList const> m_cached_computed_font_list;
mutable TreeScopeID m_cached_computed_font_list_scope;
diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp
index 5d15909bec4..6c568936398 100644
--- a/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -789,6 +789,7 @@ NonnullOwnPtr<StyleComputer::AnimationSample> StyleComputer::begin_animation_sam
custom_property_data ? custom_property_data->identity() : 0,
inheritance_custom_property_data ? inheritance_custom_property_data->identity() : 0,
},
+ .custom_property_registration_generation = document().custom_property_registration_generation(),
.inheritance_parent_style_record = inheritance_parent.has_value() ? inheritance_parent->style_record_identity().value() : 0,
.environment = &sample->environment,
.element_box_slot = Layout::Node::slot_id(abstract_element.element().unsafe_layout_node(read)).index,
@@ -841,6 +842,7 @@ void StyleComputer::finish_animation_sample(AnimationSample& sample, ComputedVal
case ComputedValuesFFI::FfiHostAnimationSampleOutcome::Evaluated:
break;
}
+ computed_properties.set_animated_custom_properties_trigger_restyle(Badge<StyleComputer> {}, result.custom_properties_trigger_restyle);
m_keyframes_inherited_non_inherited_style_groups |= result.keyframes_inherited_non_inherited_style_groups;
if (result.depends_on_viewport_metrics)
computed_properties.set_depends_on_viewport_metrics();
@@ -867,7 +869,7 @@ void StyleComputer::publish_animated_custom_properties(Layout::BegunRead const&
if (animated_values.is_empty()) {
if (base.ptr() != data.ptr()) {
abstract_element.replace_custom_property_data(Badge<StyleComputer> {}, base);
- invalidate_animated_custom_property_readers(read, abstract_element, animated_values, move(data));
+ invalidate_animated_custom_property_readers(read, abstract_element, animated_values, move(data), true);
}
return;
}
@@ -895,16 +897,19 @@ void StyleComputer::publish_animated_custom_properties(Layout::BegunRead const&
});
}
abstract_element.replace_custom_property_data(Badge<StyleComputer> {}, CustomPropertyData::create_animation_overlay(move(overlay_values), move(base), abstract_element));
- invalidate_animated_custom_property_readers(read, abstract_element, animated_values, move(data));
+ invalidate_animated_custom_property_readers(read, abstract_element, animated_values, move(data), computed_properties.animated_custom_properties_trigger_restyle());
}
-void StyleComputer::invalidate_animated_custom_property_readers(Layout::BegunRead const& read, DOM::AbstractElement abstract_element, OrderedHashMap<Utf16FlyString, NonnullRefPtr<StyleValue const>> const& animated_values, RefPtr<CustomPropertyData const> old_data) const
+void StyleComputer::invalidate_animated_custom_property_readers(Layout::BegunRead const& read, DOM::AbstractElement abstract_element, OrderedHashMap<Utf16FlyString, NonnullRefPtr<StyleValue const>> const& animated_values, RefPtr<CustomPropertyData const> old_data, bool recompute_style) const
{
auto& element = abstract_element.element();
- // Which custom properties the element's own declarations read is not recorded: an element
- // whose custom properties animate recomputes.
auto& style_engine = element.document().style_computer().style_engine();
- style_engine.record_derived_element_style_input_change(element.style_node_id(), StyleEngine::PublishedStyle | StyleEngine::RecomputeStyle);
+ if (recompute_style) {
+ style_engine.record_derived_element_style_input_change(element.style_node_id(), StyleEngine::PublishedStyle | StyleEngine::RecomputeStyle);
+ } else if (!abstract_element.pseudo_element().has_value()) {
+ // Style container queries can read animated values even when those values do not inherit.
+ element.invalidate_descendant_styles_depending_on_style_container_query();
+ }
if (abstract_element.pseudo_element().has_value())
return;
diff --git a/Libraries/LibWeb/CSS/StyleComputer.h b/Libraries/LibWeb/CSS/StyleComputer.h
index 5dd1b2c0c50..5769b305d9a 100644
--- a/Libraries/LibWeb/CSS/StyleComputer.h
+++ b/Libraries/LibWeb/CSS/StyleComputer.h
@@ -190,7 +190,7 @@ private:
void finish_animation_sample(AnimationSample&, ComputedValuesFFI::FfiHostAnimationSampleResult const&) const;
void finish_animation_refresh(Layout::BegunRead const& read, DOM::AbstractElement, ComputedStyleWorkingSet&) const;
void publish_animated_custom_properties(Layout::BegunRead const&, ComputedStyleWorkingSet&, DOM::AbstractElement) const;
- void invalidate_animated_custom_property_readers(Layout::BegunRead const&, DOM::AbstractElement, OrderedHashMap<Utf16FlyString, NonnullRefPtr<StyleValue const>> const& animated_values, RefPtr<CustomPropertyData const> old_data) const;
+ void invalidate_animated_custom_property_readers(Layout::BegunRead const&, DOM::AbstractElement, OrderedHashMap<Utf16FlyString, NonnullRefPtr<StyleValue const>> const& animated_values, RefPtr<CustomPropertyData const> old_data, bool recompute_style) const;
RefPtr<ComputedStyleWorkingSet> start_needed_transitions(Layout::BegunRead const& read, DOM::AbstractElement, StyleRecordID before_change_style_record) const;
[[nodiscard]] bool has_provisional_transition_states(DOM::AbstractElement) const;
void finalize_animated_box_type(Layout::BegunRead const& read, ComputedStyleWorkingSet&, DOM::AbstractElement) const;
diff --git a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
index bbf914a68a8..39d91a28e0c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/engine_sample.rs
@@ -686,6 +686,7 @@ impl super::StyleEngine {
custom_property_environments,
inheritance_parent_style_record,
environment: &environment,
+ custom_property_registration_generation: inputs.custom_property_registration_generation,
element_box_slot: crate::layout::node_data::NodeSlotId::INVALID.index,
};
crate::css::style_compute::sample_without_host(
diff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
index 1434269b8e4..e323dc6779b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
@@ -1573,6 +1573,11 @@ impl RetainedState {
self.document_style_computation_inputs.custom_property_registry()
}
+ pub(crate) fn custom_property_registration_generation(&self) -> u64 {
+ self.document_style_computation_inputs
+ .custom_property_registration_generation
+ }
+
/// The effects one of an element's animation lists holds, as the host described them.
#[must_use]
pub(crate) fn element_animation_effects(
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rs
index 25630678049..adceec81517 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs
@@ -3179,6 +3179,104 @@ impl RetainedState {
self.state_summary(node, state).has_substitutions
}
+ /// Whether publishing sampled custom properties requires another style computation.
+ /// The sample has already resolved the target's custom declarations that read animated values.
+ pub(crate) fn animated_custom_properties_trigger_restyle(
+ &self,
+ node: StyleNodeID,
+ pseudo: Option<u8>,
+ has_non_custom_property_animation: bool,
+ uncached_interval_values_may_need_substitution: bool,
+ host_custom_property_registration_generation: u64,
+ ) -> bool {
+ // Animations of non-custom properties may read the sampled custom properties or change the font context
+ // their registered readers compute against.
+ if has_non_custom_property_animation {
+ return true;
+ }
+
+ let has_unresolved_keyframe_easing = self
+ .element_animation_effects(node, pseudo.map_or(0, |kind| kind + 1))
+ .iter()
+ .any(|effect| {
+ effect.keyframes.iter().any(|keyframe| {
+ keyframe
+ .easing_value
+ .as_ref()
+ .is_some_and(|value| matches!(value.data(), StyleValueData::Unresolved { .. }))
+ })
+ });
+
+ // Unresolved keyframe easing may read the sampled custom properties.
+ if has_unresolved_keyframe_easing {
+ return true;
+ }
+
+ // Retained discrete intervals keep their substituted values. Fresh intervals may need
+ // another sample against the custom properties this sample publishes.
+ if uncached_interval_values_may_need_substitution {
+ return true;
+ }
+
+ // Animation sampling precedes the transaction that consumes pending registration changes.
+ // In that case, the sample used the engine's outdated registrations and underlying values.
+ if host_custom_property_registration_generation != self.custom_property_registration_generation() {
+ return true;
+ }
+
+ let target = computed::ComputedStyleTarget::new(node, pseudo.unwrap_or(u8::MAX));
+
+ // Without an assigned style record, we cannot establish that sampling covers all consumers.
+ let Some(record) = self.computed_group_sets.assigned_final_style_record(target) else {
+ return true;
+ };
+
+ // The record must still be available so we can inspect the target's current style.
+ let Some(view) = self.computed_group_sets.style_record_view(record.raw()) else {
+ return true;
+ };
+
+ if pseudo.is_none() && self.has_pseudo_styles_to_recompute(node, &view) {
+ return true;
+ }
+
+ self.ordinary_properties_may_need_substitution(node, pseudo)
+ }
+
+ /// Whether pseudo styles need updating when the element's custom properties change.
+ fn has_pseudo_styles_to_recompute(&self, node: StyleNodeID, view: &computed::StyleRecordView<'_>) -> bool {
+ // Existing pseudo-element styles may inherit the sampled values and need to be recomputed.
+ if self.computed_group_sets.assigned_pseudo_kinds(node).next().is_some() {
+ return true;
+ }
+
+ // Ignore rules for pseudo-elements that generate no box.
+ let pseudo_kinds = view.pseudo_element_styles & !self.inert_pseudo_kinds(node);
+ let marker_is_live = view.longhand_table.is_none_or(|table| table.display_is_list_item());
+ self.filter_non_generating_pseudo_kinds(node, pseudo_kinds, marker_is_live) != 0
+ }
+
+ /// Whether ordinary properties may need to compute against changed custom properties.
+ /// Missing winners or values prevent ruling out substitution.
+ fn ordinary_properties_may_need_substitution(&self, node: StyleNodeID, pseudo: Option<u8>) -> bool {
+ let key = match pseudo {
+ Some(kind) => WinnerGroupKey::current_pseudo(
+ node,
+ tree::PseudoElementTarget::new(tree::PseudoElementKind(u16::from(kind))),
+ self.program.version(),
+ ),
+ None => WinnerGroupKey::current(node, self.program.version()),
+ };
+
+ let Lookup::Known((_, state)) = self.current_winner_groups().token_for(key) else {
+ return true;
+ };
+
+ let summary = self.state_summary(node, state);
+
+ summary.has_unknown_values || summary.has_substitutions
+ }
+
pub(super) fn state_custom_property_reads(
&self,
node: StyleNodeID,
diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rs
index 4186f583e6d..e7244075836 100644
--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs
@@ -6297,6 +6297,8 @@ pub struct FfiHostAnimationSample {
/// The identities of the element's custom-property environment and the one it inherits, under
/// which values substituted against the element hold.
pub custom_property_environments: [u64; 2],
+ /// The host's current registrations, which the engine may not have consumed yet.
+ pub custom_property_registration_generation: u64,
pub inheritance_parent_style_record: u64,
/// The document's side of the environment keyframes compute in. The engine fills in the
/// element's own: its place among its siblings and its random bases.
@@ -6334,6 +6336,7 @@ pub struct FfiAnimatedCustomPropertyResult {
#[repr(C)]
pub struct FfiHostAnimationSampleResult {
pub outcome: FfiHostAnimationSampleOutcome,
+ pub custom_properties_trigger_restyle: bool,
/// The non-inherited style groups a keyframe saying `inherit` read from the parent.
pub keyframes_inherited_non_inherited_style_groups: u32,
pub depends_on_viewport_metrics: bool,
@@ -6354,6 +6357,7 @@ impl FfiHostAnimationSampleResult {
fn with_outcome(outcome: FfiHostAnimationSampleOutcome) -> Self {
Self {
outcome,
+ custom_properties_trigger_restyle: true,
keyframes_inherited_non_inherited_style_groups: 0,
depends_on_viewport_metrics: false,
font_metrics_depend_on_viewport_metrics: false,
@@ -6438,6 +6442,7 @@ pub(crate) struct AnimationSampleInput<'a> {
/// The identities of the element's custom-property environment and the one it inherits, under
/// which values substituted against the element hold.
pub(crate) custom_property_environments: [u64; 2],
+ pub(crate) custom_property_registration_generation: u64,
pub(crate) inheritance_parent_style_record: u64,
/// The document's side of the environment keyframes compute in.
pub(crate) environment: &'a FfiStyleComputationEnvironment,
@@ -6552,6 +6557,7 @@ impl FfiHostAnimationSample {
element_declares_custom_properties: self.element_declares_own_custom_properties,
},
custom_property_environments: self.custom_property_environments,
+ custom_property_registration_generation: self.custom_property_registration_generation,
inheritance_parent_style_record: self.inheritance_parent_style_record,
environment,
element_box_slot: self.element_box_slot,
@@ -7030,6 +7036,9 @@ fn finish_animation_sample(
&& resolved.container_relative_length_unit_mask == 0
&& !resolved.needs_document_base_url
&& resolved.unfixed_random_sharings.is_empty();
+
+ let has_non_custom_property_animation = resolved.properties.iter().any(|property| property.custom_name_id == 0);
+
let custom_results = anim::evaluate_animations(anim::ComputedAnimationBatch {
context: input.animation_context(Some(&length_contexts.remaining), reference_box),
device_pixels_per_css_pixel: input.environment.device_pixels_per_css_pixel,
@@ -7064,8 +7073,21 @@ fn finish_animation_sample(
&retained,
finalization,
);
+ // Failed resolution keeps the default full restyle. On success, only consumers not
+ // updated by this sample can require one.
if let Ok(readers) = readers {
retained.extend(readers);
+
+ let uncached_interval_values_may_need_substitution =
+ custom_properties.has_uncached_interval_values && result.substitution_marks != 0;
+
+ result.custom_properties_trigger_restyle = engine.animated_custom_properties_trigger_restyle(
+ node,
+ pseudo,
+ has_non_custom_property_animation,
+ uncached_interval_values_may_need_substitution,
+ input.custom_property_registration_generation,
+ );
}
let rows = retained
.iter()
diff --git a/Tests/LibWeb/Text/expected/css/animated-custom-property-restyle.txt b/Tests/LibWeb/Text/expected/css/animated-custom-property-restyle.txt
new file mode 100644
index 00000000000..1ad1e81b300
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/animated-custom-property-restyle.txt
@@ -0,0 +1,35 @@
+fresh at 250ms: 25, 25
+fresh at 750ms: 75, 75
+fresh at 250ms: 25, 25
+retained at 250ms: 0, 0
+retained at 750ms: 100, 0
+retained at 250ms: 0, 0
+mixed at 250ms: 10px, 10px
+mixed at 750ms: 30px, 30px
+mixed at 250ms: 10px, 10px
+eased at 125ms: start
+eased at 375ms: end
+eased at 125ms: start
+pseudos at 250ms: 25px, 25px, 25px
+pseudos at 750ms: 75px, 75px, 75px
+pseudos at 250ms: 25px, 25px, 25px
+pseudos cancelled: 0px, 0px, 0px
+new pseudos at 750ms: 75px, 75px
+new pseudos at 250ms: 25px, 25px
+own readers at 250ms: 25, 25px, 25
+own readers at 750ms: 75, 75px, 75
+own readers cancelled: 0, 0px, 0
+non-inheriting query at 0ms: rgb(255, 0, 0)
+non-inheriting query at 1000ms: rgb(0, 0, 255)
+non-inheriting query at 0ms: rgb(255, 0, 0)
+non-inheriting query at 1000ms: rgb(0, 0, 255)
+non-inheriting query cancelled: rgb(0, 0, 0)
+function in 100px container: 50
+function in 0px container: 75
+function in 100px container: 50
+initial layer order: 50
+pending layer order change: 75
+pending ordinary declaration: 25, 25px
+pending custom declaration: 225, 75px
+pending registration change: 7px
+pending new registration: 11px
diff --git a/Tests/LibWeb/Text/expected/css/style-invalidation/animated-custom-property-skips-restyle.txt b/Tests/LibWeb/Text/expected/css/style-invalidation/animated-custom-property-skips-restyle.txt
new file mode 100644
index 00000000000..c44ca377d52
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/style-invalidation/animated-custom-property-skips-restyle.txt
@@ -0,0 +1,3 @@
+plain: skipped, rotate(45deg)
+inactive: skipped, rotate(45deg)
+ordinary: recomputed, rotate(45deg)
diff --git a/Tests/LibWeb/Text/input/css/animated-custom-property-restyle.html b/Tests/LibWeb/Text/input/css/animated-custom-property-restyle.html
new file mode 100644
index 00000000000..0dc06b28806
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/animated-custom-property-restyle.html
@@ -0,0 +1,223 @@
+<!doctype html>
+<script src="../include.js"></script>
+<style id="layers">
+ @layer earlier, later;
+</style>
+<style id="registration">
+ @property --derived {
+ syntax: "<number>";
+ inherits: false;
+ initial-value: 0;
+ }
+</style>
+<style>
+ @property --input {
+ syntax: "<number>";
+ inherits: true;
+ initial-value: 0;
+ }
+ @property --fresh {
+ syntax: "<number>";
+ inherits: false;
+ initial-value: 0;
+ }
+ @keyframes input {
+ from {
+ --input: 0;
+ }
+ to {
+ --input: 100;
+ }
+ }
+ @keyframes easing-source {
+ from {
+ --timing: linear;
+ }
+ to {
+ --timing: steps(1, jump-start);
+ }
+ }
+ @keyframes eased {
+ from {
+ --eased: start;
+ animation-timing-function: var(--timing);
+ }
+ to {
+ --eased: end;
+ }
+ }
+ .animated,
+ #pseudo-own::before {
+ animation: input 1s linear both paused;
+ }
+ #eased {
+ --timing: linear;
+ animation:
+ easing-source 500ms linear both paused,
+ eased 1s linear both paused;
+ }
+ #pseudos::before,
+ #pseudos::after,
+ #pseudos::marker,
+ #inactive::before,
+ #inactive::marker {
+ content: "";
+ font-size: calc(var(--input) * 1px);
+ }
+ #pseudos,
+ #inactive.generated {
+ display: list-item;
+ }
+ #inactive::before {
+ content: none;
+ }
+ #inactive.generated::before,
+ #pseudo-own::before {
+ content: "";
+ }
+ #own,
+ #pseudo-own::before {
+ --copy: var(--input);
+ }
+ #own-child {
+ width: calc(var(--input) * 1px);
+ }
+ #query {
+ --fresh: -1;
+ }
+ #query-child {
+ @container style(--fresh: 0) {
+ color: red;
+ }
+ @container style(--fresh: 1) {
+ color: blue;
+ }
+ }
+ @layer earlier {
+ #rules {
+ --factor: 1;
+ }
+ }
+ @layer later {
+ #rules {
+ --factor: 2;
+ }
+ }
+ #rules {
+ --derived: calc(var(--input) * var(--factor));
+ --late: var(--input);
+ }
+ @function --read-input() returns <number> {
+ result: var(--input);
+ @container (width > 50px) {
+ result: calc(var(--input) * 2);
+ }
+ }
+ #container {
+ container-type: inline-size;
+ width: 100px;
+ }
+ #function {
+ --derived: --read-input();
+ }
+</style>
+<div id="fresh"></div>
+<div id="retained" style="--discrete-input: 0"></div>
+<div id="mixed" style="--width: 10px"></div>
+<div id="eased" class="animated"></div>
+<div id="pseudos" class="animated"></div>
+<div id="inactive" class="animated"></div>
+<div id="own" class="animated"><div id="own-child"></div></div>
+<div id="pseudo-own"></div>
+<div id="query"><div id="query-child"></div></div>
+<div id="rules" class="animated"></div>
+<div id="container"><div id="function" class="animated"></div></div>
+<script>
+ test(() => {
+ const animations = Object.fromEntries(
+ [...document.querySelectorAll(".animated")].map(target => [target.id, target.getAnimations()])
+ );
+ animations["pseudo-own"] = document.getElementById("pseudo-own").getAnimations({ subtree: true });
+ const seek = (id, time) => animations[id].forEach(animation => (animation.currentTime = time));
+ const read = (id, names, pseudo = null) => {
+ const style = getComputedStyle(document.getElementById(id), pseudo);
+ return names.map(name => style.getPropertyValue(name).trim()).join(", ");
+ };
+ const animate = (id, keyframes) => {
+ const animation = document.getElementById(id).animate(keyframes, { duration: 1000, fill: "both" });
+ animation.pause();
+ return animation;
+ };
+ for (const [id, source, values, reader] of [
+ ["fresh", "--input", [0, 100], "--fresh"],
+ ["retained", "--discrete-input", [0, 100], "--retained"],
+ ["mixed", "--width", ["10px", "30px"], "width"],
+ ]) {
+ const animation = animate(id, { [source]: values, [reader]: [`var(${source})`, `var(${source})`] });
+ for (const time of [250, 750, 250]) {
+ animation.currentTime = time;
+ println(`${id} at ${time}ms: ${read(id, [source, reader])}`);
+ }
+ }
+ for (const time of [125, 375, 125]) {
+ seek("eased", time);
+ println(`eased at ${time}ms: ${read("eased", ["--eased"])}`);
+ }
+ const readPseudos = (id, kinds = ["::before", "::after", "::marker"]) =>
+ kinds.map(kind => read(id, ["font-size"], kind)).join(", ");
+ for (const time of [250, 750, 250]) {
+ seek("pseudos", time);
+ println(`pseudos at ${time}ms: ${readPseudos("pseudos")}`);
+ }
+ animations.pseudos[0].cancel();
+ println(`pseudos cancelled: ${readPseudos("pseudos")}`);
+ seek("inactive", 750);
+ read("inactive", ["--input"]);
+ document.getElementById("inactive").classList.add("generated");
+ for (const time of [750, 250]) {
+ seek("inactive", time);
+ println(`new pseudos at ${time}ms: ${readPseudos("inactive", ["::before", "::marker"])}`);
+ }
+ const readOwn = () =>
+ `${read("own", ["--copy"])}, ${read("own-child", ["width"])}, ${read("pseudo-own", ["--copy"], "::before")}`;
+ for (const time of [250, 750]) {
+ for (const id of ["own", "pseudo-own"]) seek(id, time);
+ println(`own readers at ${time}ms: ${readOwn()}`);
+ }
+ for (const id of ["own", "pseudo-own"]) animations[id][0].cancel();
+ println(`own readers cancelled: ${readOwn()}`);
+ const queryAnimation = animate("query", { "--fresh": [0, 1] });
+ for (const time of [0, 1000, 0, 1000]) {
+ queryAnimation.currentTime = time;
+ println(`non-inheriting query at ${time}ms: ${read("query-child", ["color"])}`);
+ }
+ queryAnimation.cancel();
+ println(`non-inheriting query cancelled: ${read("query-child", ["color"])}`);
+ for (const [width, time] of [
+ [100, 250],
+ [0, 750],
+ [100, 250],
+ ]) {
+ document.getElementById("container").style.width = `${width}px`;
+ seek("function", time);
+ println(`function in ${width}px container: ${read("function", ["--derived"])}`);
+ }
+ const sampleRules = (label, time, names = ["--derived"]) => {
+ seek("rules", time);
+ println(`${label}: ${read("rules", names)}`);
+ };
+ const rules = document.getElementById("rules");
+ sampleRules("initial layer order", 250);
+ document.getElementById("layers").textContent = "@layer later, earlier;";
+ sampleRules("pending layer order change", 750);
+ rules.style.width = "calc(var(--input) * 1px)";
+ sampleRules("pending ordinary declaration", 250, ["--derived", "width"]);
+ rules.style.setProperty("--factor", "3");
+ sampleRules("pending custom declaration", 750, ["--derived", "width"]);
+ document.getElementById("registration").textContent =
+ '@property --derived { syntax: "<length>"; inherits: false; initial-value: 7px; }';
+ sampleRules("pending registration change", 250);
+ CSS.registerProperty({ name: "--late", syntax: "<length>", inherits: false, initialValue: "11px" });
+ sampleRules("pending new registration", 750, ["--late"]);
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/css/style-invalidation/animated-custom-property-skips-restyle.html b/Tests/LibWeb/Text/input/css/style-invalidation/animated-custom-property-skips-restyle.html
new file mode 100644
index 00000000000..6b4349f7eab
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/style-invalidation/animated-custom-property-skips-restyle.html
@@ -0,0 +1,43 @@
+<!doctype html>
+<script src="../../include.js"></script>
+<style>
+ div {
+ --rotation: rotate(var(--turn));
+ }
+ #inactive::marker {
+ content: "marker";
+ color: red;
+ }
+ #inactive::backdrop {
+ color: red;
+ }
+ #ordinary {
+ rotate: var(--turn);
+ }
+</style>
+<div id="plain"></div>
+<div id="inactive"></div>
+<div id="ordinary"></div>
+<script>
+ test(() => {
+ CSS.registerProperty({ name: "--turn", syntax: "<angle>", inherits: false, initialValue: "0deg" });
+ const results = [];
+ for (const id of ["plain", "inactive", "ordinary"]) {
+ const target = document.getElementById(id);
+ const animation = target.animate({ "--turn": ["0deg", "360deg"], easing: "linear" }, 1000);
+ animation.pause();
+ animation.currentTime = 125;
+ internals.updateStyle();
+ internals.resetStyleInvalidationCounters();
+ for (const time of [375, 625, 125]) {
+ animation.currentTime = time;
+ internals.updateStyle();
+ }
+ const counters = internals.getStyleInvalidationCounters();
+ const recomputations = counters.elementStyleRecomputations + counters.engineComputedStyleRecords;
+ const rotation = getComputedStyle(target).getPropertyValue("--rotation");
+ results.push(`${id}: ${recomputations === 0 ? "skipped" : "recomputed"}, ${rotation}`);
+ }
+ results.forEach(println);
+ });
+</script>