Truly independent web browser
LibWeb: Name scroll timelines by identity in clock plans
Andreas Klingb1c144ea9ded
diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.cpp b/Libraries/LibWeb/Animations/ScrollTimeline.cppindex edcab600dd0..133a1d1c8fa 100644--- a/Libraries/LibWeb/Animations/ScrollTimeline.cpp+++ b/Libraries/LibWeb/Animations/ScrollTimeline.cpp@@ -248,6 +248,8 @@ ScrollTimeline::ScrollTimeline(DOM::Document& document, Source source, ScrollAxi, m_source(source), m_axis(axis){+ static u64 s_next_clock_identity = 1;+ m_clock_identity = s_next_clock_identity++;}void ScrollTimeline::visit_edges(GC::Cell::Visitor& visitor)diff --git a/Libraries/LibWeb/Animations/ScrollTimeline.h b/Libraries/LibWeb/Animations/ScrollTimeline.hindex e712d0330da..546b3c468e1 100644--- a/Libraries/LibWeb/Animations/ScrollTimeline.h+++ b/Libraries/LibWeb/Animations/ScrollTimeline.h@@ -61,6 +61,9 @@ public:};Optional<FollowedScroller> const& followed_scroller() const { return m_followed_scroller; }+ // What names the timeline to the render clock, whose ticks sample its animations.+ u64 clock_identity() const { return m_clock_identity; }+virtual bool is_progress_based() const override { return true; }virtual AttachmentInterval interval_for_attachment_range(AnimationAttachmentRange const&) const override;@@ -102,6 +105,7 @@ private:Optional<double> m_last_max_scroll_offset;Optional<FollowedScroller> m_followed_scroller;+ u64 m_clock_identity { 0 };};ScrollAxis scroll_axis_from_css_axis(CSS::Axis);diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cppindex 48471bc14e5..9961f4281d9 100644--- a/Libraries/LibWeb/CSS/StyleComputer.cpp+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp@@ -610,13 +610,11 @@ ComputedValuesFFI::FfiEffectTiming style_engine_effect_timing(Animations::Keyfratiming.has_timeline_origin_time = origin_time.has_value();timing.timeline_origin_time = origin_time.value_or(0);}- // A scroll timeline's time is the scroll progress of the scroller it follows, which is what lets a clock tick- // sample it where the compositor has scrolled to.+ // A scroll timeline's time is the progress of the scroller it follows, which is what lets a clock tick sample+ // it where the compositor has scrolled to.if (auto const* scroll_timeline = as_if<Animations::ScrollTimeline>(*timeline); scroll_timeline && scroll_timeline->followed_scroller().has_value()) {- auto const& scroller = *scroll_timeline->followed_scroller();timing.has_timeline_scroller = true;- timing.timeline_scroller_is_vertical = scroller.vertical;- timing.timeline_scroller = scroller.scroll_node.node_id.value();+ timing.scroll_timeline = scroll_timeline->clock_identity();}if (auto minimum = timeline->minimum_timeline_time(), maximum = timeline->maximum_timeline_time(); minimum.has_value() && maximum.has_value()) {timing.has_timeline_boundaries = true;diff --git a/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp b/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cppindex 995f4f53e95..fedbf9b64bc 100644--- a/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp+++ b/Libraries/LibWeb/HTML/EventLoop/ClockPlan.cpp@@ -36,8 +36,8 @@ static bool timing_is_in(Animations::KeyframeEffect const& effect, Animations::Treturn effect.start_delay().type == type && effect.iteration_duration().type == type && effect.active_duration().type == type;}-// Adds the scroll timeline `timeline` that `effect` runs on, at `local_time`, to `scroll_timelines`. Answers whether a-// tick may sample it.+// Adds the scroll timeline `timeline` that `effect` runs on, at `local_time`, to `scroll_timelines`, whose last entry is+// the timeline's where an effect of it was planned before. Answers whether a tick may sample it.static bool plan_scroll_timeline(Vector<Layout::RustFFI::FfiPlannedScrollTimeline>& scroll_timelines, Animations::ScrollTimeline const& timeline, Animations::KeyframeEffect const& effect, Optional<Animations::TimeValue> local_time){auto const& scroller = timeline.followed_scroller();@@ -46,10 +46,10 @@ static bool plan_scroll_timeline(Vector<Layout::RustFFI::FfiPlannedScrollTimelin|| !local_time.has_value() || local_time->type != Animations::TimeValue::Type::Percentage|| !timing_is_in(effect, Animations::TimeValue::Type::Percentage))return false;- auto scroller_id = scroller->scroll_node.node_id.value();- if (!scroll_timelines.find_first_index_if([&](auto const& planned) { return planned.scroller == scroller_id && planned.vertical == scroller->vertical; }).has_value()) {+ if (scroll_timelines.is_empty() || scroll_timelines.last().timeline != timeline.clock_identity()) {scroll_timelines.append({- .scroller = scroller_id,+ .timeline = timeline.clock_identity(),+ .scroller = scroller->scroll_node.node_id.value(),.vertical = scroller->vertical,.max_scroll_offset = scroller->max_scroll_offset,.progress = progress->value,diff --git a/Libraries/LibWeb/Rust/src/css/style/animations.rs b/Libraries/LibWeb/Rust/src/css/style/animations.rsindex 0604f20d444..14cdff143c0 100644--- a/Libraries/LibWeb/Rust/src/css/style/animations.rs+++ b/Libraries/LibWeb/Rust/src/css/style/animations.rs@@ -395,18 +395,16 @@ pub(crate) struct AnimationTimelineSamples<'a> {scroll_progress: &'a [ScrollProgress],}-/// The scroll progress, in percent, of the scroll node of an element or of a document's viewport, by its-/// unique node id, along one axis: the time of a scroll timeline that follows it.+/// The progress, in percent, of a scroll timeline, which is its time, by the identity the host gave the timeline.#[derive(Clone, Copy, Debug, PartialEq)]pub(crate) struct ScrollProgress {- pub(crate) scroller: i64,- pub(crate) vertical: bool,+ pub(crate) timeline: u64,pub(crate) progress: f64,}impl<'a> AnimationTimelineSamples<'a> {/// The times a clock tick at `timestamp` samples at, which moves every document timeline: a timestamp less its- /// timeline's origin time, and every scroll timeline that follows a scroller in `scroll_progress` to its progress+ /// timeline's origin time, and every scroll timeline in `scroll_progress`, sorted by timeline, to its progress/// there. No other timeline is sampled with it.#[must_use]pub(crate) fn at_tick(timestamp: f64, scroll_progress: &'a [ScrollProgress]) -> Self {@@ -423,12 +421,9 @@ impl<'a> AnimationTimelineSamples<'a> {None => Some(timing.has_timeline_time.then_some(timing.timeline_time)),Some(_) if timing.has_timeline_scroller => self.scroll_progress- .iter()- .find(|scroll| {- scroll.scroller == timing.timeline_scroller- && scroll.vertical == timing.timeline_scroller_is_vertical- })- .map(|scroll| Some(scroll.progress)),+ .binary_search_by_key(&timing.scroll_timeline, |scroll| scroll.timeline)+ .ok()+ .map(|index| Some(self.scroll_progress[index].progress)),Some(timestamp) => timing.has_timeline_origin_time.then_some(Some(timestamp - timing.timeline_origin_time)),@@ -851,8 +846,7 @@ mod tests {timing: FfiEffectTiming {has_timeline_origin_time: false,has_timeline_scroller: true,- timeline_scroller_is_vertical: true,- timeline_scroller: 7,+ scroll_timeline: 7,has_timeline_boundaries: false,minimum_timeline_time: 0.0,maximum_timeline_time: 0.0,@@ -861,10 +855,9 @@ mod tests {},..timing_at(25.0)};- let scrolled = |vertical| {+ let scrolled = |timeline| {[ScrollProgress {- scroller: 7,- vertical,+ timeline,progress: 60.0,}]};@@ -874,13 +867,13 @@ mod tests {"where the host sampled it");assert_eq!(- on_scroll_timeline.key_at(AnimationTimelineSamples::at_tick(1000.0, &scrolled(true))),+ on_scroll_timeline.key_at(AnimationTimelineSamples::at_tick(1000.0, &scrolled(7))),Some(Some(60_000.0)));assert_eq!(- on_scroll_timeline.key_at(AnimationTimelineSamples::at_tick(1000.0, &scrolled(false))),+ on_scroll_timeline.key_at(AnimationTimelineSamples::at_tick(1000.0, &scrolled(8))),None,- "a tick that has no progress for its scroller does not move it"+ "a tick that has no progress for its timeline does not move it");let finished = EffectTiming {timing: FfiEffectTiming {@@ -892,7 +885,7 @@ mod tests {..on_scroll_timeline};assert_eq!(- finished.key_at(AnimationTimelineSamples::at_tick(1000.0, &scrolled(true))),+ finished.key_at(AnimationTimelineSamples::at_tick(1000.0, &scrolled(7))),Some(Some(60_000.0)),"a finished animation runs again as a tick scrolls back before its end");@@ -905,7 +898,7 @@ mod tests {..finished};assert_eq!(- paused.key_at(AnimationTimelineSamples::at_tick(1000.0, &scrolled(true))),+ paused.key_at(AnimationTimelineSamples::at_tick(1000.0, &scrolled(7))),Some(Some(40_000.0)),"a paused animation holds");diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex eb704955801..4ea4c579ec0 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -7410,7 +7410,7 @@ pub const SUBSTITUTION_MARK_CUSTOM_FUNCTION: u8 = 1 << 4;#[repr(C)]#[derive(Clone, Copy, Debug, Default, PartialEq)]pub struct FfiEffectTiming {- pub timeline_scroller: i64,+ pub scroll_timeline: u64,pub minimum_timeline_time: f64,pub maximum_timeline_time: f64,pub timeline_time: f64,@@ -7430,11 +7430,9 @@ pub struct FfiEffectTiming {/// The effect's animation runs on a document timeline, whose time is a timestamp less this origin/// time.pub has_timeline_origin_time: bool,- /// The effect's animation runs on a scroll timeline, whose time is the scroll progress, in percent, of- /// the scroll node `timeline_scroller` names, a unique node id (an element's, or a document's for its- /// viewport), along the vertical or the horizontal axis.+ /// The effect's animation runs on the scroll timeline `scroll_timeline` names, whose time is its progress, in+ /// percent, where the scroller it follows is scrolled to.pub has_timeline_scroller: bool,- pub timeline_scroller_is_vertical: bool,/// The effect's animation runs on a progress-based timeline, whose minimum and maximum timeline times/// `minimum_timeline_time` and `maximum_timeline_time` are.pub has_timeline_boundaries: bool,diff --git a/Libraries/LibWeb/Rust/src/css/transition.rs b/Libraries/LibWeb/Rust/src/css/transition.rsindex 32eba671c4b..b101b109b71 100644--- a/Libraries/LibWeb/Rust/src/css/transition.rs+++ b/Libraries/LibWeb/Rust/src/css/transition.rs@@ -1203,8 +1203,7 @@ fn started_transition_timing(has_timeline_time: false,has_timeline_origin_time: false,has_timeline_scroller: false,- timeline_scroller_is_vertical: false,- timeline_scroller: 0,+ scroll_timeline: 0,has_timeline_boundaries: false,minimum_timeline_time: 0.0,maximum_timeline_time: 0.0,diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex 05b5e34e031..04334576e1f 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -89,6 +89,8 @@ pub(crate) struct ClockPlan {#[repr(C)]#[derive(Clone, Copy, Debug)]pub struct FfiPlannedScrollTimeline {+ /// The identity the host gave the timeline.+ pub timeline: u64,/// The unique node id of the element whose scroll node the timeline follows, or of the document for its viewport,/// and whether along the vertical axis.pub scroller: i64,@@ -118,6 +120,8 @@ impl ClockPlan {round: ClockRound,hover: Option<hover::HoverPlan>,) -> Self {+ let mut scroll_timelines = scroll_timelines;+ scroll_timelines.sort_unstable_by_key(|timeline| timeline.timeline);Self {elements,time_origin,@@ -129,8 +133,8 @@ impl ClockPlan {}}- /// The progress of the scroll timelines where `scroll_offsets` scrolled their scrollers to, or where the host laid- /// out those it has none for.+ /// The progress of the scroll timelines, sorted by timeline, where `scroll_offsets` scrolled their scrollers to, or+ /// where the host laid out those it has none for.fn scroll_progress(&self, scroll_offsets: &[FfiScrollOffset]) -> SmallVec<[ScrollProgress; 2]> {self.scroll_timelines.iter()@@ -143,8 +147,7 @@ impl ClockPlan {position / timeline.max_scroll_offset * 100.0});ScrollProgress {- scroller: timeline.scroller,- vertical: timeline.vertical,+ timeline: timeline.timeline,progress,}})