Skip to content

Truly independent web browser

LibWeb: Animate pseudo-elements backed by shadow tree elements

Tim Ledbetterad285acc73c2
diff --git a/Libraries/LibWeb/Rust/src/css/style/matching.rs b/Libraries/LibWeb/Rust/src/css/style/matching.rs
index 27b9faea8aa..611860c40c2 100644
--- a/Libraries/LibWeb/Rust/src/css/style/matching.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/matching.rs
@@ -3616,7 +3616,10 @@ impl RetainedState {
) -> bool {
// Identity equality is NOT a proof: a stale retained answer compares equal to itself. Nor
// is an added losing rule harmless to a record that rolled back below its winners.
- if previous_input == current_input || self.record_rolls_back_substitution(node) {
+ if previous_input == current_input
+ || self.record_rolls_back_substitution(node)
+ || self.backed_host_pseudo_element(node).is_some()
+ {
return false;
}
let target = computed::ComputedStyleTarget::new(node, u8::MAX);
@@ -3809,7 +3812,7 @@ impl RetainedState {
/// stops the reaction.
pub(super) fn exact_cascade_output_is_unchanged(&self, effects: &AnswerEffects, node: StyleNodeID) -> bool {
// A record that rolled back below its winners holds declarations they do not name.
- if self.record_rolls_back_substitution(node) {
+ if self.record_rolls_back_substitution(node) || self.backed_host_pseudo_element(node).is_some() {
return false;
}
let target = computed::ComputedStyleTarget::new(node, u8::MAX);
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rs
index 8cfcdb613e6..23711cd7ed7 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs
@@ -3290,19 +3290,38 @@ impl RetainedState {
self.filter_non_generating_pseudo_kinds(node, pseudo_kinds, marker_is_live) != 0
}
+ pub(super) fn element_record_winner_state(&self, node: StyleNodeID) -> Option<CascadeStateID> {
+ if self.backed_host_pseudo_element(node).is_some() {
+ return self
+ .computed_group_sets
+ .cascade_state(computed::ComputedStyleTarget::new(node, u8::MAX))
+ .map(|(_, state)| state);
+ }
+ match self
+ .current_winner_groups()
+ .token_for(WinnerGroupKey::current(node, self.program.version()))
+ {
+ Lookup::Known((_, state)) => Some(state),
+ Lookup::KnownAbsent | Lookup::Missing(_) => None,
+ }
+ }
+
/// 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(
+ let state = match pseudo {
+ Some(kind) => match self.current_winner_groups().token_for(WinnerGroupKey::current_pseudo(
node,
tree::PseudoElementTarget::new(tree::PseudoElementKind(u16::from(kind))),
self.program.version(),
- ),
- None => WinnerGroupKey::current(node, self.program.version()),
+ )) {
+ Lookup::Known((_, state)) => Some(state),
+ Lookup::KnownAbsent | Lookup::Missing(_) => None,
+ },
+ None => self.element_record_winner_state(node),
};
- let Lookup::Known((_, state)) = self.current_winner_groups().token_for(key) else {
+ let Some(state) = state else {
return true;
};
@@ -4009,6 +4028,9 @@ impl RetainedState {
/// nothing inherited moves, and no custom property does, so a descendant's engine-computed
/// record stays exact even though this ancestor changes in the same batch.
pub(super) fn winner_delta_is_engine_confined(&self, node: StyleNodeID) -> bool {
+ if self.backed_host_pseudo_element(node).is_some() {
+ return false;
+ }
let target = computed::ComputedStyleTarget::new(node, u8::MAX);
let Lookup::Known((generation, state)) = self
.current_winner_groups()
diff --git a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
index 9347e5478d8..b717d4bd0f0 100644
--- a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs
@@ -954,12 +954,9 @@ impl RetainedState {
use bridge::element_adjustment_fact as fact;
let facts = self.computed_group_sets.adjustment_facts(node);
// The host samples the element's animations over the record it installs, as it does for
- // any element, and a record demand installs none of its own. A CSS animation needs a plan,
- // which this drive does not decide.
+ // any element, and a record demand installs none of its own.
let animates = facts & fact::HAS_ANIMATIONS != 0;
- if animates
- && (!scratch.host_applies_animation_plans || self.css_defined_animations.node_runs_a_css_animation(node))
- {
+ if animates && !scratch.host_applies_animation_plans {
self.counters.bump(Counter::EngineComputedRecordBailWinnerElement);
return Err(Unanswered::Refused);
}
@@ -1180,22 +1177,23 @@ impl RetainedState {
.bind_cascade_state(computed::ComputedStyleTarget::new(node, u8::MAX), (generation, state));
let old_record = old_record.unwrap_or(computed::FinalStyleRecordID::NONE);
let owes_a_transition_step = owes_a_transition_step && old_record != record;
- if owes_a_transition_step || detached_composition.is_some() {
- self.engine_computed_records_pending
- .entry(node)
- .or_default()
- .push(PendingEngineComputedRecord {
- node,
- pseudo_kind: u8::MAX,
- old_style_record: old_record,
- new_style_record: record,
- replaced: Some(replaced),
- cascade_state: None,
- longhand_evaluations: 0,
- owes_a_transition_step,
- detached_composition,
- });
- }
+ let cascade_state = (generation, state);
+ self.computed_group_sets
+ .set_pending_cascade_state(computed::ComputedStyleTarget::new(node, u8::MAX), cascade_state);
+ self.engine_computed_records_pending
+ .entry(node)
+ .or_default()
+ .push(PendingEngineComputedRecord {
+ node,
+ pseudo_kind: u8::MAX,
+ old_style_record: old_record,
+ new_style_record: record,
+ replaced: Some(replaced),
+ cascade_state: Some(cascade_state),
+ longhand_evaluations: 0,
+ owes_a_transition_step,
+ detached_composition,
+ });
Ok((old_record, record))
}
diff --git a/Tests/LibWeb/Text/expected/css/element-backed-pseudo-element-animations.txt b/Tests/LibWeb/Text/expected/css/element-backed-pseudo-element-animations.txt
new file mode 100644
index 00000000000..81f55aff53f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/element-backed-pseudo-element-animations.txt
@@ -0,0 +1,13 @@
+::placeholder: rgb(0, 64, 128)
+::details-content: rgb(0, 64, 128)
+::details-content child: rgb(0, 64, 128)
+::details-content after animating a custom property: rgb(0, 64, 128), child rgb(0, 64, 128)
+::placeholder after host restyle: rgb(0, 64, 128), rgb(1, 2, 3)
+late rule, before: none, rgb(128, 128, 128)
+late rule, after: recolor, rgb(0, 64, 128)
+document.getAnimations(): control
+getAnimations({ subtree: true }): 0, 0
+events: animationstart on control
+::placeholder with a value: none, rgb(128, 128, 128)
+::placeholder without a value: block, rgb(0, 64, 128)
+::placeholder after animation-name: none: none, rgb(128, 128, 128)
diff --git a/Tests/LibWeb/Text/input/css/element-backed-pseudo-element-animations.html b/Tests/LibWeb/Text/input/css/element-backed-pseudo-element-animations.html
new file mode 100644
index 00000000000..9c547a37192
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/element-backed-pseudo-element-animations.html
@@ -0,0 +1,77 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ @keyframes recolor {
+ from { color: rgb(0, 0, 255); }
+ to { color: rgb(0, 128, 0); }
+ }
+ #input::placeholder, #details::details-content, #control {
+ animation: recolor 100s linear -50s paused;
+ }
+ #input.moved::placeholder {
+ background-color: rgb(1, 2, 3);
+ }
+ #input.stopped::placeholder {
+ animation-name: none;
+ }
+ @property --shade {
+ syntax: "<color>";
+ inherits: true;
+ initial-value: rgb(255, 0, 0);
+ }
+ @keyframes reshade {
+ from { --shade: rgb(0, 0, 255); }
+ to { --shade: rgb(0, 128, 0); }
+ }
+ #shaded::details-content {
+ color: var(--shade);
+ }
+ #shaded.started::details-content {
+ animation: reshade 100s linear -50s paused;
+ }
+</style>
+<input id="input" placeholder="Placeholder">
+<details id="details" open><summary>Summary</summary><p id="content">Content</p></details>
+<details id="shaded" open><summary>Summary</summary><p>Content</p></details>
+<input id="late" placeholder="Placeholder">
+<div id="control"></div>
+<script>
+ promiseTest(async () => {
+ const events = [];
+ for (const type of ["animationstart", "animationend", "animationcancel"])
+ document.addEventListener(type, event => events.push(`${type} on ${event.target.id}`), true);
+
+ const placeholderStyle = getComputedStyle(input, "::placeholder");
+ println(`::placeholder: ${placeholderStyle.color}`);
+ println(`::details-content: ${getComputedStyle(details, "::details-content").color}`);
+ println(`::details-content child: ${getComputedStyle(content).color}`);
+
+ shaded.classList.add("started");
+ println(`::details-content after animating a custom property: ${getComputedStyle(shaded, "::details-content").color}, child ${getComputedStyle(shaded.querySelector("p")).color}`);
+
+ input.classList.add("moved");
+ println(`::placeholder after host restyle: ${placeholderStyle.color}, ${placeholderStyle.backgroundColor}`);
+
+ const lateStyle = getComputedStyle(late, "::placeholder");
+ println(`late rule, before: ${lateStyle.animationName}, ${lateStyle.color}`);
+ const style = document.createElement("style");
+ style.textContent = "#late::placeholder { animation: recolor 100s linear -50s paused; }";
+ document.head.appendChild(style);
+ println(`late rule, after: ${lateStyle.animationName}, ${lateStyle.color}`);
+
+ await animationFrame();
+ const describe = animation => animation.effect.target.id;
+ println(`document.getAnimations(): ${document.getAnimations().map(describe).join(", ")}`);
+ println(`getAnimations({ subtree: true }): ${input.getAnimations({ subtree: true }).length}, ${details.getAnimations({ subtree: true }).length}`);
+ println(`events: ${events.join(", ")}`);
+
+ input.value = "Value";
+ await animationFrame();
+ println(`::placeholder with a value: ${placeholderStyle.display}, ${placeholderStyle.color}`);
+ input.value = "";
+ println(`::placeholder without a value: ${placeholderStyle.display}, ${placeholderStyle.color}`);
+
+ input.classList.add("stopped");
+ println(`::placeholder after animation-name: none: ${placeholderStyle.animationName}, ${placeholderStyle.color}`);
+ });
+</script>