Truly independent web browser
LibWeb: Keep clock lanes running beside the task that handles a press
Andreas Kling481130bb8b3e
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cppindex 99131b815d3..c18512077e9 100644--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp@@ -753,8 +753,9 @@ static bool is_renderable(DOM::Document const& document)}// Takes in what the render clock's lanes did, then the queued input events. The lanes wait for the plan of the rendering-// update with the serial number `update_serial`. Answers the documents whose lanes were taken in.-Vector<GC::Root<DOM::Document>> EventLoop::take_clock_lanes_and_input_events_in(u64 update_serial)+// update with the serial number `update_serial`, or tick on beside the task that handles a press where no update comes+// with it. Answers the documents whose lanes were taken in.+Vector<GC::Root<DOM::Document>> EventLoop::take_clock_lanes_and_input_events_in(Optional<u64> update_serial){// AD-HOC: The render clock's lanes present frames of a document's animations and hover beside the tasks since the// last update, at display ticks later than the opportunity this update renders for, which reached the event@@ -788,7 +789,10 @@ Vector<GC::Root<DOM::Document>> EventLoop::take_clock_lanes_and_input_events_in(if (auto* root_arena = root_document ? root_document->layout_node_arena_if_created() : nullptr)outer_input_event = Layout::RustFFI::document_host_newest_pointer_input_event(root_arena->host());}- if (Layout::RustFFI::document_host_take_clock_lanes_in(arena->host(), update_serial, outer_input_event)) {+ auto const lane_presented = update_serial.has_value()+ ? Layout::RustFFI::document_host_take_clock_lanes_in(arena->host(), *update_serial, outer_input_event)+ : Layout::RustFFI::document_host_take_in_what_clock_lanes_did(arena->host(), outer_input_event);+ if (lane_presented) {tick_presented = true;navigable->set_needs_to_record_display_list();navigable->set_needs_repaint();@@ -855,8 +859,9 @@ Vector<GC::Root<DOM::Document>> EventLoop::take_clock_lanes_and_input_events_in(if (!style_computer)continue;auto* arena = document->layout_node_arena_if_created();- bool const lanes_taken_in = any_of(documents_with_lanes, [&](auto const& taken_in) { return taken_in.ptr() == document.ptr(); });- if (lanes_taken_in || !arena || !Layout::RustFFI::document_host_may_have_lanes(arena->host()))+ // NB: Lanes that tick on beside a task may still name them, and report that later.+ bool const lanes_stopped = update_serial.has_value() && any_of(documents_with_lanes, [&](auto const& taken_in) { return taken_in.ptr() == document.ptr(); });+ if (lanes_stopped || !arena || !Layout::RustFFI::document_host_may_have_lanes(arena->host()))style_computer->forget_style_nodes_retired_beside_lanes();}return documents_with_lanes;@@ -874,7 +879,9 @@ void EventLoop::queue_task_to_process_input_events()m_input_events_task_queued = false;if (m_running_rendering_task || m_rendering_update_in_flight)return;- take_clock_lanes_and_input_events_in(m_rendering_update_serial + 1);+ // NB: No rendering update comes with this task, and script may run for long before the next one: the lanes+ // tick on.+ take_clock_lanes_and_input_events_in({});}));}diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h b/Libraries/LibWeb/HTML/EventLoop/EventLoop.hindex 863497c084e..7479644bf12 100644--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.h+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.h@@ -221,7 +221,7 @@ private:virtual void visit_edges(Visitor&) override;void process_input_events() const;- Vector<GC::Root<DOM::Document>> take_clock_lanes_and_input_events_in(u64 update_serial);+ Vector<GC::Root<DOM::Document>> take_clock_lanes_and_input_events_in(Optional<u64> update_serial);void update_the_rendering();// How the steps after style and layout take the layout of the docs: up to date, or as the update's layout that flew// left it, whatever was written since.diff --git a/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs b/Libraries/LibWeb/Rust/src/css/style/hover_lane.rsindex 2ab00656f0f..3c6b065f224 100644--- a/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs+++ b/Libraries/LibWeb/Rust/src/css/style/hover_lane.rs@@ -906,7 +906,7 @@ pub unsafe extern "C" fn style_engine_adopt_lane_transitions(transition_count: usize,),) {- for transitions in host.take_lane_transitions() {+ host.adopt_lane_transitions(|transitions| {let lane_transitions: Vec<_> = transitions.lane_transitions().collect();let host_seen = &transitions.host_seen;// SAFETY: Guaranteed by the caller; the element's transitions keep the values alive across the call.@@ -922,5 +922,5 @@ pub unsafe extern "C" fn style_engine_adopt_lane_transitions(lane_transitions.len(),);}- }+ });}diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex 3544696b2c2..f4b05edadd8 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -66,7 +66,7 @@ pub(crate) mod hover;mod lane;pub(crate) use hover::PendingPointer;pub(crate) use lane::LaneDelivery;-pub(super) use lane::{LaneSlot, note_host_write, retire_slot, seal_plan, take_lanes_in};+pub(super) use lane::{LaneSlot, note_host_write, retire_slot, seal_plan, take_lane_report, take_lanes_in};/// What the ticks of a lane sample, sealed at the end of the lane's frame's rendering update.pub(crate) struct ClockPlan {@@ -1822,7 +1822,7 @@ pub extern "C" fn document_host_drop_clock_plan(host: &DocumentHost, update: u64/// stand, and the lanes' hover goes on.#[unsafe(no_mangle)]pub extern "C" fn document_host_note_animation_change(host: &DocumentHost) {- host.clock_ticks().note_animation_change();+ host.note_animation_change();}/// Takes in what the lanes of `host`'s document did, as a rendering update begins, and answers whether a tick of a lane@@ -1837,6 +1837,14 @@ pub extern "C" fn document_host_take_clock_lanes_in(host: &DocumentHost, update:host.take_clock_lanes_in(update, outer_input_event)}+/// Takes in what the lanes of `host`'s document did, as a task between two rendering updates handles a press, and+/// answers as [`document_host_take_clock_lanes_in`] does. No frame of the host's follows yet, so the lanes tick on.+/// `outer_input_event` is as there.+#[unsafe(no_mangle)]+pub extern "C" fn document_host_take_in_what_clock_lanes_did(host: &DocumentHost, outer_input_event: u64) -> bool {+ host.take_in_what_clock_lanes_did(outer_input_event)+}+/// Whether the lanes of `host`'s document may hover or run transitions beside the tasks: the last plan the host sealed for/// them was one.#[unsafe(no_mangle)]diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rsindex fe33258078f..8406637a799 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/lane.rs@@ -284,6 +284,13 @@ pub(in crate::render_state) fn take_lanes_in(ticks: &Arc<ClockTicks>, update: u6.unwrap_or_default()}+/// On the render owner: answers what the hover of the lanes of the document `ticks` belong to did so far, and leaves+/// them ticking, for the host to take in between two rendering updates.+#[must_use]+pub(in crate::render_state) fn take_lane_report(ticks: &Arc<ClockTicks>) -> LaneReport {+ with_slot(ticks.document, LaneSlot::take_report).unwrap_or_default()+}+/// On the render owner: runs the tick queued for the lanes `ticks` belong to.pub(super) fn tick(ticks: &Arc<ClockTicks>) {ticks.queued.swap(false, Ordering::AcqRel);diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rsindex ea91dff4609..8f00ea7ba31 100644--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs@@ -121,6 +121,8 @@ pub struct DocumentHost {/// The steps the hover of the lanes decided that the last rendering update took in, which the host runs as the lanes/// do from then.lane_transitions: RefCell<Vec<Arc<HoverTransitions>>>,+ /// Whether the host is taking over transitions the hover of the lane started, as it changes the animations it runs.+ adopts_lane_transitions: Cell<bool>,/// Whether the frame in flight waits for a test to release it.frame_held_for_testing: Cell<bool>,/// The root and the sealed document computation inputs of the last style update the host took or let fly,@@ -220,6 +222,7 @@ impl DocumentHost {lent_relational_arrival_keys: RefCell::default(),ticks: ClockTicks::new(document),lane_transitions: RefCell::default(),+ adopts_lane_transitions: Cell::default(),frame_held_for_testing: Cell::default(),style_inputs: RefCell::default(),hover_target: Cell::default(),@@ -519,10 +522,24 @@ impl DocumentHost {}}- /// Takes the transitions the hover of the lane leaves elements running that the host has yet to run as the lane does,- /// which it runs from now on.- pub(crate) fn take_lane_transitions(&self) -> Vec<Arc<HoverTransitions>> {- std::mem::take(&mut *self.lane_transitions.borrow_mut())+ /// Hands `adopt` each of the transitions the hover of the lane leaves elements running that the host has yet to run+ /// as the lane does, which it runs from now on. What that changes of the host's animations is what the lane samples+ /// already, so the animations of its plan stand.+ pub(crate) fn adopt_lane_transitions(&self, mut adopt: impl FnMut(&HoverTransitions)) {+ self.adopts_lane_transitions.set(true);+ let lane_transitions = std::mem::take(&mut *self.lane_transitions.borrow_mut());+ for transitions in lane_transitions {+ adopt(&transitions);+ }+ self.adopts_lane_transitions.set(false);+ }++ /// Notes that script changed an animation of the document: the animations of the plans sealed before no longer+ /// stand.+ pub(super) fn note_animation_change(&self) {+ if !self.adopts_lane_transitions.get() {+ self.ticks.note_animation_change();+ }}/// Keeps the root and the sealed inputs of a style update the host takes or lets fly, for the hover of a lane@@ -869,6 +886,25 @@ impl DocumentHost {}None => Some(on_render_side(0, move || super::clock::take_lanes_in(&ticks, update))),};+ self.keep_what_lanes_did(report, outer_input_event)+ }++ /// Takes in what the lanes did, as a task between two rendering updates handles a press, and answers whether a tick+ /// of a lane presented a frame since the host last took in what they did. The host hovers as+ /// [`Self::take_clock_lanes_in`] has it, but no frame of the host's follows yet, so the lanes tick on from their+ /// fork beside the task and the tasks after it.+ pub(super) fn take_in_what_clock_lanes_did(&self, outer_input_event: u64) -> bool {+ // NB: Lanes an update took in did nothing since, and wait for its plan.+ let report = (!self.lanes_wait_for_the_update()).then(|| {+ let ticks = Arc::clone(&self.ticks);+ on_render_side(0, move || super::clock::take_lane_report(&ticks))+ });+ self.keep_what_lanes_did(report, outer_input_event)+ }++ /// Keeps `report` of what the lanes did, if any, and has the host hover where the compositor said the pointer went+ /// last. Answers whether a tick of a lane presented a frame the report tells of.+ fn keep_what_lanes_did(&self, report: Option<super::clock::LaneReport>, outer_input_event: u64) -> bool {// A same-process iframe's lanes hear of the pointer from the lanes of the document around it, which handed them// nothing of a newer move the compositor told that document of: the pointer may have gone elsewhere, and the// host hovers nothing of the older move, nor does the next lane. It hovers where the pointer went as it handles@@ -885,7 +921,7 @@ impl DocumentHost {}if super::clock::hover::logs_hover() {eprintln!(- "{} hover lane: update takes the lanes in: moved {}, presented {presented}, {} steps to adopt, newest pointer {:?}",+ "{} hover lane: host takes in what the lanes did: moved {}, presented {presented}, {} steps to adopt, newest pointer {:?}",super::clock::hover::log_time(),self.lane_move.get().is_some(),self.lane_transitions.borrow().len(),@@ -940,6 +976,8 @@ impl DocumentHost {return true;}self.newest_pointer_input_event.set(input_event_id);+ // NB: Lanes may tick beside a task that handles a press, and no tick hovers a move older than this event.+ self.ticks.note_input_handled(input_event_id);false}diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-ticks-on-after-a-press.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-ticks-on-after-a-press.txtindex 0e611a59c5f..4ea1c49f377 100644--- a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-ticks-on-after-a-press.txt+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/clock-lane-ticks-on-after-a-press.txt@@ -1,2 +1,2 @@the animation moved before the press: true-a tick after the press moved the animation on: false+a tick after the press moved the animation on: truediff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-hovers-on-after-a-press.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-hovers-on-after-a-press.txtindex 4b62221a7c4..dbf2e2e13e9 100644--- a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-hovers-on-after-a-press.txt+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-hovers-on-after-a-press.txt@@ -1,2 +1,2 @@-last frame presented by: commit+last frame presented by: clockbox matches :hover: truediff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-transition-runs-on-after-a-press.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-transition-runs-on-after-a-press.txtindex 63ee795f237..57459df9f29 100644--- a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-transition-runs-on-after-a-press.txt+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-transition-runs-on-after-a-press.txt@@ -1,3 +1,3 @@the transition moved before the press: true-a tick after the press moved the transition on: false+a tick after the press moved the transition on: truetransitions the host runs: 1