Truly independent web browser
LibWeb: Let the hover lane hover an element whose animation it samples
Zaggy10240b3fd8609369
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rsindex db73b325856..741e3684532 100644--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/install.rs@@ -339,8 +339,8 @@ impl RetainedState {};let plan_owed = plans_owed.binary_search(&node).is_ok();let composition_owed = compositions_owed.binary_search(&node).is_ok();- let owes_an_animation_plan =- (plan_owed && self.record_declares_animations(new)) || self.row_owes_an_animation_plan(node, old, new);+ let owes_an_animation_plan = (plan_owed && self.record_declares_animations(new))+ || self.row_owes_an_animation_plan(node, old, new, record);let owes_a_transition_step = self.row_owes_a_transition_step(node, old_record, new_record);// The host composes the record where the element has animations, or the row owes their plan// or the transition step, before it settles the element's pseudo-elements. It composes it toodiff --git a/Libraries/LibWeb/Rust/src/css/style/publication.rs b/Libraries/LibWeb/Rust/src/css/style/publication.rsindex 65bfb324513..2b2298b08b3 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication.rs@@ -9,6 +9,7 @@ mod pseudo;use super::pipeline::compute::RootFontInputs;use super::*;+use crate::css::cascaded_properties::NO_PSEUDO_ELEMENT;use crate::css::computed_longhand_table::IN_DISPLAY_NONE_SUBTREE;use crate::css::computed_value_views::QuoteTransfer;use animations::DeclarationScope;@@ -118,26 +119,51 @@ impl RetainedState {}/// Whether the host owes an element the engine settled the animation plan its record decides,- /// once it installs the record: the record moved the declarations, or the element runs CSS- /// animations, whose `@keyframes` may have moved without the declarations.- pub(super) fn row_owes_an_animation_plan(&self, node: StyleNodeID, old: u64, new: u64) -> bool {- self.row_owes_an_animation_plan_declaring(node, old, new, || self.record_declares_animations(new))- }-- /// [`Self::row_owes_an_animation_plan`], for a `new` record of which `new_declares_animations`- /// answers whether it declares animations.- pub(super) fn row_owes_an_animation_plan_declaring(+ /// once it installs the record `new`: the record moved the declarations, or the element runs+ /// CSS animations the plan would change, as where their `@keyframes` moved without the+ /// declarations.+ pub(super) fn row_owes_an_animation_plan(&self,node: StyleNodeID,old: u64,new: u64,- new_declares_animations: impl Fn() -> bool,+ new_record: &std::sync::Arc<super::pipeline::Record>,) -> bool {// An element the host holds no record for, its style cleared under display:none and its// animations with it, starts the animations its record names as a first record does.let old = if self.held_style_records.contains(node) { old } else { 0 };- self.record_owes_an_animation_plan(old, new, new_declares_animations)- || self.css_defined_animations.node_runs_a_css_animation(node)+ self.record_owes_an_animation_plan(old, new, || self.record_declares_animations(new))+ || (self.css_defined_animations.node_runs_a_css_animation(node)+ && self+ .animation_plan_of_record(node, NO_PSEUDO_ELEMENT, new_record)+ .is_some())+ }++ /// The animation plan `record` decides for an element, or for its pseudo-element `pseudo_kind`,+ /// where applying it would change the animations they run: none where it would not, or where+ /// the record installs no `animation-name`. The definitions borrow the record's values.+ pub(crate) fn animation_plan_of_record(+ &self,+ node: StyleNodeID,+ pseudo_kind: u8,+ record: &std::sync::Arc<super::pipeline::Record>,+ ) -> Option<smallvec::SmallVec<[crate::css::style_compute::FfiComputedAnimation; 1]>> {+ let longhands = StyleRecordView::of_host_record(record).longhands();+ let declaration_scope = self.animation_name_declaration_scope_of(node, pseudo_kind, record)?;+ let existing_animations =+ self.element_css_defined_animations(node, crate::css::style_compute::animation_slot(pseudo_kind));+ let element_tree_scope = self.element_tree_scope(node);+ let mut definitions = smallvec::SmallVec::new();+ crate::css::style_compute::build_computed_animation_list(+ longhands,+ existing_animations,+ |name| {+ self.animation_keyframes()+ .resolve(declaration_scope, element_tree_scope, name)+ },+ &mut definitions,+ );+ (!animations::plan_changes_nothing(&definitions, existing_animations)).then_some(definitions)}/// Whether installing the `new` record the engine derived for an element, in place of thediff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex 98130af05da..856a4261c93 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -6939,7 +6939,7 @@ pub extern "C" fn rust_animation_range_edge(/// Which of an element's animation lists a computation belongs to, in the host's own numbering:/// zero for the element itself, and the pseudo-element's value plus one for each pseudo-element.-fn animation_slot(pseudo_kind: u8) -> crate::css::style::animations::AnimationSlot {+pub(crate) fn animation_slot(pseudo_kind: u8) -> crate::css::style::animations::AnimationSlot {match pseudo_kind == crate::css::cascaded_properties::NO_PSEUDO_ELEMENT {true => 0,false => pseudo_kind + 1,@@ -6989,24 +6989,8 @@ fn settled_animation_plan(pseudo_kind: u8,record: &std::sync::Arc<crate::css::style::pipeline::Record>,) -> Option<(smallvec::SmallVec<[FfiComputedAnimation; 1]>, bool)> {+ let definitions = style_engine.animation_plan_of_record(node, pseudo_kind, record)?;let longhands = crate::css::style::StyleRecordView::of_host_record(record).longhands();- let declaration_scope = style_engine.animation_name_declaration_scope_of(node, pseudo_kind, record)?;- let existing_animations = style_engine.element_css_defined_animations(node, animation_slot(pseudo_kind));- let element_tree_scope = style_engine.element_tree_scope(node);- let mut definitions = smallvec::SmallVec::new();- build_computed_animation_list(- longhands,- existing_animations,- |name| {- style_engine- .animation_keyframes()- .resolve(declaration_scope, element_tree_scope, name)- },- &mut definitions,- );- if crate::css::style::animations::plan_changes_nothing(&definitions, existing_animations) {- return None;- }let in_display_none_subtree =in_display_none_subtree_for_animations(style_engine, node, pseudo_kind, longhands, &definitions);Some((definitions, in_display_none_subtree))@@ -7081,7 +7065,7 @@ pub(crate) fn animation_names_declare_css_animations(names: &RetainedStyleValueD// https://drafts.csswg.org/css-values-4/#linked-properties// https://drafts.csswg.org/css-animations-1/#animations-fn build_computed_animation_list(+pub(crate) fn build_computed_animation_list(longhands: crate::css::style::ViewLonghands<'_>,existing_animations: &[crate::css::style::animations::CssDefinedAnimation],resolve_keyframes: impl Fn(&[u16]) -> Option<usize>,diff --git a/Libraries/LibWeb/Rust/src/css/transition.rs b/Libraries/LibWeb/Rust/src/css/transition.rsindex f370995d979..b1cb13da307 100644--- a/Libraries/LibWeb/Rust/src/css/transition.rs+++ b/Libraries/LibWeb/Rust/src/css/transition.rs@@ -759,7 +759,8 @@ struct RunningTransitionAt {const FULL_KEY: f64 = 100.0 * 1000.0;/// The transitions the host runs on the element `node` names, as they stand at `at`, the time a step decides at, in-/// the document timeline's milliseconds: every animation of the element must be one the engine describes as such.+/// the document timeline's milliseconds. The CSS animations the host runs on it are not among them: the ticks sample+/// those as they are.fn host_transitions_at(engine: &crate::css::style::StyleEngine,node: crate::css::style::tree::StyleNodeID,@@ -775,7 +776,7 @@ fn host_transitions_at(.iter().filter_map(|effect| {if !effect.is_transition {- return Some(Err("an element with animations"));+ return None;}let Some(timing) = effect.timing.clone() else {return Some(Err("a transition the host has not sampled"));@@ -1508,6 +1509,15 @@ impl HoverTransitions {if effects.is_empty() && !decided_over_running {return Ok(None);}+ // The ticks sample the transitions a hover started on an element in place of its CSS animations, which they+ // sample as they are otherwise: an element that runs transitions beside CSS animations is the host's.+ if engine+ .element_animation_effects(node, 0)+ .iter()+ .any(|effect| !effect.is_transition)+ {+ return Err("transitions beside animations");+ }let duration = runs.iter().map(|run| run.timing.timing.start_delay + run.timing.timing.iteration_duration - run.local_time)diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-hovers-an-element-whose-animation-it-samples.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-hovers-an-element-whose-animation-it-samples.txtnew file mode 100644index 00000000000..584a149f568--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-hovers-an-element-whose-animation-it-samples.txt@@ -0,0 +1,7 @@+presented left at 3 s: 100+cursor at a move over the box: Crosshair+presented height after the move: 80+presented left at 4 s: 200+last frame presented by: clock+box matches :hover after the task: true+cursor after the task: Crosshairdiff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-leaves-transitions-beside-an-animation-to-the-host.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-leaves-transitions-beside-an-animation-to-the-host.txtnew file mode 100644index 00000000000..e4ed4c1c1d3--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-leaves-transitions-beside-an-animation-to-the-host.txt@@ -0,0 +1,3 @@+height on screen beside the task: 60+box matches :hover after the task: true+height after the task: 80diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-hovers-an-element-whose-animation-it-samples.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-hovers-an-element-whose-animation-it-samples.htmlnew file mode 100644index 00000000000..d9e34f4b101--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-hovers-an-element-whose-animation-it-samples.html@@ -0,0 +1,45 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script src="frame-in-flight.js"></script>+<style>+ body { margin: 0; }+ #stage { position: relative; width: 400px; height: 150px; }+ #box { position: absolute; width: 100px; height: 60px; top: 20px; left: -200px; cursor: cell; }+ #box:hover { height: 80px; }+ #stage.active #box { animation: walk 10s linear infinite; }+ @keyframes walk { from { left: -200px; } to { left: 800px; } }+</style>+<div id="stage"><div id="box"></div></div>+<script>+ // A box the clock lane moves across the pointer at rest is hovered by the lane as the pointer moves, like any other+ // box: a hover that changes nothing of the element's animations leaves their plan as it is, so the lane installs the+ // hover's style itself and keeps sampling the animation over it, and shows the cursor of the box. The host hovers+ // the same box afterwards.+ asyncTest(async done => {+ internals.mouseMove(150, 50);+ await twoFrames();+ const result = await whileLaneAnimates(() => {+ stage.classList.add("active");+ return box.getAnimations()[0];+ }, (frameTime, animation, startTime) => {+ const lines = [];+ // 3 s in, the box spans 100..200 by 20..80, under the pointer.+ internals.injectClockTick(startTime + 3000);+ lines.push(`presented left at 3 s: ${internals.presentedBorderBox(box)?.x}`);+ internals.injectHoverPointer(150, 50, startTime + 3016);+ lines.push(`cursor at a move over the box: ${internals.currentCursor()}`);+ lines.push(`presented height after the move: ${internals.presentedBorderBox(box)?.height}`);+ // 4 s in, the lane still samples the animation over the hovered style.+ internals.injectClockTick(startTime + 4000);+ lines.push(`presented left at 4 s: ${internals.presentedBorderBox(box)?.x}`);+ lines.push(`last frame presented by: ${internals.lastFramePresentedBy(document)}`);+ return lines;+ });+ for (const line of result)+ println(line);+ await nextFrame();+ println(`box matches :hover after the task: ${box.matches(":hover")}`);+ println(`cursor after the task: ${internals.currentCursor()}`);+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-leaves-transitions-beside-an-animation-to-the-host.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-leaves-transitions-beside-an-animation-to-the-host.htmlnew file mode 100644index 00000000000..258aeaa6d2f--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-leaves-transitions-beside-an-animation-to-the-host.html@@ -0,0 +1,26 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script src="frame-in-flight.js"></script>+<style>+ body { margin: 0; }+ #box { width: 100px; height: 60px; animation: fade 100s linear infinite; transition: outline-color 100s linear; outline: 4px solid rgb(0, 0, 255); }+ @keyframes fade { to { opacity: 0.5; } }+ #box:hover { height: 80px; outline-color: rgb(0, 128, 0); }+</style>+<div id="box"></div>+<script>+ // The ticks of the lane sample either the animations the host runs on an element or the transitions the lane's+ // hover started on it. A hover that starts a transition on an element that runs a CSS animation is left to the+ // host, which runs both: the box shows nothing of the hover beside the task.+ asyncTest(async done => {+ const result = await whileLaneHovers(frameTime => {+ internals.injectHoverPointer(50, 30, frameTime + 16);+ return internals.presentedBorderBox(box)?.height;+ });+ println(`height on screen beside the task: ${result}`);+ await nextFrame();+ println(`box matches :hover after the task: ${box.matches(":hover")}`);+ println(`height after the task: ${box.getBoundingClientRect().height}`);+ done();+ });+</script>