Truly independent web browser
LibWeb: Keep clock lanes off rows a removal left ahead of layout
Aliaksandr Kalenik0a2dffc13501
diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex fc281fb6281..ad34e8749e0 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -1232,6 +1232,9 @@ pub(crate) struct LayoutNodeArena {/// The boxes whose committed links a full commit met at the top of its pass, which no fragment holds.pass_level_committed_links: Vec<NodeSlotId>,pub(crate) links_held_apart_from_their_containing_blocks: CowSet<NodeSlotId>,+ /// Whether a node left the document since a layout round last left layout up to date. Its boxes leave the rows at+ /// once, while the committed layout of the boxes around them names them until that round lays those out again.+ boxes_removed_ahead_of_layout: bool,pre_order_labels: ForkVec<u64>,free_list: ForkVec<u32>,/// A row a tree build made already, which the next allocation hands out: see [`Self::allocate_preallocated_row`].@@ -1379,6 +1382,7 @@ impl LayoutNodeArena {committed_link_holders: ForkVec::default(),pass_level_committed_links: Vec::new(),links_held_apart_from_their_containing_blocks: Default::default(),+ boxes_removed_ahead_of_layout: false,pre_order_labels: ForkVec::default(),free_list: ForkVec::default(),preallocated_row: None,@@ -3392,6 +3396,24 @@ impl LayoutNodeArena {&& !self.has_partial_relayout_boundary_roots()}+ /// Whether the rows may hold boxes of nodes that left the document, which the committed layout of the boxes around+ /// them still names: only a layout round that leaves layout up to date takes them out of it.+ pub(crate) fn has_boxes_removed_ahead_of_layout(&self) -> bool {+ self.boxes_removed_ahead_of_layout+ }++ pub(crate) fn note_boxes_removed_ahead_of_layout(&mut self) {+ self.boxes_removed_ahead_of_layout = true;+ }++ /// Notes that a layout round ended, which took the boxes of the nodes that left the document out of the committed+ /// layout where it left layout up to date.+ pub(crate) fn note_layout_round_ended(&mut self) {+ if self.layout_is_up_to_date(false) {+ self.boxes_removed_ahead_of_layout = false;+ }+ }+pub(crate) fn layout_tree_update_marks_need_build(&self) -> bool {self.layout_tree_update_marks().need_build()}diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 83896d1fe36..88a4d40b538 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -648,12 +648,16 @@ pub(crate) fn detach_remaining_rows_for_removal({arena.set_needs_full_layout_tree_update(true);}+ if arena.has_bound_pseudo_element_rows(node) {+ arena.note_boxes_removed_ahead_of_layout();+ }clear_synthetic_pseudo_element_boxes(host_calls, arena, node);}let row = arena.bound_row(node);if row.is_invalid() {return;}+ arena.note_boxes_removed_ahead_of_layout();arena.pin_style_record_for_detachment(row);crate::painting::ffi::paintable_cleared_from_node_leaving_ancestors(host_calls, arena, row);let top_layer_placement = topmost_layout_node_of_top_layer_placement(arena, row);diff --git a/Libraries/LibWeb/Rust/src/layout/update_layout.rs b/Libraries/LibWeb/Rust/src/layout/update_layout.rsindex 533821186bf..2ed6f253445 100644--- a/Libraries/LibWeb/Rust/src/layout/update_layout.rs+++ b/Libraries/LibWeb/Rust/src/layout/update_layout.rs@@ -737,6 +737,7 @@ impl LayoutRoundJob {let mut answer = self.run_with(state, &work);answer.work = work.resolve(state.arena_mut());answer.owed_images = OwedImage::take_from(state.arena_mut());+ state.arena_mut().note_layout_round_ended();answer}diff --git a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rsindex 9b96466beed..04ee81e1b3d 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock/hover.rs@@ -1469,6 +1469,9 @@ impl Lane {frame_time_nanoseconds: i64,) -> Result<Arc<VisualContextTree>, &'static str> {let structural_epoch_on_screen = self.structural_epoch_on_screen().ok_or("no frame on screen")?;+ if state.arena.arena().has_boxes_removed_ahead_of_layout() {+ return Err("boxes the host removed ahead of its layout");+ }let visual_context = &state.arena.arena().paint_state().visual_context;let tree = visual_context.tree.clone().ok_or("no visual context tree")?;// A hit test of the host's may have built the tree anew since without presenting it.diff --git a/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-a-cursor-beside-inline-boxes-a-rendering-update-removed.txt b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-a-cursor-beside-inline-boxes-a-rendering-update-removed.txtnew file mode 100644index 00000000000..441ebd34e38--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/frame-in-flight/hover-lane-shows-a-cursor-beside-inline-boxes-a-rendering-update-removed.txt@@ -0,0 +1,2 @@+inline boxes left: 0+cursor: IBeamdiff --git a/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-a-cursor-beside-inline-boxes-a-rendering-update-removed.html b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-a-cursor-beside-inline-boxes-a-rendering-update-removed.htmlnew file mode 100644index 00000000000..60cc3f25e0c--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/frame-in-flight/hover-lane-shows-a-cursor-beside-inline-boxes-a-rendering-update-removed.html@@ -0,0 +1,39 @@+<!DOCTYPE html>+<script src="../../include.js"></script>+<script src="frame-in-flight.js"></script>+<style>+ body { margin: 0; font: 20px SerenitySans, sans-serif; line-height: 40px; }+ span { background: rgb(200, 200, 255); }+ p:hover { color: rgb(0, 128, 0); }+</style>+<p id="paragraph">kept text </p>+<script>+ // An animation frame callback of a rendering update removes enough inline boxes from a line for the host to stream+ // its writes to the render state before the update lays the line out again. A pointer move over the text the line+ // keeps waits for the update's frame, and the lane leaves its cursor to the host rather than reading the boxes the+ // line no longer has.+ asyncTest(async done => {+ for (let i = 0; i < 300; ++i) {+ const span = document.createElement("span");+ span.textContent = "word ";+ paragraph.appendChild(span);+ }+ await twoFramesLanded();+ const y = paragraph.getBoundingClientRect().top + 20;+ await whileLaneHovers(async frameTime => {+ const { promise, resolve } = Promise.withResolvers();+ requestAnimationFrame(() => {+ for (const span of [...paragraph.children])+ span.remove();+ internals.injectHoverPointer(10, y, frameTime + 16);+ resolve();+ });+ internals.injectRenderingOpportunity(frameTime + 16);+ await promise;+ });+ await twoFrames();+ println(`inline boxes left: ${paragraph.children.length}`);+ println(`cursor: ${internals.currentCursor()}`);+ done();+ });+</script>