Truly independent web browser
LibCompositing+LibWeb: Record only a window around the viewport
Aliaksandr Kalenik278230c5bc6c
diff --git a/Libraries/LibCompositing/Rust/src/display_list/mod.rs b/Libraries/LibCompositing/Rust/src/display_list/mod.rsindex 13e54126448..830ad700782 100644--- a/Libraries/LibCompositing/Rust/src/display_list/mod.rs+++ b/Libraries/LibCompositing/Rust/src/display_list/mod.rs@@ -23,4 +23,5 @@ pub mod storage;pub mod summary;pub mod tape;pub mod validate;+pub mod window;pub mod window_server_placement;diff --git a/Libraries/LibCompositing/Rust/src/display_list/window.rs b/Libraries/LibCompositing/Rust/src/display_list/window.rsnew file mode 100644index 00000000000..b9142272a79--- /dev/null+++ b/Libraries/LibCompositing/Rust/src/display_list/window.rs@@ -0,0 +1,457 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! The part of a document a recording of a window holds, and whether it still holds what a viewport shows.+//!+//! A recording of a window holds what shows in a rect around the viewport, with every scroller where it was when the+//! window was placed. Whether part of the document shows there is decided in the space of the visual viewport: a rect+//! in the space of a spatial node is taken there through the tree, with the scrollers where they were. That holds for+//! every node that moves only when the document is recorded again. A node that moves on its own, as a sticky box, an+//! anchor's shift, a perspective or a transform the compositor animates does, holds what is below it wherever it is,+//! so nothing below it is left out.++use crate::display_list::commands::SpatialNodeIndex;+use crate::host::FfiVisualAnimationTargetKind;+use crate::visual_context::{ScrollData, SpatialData, VISUAL_VIEWPORT_NODE_INDEX, VisualContextTree, WorldTransforms};+use libgfx_rust::{AffineTransform, FloatPoint, FloatRect, FloatSize, IntSize};+use std::sync::Arc;++/// How far a window reaches past the viewport on each side, in viewports.+const MARGIN_IN_VIEWPORTS: f32 = 2.0;+/// The margin of a viewport smaller than this is the margin of one this size, in CSS pixels.+const SMALLEST_VIEWPORT_THE_MARGIN_FOLLOWS: f32 = 500.0;++#[derive(Clone, Debug, PartialEq)]+pub struct RecordedWindow {+ /// The viewport with the margin around it, in device pixels in the space of the visual viewport.+ pub rect: FloatRect,+ pub device_viewport_size: IntSize,+ pub device_pixels_per_css_pixel: f64,+ /// How far each scroller had moved what it holds when the window was placed, in device pixels, by the index of its+ /// node in the visual context tree the window was placed in. Only a tree of the same structure is ever placed+ /// against the window, which names its nodes by the same indices in every process.+ pub scroll_offsets: Arc<[FloatPoint]>,+}++impl RecordedWindow {+ /// The window around a viewport of `device_viewport_size` with the scrollers at `scroll_offsets`.+ pub fn placed_at(+ device_viewport_size: IntSize,+ device_pixels_per_css_pixel: f64,+ scroll_offsets: Arc<[FloatPoint]>,+ ) -> Self {+ let margin = Self::margin_of(device_viewport_size, device_pixels_per_css_pixel);+ Self {+ rect: FloatRect::new(+ -margin.width,+ -margin.height,+ device_viewport_size.width as f32 + 2.0 * margin.width,+ device_viewport_size.height as f32 + 2.0 * margin.height,+ ),+ device_viewport_size,+ device_pixels_per_css_pixel,+ scroll_offsets,+ }+ }++ fn margin_of(device_viewport_size: IntSize, device_pixels_per_css_pixel: f64) -> FloatSize {+ let scale = device_pixels_per_css_pixel as f32;+ let margin = |device_extent: i32| {+ (device_extent as f32 / scale).max(SMALLEST_VIEWPORT_THE_MARGIN_FOLLOWS) * MARGIN_IN_VIEWPORTS * scale+ };+ FloatSize {+ width: margin(device_viewport_size.width),+ height: margin(device_viewport_size.height),+ }+ }++ /// How far the window reaches past the viewport on each side, in device pixels.+ pub fn margin(&self) -> FloatSize {+ Self::margin_of(self.device_viewport_size, self.device_pixels_per_css_pixel)+ }++ pub fn placed_offset_of(&self, scroll_node: SpatialNodeIndex) -> FloatPoint {+ self.scroll_offsets+ .get(scroll_node.0 as usize)+ .copied()+ .unwrap_or_default()+ }++ /// The spaces of `tree` with the scrollers where they were when the window was placed.+ pub fn placed_spaces<'a>(&self, tree: &'a VisualContextTree) -> PlacedSpaces<'a> {+ PlacedSpaces::new(tree, |node, _| self.placed_offset_of(node))+ }++ /// Whether the window of a recording made against `tree_of_recording` still holds what a viewport of+ /// `device_viewport_size` shows of `tree_now`, with each scroller moving what it holds by `live_scroll_offset` of+ /// its node, and `keep_ahead` more on each side. In each space content can be left out in, what+ /// shows of it now is taken back to where it was placed when the recording was made, through the scrollers and the+ /// transforms of both trees, and must lie inside the window.+ pub fn still_covers(+ &self,+ tree_of_recording: &VisualContextTree,+ tree_now: &VisualContextTree,+ device_viewport_size: IntSize,+ device_pixels_per_css_pixel: f64,+ live_scroll_offset: impl Fn(SpatialNodeIndex, &ScrollData) -> FloatPoint,+ keep_ahead: FloatSize,+ ) -> bool {+ if self.device_viewport_size != device_viewport_size+ || self.device_pixels_per_css_pixel != device_pixels_per_css_pixel+ || tree_of_recording.structural_epoch != tree_now.structural_epoch+ || tree_of_recording.spatial_nodes.len() != tree_now.spatial_nodes.len()+ {+ return false;+ }+ let shown = FloatRect::new(+ -keep_ahead.width,+ -keep_ahead.height,+ device_viewport_size.width as f32 + 2.0 * keep_ahead.width,+ device_viewport_size.height as f32 + 2.0 * keep_ahead.height,+ );+ let placed = self.placed_spaces(tree_of_recording);+ let live = PlacedSpaces::new(tree_now, live_scroll_offset);+ (0..tree_now.spatial_nodes.len()).all(|index| {+ let node = SpatialNodeIndex(index as u32);+ // The recording left nothing out below a node that moved on its own then.+ let Some(then) = placed.affine(node) else {+ return true;+ };+ // What a node that moves on its own now moves may come from anywhere the recording left out.+ let Some(now) = live.affine(node) else {+ return false;+ };+ // A space flattened to nothing shows nothing.+ let Some(now_inverse) = now.inverse() else {+ return true;+ };+ self.rect.contains_rect(then.map_rect(now_inverse.map_rect(shown)))+ })+ }+}++/// Whether content in each space of `first` that moves only when it is recorded again lies where it does in `second`:+/// both have the same nodes, and their transforms take the same values.+pub fn spaces_place_alike(first: &VisualContextTree, second: &VisualContextTree) -> bool {+ first.structural_epoch == second.structural_epoch+ && first.spatial_nodes.len() == second.spatial_nodes.len()+ && first+ .spatial_nodes+ .iter()+ .zip(&second.spatial_nodes)+ .all(|(first, second)| match (&first.data, &second.data) {+ (SpatialData::Transform(first), SpatialData::Transform(second)) => {+ first.matrix == second.matrix && first.origin == second.origin+ }+ (first, second) => std::mem::discriminant(first) == std::mem::discriminant(second),+ })+}++/// The spaces of a tree, with its scrollers where a window was placed or where they are now.+pub struct PlacedSpaces<'a> {+ tree: &'a VisualContextTree,+ world: WorldTransforms,+ moves_without_a_recording: Vec<bool>,+}++impl<'a> PlacedSpaces<'a> {+ /// The spaces of `tree` with each scroller moving what it holds by `scroll_offset` of its node, in device pixels.+ pub fn new(+ tree: &'a VisualContextTree,+ scroll_offset: impl Fn(SpatialNodeIndex, &ScrollData) -> FloatPoint,+ ) -> Self {+ let scroll_offsets: Vec<FloatPoint> = tree+ .spatial_nodes+ .iter()+ .enumerate()+ .map(|(index, node)| match &node.data {+ SpatialData::Scroll(scroll) => scroll_offset(SpatialNodeIndex(index as u32), scroll),+ _ => FloatPoint::default(),+ })+ .collect();+ let world = WorldTransforms::new(tree, &scroll_offsets, None);+ let mut animated = vec![false; tree.spatial_nodes.len()];+ for animation in tree.visual_animations() {+ if animation.target_kind != FfiVisualAnimationTargetKind::Transform {+ continue;+ }+ for &index in &animation.node_indices {+ if let Some(flag) = animated.get_mut(index as usize) {+ *flag = true;+ }+ }+ }+ let mut moves_without_a_recording = vec![false; tree.spatial_nodes.len()];+ for index in 0..tree.spatial_nodes.len() {+ let node = &tree.spatial_nodes[index];+ let parent_moves = index != VISUAL_VIEWPORT_NODE_INDEX.0 as usize+ && moves_without_a_recording+ .get(node.parent.0 as usize)+ .copied()+ .unwrap_or(true);+ let moves_on_its_own = match &node.data {+ SpatialData::Sticky(_) | SpatialData::AnchorScrollShift(_) | SpatialData::Perspective(_) => true,+ SpatialData::Transform(_) => {+ animated[index] || !world.draw_matrix(SpatialNodeIndex(index as u32)).is_2d_affine()+ }+ SpatialData::Scroll(_) | SpatialData::BackfaceVisibility(_) | SpatialData::Dead => false,+ };+ moves_without_a_recording[index] = parent_moves || moves_on_its_own;+ }+ Self {+ tree,+ world,+ moves_without_a_recording,+ }+ }++ pub fn tree(&self) -> &'a VisualContextTree {+ self.tree+ }++ /// Whether something above `node`, or `node` itself, moves what it holds without the document being recorded again.+ pub fn moves_without_a_recording(&self, node: SpatialNodeIndex) -> bool {+ self.moves_without_a_recording+ .get(node.0 as usize)+ .copied()+ .unwrap_or(true)+ }++ /// What takes the space of `node` to the space of the visual viewport, or none for a node that moves without a+ /// recording.+ pub fn affine(&self, node: SpatialNodeIndex) -> Option<AffineTransform> {+ if self.moves_without_a_recording(node) {+ return None;+ }+ let matrix = self.world.draw_matrix(node);+ matrix.is_2d_affine().then(|| matrix.extract_2d_affine())+ }++ /// Where `rect` in the space of `node` lands in the space of the visual viewport, or none for a node that moves+ /// without a recording.+ pub fn to_root(&self, node: SpatialNodeIndex, rect: FloatRect) -> Option<FloatRect> {+ self.affine(node).map(|affine| affine.map_rect(rect))+ }+}++#[cfg(test)]+mod tests {+ use super::*;+ use crate::node_slot_id::NodeSlotId;+ use crate::visual_context::{StickyData, TransformData, TransformDataRole};+ use libgfx_rust::FloatMatrix4x4;++ fn transform(matrix: FloatMatrix4x4) -> SpatialData {+ SpatialData::Transform(TransformData {+ matrix,+ origin: FloatPoint::default(),+ sorting_context_root_index: None,+ flattens_inherited_transform: false,+ role: TransformDataRole::CssTransform,+ synthetic_plane: false,+ establishes_sorting_context: false,+ bounds: FloatRect::default(),+ })+ }++ fn scroller(state_slot: usize) -> SpatialData {+ SpatialData::Scroll(ScrollData {+ state_slot,+ owner_paintable: NodeSlotId::INVALID,+ })+ }++ fn empty_tree() -> VisualContextTree {+ let SpatialData::Transform(identity) = transform(FloatMatrix4x4::identity()) else {+ unreachable!()+ };+ VisualContextTree::create(identity)+ }++ const VIEWPORT: IntSize = IntSize {+ width: 800,+ height: 600,+ };++ // The offsets of the scrollers of `tree` by node, from `offsets` by scroll state slot.+ fn offsets(tree: &VisualContextTree, offsets: &[(f32, f32)]) -> Arc<[FloatPoint]> {+ tree.spatial_nodes+ .iter()+ .map(|node| match &node.data {+ SpatialData::Scroll(scroll) => offsets+ .get(scroll.state_slot)+ .map(|&(x, y)| FloatPoint { x, y })+ .unwrap_or_default(),+ _ => FloatPoint::default(),+ })+ .collect()+ }++ fn live(offsets: &[(f32, f32)]) -> impl Fn(SpatialNodeIndex, &ScrollData) -> FloatPoint + '_ {+ move |_, scroll| {+ offsets+ .get(scroll.state_slot)+ .map(|&(x, y)| FloatPoint { x, y })+ .unwrap_or_default()+ }+ }++ // Keeping half the margin ahead, as the main thread does.+ fn covers(window: &RecordedWindow, tree: &VisualContextTree, now: &[(f32, f32)]) -> bool {+ covers_with(window, tree, tree, now)+ }++ fn covers_with(+ window: &RecordedWindow,+ tree_of_recording: &VisualContextTree,+ tree_now: &VisualContextTree,+ now: &[(f32, f32)],+ ) -> bool {+ let margin = window.margin();+ window.still_covers(+ tree_of_recording,+ tree_now,+ VIEWPORT,+ 1.0,+ live(now),+ FloatSize {+ width: margin.width / 2.0,+ height: margin.height / 2.0,+ },+ )+ }++ #[test]+ fn a_window_reaches_two_viewports_past_the_viewport() {+ let window = RecordedWindow::placed_at(VIEWPORT, 1.0, Arc::default());+ assert_eq!(window.rect, FloatRect::new(-1600.0, -1200.0, 4000.0, 3000.0));+ let small = RecordedWindow::placed_at(+ IntSize {+ width: 100,+ height: 100,+ },+ 2.0,+ Arc::default(),+ );+ assert_eq!(+ small.margin(),+ FloatSize {+ width: 2000.0,+ height: 2000.0+ }+ );+ }++ #[test]+ fn a_window_holds_while_what_shows_stays_half_a_margin_inside_it() {+ let mut tree = empty_tree();+ tree.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ let window = RecordedWindow::placed_at(VIEWPORT, 1.0, offsets(&tree, &[(0.0, -1000.0)]));+ assert!(covers(&window, &tree, &[(0.0, -1000.0)]));+ assert!(covers(&window, &tree, &[(0.0, -1600.0)]));+ assert!(covers(&window, &tree, &[(0.0, -400.0)]));+ assert!(!covers(&window, &tree, &[(0.0, -1601.0)]));+ assert!(!covers(&window, &tree, &[(0.0, -399.0)]));+ // Another viewport or another scale is another window.+ let taller = IntSize {+ width: 800,+ height: 601,+ };+ assert!(!window.still_covers(&tree, &tree, taller, 1.0, live(&[(0.0, -1000.0)]), FloatSize::default()));+ assert!(!window.still_covers(+ &tree,+ &tree,+ VIEWPORT,+ 2.0,+ live(&[(0.0, -1000.0)]),+ FloatSize::default()+ ));+ }++ #[test]+ fn scrollers_in_one_chain_move_what_the_innermost_holds_by_their_sum() {+ // An 800 by 600 viewport, the page scroller A in it and a scroller B in A. Each moved by 600 since the window+ // was placed stays within the slack a scroller has alone, but what B holds moved by 1200.+ let mut tree = empty_tree();+ let page = tree.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ let a = tree.append_spatial(scroller(1), page);+ tree.append_spatial(scroller(2), a);+ let window = RecordedWindow::placed_at(VIEWPORT, 1.0, offsets(&tree, &[(0.0, 0.0), (0.0, 0.0), (0.0, 0.0)]));+ assert!(covers(&window, &tree, &[(0.0, -600.0), (0.0, 0.0), (0.0, 0.0)]));+ assert!(!covers(&window, &tree, &[(0.0, -600.0), (0.0, -600.0), (0.0, 0.0)]));+ assert!(!covers(&window, &tree, &[(0.0, -600.0), (0.0, -600.0), (0.0, -600.0)]));+ // Scrolling one way and back the other leaves what B holds where it was.+ assert!(covers(&window, &tree, &[(0.0, -600.0), (0.0, 600.0), (0.0, 0.0)]));+ }++ #[test]+ fn a_static_transform_scales_how_far_a_scroller_below_it_moves_what_it_holds() {+ let mut tree = empty_tree();+ let page = tree.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ let scaled = tree.append_spatial(transform(libgfx_rust::scale_matrix(2.0, 2.0, 1.0)), page);+ let inner = tree.append_spatial(scroller(1), scaled);+ let window = RecordedWindow::placed_at(VIEWPORT, 1.0, offsets(&tree, &[(0.0, 0.0), (0.0, 0.0)]));+ // 400 in the scroller is 800 on screen.+ assert!(covers(&window, &tree, &[(0.0, 0.0), (0.0, -300.0)]));+ assert!(!covers(&window, &tree, &[(0.0, 0.0), (0.0, -400.0)]));+ let spaces = window.placed_spaces(&tree);+ assert_eq!(+ spaces.to_root(inner, FloatRect::new(0.0, 100.0, 10.0, 10.0)),+ Some(FloatRect::new(0.0, 200.0, 20.0, 20.0))+ );+ }++ #[test]+ fn a_transform_that_changed_since_the_recording_moves_what_it_holds_as_scrolling_does() {+ let mut tree_of_recording = empty_tree();+ let page = tree_of_recording.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ let moved = tree_of_recording.append_spatial(transform(FloatMatrix4x4::identity()), page);+ let window = RecordedWindow::placed_at(VIEWPORT, 1.0, offsets(&tree_of_recording, &[(0.0, 0.0)]));+ let moved_by = |y: f32| {+ let mut tree = tree_of_recording.clone();+ tree.spatial_nodes[moved.0 as usize].data = transform(libgfx_rust::translation_matrix(0.0, y, 0.0));+ tree+ };+ assert!(covers_with(+ &window,+ &tree_of_recording,+ &moved_by(-600.0),+ &[(0.0, 0.0)]+ ));+ assert!(!covers_with(+ &window,+ &tree_of_recording,+ &moved_by(-3900.0),+ &[(0.0, 0.0)]+ ));+ assert!(spaces_place_alike(&tree_of_recording, &tree_of_recording.clone()));+ assert!(!spaces_place_alike(&tree_of_recording, &moved_by(-600.0)));+ // Another tree structure is never covered.+ let mut rebuilt = tree_of_recording.clone();+ rebuilt.structural_epoch += 1;+ assert!(!covers_with(&window, &tree_of_recording, &rebuilt, &[(0.0, 0.0)]));+ }++ #[test]+ fn nothing_below_a_node_that_moves_on_its_own_is_placed() {+ let mut tree = empty_tree();+ let page = tree.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ let sticky = tree.append_spatial(+ SpatialData::Sticky(StickyData::unconstrained(page, None, 1, NodeSlotId::INVALID)),+ page,+ );+ let below_sticky = tree.append_spatial(scroller(1), sticky);+ let moved = tree.append_spatial(transform(libgfx_rust::translation_matrix(0.0, 50.0, 0.0)), page);+ let window = RecordedWindow::placed_at(VIEWPORT, 1.0, offsets(&tree, &[(0.0, 0.0), (0.0, 0.0)]));+ let spaces = window.placed_spaces(&tree);+ let rect = FloatRect::new(0.0, 0.0, 10.0, 10.0);+ assert_eq!(spaces.to_root(sticky, rect), None);+ assert_eq!(spaces.to_root(below_sticky, rect), None);+ assert_eq!(spaces.to_root(moved, rect), Some(FloatRect::new(0.0, 50.0, 10.0, 10.0)));+ // A scroller below a node that moves on its own leaves nothing out, so scrolling it never runs out.+ assert!(covers(&window, &tree, &[(0.0, 0.0), (0.0, -100_000.0)]));+ }+}diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 1283e611c3e..22b7fe6b3d8 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -11759,7 +11759,7 @@ Utf16String Document::dump_display_list()if (paint_state().has_visual_context_tree(read))schedule_full_accumulated_visual_context_rebuild(Layout::RustFFI::VisualContextUpdateScope::FreshTree);- if (!record_display_list(read, HTML::PaintConfig {}, Painting::PaintCommandCacheMode::ReadOnly))+ if (!record_display_list(read, HTML::PaintConfig { .records_whole_document = true }, Painting::PaintCommandCacheMode::ReadOnly))return "No display list"_utf16;return Painting::serialize_painting_dump(read, *this);diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cppindex b10e205e84d..1b60edd1623 100644--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp@@ -7442,6 +7442,7 @@ void LocalNavigable::render_screenshot_of_painted_subtree(NonnullRefPtr<Gfx::Bitnavigable->paint_next_frame_if_needed(DOM::UpdateLayoutReason::ProcessScreenshot);}+ paint_config.records_whole_document = true;if (!commit_frame(paint_config)) {callback(Compositor::ScreenshotResult::Failed);return;diff --git a/Libraries/LibWeb/HTML/PaintConfig.h b/Libraries/LibWeb/HTML/PaintConfig.hindex 3d9f5ec4e6b..1c12a428a1e 100644--- a/Libraries/LibWeb/HTML/PaintConfig.h+++ b/Libraries/LibWeb/HTML/PaintConfig.h@@ -21,6 +21,9 @@ struct PaintConfig {// Cuts what a recording keeps for the next one to copy from as finely as it goes. Tests of what a change records// again ask for it: their pages are too small to span the rows a recording is otherwise cut along.bool records_in_finest_runs { false };+ // Records everything the document paints and not just what shows in a window around the viewport. A screenshot,+ // which may be of more than the viewport, and a dump of the display list ask for it.+ bool records_whole_document { false };bool should_show_line_box_borders { false };bool should_show_caret_hit_test_debug_overlay { false };bool force_dark_enabled { false };diff --git a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp b/Libraries/LibWeb/Painting/PaintingRustBridge.cppindex 427924eb22d..c51ae820464 100644--- a/Libraries/LibWeb/Painting/PaintingRustBridge.cpp+++ b/Libraries/LibWeb/Painting/PaintingRustBridge.cpp@@ -537,6 +537,7 @@ Optional<DisplayListRecording> start_rust_display_list_recording(Layout::BegunReinputs.force_dark_background_threshold = config.force_dark_background_threshold;inputs.should_paint_overlay = config.paint_overlay;inputs.records_in_finest_runs = config.records_in_finest_runs;+ inputs.records_whole_document = config.records_whole_document;inputs.has_blocking_wheel_event_region_covering_viewport = wheel_event_region_state.has_blocking_wheel_event_region_covering_viewport;inputs.wheel_event_listener_state_generation = document.page().wheel_event_listener_state_generation();inputs.chrome_metrics = document.page().chrome_metrics();diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex e64010742bc..55a56ef35f4 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -932,7 +932,13 @@ impl<'tree> Commit<'_, 'tree> {if std::sync::Arc::ptr_eq(&previous, line_data) || *previous == **line_data {return (false, false);}- (true, !previous.has_same_item_order(line_data))+ let fragments_became_or_stopped_being_producers =+ crate::painting::paint_order_plan::text_fragments_of_content_are_producers(&previous)+ != crate::painting::paint_order_plan::text_fragments_of_content_are_producers(line_data);+ (+ true,+ !previous.has_same_item_order(line_data) || fragments_became_or_stopped_being_producers,+ )});self.arena_mut().committed_side_data_mut(slot).inline_content = Some(line_data.clone());if item_order_changed {diff --git a/Libraries/LibWeb/Rust/src/painting/host/paint.rs b/Libraries/LibWeb/Rust/src/painting/host/paint.rsindex 89449452764..f223256c025 100644--- a/Libraries/LibWeb/Rust/src/painting/host/paint.rs+++ b/Libraries/LibWeb/Rust/src/painting/host/paint.rs@@ -23,6 +23,7 @@ pub struct FfiRecordingInputs {pub force_dark_background_threshold: i32,pub should_paint_overlay: bool,pub records_in_finest_runs: bool,+ pub records_whole_document: bool,pub has_blocking_wheel_event_region_covering_viewport: bool,pub has_navigable_container_with_composited_context: bool,pub wheel_event_listener_state_generation: u64,@@ -179,6 +180,7 @@ impl FfiRecordingInputs {},should_paint_overlay: self.should_paint_overlay,records_in_finest_runs: self.records_in_finest_runs,+ records_whole_document: self.records_whole_document,canvas_fill_rect: self.canvas_fill_rect.has_value.then_some(self.canvas_fill_rect.value),opaque_canvas: self.opaque_canvas,bitmap_rect: self.bitmap_rect,diff --git a/Libraries/LibWeb/Rust/src/painting/ink_overflow.rs b/Libraries/LibWeb/Rust/src/painting/ink_overflow.rsindex e52c74feee7..d9247c57192 100644--- a/Libraries/LibWeb/Rust/src/painting/ink_overflow.rs+++ b/Libraries/LibWeb/Rust/src/painting/ink_overflow.rs@@ -25,6 +25,9 @@ pub(crate) struct InkOverflow {pub rect: CssPixelRect,pub unbounded: bool,pub contribution_unbounded: bool,+ /// Whether something the rect bounds is there by the transform of a box below this one. A transform changes+ /// without anything being painted again, so the rect bounds where that is now and not where it will be.+ pub holds_what_a_transform_moves: bool,}fn inflated(rect: CssPixelRect, reach: CssPixels) -> CssPixelRect {@@ -233,6 +236,37 @@ fn highlight_style<'a>(styles.get(&element).map(|answer| answer.as_ref())}+/// What text fragment `index` of the line root `root` draws, in absolute layout CSS pixels, in the space the root+/// paints its lines in.+pub(crate) fn text_fragment_ink_rect(+ source: &impl PaintRead,+ state: &PublishedPaintState,+ root: NodeSlotId,+ index: u32,+) -> CssPixelRect {+ let mut rect = CssPixelRect::default();+ include_text_fragment(source, state, root, index, &mut rect);+ rect+}++/// What inline box piece `index` of the line root `root` draws, where `positions` places the root's lines, in absolute+/// layout CSS pixels. A piece can record the backdrop filter region of its whole inline.+pub(crate) fn inline_piece_ink(+ source: &impl PaintRead,+ root: NodeSlotId,+ positions: &paintable_geometry::LineRootPositions,+ index: u32,+) -> InkOverflow {+ let side = source.committed_side_data(root);+ let piece = &side.inline_box_pieces()[index as usize];+ let border_box = CssPixelRect::from(piece.border_box_rect)+ .translated_by(positions.of_line(side.lines(), piece.line_index as usize));+ let mut ink = box_decoration_ink(source, piece.node, border_box);+ ink.rect+ .unite(paintable_geometry::absolute_border_box_rect(source, piece.node));+ ink+}+fn include_text_fragment(source: &impl PaintRead,state: &PublishedPaintState,@@ -401,6 +435,7 @@ pub(crate) fn scope_ink_bound(source: &impl PaintRead, scope: PaintScope) -> Scofn include_child(ink: &mut InkOverflow, child: InkOverflow) {ink.rect.unite(child.rect);ink.unbounded |= child.contribution_unbounded;+ ink.holds_what_a_transform_moves |= child.holds_what_a_transform_moves;}/// Cuts the content a box gathered down to what its overflow clip keeps. The box's own ink is not content.@@ -410,8 +445,10 @@ fn clip_content_to_overflow_clip(ink: &mut InkOverflow, own: InkOverflow, clip:ink.rect = own.rect;ink.rect.unite(CssPixelRect::new(left, top, right - left, bottom - top));if clip.horizontal.is_some() && clip.vertical.is_some() {- // Whatever made a child's contribution unbounded is cut off with the rest of it.+ // Whatever made a child's contribution unbounded is cut off with the rest of it, and so is whatever a+ // transform moves.ink.unbounded = own.unbounded;+ ink.holds_what_a_transform_moves = own.holds_what_a_transform_moves;}}@@ -482,6 +519,7 @@ fn recalculated_ink_overflow(crate::painting::visual_context::node_values::compute_transform(source, child, 1.0){contribution = mapped_ink(contribution, &transform);+ contribution.holds_what_a_transform_moves = true;}include_child(&mut ink, contribution);}@@ -770,6 +808,47 @@ mod tests {assert!(!ink.unbounded);}+ #[test]+ fn what_a_transform_moves_is_remembered_up_to_a_box_that_cuts_it_off() {+ let mut ink = InkOverflow {+ rect: rect(0, 0, 100, 100),+ ..Default::default()+ };+ include_child(+ &mut ink,+ InkOverflow {+ rect: rect(10, 10, 20, 20),+ holds_what_a_transform_moves: true,+ ..Default::default()+ },+ );+ assert!(ink.holds_what_a_transform_moves);+ let pixels = CssPixels::from_integer;+ let own = InkOverflow {+ rect: rect(0, 0, 100, 100),+ ..Default::default()+ };+ let mut cut_on_one_axis = ink;+ clip_content_to_overflow_clip(+ &mut cut_on_one_axis,+ own,+ &OverflowClipRanges {+ horizontal: Some((pixels(0), pixels(100))),+ vertical: None,+ },+ );+ assert!(cut_on_one_axis.holds_what_a_transform_moves);+ clip_content_to_overflow_clip(+ &mut ink,+ own,+ &OverflowClipRanges {+ horizontal: Some((pixels(0), pixels(100))),+ vertical: Some((pixels(0), pixels(100))),+ },+ );+ assert!(!ink.holds_what_a_transform_moves);+ }+#[test]fn affine_transforms_enclose_ink_and_non_affine_transforms_are_unbounded() {use crate::painting::visual_context::{TransformData, TransformDataRole};diff --git a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rsindex 82b5cfc59d0..1d4f9ad0c8f 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs@@ -97,6 +97,33 @@ pub(crate) enum PaintOrderItem {Scope(PaintScope),}+/// A line root whose plain text is taller than this, in CSS pixels, has its text fragments planned one at a time, so+/// that a recording of a window can leave out the lines far from it.+const TALLEST_TEXT_PLANNED_IN_ONE_PIECE: i64 = 512;++/// Whether the foreground of a box with lines of `content` is planned with a producer for each of its text fragments:+/// where its lines interleave text with boxes, or where its lines of text reach further than may be painted in one+/// piece.+pub(crate) fn text_fragments_of_content_are_producers(content: &crate::layout::inline_content::InlineContent) -> bool {+ if !content.items.is_empty() {+ return true;+ }+ let (Some(first), Some(last)) = (content.lines.first(), content.lines.last()) else {+ return false;+ };+ let top = first.rect.y.min(last.rect.y);+ let bottom = (first.rect.y + first.rect.height).max(last.rect.y + last.rect.height);+ !content.fragments.is_empty()+ && bottom - top > crate::css::css_pixels::CssPixels::from_integer(TALLEST_TEXT_PLANNED_IN_ONE_PIECE)+}++pub(crate) fn text_fragments_are_producers(rows: &impl PaintRead, root: NodeSlotId) -> bool {+ rows.committed_side_data(root)+ .inline_content+ .as_ref()+ .is_some_and(|content| text_fragments_of_content_are_producers(content))+}+pub(crate) struct PaintScopePlan {pub establishes_stacking_context: bool,pub items: SmallVec<[PaintOrderItem; 16]>,@@ -291,17 +318,29 @@ impl<R: PaintRead> PaintOrderBuilder<'_, R> {self.append_box_phase(PaintPhase::Foreground);return;}- let side = arena.committed_side_data(root);- let Some(content) = side.inline_content.as_ref().filter(|content| !content.items.is_empty()) else {+ if !text_fragments_are_producers(arena, root) {self.append_box_phase(PaintPhase::Foreground);return;- };+ }+ let side = arena.committed_side_data(root);+ let content = side+ .inline_content+ .as_ref()+ .expect("text fragments are producers of a root with lines");self.items.push(PaintOrderItem::Producer(PaintProducer::ForegroundHitTest));+ let filter = crate::painting::fragment_ownership::effective_filter(arena, paintable);+ if content.items.is_empty() {+ for index in 0..content.fragments.len() as u32 {+ if filter.owns_fragment(index) {+ self.items+ .push(PaintOrderItem::Producer(PaintProducer::TextFragment(index)));+ }+ }+ }// CSS 2.2 Appendix E, step 7.2: backgrounds, borders and text are// interleaved in each line. Layout retains that order alongside geometry.- let filter = crate::painting::fragment_ownership::effective_filter(arena, paintable);for item in &content.items {use crate::layout::inline_content::InlineItem;match *item {diff --git a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs b/Libraries/LibWeb/Rust/src/painting/paint_passes.rsindex 87112dcc1b1..f068472574c 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_passes.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_passes.rs@@ -594,12 +594,33 @@ pub(crate) fn refresh_scroll_state(device_viewport_size,},);- if !state.needs_to_refresh_scroll_state {- return (None, outcome);- }- let snapshot = scroll_state_snapshot(&arena.paintable_rows(), state, device_pixels_per_css_pixel);- state.needs_to_refresh_scroll_state = false;- (Some(snapshot), outcome)+ let snapshot = state.needs_to_refresh_scroll_state.then(|| {+ let snapshot = scroll_state_snapshot(&arena.paintable_rows(), state, device_pixels_per_css_pixel);+ state.needs_to_refresh_scroll_state = false;+ snapshot+ });+ // The published recording holds a window of the document, which no longer covers what the viewport shows with+ // the scrollers and the transforms where they are now: the next recording places it again.+ let window_no_longer_covers = arena+ .paint_state()+ .window_of_published_recording+ .as_ref()+ .zip(state.tree.as_deref())+ .is_some_and(|((window, tree_of_recording), tree)| {+ !crate::painting::record::window::still_covers(+ window,+ tree_of_recording,+ tree,+ device_viewport_size,+ device_pixels_per_css_pixel,+ state.scroll_state.own_offsets(),+ )+ });+ let outcome = CompositorScrollRefreshOutcome {+ requires_display_list_recording: outcome.requires_display_list_recording || window_no_longer_covers,+ ..outcome+ };+ (snapshot, outcome)})}diff --git a/Libraries/LibWeb/Rust/src/painting/paint_state.rs b/Libraries/LibWeb/Rust/src/painting/paint_state.rsindex d6d212e5b7f..10a7135c0f9 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_state.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_state.rs@@ -33,6 +33,12 @@ pub struct PaintState {pub(crate) visual_context: crate::painting::visual_context::VisualContextState,pub(crate) root_background_source: Option<crate::painting::host::RootBackgroundSource>,pub(crate) last_recording: Option<Arc<crate::painting::record::RecordingOutput>>,+ /// The window of the document that the recording published last holds, with the visual context tree the recording+ /// was made against, or none where that holds all of it.+ pub(crate) window_of_published_recording: Option<(+ Arc<crate::painting::record::window::RecordedWindow>,+ Arc<crate::painting::visual_context::VisualContextTree>,+ )>,/// The selection, shared with the frames published while it holds.pub(crate) selection: Option<Arc<SelectionRange>>,/// The `::selection` styles, shared with the frames published while they hold, so a writediff --git a/Libraries/LibWeb/Rust/src/painting/published_frame.rs b/Libraries/LibWeb/Rust/src/painting/published_frame.rsindex f2641225c41..0cc06caf115 100644--- a/Libraries/LibWeb/Rust/src/painting/published_frame.rs+++ b/Libraries/LibWeb/Rust/src/painting/published_frame.rs@@ -235,6 +235,10 @@ impl PublishedPaintState {.map_or(0, |tree| tree.structural_epoch)}+ pub(crate) fn scroll_own_offsets(&self) -> &[CssPixelPoint] {+ &self.scroll_own_offsets+ }+pub(crate) fn scroll_own_offset(&self, slot: usize) -> CssPixelPoint {let offset = self.scroll_own_offsets.get(slot).copied();debug_assert!(offset.is_some(), "the tree's scroll node has a scroll state");diff --git a/Libraries/LibWeb/Rust/src/painting/record/assemble.rs b/Libraries/LibWeb/Rust/src/painting/record/assemble.rsindex 8d8ce73de17..2ede490a583 100644--- a/Libraries/LibWeb/Rust/src/painting/record/assemble.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/assemble.rs@@ -9,12 +9,16 @@//! moved, is reused whole. Otherwise its plan is walked: each run of items reuses the chunk the published recording//! recorded it into, or is recorded again into a chunk of its own, from its first item to its last, when something it//! reads changed or an ancestor moved it.+//!+//! A recording of a window of the document leaves out the runs and the walked child scopes that lie outside the+//! window, and remembers that it did, so that the recording after it records them once they lie inside.use super::PaintPhase;use super::order_tree::{OutputFacts, ProducerKind, RecordedChunk, RecordedRun, RecordedScope, RecordedSegment, RowPlacement, Segment,SegmentedPlan,};+use super::window::InkBound;use crate::css::style::fast_hash::FastMap;use crate::layout::node_data::NodeSlotId;use crate::painting::paint_order_plan::{PaintOrderItem, PaintProducer, PaintScope};@@ -89,6 +93,19 @@ pub(crate) enum AssemblyEvent {ScopeEnd(PaintScope),ScopeCopied(PaintScope),ProducerCopied(NodeSlotId, ProducerKind),+ ScopeLeftOut(PaintScope),+ ProducerLeftOut(NodeSlotId, ProducerKind),+}++/// How much of the document a recording holds, against what the published recording holds.+#[derive(Clone, Copy, Debug, PartialEq, Eq)]+pub(crate) enum Coverage {+ WholeDocument,+ /// What shows in the window the published recording was made for, with every space placing what it holds where it+ /// did then, so that what lay outside it then still does unless something changed since.+ PublishedWindow,+ /// What shows in a window the published recording was not made for.+ AnotherWindow,}/// Where the plan of a walked scope is cut at one of its items.@@ -127,6 +144,26 @@ pub(crate) trait AssemblyHost {fn producer_reads_descendants(&mut self, owner: NodeSlotId, kind: ProducerKind) -> bool;+ /// What bounds everything `item` of the plan of `scope` paints, or none where nothing in the spaces of the tree+ /// does. Only a recording of a window asks.+ fn bound_of_item(&mut self, _scope: PaintScope, _item: PaintOrderItem) -> Option<InkBound> {+ None+ }++ fn is_outside_window(&mut self, _bound: &InkBound) -> bool {+ false+ }++ fn is_wholly_inside_window(&mut self, _bound: &InkBound) -> bool {+ false+ }++ /// Whether a box cuts off some of what it holds, as a scroller does. What bounds its scopes then bounds what+ /// shows of them, and what they paint may lie outside it.+ fn cuts_off_what_it_holds(&mut self, _owner: NodeSlotId) -> bool {+ false+ }+fn observe(&mut self, _event: AssemblyEvent) {}}@@ -142,22 +179,30 @@ pub(crate) fn frame_is_unchanged(published_root: &RecordedScope,anything_changed: bool,window_focus_changed: bool,+ coverage: Coverage,) -> bool {let facts = published_root.facts;- !anything_changed && !facts.live && !(window_focus_changed && facts.reads_window_focus)+ let covers_the_same = match coverage {+ Coverage::PublishedWindow => true,+ Coverage::WholeDocument => !published_root.leaves_out_what_lies_outside_the_window,+ Coverage::AnotherWindow => false,+ };+ !anything_changed && !facts.live && !(window_focus_changed && facts.reads_window_focus) && covers_the_same}pub(crate) struct Assembler<'a, H: AssemblyHost> {host: &'a mut H,// The published recording was made in the other window focus state.window_focus_changed: bool,+ coverage: Coverage,}impl<'a, H: AssemblyHost> Assembler<'a, H> {- pub(crate) fn new(host: &'a mut H, window_focus_changed: bool) -> Self {+ pub(crate) fn new(host: &'a mut H, window_focus_changed: bool, coverage: Coverage) -> Self {Self {host,window_focus_changed,+ coverage,}}@@ -175,7 +220,84 @@ impl<'a, H: AssemblyHost> Assembler<'a, H> {published_root: Option<&Arc<RecordedScope>>,) -> Arc<RecordedScope> {let published = published_root.filter(|root| root.scope == root_scope);- self.walk_scope(root_scope, published)+ let root_bound = match self.coverage {+ Coverage::WholeDocument => None,+ Coverage::PublishedWindow | Coverage::AnotherWindow => {+ self.host.bound_of_item(root_scope, PaintOrderItem::Scope(root_scope))+ }+ };+ let root_cuts_off_what_it_holds = self.host.cuts_off_what_it_holds(root_scope.owner);+ let is_wholly_inside_window =+ self.is_wholly_inside_window(root_bound.as_ref(), false, root_cuts_off_what_it_holds);+ self.walk_scope(root_scope, published, is_wholly_inside_window)+ }++ // Nothing of what a scope paints directly is left out: the recording holds everything, or the scope is in a+ // scope that is wholly inside the window or is bounded by something that is. The scope of a box that cuts off+ // what it holds paints outside what bounds it, so being inside the window says nothing about what it holds.+ fn is_wholly_inside_window(+ &mut self,+ bound: Option<&InkBound>,+ is_in_a_scope_wholly_inside_window: bool,+ owner_cuts_off_what_it_holds: bool,+ ) -> bool {+ if self.coverage == Coverage::WholeDocument {+ return true;+ }+ if owner_cuts_off_what_it_holds {+ return false;+ }+ is_in_a_scope_wholly_inside_window || bound.is_some_and(|bound| self.host.is_wholly_inside_window(bound))+ }++ // Whether a clean walked scope of the published recording holds what this recording holds of it: neither left+ // out what this one records, nor recorded what this one leaves out. In another window that is so where the scope+ // is wholly inside both, down to the scopes below it that paint outside what bounds it.+ fn published_scope_covers_the_same(&self, published: &RecordedScope, is_wholly_inside_window: bool) -> bool {+ match self.coverage {+ Coverage::PublishedWindow => true,+ Coverage::WholeDocument => !published.leaves_out_what_lies_outside_the_window,+ Coverage::AnotherWindow => {+ !published.leaves_out_what_lies_outside_the_window+ && !published.walks_a_scope_of_a_box_that_cuts_off_what_it_holds+ && is_wholly_inside_window+ }+ }+ }++ fn bound_of_segment(&mut self, scope: PaintScope, plan: &SegmentedPlan, segment: &Segment) -> Option<InkBound> {+ match segment {+ Segment::Walked(item) => self.host.bound_of_item(scope, plan.items[*item as usize]),+ Segment::Run(run) => {+ let mut bound_of_run: Option<InkBound> = None;+ for item in plan.items_of(run) {+ let bound = self.host.bound_of_item(scope, *item)?;+ bound_of_run = Some(match bound_of_run {+ Some(bound_so_far) => bound_so_far.united(&bound)?,+ None => bound,+ });+ }+ bound_of_run+ }+ }+ }++ fn observe_left_out(&mut self, scope: PaintScope, plan: &SegmentedPlan, segment: &Segment) {+ match segment {+ Segment::Walked(item) => self.host.observe(AssemblyEvent::ScopeLeftOut(plan.walked_scope(*item))),+ Segment::Run(run) => {+ for item in plan.items_of(run) {+ match *item {+ PaintOrderItem::Producer(producer) => {+ for kind in producer_kinds(producer) {+ self.host.observe(AssemblyEvent::ProducerLeftOut(scope.owner, kind));+ }+ }+ PaintOrderItem::Scope(child) => self.host.observe(AssemblyEvent::ScopeLeftOut(child)),+ }+ }+ }+ }}fn scope_is_clean(&mut self, scope: PaintScope, recorded_placement: RowPlacement) -> bool {@@ -232,8 +354,15 @@ impl<'a, H: AssemblyHost> Assembler<'a, H> {}}- /// Walks the plan of `scope`, which changed or the published recording did not walk.- fn walk_scope(&mut self, scope: PaintScope, published: Option<&Arc<RecordedScope>>) -> Arc<RecordedScope> {+ /// Walks the plan of `scope`, which changed or the published recording did not walk, or which holds something the+ /// window of the published recording left out. A scope that is wholly inside the window of this recording leaves+ /// nothing out, so nothing asks what bounds its segments.+ fn walk_scope(+ &mut self,+ scope: PaintScope,+ published: Option<&Arc<RecordedScope>>,+ is_wholly_inside_window: bool,+ ) -> Arc<RecordedScope> {let owner_changes = self.host.changes_of_row(scope.owner);let owner_placement = self.host.placement_of_row(scope.owner);let owner_moved = published.is_some_and(|published| published.owner_placement != owner_placement);@@ -261,10 +390,33 @@ impl<'a, H: AssemblyHost> Assembler<'a, H> {segments: Vec::with_capacity(plan.segments.len()),facts: OutputFacts::default(),owner_placement,+ segment_bounds: None,+ leaves_out_what_lies_outside_the_window: false,+ walks_a_scope_of_a_box_that_cuts_off_what_it_holds: false,};if plan.active {+ if !is_wholly_inside_window {+ // A scope whose cuts were kept holds every item where it was, so what bounded its segments does.+ let kept_bounds = published+ .filter(|_| cuts_were_kept)+ .and_then(|published| published.segment_bounds.clone());+ recorded.segment_bounds = Some(kept_bounds.unwrap_or_else(|| {+ plan.segments+ .iter()+ .map(|segment| self.bound_of_segment(scope, &plan, segment))+ .collect()+ }));+ }+ let segment_bounds = recorded.segment_bounds.clone();let published_segments = published.map(|published| PublishedSegments::new(published, cuts_were_kept));for (index, segment) in plan.segments.iter().enumerate() {+ let bound = segment_bounds.as_ref().and_then(|bounds| bounds[index].as_ref());+ if bound.is_some_and(|bound| self.host.is_outside_window(bound)) {+ self.observe_left_out(scope, &plan, segment);+ recorded.leaves_out_what_lies_outside_the_window = true;+ recorded.segments.push(RecordedSegment::Outside);+ continue;+ }let published_segment = published_segments.as_ref().and_then(|segments| segments.matching(index, segment, &plan));@@ -277,10 +429,19 @@ impl<'a, H: AssemblyHost> Assembler<'a, H> {owner_moved,)),Segment::Walked(item) => {- RecordedSegment::Walked(self.assemble_walked_child(plan.walked_scope(*item), published_segment))+ let child = plan.walked_scope(*item);+ let child_cuts_off_what_it_holds = self.host.cuts_off_what_it_holds(child.owner);+ let child_is_wholly_inside_window =+ self.is_wholly_inside_window(bound, is_wholly_inside_window, child_cuts_off_what_it_holds);+ let assembled_child =+ self.assemble_walked_child(child, published_segment, child_is_wholly_inside_window);+ recorded.walks_a_scope_of_a_box_that_cuts_off_what_it_holds |= child_cuts_off_what_it_holds+ || assembled_child.walks_a_scope_of_a_box_that_cuts_off_what_it_holds;+ RecordedSegment::Walked(assembled_child)}};recorded.facts.add(assembled.facts());+ recorded.leaves_out_what_lies_outside_the_window |= assembled.leaves_out_what_lies_outside_the_window();recorded.segments.push(assembled);}}@@ -288,19 +449,25 @@ impl<'a, H: AssemblyHost> Assembler<'a, H> {Arc::new(recorded)}- fn assemble_walked_child(&mut self, child: PaintScope, published: Option<&RecordedSegment>) -> Arc<RecordedScope> {+ fn assemble_walked_child(+ &mut self,+ child: PaintScope,+ published: Option<&RecordedSegment>,+ is_wholly_inside_window: bool,+ ) -> Arc<RecordedScope> {let published = published.and_then(|segment| match segment {RecordedSegment::Walked(scope) => Some(scope),- RecordedSegment::Run(_) => None,+ RecordedSegment::Run(_) | RecordedSegment::Outside => None,});if let Some(published) = published&& !self.records_again(published.facts)+ && self.published_scope_covers_the_same(published, is_wholly_inside_window)&& self.scope_is_clean(child, published.owner_placement){self.host.observe(AssemblyEvent::ScopeCopied(child));return Arc::clone(published);}- self.walk_scope(child, published)+ self.walk_scope(child, published, is_wholly_inside_window)}fn assemble_run(@@ -313,7 +480,7 @@ impl<'a, H: AssemblyHost> Assembler<'a, H> {) -> RecordedRun {let published = published.and_then(|segment| match segment {RecordedSegment::Run(run) => Some(run),- RecordedSegment::Walked(_) => None,+ RecordedSegment::Walked(_) | RecordedSegment::Outside => None,});// Only a chunk without placeholders for SVG images can be drawn by another recording than the one that made// it, which the publication of a recording finishes every chunk of.@@ -532,6 +699,7 @@ mod tests {struct Frame {display_list: RecordedDisplayList,root: Arc<RecordedScope>,+ window: Option<(i32, i32)>,}fn new_output() -> DisplayListRecorder {@@ -550,6 +718,13 @@ mod tests {events: Vec<AssemblyEvent>,output: DisplayListRecorder,source: Option<Frame>,+ // The rows a recording holds what shows in, from the first of them to the last, or none for a recording+ // that holds everything. A row is as tall as a row of the grid.+ window: Option<(i32, i32)>,+ // The grid rows a child scope's owner paints in, from the first to the last.+ rows_painted_in: HashMap<NodeSlotId, (i32, i32)>,+ cutting_off_what_they_hold: HashSet<NodeSlotId>,+ bounds_asked: usize,}impl Default for TestHost {@@ -566,11 +741,47 @@ mod tests {events: Vec::new(),output: new_output(),source: None,+ window: None,+ rows_painted_in: HashMap::new(),+ cutting_off_what_they_hold: HashSet::new(),+ bounds_asked: 0,}}}+ const ROW_HEIGHT: f32 = 512.0;++ fn bound_of_rows(first: i32, last: i32) -> InkBound {+ InkBound::in_space(+ crate::painting::display_list::commands::SpatialNodeIndex(0),+ rect_of_rows(first, last),+ )+ }++ fn rect_of_rows(first: i32, last: i32) -> libgfx_rust::FloatRect {+ libgfx_rust::FloatRect::new(+ 0.0,+ first as f32 * ROW_HEIGHT,+ 100.0,+ (last - first + 1) as f32 * ROW_HEIGHT,+ )+ }+impl TestHost {+ fn left_out_scopes(&self) -> Vec<PaintScope> {+ self.events+ .iter()+ .filter_map(|event| match event {+ AssemblyEvent::ScopeLeftOut(scope) => Some(*scope),+ _ => None,+ })+ .collect()+ }++ fn rows_recorded(&self) -> std::collections::BTreeSet<u32> {+ self.recorded.iter().map(|(owner, _)| owner.slot_index()).collect()+ }+fn plan(&mut self, scope: PaintScope, active: bool, items: &[PaintOrderItem]) {self.plans.insert(scope,@@ -665,6 +876,34 @@ mod tests {(!chunk.records.is_empty()).then(|| RecordedChunk::new(chunk, false))}+ fn bound_of_item(&mut self, _scope: PaintScope, item: PaintOrderItem) -> Option<InkBound> {+ self.bounds_asked += 1;+ let PaintOrderItem::Scope(child) = item else {+ return None;+ };+ let (first, last) = *self.rows_painted_in.get(&child.owner)?;+ Some(bound_of_rows(first, last))+ }++ fn is_outside_window(&mut self, bound: &InkBound) -> bool {+ let (first, last) = self.window.expect("only a recording of a window asks");+ let window = rect_of_rows(first, last);+ bound+ .rects()+ .iter()+ .all(|(_, rect)| rect.intersected(window).is_empty())+ }++ fn is_wholly_inside_window(&mut self, bound: &InkBound) -> bool {+ let (first, last) = self.window.expect("only a recording of a window asks");+ let window = rect_of_rows(first, last);+ bound.rects().iter().all(|(_, rect)| window.contains_rect(*rect))+ }++ fn cuts_off_what_it_holds(&mut self, owner: NodeSlotId) -> bool {+ self.cutting_off_what_they_hold.contains(&owner)+ }+fn changes_of_row(&mut self, row: NodeSlotId) -> RowChanges {self.changes.get(&row).copied().unwrap_or_default()}@@ -705,12 +944,20 @@ mod tests {);let prologue = host.output.take_chunk();let published = host.source.as_ref().map(|frame| Arc::clone(&frame.root));- let root = Assembler::new(host, window_focus_changed).assemble_root(context(row(0)), published.as_ref());+ let window = host.window;+ let coverage = match (window, host.source.as_ref().map(|frame| frame.window)) {+ (None, _) => Coverage::WholeDocument,+ (Some(window), Some(Some(published_window))) if window == published_window => Coverage::PublishedWindow,+ (Some(_), _) => Coverage::AnotherWindow,+ };+ let root =+ Assembler::new(host, window_focus_changed, coverage).assemble_root(context(row(0)), published.as_ref());let mut chunks = vec![Arc::new(prologue)];root.for_each_chunk(&mut |chunk| chunks.push(Arc::clone(chunk.latest())));Frame {display_list: RecordedDisplayList::of_chunks(chunks.iter().map(|chunk| &**chunk)),root,+ window,}}@@ -752,7 +999,9 @@ mod tests {host.plan(context(row(0)), true, &items);host.produce(row(0), ProducerKind::DrawBackground, content(1));for card in cards {- host.grid_rows.insert(row(card), (card as i32 - 1) / 2);+ let grid_row = (card as i32 - 1) / 2;+ host.grid_rows.insert(row(card), grid_row);+ host.rows_painted_in.insert(row(card), (grid_row, grid_row));host.plan(backgrounds(row(card)), true, &[phase(PaintPhase::Background)]);host.plan(foreground(row(card)), true, &[phase(PaintPhase::Foreground)]);host.produce(row(card), ProducerKind::DrawBackground, content(1));@@ -784,8 +1033,8 @@ mod tests {);// A chunk for the prologue, one for each of the six runs and one for the run of the walked card.assert_eq!(frame.display_list.chunks.len(), 1 + 6 + 1);- assert!(frame_is_unchanged(&frame.root, false, false));- assert!(!frame_is_unchanged(&frame.root, true, false));+ assert!(frame_is_unchanged(&frame.root, false, false, Coverage::WholeDocument));+ assert!(!frame_is_unchanged(&frame.root, true, false, Coverage::WholeDocument));}#[test]@@ -856,7 +1105,7 @@ mod tests {.iter().find_map(|segment| match segment {RecordedSegment::Walked(scope) => Some(Arc::clone(scope)),- RecordedSegment::Run(_) => None,+ RecordedSegment::Run(_) | RecordedSegment::Outside => None,}).unwrap()};@@ -927,7 +1176,7 @@ mod tests {.unwrap().reads_window_focus = true;let first = record_frame(&mut host);- assert!(!frame_is_unchanged(&first.root, false, false));+ assert!(!frame_is_unchanged(&first.root, false, false, Coverage::WholeDocument));publish(&mut host, first);let quiet = record_frame(&mut host);@@ -956,4 +1205,210 @@ mod tests {assert_eq!(frame.root.facts, OutputFacts::default());assert_eq!(frame.display_list.chunks.len(), 1);}++ #[test]+ fn a_recording_of_a_window_leaves_out_the_runs_and_walked_children_outside_it() {+ let mut host = cards_host();+ host.walked.insert(foreground(row(4)));+ host.window = Some((2, 2));++ let frame = record_frame(&mut host);++ // The run with the viewport's own background is not bounded, so the backgrounds of the first two cards+ // are recorded with it.+ assert_eq!(+ host.left_out_scopes(),+ vec![+ backgrounds(row(3)),+ backgrounds(row(4)),+ foreground(row(1)),+ foreground(row(2)),+ foreground(row(3)),+ foreground(row(4)),+ ]+ );+ assert_eq!(+ host.rows_recorded().into_iter().collect::<Vec<_>>(),+ vec![0, 1, 2, 5, 6]+ );+ assert!(matches!(frame.root.segments[1], RecordedSegment::Outside));+ assert!(frame.root.leaves_out_what_lies_outside_the_window);+ assert_matches_from_scratch(&mut host, &frame);+ }++ #[test]+ fn a_window_that_moved_records_what_came_into_it_and_drops_what_left_it() {+ let mut host = cards_host();+ host.window = Some((0, 0));+ let first = record_frame(&mut host);+ assert_eq!(host.rows_recorded().into_iter().collect::<Vec<_>>(), vec![0, 1, 2]);+ publish(&mut host, first);++ host.window = Some((1, 2));+ let second = record_frame(&mut host);+ assert_eq!(host.rows_recorded().into_iter().collect::<Vec<_>>(), vec![3, 4, 5, 6]);+ assert_eq!(host.left_out_scopes(), vec![foreground(row(1)), foreground(row(2))]);+ assert!(host.copied_scopes().contains(&backgrounds(row(1))));+ assert_matches_from_scratch(&mut host, &second);+ publish(&mut host, second);++ // With the window where it was, nothing is recorded, and nothing asks what bounds the segments again but+ // for the viewport's scope itself.+ host.bounds_asked = 0;+ let third = record_frame(&mut host);+ assert!(host.recorded.is_empty());+ assert_eq!(host.bounds_asked, 1);+ assert!(frame_is_unchanged(&third.root, false, false, Coverage::PublishedWindow));+ assert!(!frame_is_unchanged(&third.root, false, false, Coverage::AnotherWindow));+ assert!(!frame_is_unchanged(&third.root, false, false, Coverage::WholeDocument));+ assert_matches_from_scratch(&mut host, &third);+ }++ #[test]+ fn a_recording_of_the_whole_document_records_what_a_window_left_out() {+ let mut host = cards_host();+ host.window = Some((0, 0));+ let first = record_frame(&mut host);+ publish(&mut host, first);++ host.window = None;+ let second = record_frame(&mut host);+ assert_eq!(host.rows_recorded().into_iter().collect::<Vec<_>>(), vec![3, 4, 5, 6]);+ assert!(host.left_out_scopes().is_empty());+ assert!(!second.root.leaves_out_what_lies_outside_the_window);+ assert!(frame_is_unchanged(&second.root, false, false, Coverage::WholeDocument));+ assert_matches_from_scratch(&mut host, &second);+ }++ #[test]+ fn a_clean_walked_child_is_reused_whole_where_neither_window_leaves_any_of_it_out() {+ let mut host = cards_host();+ // The fourth card's foreground is walked, and paints two cards of its own in the second and fourth rows.+ host.walked.insert(foreground(row(4)));+ host.rows_painted_in.insert(row(4), (1, 3));+ host.plan(+ foreground(row(4)),+ true,+ &[+ phase(PaintPhase::Foreground),+ child(foreground(row(7))),+ child(foreground(row(8))),+ ],+ );+ for (card, grid_row) in [(7, 1), (8, 3)] {+ host.grid_rows.insert(row(card), grid_row);+ host.rows_painted_in.insert(row(card), (grid_row, grid_row));+ host.plan(foreground(row(card)), true, &[phase(PaintPhase::Foreground)]);+ host.produce(row(card), ProducerKind::DrawForeground, content(1));+ }+ let record_in_window = |host: &mut TestHost, window: (i32, i32)| {+ host.window = Some(window);+ let frame = record_frame(host);+ assert_matches_from_scratch(host, &frame);+ frame+ };++ // The window cuts the walked card: the card in the fourth row is left out.+ let first = record_in_window(&mut host, (0, 1));+ assert!(host.rows_recorded().contains(&7));+ assert!(host.left_out_scopes().contains(&foreground(row(8))));+ publish(&mut host, first);++ // The window holds all of the walked card now, but the recording it would be reused from left some of it+ // out, so it is walked and what was left out is recorded.+ let second = record_in_window(&mut host, (0, 3));+ assert_eq!(host.action_of(foreground(row(4))), Some(ScopeAction::Assembled));+ assert_eq!(host.rows_recorded().into_iter().collect::<Vec<_>>(), vec![5, 6, 8]);+ publish(&mut host, second);++ // Both windows hold all of it: it is reused whole.+ let third = record_in_window(&mut host, (0, 5));+ assert!(host.copied_scopes().contains(&foreground(row(4))));+ assert_eq!(host.action_of(foreground(row(4))), None);+ assert!(host.recorded.is_empty());+ publish(&mut host, third);++ // The window cuts it again: it is walked, and the card in the fourth row is dropped.+ record_in_window(&mut host, (0, 1));+ assert_eq!(host.action_of(foreground(row(4))), Some(ScopeAction::Assembled));+ assert!(host.left_out_scopes().contains(&foreground(row(8))));+ assert!(host.recorded.is_empty());+ }++ #[test]+ fn what_a_box_cuts_off_is_left_out_though_the_box_is_wholly_inside_the_window() {+ let mut host = cards_host();+ // The fourth card is in the second row, and scrolls two cards of its own, one of them far down.+ host.walked.insert(foreground(row(4)));+ host.cutting_off_what_they_hold.insert(row(4));+ host.plan(+ foreground(row(4)),+ true,+ &[+ phase(PaintPhase::Foreground),+ child(foreground(row(7))),+ child(foreground(row(8))),+ ],+ );+ for (card, grid_row) in [(7, 1), (8, 9)] {+ host.grid_rows.insert(row(card), grid_row);+ host.rows_painted_in.insert(row(card), (grid_row, grid_row));+ host.plan(foreground(row(card)), true, &[phase(PaintPhase::Foreground)]);+ host.produce(row(card), ProducerKind::DrawForeground, content(1));+ }+ host.window = Some((0, 2));++ let frame = record_frame(&mut host);++ assert_eq!(host.left_out_scopes(), vec![foreground(row(8))]);+ assert!(host.rows_recorded().contains(&7));+ assert!(frame.root.leaves_out_what_lies_outside_the_window);+ assert_matches_from_scratch(&mut host, &frame);+ }++ #[test]+ fn a_scope_that_holds_what_a_box_cuts_off_is_not_reused_whole_into_another_window() {+ let mut host = cards_host();+ // The fourth card's foreground is walked and holds a walked scope of a box that scrolls two cards, one of+ // them far down.+ host.walked.insert(foreground(row(4)));+ host.walked.insert(foreground(row(9)));+ host.cutting_off_what_they_hold.insert(row(9));+ host.plan(+ foreground(row(4)),+ true,+ &[phase(PaintPhase::Foreground), child(foreground(row(9)))],+ );+ host.grid_rows.insert(row(9), 1);+ host.rows_painted_in.insert(row(9), (1, 1));+ host.plan(+ foreground(row(9)),+ true,+ &[+ phase(PaintPhase::Foreground),+ child(foreground(row(7))),+ child(foreground(row(8))),+ ],+ );+ for (card, grid_row) in [(7, 1), (8, 9)] {+ host.grid_rows.insert(row(card), grid_row);+ host.rows_painted_in.insert(row(card), (grid_row, grid_row));+ host.plan(foreground(row(card)), true, &[phase(PaintPhase::Foreground)]);+ host.produce(row(card), ProducerKind::DrawForeground, content(1));+ }++ // A recording of the whole document holds the far card.+ let whole = record_frame(&mut host);+ assert!(host.rows_recorded().contains(&8));+ publish(&mut host, whole);++ // The fourth card is wholly inside the window, and nothing of it was left out, but what the box in it cuts+ // off reaches outside: the card is walked and the far card is dropped.+ host.window = Some((0, 2));+ let windowed = record_frame(&mut host);+ assert_eq!(host.action_of(foreground(row(4))), Some(ScopeAction::Assembled));+ assert_eq!(host.left_out_scopes(), vec![foreground(row(8))]);+ assert!(host.recorded.is_empty());+ assert_matches_from_scratch(&mut host, &windowed);+ }}diff --git a/Libraries/LibWeb/Rust/src/painting/record/ink_bounds.rs b/Libraries/LibWeb/Rust/src/painting/record/ink_bounds.rsindex c711ea104cc..b4b3773f609 100644--- a/Libraries/LibWeb/Rust/src/painting/record/ink_bounds.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/ink_bounds.rs@@ -86,7 +86,7 @@ const COUNT_NAMES: [&str; 17] = ["checked-against-scopes",];-const COMPARISON_SLACK_IN_DEVICE_PIXELS: i32 = 2;+pub(super) const COMPARISON_SLACK_IN_DEVICE_PIXELS: i32 = 2;struct AuditedScopeBound {css_rect: CssPixelRect,@@ -364,7 +364,10 @@ impl<O: Observer> PaintRecorder<'_, O> {);self.ink_bounds_audit.open_scopes_with_a_bound -= usize::from(closed.bound.is_some());}- AssemblyEvent::ScopeCopied(_) | AssemblyEvent::ProducerCopied(..) => {}+ AssemblyEvent::ScopeCopied(_)+ | AssemblyEvent::ProducerCopied(..)+ | AssemblyEvent::ScopeLeftOut(_)+ | AssemblyEvent::ProducerLeftOut(..) => {}}}diff --git a/Libraries/LibWeb/Rust/src/painting/record/inputs.rs b/Libraries/LibWeb/Rust/src/painting/record/inputs.rsindex f76f85e6562..3b5cc173ae8 100644--- a/Libraries/LibWeb/Rust/src/painting/record/inputs.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/inputs.rs@@ -69,6 +69,9 @@ pub(crate) struct RecordingInputs {/// and a run holds only what starts in one pixel row. Tests ask for it to see which boxes a change records/// again on pages too small to span the rows a recording is otherwise cut along.pub records_in_finest_runs: bool,+ /// Records everything the document paints, wherever it is, and not just what shows in a window around the+ /// viewport: what a screenshot of more than the viewport and a dump of the display list read.+ pub records_whole_document: bool,pub canvas_fill_rect: Option<IntRect>,pub opaque_canvas: bool,pub bitmap_rect: IntRect,diff --git a/Libraries/LibWeb/Rust/src/painting/record/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/mod.rsindex fd74d4f111b..a0217764c2f 100644--- a/Libraries/LibWeb/Rust/src/painting/record/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/mod.rs@@ -25,6 +25,7 @@ pub mod svg_resources;pub mod trace;pub mod traversal;pub(crate) mod vector_images;+pub(crate) mod window;use crate::css::css_enums;use crate::css::css_pixels::CssPixelRect;@@ -66,6 +67,8 @@ pub struct RecordingOutput {/// The scopes the recording walked, with what each part of them recorded, which the next recording reuses its/// clean output by.pub(crate) recorded_root: Option<Arc<order_tree::RecordedScope>>,+ /// The part of the document the recording holds, or none where it holds all of it.+ pub(crate) window: Option<Arc<window::RecordedWindow>>,pub has_blocking_wheel_event_listeners: bool,pub wheel_event_listener_state_generation: u64,pub is_identical_to_published_recording: bool,@@ -140,6 +143,9 @@ pub struct PaintRecorder<'a, O: Observer> {pub(crate) scratch: &'a mut scratch::RecordingScratch,pub(crate) resources: resources::RecordingResourceManifest,line_root_positions: Option<(NodeSlotId, crate::painting::paintable_geometry::LineRootPositions)>,+ // The spaces of the frame's tree against the window of the recording, for one that does not hold the whole+ // document.+ pub(crate) window_spaces: Option<window::WindowSpaces<'a>>,}#[derive(Clone, Copy, Default)]diff --git a/Libraries/LibWeb/Rust/src/painting/record/order_tree.rs b/Libraries/LibWeb/Rust/src/painting/record/order_tree.rsindex c7ced2f15ef..454881bbc40 100644--- a/Libraries/LibWeb/Rust/src/painting/record/order_tree.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/order_tree.rs@@ -16,6 +16,7 @@use crate::css::css_pixels::CssPixelPoint;use crate::painting::display_list::chunks::Chunk;use crate::painting::paint_order_plan::{PaintOrderItem, PaintScope};+use crate::painting::record::window::InkBound;use std::ops::Range;use std::sync::{Arc, OnceLock};@@ -164,6 +165,8 @@ pub(crate) struct RecordedRun {pub(crate) enum RecordedSegment {Run(RecordedRun),Walked(Arc<RecordedScope>),+ /// Nothing of the segment was recorded, because all of it lay outside the window of the recording.+ Outside,}impl RecordedSegment {@@ -171,6 +174,15 @@ impl RecordedSegment {match self {Self::Run(run) => run.facts,Self::Walked(scope) => scope.facts,+ Self::Outside => OutputFacts::default(),+ }+ }++ pub(crate) fn leaves_out_what_lies_outside_the_window(&self) -> bool {+ match self {+ Self::Run(_) => false,+ Self::Walked(scope) => scope.leaves_out_what_lies_outside_the_window,+ Self::Outside => true,}}}@@ -185,6 +197,15 @@ pub(crate) struct RecordedScope {pub facts: OutputFacts,/// Where the scope's owner was, which the producers of the owner in the scope's runs were recorded against.pub owner_placement: RowPlacement,+ /// What bounds each segment, or none for a segment that may paint anywhere, where the recording had to ask:+ /// it holds a window of the document that the scope is not wholly inside.+ pub segment_bounds: Option<Arc<[Option<InkBound>]>>,+ /// Whether a segment of the scope, or of a scope walked below it, was left out for lying outside the window.+ pub leaves_out_what_lies_outside_the_window: bool,+ /// Whether a scope walked below this one belongs to a box that cuts off some of what it holds, as a scroller+ /// does: such a scope paints outside what bounds this one, so a recording of a window may leave some of it out+ /// though this scope is wholly inside the window.+ pub walks_a_scope_of_a_box_that_cuts_off_what_it_holds: bool,}impl RecordedScope {@@ -198,6 +219,7 @@ impl RecordedScope {}}RecordedSegment::Walked(scope) => scope.for_each_chunk(visit),+ RecordedSegment::Outside => {}}}}diff --git a/Libraries/LibWeb/Rust/src/painting/record/paint/mod.rs b/Libraries/LibWeb/Rust/src/painting/record/paint/mod.rsindex 3e1845600e0..41391ce8fc8 100644--- a/Libraries/LibWeb/Rust/src/painting/record/paint/mod.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/paint/mod.rs@@ -113,13 +113,7 @@ pub(crate) fn paint<O: Observer>(recorder: &mut PaintRecorder<'_, O>, paintable:}if math_paint_data.is_some_and(|data| data.replaces_text) {// NB: The glyph of a stretched or large operator is painted instead of its text.- } else if recorder- .source- .committed_side_data(paintable)- .inline_content- .as_ref()- .is_none_or(|content| content.items.is_empty())- {+ } else if !crate::painting::paint_order_plan::text_fragments_are_producers(recorder.source, paintable) {text::paint_fragments_foreground(recorder, paintable);}// visibility: hidden on this block does not hide descendants that set visibility:diff --git a/Libraries/LibWeb/Rust/src/painting/record/producers.rs b/Libraries/LibWeb/Rust/src/painting/record/producers.rsindex 0ba68415c50..064788a9613 100644--- a/Libraries/LibWeb/Rust/src/painting/record/producers.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/producers.rs@@ -12,13 +12,14 @@use super::assemble::{AssemblyEvent, AssemblyHost, ItemCut, ProducerOutcome, ScopeAction, ScopePlan};use super::order_tree::{ProducerKind, RecordedChunk, RowPlacement};use super::trace::{Action, Observer, Operation};+use super::window::InkBound;use super::{PaintPhase, PaintRecorder};use crate::css::css_pixels::{CssPixelRect, CssPixels};use crate::layout::node_data::NodeSlotId;use crate::painting::display_list::commands::ContextRef;use crate::painting::force_dark::ForceDarkRole;use crate::painting::paint_order_plan::{PaintOrderItem, PaintProducer, PaintScope, PaintScopePlan};-use crate::painting::paint_read::GeometryRead;+use crate::painting::paint_read::{GeometryRead, PaintRead, PaintSource};use crate::painting::record::change_ticks::RowChanges;use crate::painting::record::svg_resources::MaskLayerSet;use crate::painting::{node_painting, paintable_geometry};@@ -327,6 +328,96 @@ impl<O: Observer> AssemblyHost for PaintRecorder<'_, O> {}}+ // A child scope is bounded by its owner's ink overflow, in the space its own box is painted in, unless a transform+ // below that box moves some of it, and the text fragments and inline box pieces of a line root by what each draws.+ // The other producers of the scope's owner are not bounded unless they paint nothing: the owner of a walked scope+ // is in the window when the scope is, and its own producers mostly cover it.+ fn bound_of_item(&mut self, scope: PaintScope, item: PaintOrderItem) -> Option<InkBound> {+ use crate::painting::ink_overflow::{ScopeInkBound, inline_piece_ink, scope_ink_bound, text_fragment_ink_rect};+ let line_root = |rows: &PaintSource<'_>| {+ if node_painting::has_lines(rows, scope.owner) {+ scope.owner+ } else {+ rows.paintable_data(scope.owner).containing_block+ }+ };+ let (rect, space) = match item {+ PaintOrderItem::Scope(child) => {+ let ScopeInkBound::Rect(bound) = scope_ink_bound(self.source, child) else {+ return None;+ };+ // The bound says where a transform below the child's own box has put what it moves, and nothing records+ // again when the transform puts it elsewhere.+ if self+ .source+ .stored_ink_overflow(child.owner)+ .holds_what_a_transform_moves+ {+ return None;+ }+ (bound, self.own_context(child.owner).spatial)+ }+ PaintOrderItem::Producer(PaintProducer::TextFragment(index)) => {+ let rect = text_fragment_ink_rect(self.source, self.paint_state, line_root(self.source), index);+ if rect.is_empty() {+ return None;+ }+ (+ rect,+ self.context_for_phase(scope.owner, PaintPhase::Foreground).spatial,+ )+ }+ PaintOrderItem::Producer(PaintProducer::InlinePiece(index)) => {+ let root = line_root(self.source);+ let positions = self.line_root_positions(root);+ let ink = inline_piece_ink(self.source, root, &positions, index);+ if ink.unbounded {+ return None;+ }+ let piece_node = self.source.committed_side_data(root).inline_box_pieces()[index as usize].node;+ (+ ink.rect,+ self.context_for_phase(piece_node, PaintPhase::Background).spatial,+ )+ }+ PaintOrderItem::Producer(producer) => {+ let paints_nothing = crate::painting::record::assemble::producer_kinds(producer)+ .into_iter()+ .all(|kind| self.producer_is_skipped(scope.owner, kind));+ return paints_nothing.then(InkBound::nothing);+ }+ };+ let slack = super::ink_bounds::COMPARISON_SLACK_IN_DEVICE_PIXELS;+ Some(InkBound::in_space(+ space,+ self.converter+ .enclosing_device_rect(rect)+ .inflated_edges(slack, slack, slack, slack)+ .to_float(),+ ))+ }++ fn is_outside_window(&mut self, bound: &InkBound) -> bool {+ self.window_spaces+ .as_ref()+ .is_some_and(|spaces| spaces.is_outside(bound))+ }++ fn is_wholly_inside_window(&mut self, bound: &InkBound) -> bool {+ self.window_spaces+ .as_ref()+ .is_some_and(|spaces| spaces.is_wholly_inside(bound))+ }++ // Any box whose overflow is not visible, though not every one of them clips: saying so of a box that does not+ // only has its scopes ask what bounds their segments.+ fn cuts_off_what_it_holds(&mut self, owner: NodeSlotId) -> bool {+ use crate::css::css_enums::overflow;+ self.source+ .node_style_if_live(owner)+ .is_some_and(|style| style.overflow_x() != overflow::VISIBLE || style.overflow_y() != overflow::VISIBLE)+ }+// SVG content is recorded by its root.fn producer_reads_descendants(&mut self, owner: NodeSlotId, kind: ProducerKind) -> bool {match kind {@@ -359,6 +450,10 @@ impl<O: Observer> AssemblyHost for PaintRecorder<'_, O> {AssemblyEvent::ProducerCopied(owner, kind) => {log.leaf(Operation::Producer(owner, kind), Action::Copy, false);}+ AssemblyEvent::ScopeLeftOut(scope) => log.leaf(Operation::Scope(scope), Action::LeaveOut, false),+ AssemblyEvent::ProducerLeftOut(owner, kind) => {+ log.leaf(Operation::Producer(owner, kind), Action::LeaveOut, false);+ }});}}diff --git a/Libraries/LibWeb/Rust/src/painting/record/publish.rs b/Libraries/LibWeb/Rust/src/painting/record/publish.rsindex e2ed0275499..22b571ed9f9 100644--- a/Libraries/LibWeb/Rust/src/painting/record/publish.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/publish.rs@@ -351,6 +351,7 @@ pub(crate) fn take_in_recording(arena: &mut LayoutNodeArena, output: Arc<Recordilet paint_state = arena.paint_state_mut();if publishes_recording {paint_state.visual_context.quarantined_slots_are_releasable = true;+ paint_state.window_of_published_recording = output.window.clone().zip(output.visual_context_tree.clone());}paint_state.last_recording = Some(output);}diff --git a/Libraries/LibWeb/Rust/src/painting/record/trace.rs b/Libraries/LibWeb/Rust/src/painting/record/trace.rsindex 80b7f96a5f9..c114e86df5c 100644--- a/Libraries/LibWeb/Rust/src/painting/record/trace.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/trace.rs@@ -58,7 +58,8 @@ impl Observer for Trace {/// What a recording did with a scope or producer. A scope is assembled when its published child/// list is walked, replanned when its plan is rebuilt, recorded when it has no published/// counterpart and copied when it is clean. A producer is recorded, copied, or skipped when its-/// phase is masked off; an inactive stacking context is skipped as a whole.+/// phase is masked off; an inactive stacking context is skipped as a whole. Either is left out when it lies outside+/// the window of the recording.#[derive(Clone, Copy, Debug, PartialEq, Eq)]pub(crate) enum Action {Assemble,@@ -66,6 +67,7 @@ pub(crate) enum Action {Record,Copy,Skip,+ LeaveOut,}#[derive(Clone, Copy, Debug)]@@ -153,6 +155,7 @@ impl CaptureLog {Action::Record => "RECORD",Action::Copy => "COPY",Action::Skip => "SKIP",+ Action::LeaveOut => "OUTSIDE",};let empty = if event.empty && event.action == Action::Record {" (empty)"diff --git a/Libraries/LibWeb/Rust/src/painting/record/traversal.rs b/Libraries/LibWeb/Rust/src/painting/record/traversal.rsindex 536665886db..178027f3707 100644--- a/Libraries/LibWeb/Rust/src/painting/record/traversal.rs+++ b/Libraries/LibWeb/Rust/src/painting/record/traversal.rs@@ -16,7 +16,7 @@ use crate::painting::node_painting;use crate::painting::paint_order_plan::PaintScope;use crate::painting::paint_read::{GeometryRead, PaintSource};use crate::painting::record::RecordingInputs;-use crate::painting::record::assemble::{Assembler, AssemblyHost, frame_is_unchanged};+use crate::painting::record::assemble::{Assembler, AssemblyHost, Coverage, frame_is_unchanged};use crate::painting::record::frame_inputs::FrameInputs;use crate::painting::record::order_tree::{ProducerKind, RecordedChunk};use crate::painting::record::paint::background_resolution::root_background_canvas_rect;@@ -24,7 +24,9 @@ use crate::painting::record::resources::RecordingResourceManifest;use crate::painting::record::scratch::RecordingScratch;use crate::painting::record::svg_resources::MaskLayerSet;use crate::painting::record::trace::{Action, Operation};+use crate::painting::record::window::{RecordedWindow, WindowSpaces};use crate::painting::record::{RecordingOutput, RecordingResult};+use libcompositing_rust::display_list::window::spaces_place_alike;use std::sync::Arc;pub(crate) fn record_display_list(@@ -33,12 +35,13 @@ pub(crate) fn record_display_list(viewport: NodeSlotId,inputs: &RecordingInputs,source_recording: Option<Arc<RecordingOutput>>,+ window: Option<Arc<RecordedWindow>>,trace: bool,) -> RecordingResult {scratch.begin_recording(source.frame().paintable_row_capacity());macro_rules! record {($observer:ty) => {- record_display_list_impl::<$observer>(source, scratch, viewport, inputs, source_recording)+ record_display_list_impl::<$observer>(source, scratch, viewport, inputs, source_recording, window)};}let result = if trace {@@ -63,6 +66,7 @@ fn record_display_list_impl<O: Observer>(viewport: NodeSlotId,inputs: &RecordingInputs,source_recording: Option<Arc<RecordingOutput>>,+ window: Option<Arc<RecordedWindow>>,) -> RecordingResult {let paint_state = source.frame().paint_state();let structural_epoch = paint_state.structural_epoch();@@ -82,6 +86,32 @@ fn record_display_list_impl<O: Observer>(.as_ref().is_some_and(|frame| frame.window_is_focused != inputs.window_is_focused);let force_dark_settings = inputs.force_dark_enabled.then_some(inputs.force_dark_settings);+ // A recording of a frame without a visual context tree holds all of it.+ let window = window.filter(|_| paint_state.visual_context_tree.is_some());+ // The published recording left out what this one leaves out where it was made for the same window and every space+ // places what it holds where it did then.+ let published_holds_what_this_holds = |window: &RecordedWindow, published: &RecordingOutput| {+ published+ .window+ .as_ref()+ .is_some_and(|published_window| **published_window == *window)+ && published+ .visual_context_tree+ .as_deref()+ .zip(paint_state.visual_context_tree.as_deref())+ .is_some_and(|(published_tree, tree)| spaces_place_alike(published_tree, tree))+ };+ let coverage = match (&window, source_recording.as_deref()) {+ (None, _) => Coverage::WholeDocument,+ (Some(window), Some(published)) if published_holds_what_this_holds(window, published) => {+ Coverage::PublishedWindow+ }+ (Some(_), _) => Coverage::AnotherWindow,+ };+ let window_spaces = window+ .clone()+ .zip(paint_state.visual_context_tree.as_deref())+ .map(|(window, tree)| WindowSpaces::new(window, tree));let mut recorder = PaintRecorder {source,paint_state,@@ -101,6 +131,7 @@ fn record_display_list_impl<O: Observer>(observer: O::default(),scratch,resources: RecordingResourceManifest::default(),+ window_spaces,};let root_group_color = recorder.record_canvas();let prologue = recorder.take_run_chunk();@@ -125,7 +156,7 @@ fn record_display_list_impl<O: Observer>(let anything_changed = source.paint_change_stamps(viewport).row_or_anything_below_it_changed_since(frame.recorded_as_of);- frame_is_unchanged(root, anything_changed, window_focus_changed)+ frame_is_unchanged(root, anything_changed, window_focus_changed, coverage)&& !has_inspector_overlays&& frame.prologue_id == prologue_id})@@ -153,8 +184,8 @@ fn record_display_list_impl<O: Observer>((chunks, display_list, None)}None => {- let recorded_root =- Assembler::new(&mut recorder, window_focus_changed).assemble_root(root_scope, published_root.as_ref());+ let recorded_root = Assembler::new(&mut recorder, window_focus_changed, coverage)+ .assemble_root(root_scope, published_root.as_ref());let mut chunks: Vec<Arc<RecordedChunk>> = prologue.into_iter().collect();recorded_root.for_each_chunk(&mut |chunk| chunks.push(Arc::clone(chunk)));if has_inspector_overlays {@@ -186,6 +217,7 @@ fn record_display_list_impl<O: Observer>(chunks,display_list,recorded_root,+ window: window.clone(),has_blocking_wheel_event_listeners,wheel_event_listener_state_generation: inputs.wheel_event_listener_state_generation,is_identical_to_published_recording: false,@@ -198,14 +230,107 @@ fn record_display_list_impl<O: Observer>(async_scrolling_metadata: None,};let resources = recorder.resources;- if reuses_from_published_recording && reused_output_is_verified() {- let from_scratch =- record_display_list_impl::<super::trace::NoTrace>(source, scratch, viewport, inputs, None).output;- require_same_recording(&output, &from_scratch);+ let mut record_from_scratch = |window: Option<Arc<RecordedWindow>>| {+ record_display_list_impl::<super::trace::NoTrace>(source, scratch, viewport, inputs, None, window).output+ };+ let verifies_reused_output = reuses_from_published_recording && reused_output_is_verified();+ let window_to_verify = window+ .clone()+ .filter(|_| reuses_from_published_recording && left_out_content_is_verified());+ let from_scratch =+ (verifies_reused_output || window_to_verify.is_some()).then(|| record_from_scratch(window.clone()));+ if verifies_reused_output && let Some(from_scratch) = &from_scratch {+ require_same_recording(&output, from_scratch);+ }+ if let Some(window) = window_to_verify+ && let Some(tree) = paint_state.visual_context_tree.as_deref()+ {+ let of_whole_document = record_from_scratch(None);+ require_only_what_misses_the_window_is_left_out(+ from_scratch.as_ref().unwrap_or(&output),+ &of_whole_document,+ &WindowSpaces::new(window, tree),+ );}RecordingResult { output, resources }}+fn left_out_content_is_verified() -> bool {+ static VERIFIED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();+ *VERIFIED.get_or_init(|| cfg!(debug_assertions) || std::env::var_os("LIBWEB_VERIFY_PAINT_WINDOW").is_some())+}++/// Requires a recording of a window, made from scratch, to lack only what misses the window: its tape is the tape+/// of a recording of the whole document without some of its chunks, and no command in those draws where the window+/// reaches. The commands that only describe the document to the compositor draw nothing.+fn require_only_what_misses_the_window_is_left_out(+ of_window: &RecordingOutput,+ of_whole_document: &RecordingOutput,+ spaces: &WindowSpaces<'_>,+) {+ use crate::painting::display_list::builder::for_each_command;+ use crate::painting::display_list::chunks::chunks_of;+ let (windowed, whole) = (&of_window.display_list, &of_whole_document.display_list);+ let mut chunks_of_window = chunks_of(&windowed.bytes, &windowed.command_runs, &windowed.chunks).peekable();+ for (chunk, bytes, runs) in chunks_of(&whole.bytes, &whole.command_runs, &whole.chunks) {+ let is_the_same_chunk = chunks_of_window+ .next_if(|(kept, kept_bytes, kept_runs)| {+ kept.id == chunk.id+ || (kept_bytes.len() == bytes.len()+ && kept_runs.len() == runs.len()+ && without_vector_image_ids(kept_bytes) == without_vector_image_ids(bytes))+ })+ .is_some();+ if is_the_same_chunk {+ continue;+ }+ let chunk_start = chunk.byte_end - bytes.len() as u32;+ for run in runs {+ let run_start = (run.offset - chunk_start) as usize;+ let run_bytes = &bytes[run_start..run_start + run.size as usize];+ for_each_command(run_bytes, |header, _, _| {+ if header.command_type.is_compositor_metadata() || !header.has_bounding_rect {+ return;+ }+ assert!(+ spaces.shows_in_window(header.bounding_rect.to_float(), run.context) != Some(true),+ "A recording of a window left out {} at {:?} under {:?}, which shows in the window",+ header.command_type.name(),+ header.bounding_rect,+ run.context+ );+ });+ }+ }+ assert!(+ chunks_of_window.next().is_none(),+ "A recording of a window holds a chunk that a recording of the whole document lacks"+ );+}++/// The bytes of a tape without the ids of the SVG image records it draws. A command that paints an SVG image is+/// recorded with a placeholder for the image's records, which publication replaces with the id of the records the host+/// rendered, and the placeholder follows how many images the recording met before. A reused command names the records+/// already.+fn without_vector_image_ids(bytes: &[u8]) -> Vec<u8> {+ use crate::painting::display_list::commands::{DisplayListCommandType, PaintVectorImage};+ let mut bytes = bytes.to_vec();+ let id_field = std::mem::offset_of!(PaintVectorImage, vector_image_id);+ let mut id_offsets = Vec::new();+ crate::painting::display_list::nested_records::for_each_command_including_nested(+ &bytes,+ &mut |command_type, payload_offset, _| {+ if command_type == DisplayListCommandType::PaintVectorImage {+ id_offsets.push(payload_offset + id_field);+ }+ },+ );+ for offset in id_offsets {+ bytes[offset..offset + std::mem::size_of::<u64>()].fill(0);+ }+ bytes+}+fn reused_output_is_verified() -> bool {static VERIFIED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();*VERIFIED.get_or_init(|| cfg!(debug_assertions) || std::env::var_os("LIBWEB_VERIFY_PAINT_REUSE").is_some())@@ -216,26 +341,6 @@ fn reused_output_is_verified() -> bool {fn require_same_recording(assembled: &RecordingOutput, from_scratch: &RecordingOutput) {use crate::painting::display_list::builder::for_each_command;use crate::painting::display_list::chunks::{chunk_id, chunks_of};- use crate::painting::display_list::commands::{DisplayListCommandType, PaintVectorImage};- // A command that paints an SVG image is recorded with a placeholder for the image's records, which publication- // replaces with the id of the records the host rendered. A reused command names those records already.- let without_vector_image_ids = |bytes: &[u8]| {- let mut bytes = bytes.to_vec();- let id_field = std::mem::offset_of!(PaintVectorImage, vector_image_id);- let mut id_offsets = Vec::new();- crate::painting::display_list::nested_records::for_each_command_including_nested(- &bytes,- &mut |command_type, payload_offset, _| {- if command_type == DisplayListCommandType::PaintVectorImage {- id_offsets.push(payload_offset + id_field);- }- },- );- for offset in id_offsets {- bytes[offset..offset + std::mem::size_of::<u64>()].fill(0);- }- bytes- };let (assembled_list, scratch_list) = (&assembled.display_list, &from_scratch.display_list);let assembled_bytes = without_vector_image_ids(&assembled_list.bytes);let scratch_bytes = without_vector_image_ids(&scratch_list.bytes);diff --git a/Libraries/LibWeb/Rust/src/painting/record/window.rs b/Libraries/LibWeb/Rust/src/painting/record/window.rsnew file mode 100644index 00000000000..5628cfb6052--- /dev/null+++ b/Libraries/LibWeb/Rust/src/painting/record/window.rs@@ -0,0 +1,359 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! The window a recording is made for, and where the parts of the paint order lie against it (see [`RecordedWindow`]).+//!+//! A recording holds what shows in the viewport and for a margin around it, with every scroller where it is, instead+//! of the whole document. The window stays where it was placed while it still covers what the viewport shows with half+//! the margin to spare, so scrolling a little changes nothing a recording reads. Once it does not, the next recording+//! places the window again: what came into it is recorded, and what left it is dropped.++use crate::css::css_pixels::CssPixelPoint;+use crate::painting::display_list::commands::{ClipMode, ContextRef, SpatialNodeIndex};+use crate::painting::visual_context::{ClipNodeData, ScrollData, SpatialData, VisualContextTree};+use libgfx_rust::{FloatPoint, FloatRect, FloatSize, IntSize};+use smallvec::SmallVec;+use std::sync::Arc;++pub(crate) use libcompositing_rust::display_list::window::{PlacedSpaces, RecordedWindow};++/// A bound keeps the rects of this many spaces apart before it gives up on bounding what it holds.+const MOST_SPACES_A_BOUND_KEEPS_APART: usize = 4;++/// Bounds what a part of a plan paints: rects in device pixels, each in the space of a node of the visual context+/// tree. What lies in one space is bounded by one rect.+#[derive(Clone, Debug, PartialEq)]+pub(crate) struct InkBound {+ rects: SmallVec<[(SpatialNodeIndex, FloatRect); 2]>,+}++impl InkBound {+ /// What bounds an item that paints nothing.+ pub(crate) fn nothing() -> Self {+ Self { rects: SmallVec::new() }+ }++ pub(crate) fn in_space(space: SpatialNodeIndex, rect: FloatRect) -> Self {+ Self {+ rects: smallvec::smallvec![(space, rect)],+ }+ }++ /// The rect of each space the bound has things in.+ #[cfg(test)]+ pub(crate) fn rects(&self) -> &[(SpatialNodeIndex, FloatRect)] {+ &self.rects+ }++ /// One bound for what both bound, or none where they lie in more spaces than a bound keeps apart.+ pub(crate) fn united(mut self, other: &InkBound) -> Option<Self> {+ for &(space, rect) in &other.rects {+ if let Some((_, kept)) = self.rects.iter_mut().find(|(kept, _)| *kept == space) {+ *kept = kept.united(rect);+ } else if self.rects.len() < MOST_SPACES_A_BOUND_KEEPS_APART {+ self.rects.push((space, rect));+ } else {+ return None;+ }+ }+ Some(self)+ }+}++/// How far each scroller of `tree` had moved what it holds, as a window keeps it: in device pixels by the index of its+/// node, from `scroll_own_offsets`, by scroll state slot.+pub(crate) fn device_pixel_offsets(+ tree: &VisualContextTree,+ scroll_own_offsets: &[CssPixelPoint],+ device_pixels_per_css_pixel: f64,+) -> Arc<[FloatPoint]> {+ let offset_of = scroll_offset_of_node(scroll_own_offsets, device_pixels_per_css_pixel);+ tree.spatial_nodes+ .iter()+ .enumerate()+ .map(|(index, node)| match &node.data {+ SpatialData::Scroll(scroll) => offset_of(SpatialNodeIndex(index as u32), scroll),+ _ => FloatPoint::default(),+ })+ .collect()+}++/// How far a scroller moves what it holds, in device pixels, from `scroll_own_offsets`, by scroll state slot.+fn scroll_offset_of_node(+ scroll_own_offsets: &[CssPixelPoint],+ device_pixels_per_css_pixel: f64,+) -> impl Fn(SpatialNodeIndex, &ScrollData) -> FloatPoint + '_ {+ let scale = device_pixels_per_css_pixel as f32;+ move |_, scroll| {+ scroll_own_offsets+ .get(scroll.state_slot)+ .map_or_else(FloatPoint::default, |offset| FloatPoint {+ x: offset.x.to_float() * scale,+ y: offset.y.to_float() * scale,+ })+ }+}++/// What a window keeps ahead of what the viewport shows before a recording places it again.+pub(crate) fn kept_ahead(window: &RecordedWindow) -> FloatSize {+ let margin = window.margin();+ FloatSize {+ width: margin.width / 2.0,+ height: margin.height / 2.0,+ }+}++/// Whether `window`, of a recording made against `tree_of_recording`, still covers what a viewport of+/// `device_viewport_size` shows of `tree_now` with its scrollers at `scroll_own_offsets`, half the margin to spare.+pub(crate) fn still_covers(+ window: &RecordedWindow,+ tree_of_recording: &VisualContextTree,+ tree_now: &VisualContextTree,+ device_viewport_size: IntSize,+ device_pixels_per_css_pixel: f64,+ scroll_own_offsets: &[CssPixelPoint],+) -> bool {+ window.still_covers(+ tree_of_recording,+ tree_now,+ device_viewport_size,+ device_pixels_per_css_pixel,+ scroll_offset_of_node(scroll_own_offsets, device_pixels_per_css_pixel),+ kept_ahead(window),+ )+}++/// The window a recording of a frame of `tree` is made for: the window of `published`, the recording published last+/// with the tree it was made against, where that still covers what the viewport shows with the scrollers at+/// `scroll_own_offsets`, or else one placed there.+pub(crate) fn window_of_frame(+ published: Option<(&Arc<RecordedWindow>, &VisualContextTree)>,+ tree: &VisualContextTree,+ device_viewport_size: IntSize,+ device_pixels_per_css_pixel: f64,+ scroll_own_offsets: &[CssPixelPoint],+) -> Arc<RecordedWindow> {+ if let Some((published, tree_of_recording)) = published+ && still_covers(+ published,+ tree_of_recording,+ tree,+ device_viewport_size,+ device_pixels_per_css_pixel,+ scroll_own_offsets,+ )+ {+ return Arc::clone(published);+ }+ Arc::new(RecordedWindow::placed_at(+ device_viewport_size,+ device_pixels_per_css_pixel,+ device_pixel_offsets(tree, scroll_own_offsets, device_pixels_per_css_pixel),+ ))+}++/// The spaces of a frame's visual context tree against the window of its recording.+pub(crate) struct WindowSpaces<'a> {+ window: Arc<RecordedWindow>,+ spaces: PlacedSpaces<'a>,+}++impl<'a> WindowSpaces<'a> {+ pub(crate) fn new(window: Arc<RecordedWindow>, tree: &'a VisualContextTree) -> Self {+ let spaces = window.placed_spaces(tree);+ Self { window, spaces }+ }++ /// The rects of the bound in the space of the visual viewport, or none where one lies in a space that moves+ /// without a recording.+ fn rects_in_root(&self, bound: &InkBound) -> Option<SmallVec<[FloatRect; 2]>> {+ bound+ .rects+ .iter()+ .map(|&(space, rect)| self.spaces.to_root(space, rect))+ .collect()+ }++ /// Whether nothing inside the bound shows in the window. A bound that cannot be placed is not outside it.+ pub(crate) fn is_outside(&self, bound: &InkBound) -> bool {+ // What paints nothing is as cheap to keep as to leave out.+ if bound.rects.is_empty() {+ return false;+ }+ // One device pixel of slack keeps rounding from leaving out what touches the window's edge.+ self.rects_in_root(bound).is_some_and(|rects| {+ rects+ .iter()+ .all(|rect| rect.inflated(2.0, 2.0).intersected(self.window.rect).is_empty())+ })+ }++ /// Whether everything inside the bound shows in the window.+ pub(crate) fn is_wholly_inside(&self, bound: &InkBound) -> bool {+ self.rects_in_root(bound).is_some_and(|rects| {+ rects+ .iter()+ .all(|rect| self.window.rect.contains_rect(rect.inflated(2.0, 2.0)))+ })+ }++ /// Whether what a command draws in `rect` under `context` shows in the window as the tree stands, with the+ /// scrollers where the window was placed and the clips of the context applied, or none where a node on the way to+ /// the root moves what it holds without a recording. A recording of a window that lacks the command was right to+ /// leave it out where this is false.+ pub(crate) fn shows_in_window(&self, rect: FloatRect, context: ContextRef) -> Option<bool> {+ let tree = self.spaces.tree();+ let mut shown = self.spaces.to_root(context.spatial, rect)?;+ let mut clip = context.clip;+ while !clip.is_none() {+ let clip_node = &tree.clip_nodes[clip.0 as usize];+ let clip_rect = match &clip_node.data {+ ClipNodeData::Rect(data) if data.mode == ClipMode::Intersect => Some(data.rect),+ ClipNodeData::Path(path) => Some(path.bounding_rect.to_float()),+ _ => None,+ };+ if let Some(clip_rect) = clip_rect+ && let Some(clip_in_root) = self.spaces.to_root(clip_node.spatial, clip_rect)+ {+ shown = shown.intersected(clip_in_root);+ }+ clip = clip_node.parent;+ }+ Some(!shown.intersected(self.window.rect).is_empty())+ }+}++#[cfg(test)]+mod tests {+ use super::*;+ use crate::css::css_pixels::CssPixels;+ use crate::layout::node_data::NodeSlotId;+ use crate::painting::visual_context::{+ ScrollData, SpatialData, StickyData, TransformData, TransformDataRole, VISUAL_VIEWPORT_NODE_INDEX,+ };+ use libgfx_rust::FloatMatrix4x4;++ fn transform(matrix: FloatMatrix4x4) -> SpatialData {+ SpatialData::Transform(TransformData {+ matrix,+ origin: FloatPoint::default(),+ sorting_context_root_index: None,+ flattens_inherited_transform: false,+ role: TransformDataRole::CssTransform,+ synthetic_plane: false,+ establishes_sorting_context: false,+ bounds: FloatRect::default(),+ })+ }++ fn scroller(state_slot: usize) -> SpatialData {+ SpatialData::Scroll(ScrollData {+ state_slot,+ owner_paintable: NodeSlotId::INVALID,+ })+ }++ fn empty_tree() -> VisualContextTree {+ let SpatialData::Transform(identity) = transform(FloatMatrix4x4::identity()) else {+ unreachable!()+ };+ VisualContextTree::create(identity)+ }++ fn offsets(offsets: &[(i64, i64)]) -> Vec<CssPixelPoint> {+ offsets+ .iter()+ .map(|(x, y)| CssPixelPoint::new(CssPixels::from_integer(*x), CssPixels::from_integer(*y)))+ .collect()+ }++ const VIEWPORT: IntSize = IntSize {+ width: 800,+ height: 600,+ };++ // A window of an 800 by 600 viewport, which reaches 1200 pixels above and below it.+ fn window_at(tree: &VisualContextTree, placed_offsets: &[(i64, i64)]) -> Arc<RecordedWindow> {+ window_of_frame(None, tree, VIEWPORT, 1.0, &offsets(placed_offsets))+ }++ fn bound(space: SpatialNodeIndex, y: f32) -> InkBound {+ InkBound::in_space(space, FloatRect::new(0.0, y, 100.0, 100.0))+ }++ #[test]+ fn a_frame_keeps_the_published_window_while_it_covers_what_shows() {+ let mut tree = empty_tree();+ tree.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ let published = window_at(&tree, &[(0, -1000)]);+ let window_of =+ |placed: &[(i64, i64)]| window_of_frame(Some((&published, &tree)), &tree, VIEWPORT, 1.0, &offsets(placed));+ assert!(Arc::ptr_eq(&window_of(&[(0, -1600)]), &published));+ assert!(!Arc::ptr_eq(&window_of(&[(0, -1601)]), &published));+ assert_eq!(*window_of(&[(0, -1601)]), *window_at(&tree, &[(0, -1601)]));+ }++ #[test]+ fn what_a_scroller_holds_is_placed_where_the_scroller_was_when_the_window_was_placed() {+ let mut tree = empty_tree();+ let page = tree.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ // The page is scrolled down by 5000.+ let spaces = WindowSpaces::new(window_at(&tree, &[(0, -5000)]), &tree);++ // The window reaches from 3800 to 6800 down the page.+ assert!(spaces.is_outside(&bound(page, 0.0)));+ assert!(spaces.is_outside(&bound(page, 3600.0)));+ assert!(!spaces.is_outside(&bound(page, 3750.0)));+ assert!(spaces.is_wholly_inside(&bound(page, 5000.0)));+ assert!(!spaces.is_wholly_inside(&bound(page, 3750.0)));+ assert!(spaces.is_outside(&bound(page, 6900.0)));+ // What the page does not scroll stays where the viewport is.+ assert!(!spaces.is_outside(&bound(VISUAL_VIEWPORT_NODE_INDEX, 0.0)));+ assert!(spaces.is_outside(&bound(VISUAL_VIEWPORT_NODE_INDEX, 5000.0)));+ }++ #[test]+ fn what_a_static_transform_moves_is_placed_where_it_moves_it() {+ let mut tree = empty_tree();+ let page = tree.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ let pulled = tree.append_spatial(transform(libgfx_rust::translation_matrix(0.0, -4900.0, 0.0)), page);+ let spaces = WindowSpaces::new(window_at(&tree, &[(0, 0)]), &tree);+ assert!(!spaces.is_outside(&bound(pulled, 5000.0)));+ assert!(spaces.is_outside(&bound(page, 5000.0)));+ }++ #[test]+ fn nothing_below_a_node_that_moves_on_its_own_is_outside() {+ let mut tree = empty_tree();+ let page = tree.append_spatial(scroller(0), VISUAL_VIEWPORT_NODE_INDEX);+ let sticky = tree.append_spatial(+ SpatialData::Sticky(StickyData::unconstrained(page, None, 1, NodeSlotId::INVALID)),+ page,+ );+ let spaces = WindowSpaces::new(window_at(&tree, &[(0, 0), (0, 0)]), &tree);+ assert!(!spaces.is_outside(&bound(sticky, 100_000.0)));+ assert!(!spaces.is_wholly_inside(&bound(sticky, 0.0)));+ // A bound with a part that cannot be placed is not outside, wherever its other parts are.+ let mixed = bound(page, 100_000.0).united(&bound(sticky, 100_000.0)).unwrap();+ assert!(!spaces.is_outside(&mixed));+ }++ #[test]+ fn a_bound_keeps_the_rects_of_a_few_spaces_apart() {+ let space = |index| SpatialNodeIndex(index);+ let united = bound(space(1), 0.0).united(&bound(space(1), 500.0)).unwrap();+ assert_eq!(+ united,+ InkBound::in_space(space(1), FloatRect::new(0.0, 0.0, 100.0, 600.0))+ );+ let mut many = bound(space(1), 0.0);+ for index in 2..=MOST_SPACES_A_BOUND_KEEPS_APART as u32 {+ many = many.united(&bound(space(index), 0.0)).unwrap();+ }+ assert!(many.clone().united(&bound(space(1), 10.0)).is_some());+ assert!(many.united(&bound(space(99), 0.0)).is_none());+ }+}diff --git a/Libraries/LibWeb/Rust/src/painting/recording_slot.rs b/Libraries/LibWeb/Rust/src/painting/recording_slot.rsindex 5a8b916697e..a6c2e714c6c 100644--- a/Libraries/LibWeb/Rust/src/painting/recording_slot.rs+++ b/Libraries/LibWeb/Rust/src/painting/recording_slot.rs@@ -466,6 +466,28 @@ pub(crate) fn yield_claim_hold_for_testing() {/// Records `frame` of the document's `viewport` with `inputs` and `recorder`, which keeps the inputs of a recording that/// publishes, and answers what it recorded, with the trace it left where `trace_recordings` asks for one.+/// The window a recording of `frame` with `inputs` is made for: none where it records the whole document, the window+/// of `published`, the recording published last, where that still covers what the frame's viewport shows, or else one+/// placed where the frame's scrollers are.+fn window_to_record(+ frame: &PublishedFrame,+ inputs: &RecordingInputs,+ published: Option<&RecordingOutput>,+) -> Option<Arc<crate::painting::record::window::RecordedWindow>> {+ if inputs.records_whole_document || inputs.records_without_visual_contexts {+ return None;+ }+ let paint_state = frame.paint_state();+ let tree = paint_state.visual_context_tree.as_deref()?;+ Some(crate::painting::record::window::window_of_frame(+ published.and_then(|published| published.window.as_ref().zip(published.visual_context_tree.as_deref())),+ tree,+ inputs.uncaptured.device_viewport_size,+ inputs.device_pixels_per_css_pixel,+ paint_state.scroll_own_offsets(),+ ))+}+pub(crate) fn record_frame(frame: PublishedFrame,recorder: &mut RecorderState,@@ -482,12 +504,14 @@ pub(crate) fn record_frame(} = recorder;let source = PaintSource::new(&frame, absolute_rects);let publishes_recording = published_recording_count.note_recording(inputs.publishes_recording);+ let window = window_to_record(&frame, &inputs, published_recording.as_deref());let mut recording = crate::painting::record::traversal::record_display_list(&source,scratch,viewport,&inputs,published_recording.clone(),+ window,trace_recordings,);let output = &mut recording.output;diff --git a/Tests/LibWeb/Text/expected/display_list/window-follows-a-transform-that-brings-a-box-into-view.txt b/Tests/LibWeb/Text/expected/display_list/window-follows-a-transform-that-brings-a-box-into-view.txtnew file mode 100644index 00000000000..cceeae8826b--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/window-follows-a-transform-that-brings-a-box-into-view.txt@@ -0,0 +1,3 @@+at the top: OUTSIDE+after the frames of the transform: COPY+the box in view: fardiff --git a/Tests/LibWeb/Text/expected/display_list/window-follows-what-nested-scrollers-move-together.txt b/Tests/LibWeb/Text/expected/display_list/window-follows-what-nested-scrollers-move-together.txtnew file mode 100644index 00000000000..10e04013909--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/window-follows-what-nested-scrollers-move-together.txt@@ -0,0 +1,3 @@+at the top: OUTSIDE+the target shows from 300 to 400+after the frames of the scroll: COPYdiff --git a/Tests/LibWeb/Text/expected/display_list/window-keeps-what-a-transform-may-move.txt b/Tests/LibWeb/Text/expected/display_list/window-keeps-what-a-transform-may-move.txtnew file mode 100644index 00000000000..2a581a616bf--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/window-keeps-what-a-transform-may-move.txt@@ -0,0 +1,3 @@+at the top: RECORD RECORD RECORD RECORD OUTSIDE OUTSIDE OUTSIDE OUTSIDE RECORD OUTSIDE OUTSIDE OUTSIDE+the transform moved its box into view: COPY COPY COPY COPY OUTSIDE OUTSIDE OUTSIDE OUTSIDE COPY OUTSIDE OUTSIDE OUTSIDE+the box in view: moverdiff --git a/Tests/LibWeb/Text/expected/display_list/window-leaves-out-the-lines-of-a-tall-text-block-far-from-it.txt b/Tests/LibWeb/Text/expected/display_list/window-leaves-out-the-lines-of-a-tall-text-block-far-from-it.txtnew file mode 100644index 00000000000..3b9d64609a1--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/window-leaves-out-the-lines-of-a-tall-text-block-far-from-it.txt@@ -0,0 +1,2 @@+at the top: recorded 119, reused 0, left out 281+scrolled near the bottom, and the text changed: recorded 118, reused 0, left out 282diff --git a/Tests/LibWeb/Text/expected/display_list/window-leaves-out-what-is-far-from-the-viewport.txt b/Tests/LibWeb/Text/expected/display_list/window-leaves-out-what-is-far-from-the-viewport.txtnew file mode 100644index 00000000000..74b89a2b586--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/window-leaves-out-what-is-far-from-the-viewport.txt@@ -0,0 +1,8 @@+at the top: RECORD RECORD RECORD RECORD OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE+scrolled by 500, inside the slack: @viewport COPY+a block outside the window changed: COPY COPY COPY COPY OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE+scrolled to 2000: COPY COPY COPY COPY RECORD RECORD RECORD RECORD OUTSIDE OUTSIDE OUTSIDE OUTSIDE+scrolled by 500 more: @viewport COPY+scrolled to the bottom: COPY OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE RECORD RECORD RECORD RECORD+scrolled back to the top: COPY RECORD RECORD RECORD OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE+element at the bottom after scrolling there: b11diff --git a/Tests/LibWeb/Text/expected/display_list/window-moves-with-the-frames-of-a-scroll.txt b/Tests/LibWeb/Text/expected/display_list/window-moves-with-the-frames-of-a-scroll.txtnew file mode 100644index 00000000000..241e4b3f50c--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/window-moves-with-the-frames-of-a-scroll.txt@@ -0,0 +1,3 @@+scrolled by 300, inside the slack, and b0 changed: RECORD COPY COPY COPY OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE+scrolled to 3000, and b6 changed: COPY OUTSIDE OUTSIDE COPY COPY COPY RECORD COPY COPY COPY OUTSIDE OUTSIDE+scrolled back to the top, and b2 changed: COPY COPY RECORD COPY OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDEdiff --git a/Tests/LibWeb/Text/expected/display_list/window-places-content-by-scrollers-and-transforms.txt b/Tests/LibWeb/Text/expected/display_list/window-places-content-by-scrollers-and-transforms.txtnew file mode 100644index 00000000000..e14f9bc64b7--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/window-places-content-by-scrollers-and-transforms.txt@@ -0,0 +1,12 @@+at the top:+ items: RECORD RECORD RECORD RECORD OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE+ boxes: pulled=RECORD pushed=OUTSIDE stuck=RECORD pinned=RECORD+the scroller scrolled to 3000:+ items: COPY OUTSIDE OUTSIDE COPY RECORD RECORD RECORD RECORD RECORD RECORD+ boxes: pulled=COPY pushed=OUTSIDE stuck=COPY pinned=COPY+the page scrolled to the bottom:+ items: - - - - - - - - - -+ boxes: pulled=OUTSIDE pushed=OUTSIDE stuck=COPY pinned=COPY+back at the top:+ items: RECORD RECORD RECORD RECORD OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE OUTSIDE+ boxes: pulled=RECORD pushed=OUTSIDE stuck=COPY pinned=COPYdiff --git a/Tests/LibWeb/Text/input/display_list/paint-cache-scrollability-flip-scope.html b/Tests/LibWeb/Text/input/display_list/paint-cache-scrollability-flip-scope.htmlindex 07858096460..b2a6c39db7e 100644--- a/Tests/LibWeb/Text/input/display_list/paint-cache-scrollability-flip-scope.html+++ b/Tests/LibWeb/Text/input/display_list/paint-cache-scrollability-flip-scope.html@@ -215,7 +215,13 @@ displayListTest({BlockContainer<BODY>#body/scroll-metadata COPYBlockContainer<BODY>#body/background COPYBlockContainer<BODY>#body/border COPY- Box<DIV>#row.row/descendants(background-and-borders) COPY+ Box<DIV>#row.row/descendants(background-and-borders) ASSEMBLE+ Box<DIV>#row.row/scroll-metadata COPY+ Box<DIV>#row.row/background COPY+ Box<DIV>#row.row/border COPY+ BlockContainer<DIV>#row-0.box/descendants(background-and-borders) COPY+ BlockContainer<DIV>#outer.box/descendants(background-and-borders) ASSEMBLE+ BlockContainer<DIV>#row-2.box/descendants(background-and-borders) COPYBox<DIV>#second-row.row/descendants(background-and-borders) REPLANBox<DIV>#second-row.row/scroll-metadata COPYBox<DIV>#second-row.row/background COPY@@ -227,7 +233,13 @@ displayListTest({BlockContainer<HTML>#html/foreground COPYBlockContainer<BODY>#body/descendants(foreground) ASSEMBLEBlockContainer<BODY>#body/foreground COPY- Box<DIV>#row.row/descendants(foreground) COPY+ Box<DIV>#row.row/descendants(foreground) ASSEMBLE+ Box<DIV>#row.row/foreground COPY+ BlockContainer<DIV>#row-0.box/descendants(foreground) COPY+ BlockContainer<DIV>#outer.box/descendants(foreground) ASSEMBLE+ BlockContainer<DIV>#row-2.box/descendants(foreground) COPY+ Box<DIV>#row.row/outline COPY+ Box<DIV>#row.row/overlay COPYBox<DIV>#second-row.row/descendants(foreground) REPLANBox<DIV>#second-row.row/foreground COPYBlockContainer<DIV>#second-row-0.box/descendants(foreground) COPY@@ -239,7 +251,31 @@ displayListTest({BlockContainer<BODY>#body/outline COPYBlockContainer<BODY>#body/overlay COPYBlockContainer<DIV>#row-0.box COPY- BlockContainer<DIV>#outer.box COPY+ BlockContainer<DIV>#outer.box ASSEMBLE+ BlockContainer<DIV>#outer.box/scroll-metadata COPY+ BlockContainer<DIV>#outer.box/background COPY+ BlockContainer<DIV>#outer.box/border COPY+ BlockContainer<DIV>#inner/descendants(background-and-borders) ASSEMBLE+ BlockContainer<DIV>#inner/scroll-metadata COPY+ BlockContainer<DIV>#inner/background COPY+ BlockContainer<DIV>#inner/border COPY+ BlockContainer<DIV>#inner-content.tall/descendants(background-and-borders) COPY+ BlockContainer<DIV>#filler.tall/descendants(background-and-borders) COPY+ BlockContainer<DIV>#inner/descendants(floats) ASSEMBLE+ BlockContainer<DIV>#inner-content.tall/descendants(floats) COPY+ BlockContainer<DIV>#filler.tall/descendants(floats) COPY+ BlockContainer<DIV>#inner/descendants(inline-background-and-borders) ASSEMBLE+ BlockContainer<DIV>#inner-content.tall/descendants(inline-background-and-borders) COPY+ BlockContainer<DIV>#filler.tall/descendants(inline-background-and-borders) COPY+ BlockContainer<DIV>#outer.box/foreground COPY+ BlockContainer<DIV>#inner/descendants(foreground) ASSEMBLE+ BlockContainer<DIV>#inner/foreground COPY+ BlockContainer<DIV>#inner-content.tall/descendants(foreground) COPY+ BlockContainer<DIV>#inner/outline COPY+ BlockContainer<DIV>#inner/overlay COPY+ BlockContainer<DIV>#filler.tall/descendants(foreground) COPY+ BlockContainer<DIV>#outer.box/outline COPY+ BlockContainer<DIV>#outer.box/overlay COPYBlockContainer<DIV>#row-2.box COPYBlockContainer<DIV>#second-row-0.box COPYBlockContainer<DIV>#second-row-1.box COPYdiff --git a/Tests/LibWeb/Text/input/display_list/paint-damage-scroller-slot-reuse.html b/Tests/LibWeb/Text/input/display_list/paint-damage-scroller-slot-reuse.htmlindex cd26fe802ec..ca03abcee83 100644--- a/Tests/LibWeb/Text/input/display_list/paint-damage-scroller-slot-reuse.html+++ b/Tests/LibWeb/Text/input/display_list/paint-damage-scroller-slot-reuse.html@@ -47,7 +47,11 @@ displayListTest({BlockContainer<BODY>#body/scroll-metadata RECORDBlockContainer<BODY>#body/background SKIPBlockContainer<BODY>#body/border SKIP- BlockContainer<DIV>#keep.box.scroller/descendants(background-and-borders) COPY+ BlockContainer<DIV>#keep.box.scroller/descendants(background-and-borders) ASSEMBLE+ BlockContainer<DIV>#keep.box.scroller/scroll-metadata COPY+ BlockContainer<DIV>#keep.box.scroller/background COPY+ BlockContainer<DIV>#keep.box.scroller/border COPY+ BlockContainer<DIV>.content/descendants(background-and-borders) COPYBlockContainer<DIV>#outer.box/descendants(background-and-borders) ASSEMBLEBlockContainer<DIV>#outer.box/scroll-metadata RECORDBlockContainer<DIV>#outer.box/background SKIP@@ -59,7 +63,11 @@ displayListTest({BlockContainer<HTML>#html/foreground RECORD (empty)BlockContainer<BODY>#body/descendants(foreground) REPLANBlockContainer<BODY>#body/foreground RECORD (empty)- BlockContainer<DIV>#keep.box.scroller/descendants(foreground) COPY+ BlockContainer<DIV>#keep.box.scroller/descendants(foreground) ASSEMBLE+ BlockContainer<DIV>#keep.box.scroller/foreground COPY+ BlockContainer<DIV>.content/descendants(foreground) COPY+ BlockContainer<DIV>#keep.box.scroller/outline COPY+ BlockContainer<DIV>#keep.box.scroller/overlay COPYBlockContainer<DIV>#outer.box/descendants(foreground) ASSEMBLEBlockContainer<DIV>#outer.box/foreground RECORD (empty)BlockContainer<DIV>#outer-content.content/descendants(foreground) ASSEMBLE@@ -110,7 +118,11 @@ displayListTest({BlockContainer<BODY>#body/scroll-metadata RECORDBlockContainer<BODY>#body/background SKIPBlockContainer<BODY>#body/border SKIP- BlockContainer<DIV>#keep.box.scroller/descendants(background-and-borders) COPY+ BlockContainer<DIV>#keep.box.scroller/descendants(background-and-borders) ASSEMBLE+ BlockContainer<DIV>#keep.box.scroller/scroll-metadata COPY+ BlockContainer<DIV>#keep.box.scroller/background COPY+ BlockContainer<DIV>#keep.box.scroller/border COPY+ BlockContainer<DIV>.content/descendants(background-and-borders) COPYBlockContainer<DIV>#outer.box/descendants(background-and-borders) ASSEMBLEBlockContainer<DIV>#outer.box/scroll-metadata RECORDBlockContainer<DIV>#outer.box/background SKIP@@ -122,7 +134,11 @@ displayListTest({BlockContainer<HTML>#html/foreground RECORD (empty)BlockContainer<BODY>#body/descendants(foreground) ASSEMBLEBlockContainer<BODY>#body/foreground RECORD (empty)- BlockContainer<DIV>#keep.box.scroller/descendants(foreground) COPY+ BlockContainer<DIV>#keep.box.scroller/descendants(foreground) ASSEMBLE+ BlockContainer<DIV>#keep.box.scroller/foreground COPY+ BlockContainer<DIV>.content/descendants(foreground) COPY+ BlockContainer<DIV>#keep.box.scroller/outline COPY+ BlockContainer<DIV>#keep.box.scroller/overlay COPYBlockContainer<DIV>#outer.box/descendants(foreground) ASSEMBLEBlockContainer<DIV>#outer.box/foreground RECORD (empty)BlockContainer<DIV>#outer-content.content/descendants(foreground) ASSEMBLEdiff --git a/Tests/LibWeb/Text/input/display_list/will-change-transform-value-update.html b/Tests/LibWeb/Text/input/display_list/will-change-transform-value-update.htmlindex d7df3116257..eb2f01f0f01 100644--- a/Tests/LibWeb/Text/input/display_list/will-change-transform-value-update.html+++ b/Tests/LibWeb/Text/input/display_list/will-change-transform-value-update.html@@ -12,13 +12,41 @@<script>// will-change: transform gives the box its transform node before any transform value, so the// first value, a later value and the return to none all patch that node: nothing records again.+// The box may have moved across the edge of the window the published recording was made for, so+// a recording made after the value changed walks down to it, and copies everything.const valueUpdate = `update DIRTY-PATHdiv#box transform UPDATED`;-const quiet = `+const walkedAndCopied = `@canvas RECORD (empty)- @viewport COPY+ @viewport ASSEMBLE+ @viewport/preamble COPY+ @viewport/scroll-metadata COPY+ @viewport/background COPY+ @viewport/border COPY+ BlockContainer<HTML>#html/descendants(background-and-borders) ASSEMBLE+ @viewport/foreground COPY+ BlockContainer<HTML>#html/descendants(foreground) ASSEMBLE+ BlockContainer<HTML>#html ASSEMBLE+ BlockContainer<HTML>#html/preamble COPY+ BlockContainer<HTML>#html/scroll-metadata COPY+ BlockContainer<HTML>#html/background COPY+ BlockContainer<HTML>#html/border COPY+ BlockContainer<BODY>#body/descendants(background-and-borders) ASSEMBLE+ BlockContainer<BODY>#body/scroll-metadata COPY+ BlockContainer<BODY>#body/background COPY+ BlockContainer<BODY>#body/border COPY+ BlockContainer<DIV>#box/descendants(background-and-borders) COPY+ BlockContainer<HTML>#html/foreground COPY+ BlockContainer<BODY>#body/descendants(foreground) ASSEMBLE+ BlockContainer<BODY>#body/foreground COPY+ BlockContainer<DIV>#box/descendants(foreground) COPY+ BlockContainer<BODY>#body/outline COPY+ BlockContainer<BODY>#body/overlay COPY+ BlockContainer<DIV>#box COPY+ BlockContainer<HTML>#html/outline COPY+ @viewport/outline COPY`;displayListTest({setup: async () => { removeBodyWhitespace(); },@@ -26,17 +54,17 @@ displayListTest({{name: "transform none to translateX(10px)",mutate: () => { box.style.transform = "translateX(10px)"; },- expect: { visualContexts: valueUpdate, displayList: quiet },+ expect: { visualContexts: valueUpdate, displayList: walkedAndCopied },},{name: "transform translateX(10px) to translateX(20px)",mutate: () => { box.style.transform = "translateX(20px)"; },- expect: { visualContexts: valueUpdate, displayList: quiet },+ expect: { visualContexts: valueUpdate, displayList: walkedAndCopied },},{name: "transform translateX(20px) to none",mutate: () => { box.style.transform = ""; },- expect: { visualContexts: valueUpdate, displayList: quiet },+ expect: { visualContexts: valueUpdate, displayList: walkedAndCopied },},],});diff --git a/Tests/LibWeb/Text/input/display_list/window-follows-a-transform-that-brings-a-box-into-view.html b/Tests/LibWeb/Text/input/display_list/window-follows-a-transform-that-brings-a-box-into-view.htmlnew file mode 100644index 00000000000..47e326ad427--- /dev/null+++ b/Tests/LibWeb/Text/input/display_list/window-follows-a-transform-that-brings-a-box-into-view.html@@ -0,0 +1,42 @@+<!doctype html>+<html>+<script src="../include.js"></script>+<style>+ body { margin: 0; height: 6000px; }+ #near { position: absolute; left: 200px; top: 0; width: 100px; height: 100px; background: blue; transform: translateY(0px); }+ #far { position: absolute; left: 0; top: 5000px; width: 100px; height: 100px; background: green; transform: translateY(0px); }+</style>+<body><div id="near"></div><div id="far"></div>+<script>+// A box far down the page is left out of a recording of a window around the top. Changing its transform records+// nothing again by itself, but once the transform brings the box into view the window no longer covers what shows,+// and the frames that follow record the box. The box near the top changes before each recording here, so that the+// recording walks the boxes: one the frames recorded is reused, and one they left out would be recorded here.+const frame = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));+promiseTest(async () => {+ if (document.readyState !== "complete") await new Promise(resolve => addEventListener("load", resolve, { once: true }));+ __outputElement.style.display = "none";+ await frame();+ const output = [];+ const actionOfFar = trace => {+ const scope = "#far ";+ const line = trace.split("\n").find(line => line.includes(scope));+ return line ? line.slice(line.indexOf(scope) + scope.length).trim() : "-";+ };+ const record = label => {+ near.style.backgroundColor = near.style.backgroundColor === "red" ? "blue" : "red";+ internals.beginDisplayListTrace();+ internals.recordDisplayListForTesting(true, false);+ output.push(`${label}: ${actionOfFar(internals.takeDisplayListTrace())}`);+ };++ record("at the top");+ far.style.transform = "translateY(-4900px)";+ await frame();+ record("after the frames of the transform");+ output.push(`the box in view: ${document.elementFromPoint(50, 150).id}`);++ __outputElement.style.display = "";+ for (const line of output) println(line);+});+</script>diff --git a/Tests/LibWeb/Text/input/display_list/window-follows-what-nested-scrollers-move-together.html b/Tests/LibWeb/Text/input/display_list/window-follows-what-nested-scrollers-move-together.htmlnew file mode 100644index 00000000000..c005b3b715d--- /dev/null+++ b/Tests/LibWeb/Text/input/display_list/window-follows-what-nested-scrollers-move-together.html@@ -0,0 +1,48 @@+<!doctype html>+<html>+<script src="../include.js"></script>+<style>+ body { margin: 0; }+ .scroller { height: 600px; overflow: scroll; }+ .gap { height: 500px; }+ .tail { height: 3000px; }+ #b-gap { height: 1100px; }+ #target { height: 100px; background: green; }+</style>+<body><div class="gap"></div><div id="a" class="scroller"><div class="gap"></div><div id="b" class="scroller"><div id="b-gap"></div><div id="target"></div><div class="tail"></div></div><div class="tail"></div></div><div class="tail"></div>+<script>+// The target lies 300 pixels past the bottom of the window when it is placed, in a scroller in a scroller in the page.+// Scrolling each of them by one viewport moves none of them further than a scroller alone may move before the window+// is placed again, but together they bring the target into view: the frames of the scroll record it. The inner+// scroller changes before each recording here, so that the recording walks what it holds: a target the frames recorded+// is reused, and one they left out would be recorded here, or left out again where the window stayed.+const frame = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));+promiseTest(async () => {+ if (document.readyState !== "complete") await new Promise(resolve => addEventListener("load", resolve, { once: true }));+ __outputElement.style.display = "none";+ const output = [];+ const actionOfTarget = trace => {+ const scope = "#target/descendants(background-and-borders) ";+ const line = trace.split("\n").find(line => line.includes(scope));+ return line ? line.slice(line.indexOf(scope) + scope.length).trim() : "-";+ };+ const record = (label, cold = false) => {+ b.style.backgroundColor = b.style.backgroundColor === "pink" ? "white" : "pink";+ internals.beginDisplayListTrace();+ internals.recordDisplayListForTesting(true, cold);+ output.push(`${label}: ${actionOfTarget(internals.takeDisplayListTrace())}`);+ };++ record("at the top", true);+ window.scrollTo(0, 600);+ a.scrollTop = 600;+ b.scrollTop = 600;+ await frame();+ const rect = target.getBoundingClientRect();+ output.push(`the target shows from ${rect.top} to ${rect.bottom}`);+ record("after the frames of the scroll");++ __outputElement.style.display = "";+ for (const line of output) println(line);+});+</script>diff --git a/Tests/LibWeb/Text/input/display_list/window-keeps-what-a-transform-may-move.html b/Tests/LibWeb/Text/input/display_list/window-keeps-what-a-transform-may-move.htmlnew file mode 100644index 00000000000..0308a3bcd2e--- /dev/null+++ b/Tests/LibWeb/Text/input/display_list/window-keeps-what-a-transform-may-move.html@@ -0,0 +1,55 @@+<!doctype html>+<html>+<script src="../include.js"></script>+<style>+ body { margin: 0; }+ body > div { height: 500px; }+ body > div:nth-child(odd) { background: #cde; }+ #mover { width: 100px; height: 100px; background: green; transform: translateY(0px); }+ #cut-off { height: 300px; overflow: hidden; }+ #cut-off-mover { width: 100px; height: 100px; background: blue; transform: translateY(0px); }+</style>+<body>+<script>+// A transform changes without the box it moves or the boxes around it being recorded again, and what those boxes+// hold is not bounded again either. So a box that holds a transformed box is never left out, however far from the+// viewport it is: the transform may bring what it moves into view at any time. A box that cuts off what it holds+// keeps the transformed box inside it, and is left out like any other.+for (let i = 0; i < 12; ++i) {+ const block = document.createElement("div");+ block.id = "b" + i;+ block.textContent = "block " + i;+ document.body.appendChild(block);+}+b8.innerHTML = '<div id="mover"></div>';+b10.innerHTML = '<div id="cut-off"><div id="cut-off-mover"></div></div>';+promiseTest(async () => {+ if (document.readyState !== "complete") await new Promise(resolve => addEventListener("load", resolve, { once: true }));+ await document.fonts.ready;+ __outputElement.style.display = "none";+ const output = [];+ const actionOf = (trace, id) => {+ const scope = `#${id}/descendants(background-and-borders) `;+ const line = trace.split("\n").find(line => line.includes(scope));+ return line ? line.slice(line.indexOf(scope) + scope.length).trim() : "-";+ };+ const record = (label, cold = false) => {+ internals.beginDisplayListTrace();+ internals.recordDisplayListForTesting(false, cold);+ const trace = internals.takeDisplayListTrace();+ const actions = Array.from({ length: 12 }, (_, i) => actionOf(trace, "b" + i));+ const summary = actions.every(action => action === "-") ? trace.trim().split("\n").at(-1).trim() : actions.join(" ");+ output.push(`${label}: ${summary}`);+ };++ record("at the top", true);+ // The transform brings the box from 4000 pixels down the page into the viewport. The block it is in was+ // recorded, so the recording reuses it.+ mover.style.transform = "translateY(-3900px)";+ record("the transform moved its box into view");+ output.push(`the box in view: ${document.elementFromPoint(50, 150).id}`);++ __outputElement.style.display = "";+ for (const line of output) println(line);+});+</script>diff --git a/Tests/LibWeb/Text/input/display_list/window-leaves-out-the-lines-of-a-tall-text-block-far-from-it.html b/Tests/LibWeb/Text/input/display_list/window-leaves-out-the-lines-of-a-tall-text-block-far-from-it.htmlnew file mode 100644index 00000000000..c542c17f1a6--- /dev/null+++ b/Tests/LibWeb/Text/input/display_list/window-leaves-out-the-lines-of-a-tall-text-block-far-from-it.html@@ -0,0 +1,36 @@+<!doctype html>+<html>+<script src="../include.js"></script>+<style>+ body { margin: 0; }+ pre { margin: 0; font: 16px/20px monospace; }+</style>+<body><pre id="text"></pre>+<script>+// The lines of one text block are cut into runs along the grid like any other items, and each run of lines is bounded+// by what its lines draw: a recording of a window leaves out the lines far from it, however tall the block is. The run+// that holds the block's own background is not bounded, so it is recorded wherever the window is.+text.textContent = Array.from({ length: 400 }, (_, i) => `line ${i}`).join("\n");+promiseTest(async () => {+ if (document.readyState !== "complete") await new Promise(resolve => addEventListener("load", resolve, { once: true }));+ await document.fonts.ready;+ __outputElement.style.display = "none";+ const output = [];+ const count = (trace, action) => trace.split("\n").filter(line => line.trim().endsWith(`#text/text-fragment ${action}`)).length;+ const record = (label, cold = false) => {+ internals.beginDisplayListTrace();+ internals.recordDisplayListForTesting(true, cold);+ const trace = internals.takeDisplayListTrace();+ output.push(`${label}: recorded ${count(trace, "RECORD")}, reused ${count(trace, "COPY")}, left out ${count(trace, "OUTSIDE")}`);+ };++ record("at the top", true);+ window.scrollTo(0, 7000);+ await new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));+ text.style.color = "blue";+ record("scrolled near the bottom, and the text changed");++ __outputElement.style.display = "";+ for (const line of output) println(line);+});+</script>diff --git a/Tests/LibWeb/Text/input/display_list/window-leaves-out-what-is-far-from-the-viewport.html b/Tests/LibWeb/Text/input/display_list/window-leaves-out-what-is-far-from-the-viewport.htmlnew file mode 100644index 00000000000..da8e62c1d41--- /dev/null+++ b/Tests/LibWeb/Text/input/display_list/window-leaves-out-what-is-far-from-the-viewport.html@@ -0,0 +1,62 @@+<!doctype html>+<html>+<script src="../include.js"></script>+<style>+ body { margin: 0; }+ body > div { height: 500px; }+ body > div:nth-child(odd) { background: #cde; }+</style>+<body>+<script>+// A recording holds what shows in the viewport and for two viewports around it: with a viewport 600 pixels tall,+// what lies within 1200 pixels of it. The window stays where it is until the page has scrolled 600 pixels from+// where the window was placed. The first two blocks are recorded in one run with the body's own background, which+// is not bounded, so they are never left out.+for (let i = 0; i < 12; ++i) {+ const block = document.createElement("div");+ block.id = "b" + i;+ block.textContent = "block " + i;+ document.body.appendChild(block);+}+promiseTest(async () => {+ if (document.readyState !== "complete") await new Promise(resolve => addEventListener("load", resolve, { once: true }));+ await document.fonts.ready;+ __outputElement.style.display = "none";+ const output = [];+ const actionOf = (trace, id) => {+ const scope = `#${id}/descendants(background-and-borders) `;+ const line = trace.split("\n").find(line => line.includes(scope));+ return line ? line.slice(line.indexOf(scope) + scope.length).trim() : "-";+ };+ const record = (label, cold = false) => {+ internals.beginDisplayListTrace();+ internals.recordDisplayListForTesting(false, cold);+ const trace = internals.takeDisplayListTrace();+ const actions = Array.from({ length: 12 }, (_, i) => actionOf(trace, "b" + i));+ const summary = actions.every(action => action === "-") ? trace.trim().split("\n").at(-1).trim() : actions.join(" ");+ output.push(`${label}: ${summary}`);+ };++ record("at the top", true);+ window.scrollTo(0, 500);+ record("scrolled by 500, inside the slack");+ b10.style.background = "red";+ record("a block outside the window changed");+ window.scrollTo(0, 2000);+ record("scrolled to 2000");+ window.scrollTo(0, 2500);+ record("scrolled by 500 more");+ window.scrollTo(0, 5400);+ record("scrolled to the bottom");+ window.scrollTo(0, 0);+ record("scrolled back to the top");++ // What a recording leaves out can still be found.+ window.scrollTo(0, 5400);+ output.push(`element at the bottom after scrolling there: ${document.elementFromPoint(10, 590).id}`);+ window.scrollTo(0, 0);++ __outputElement.style.display = "";+ for (const line of output) println(line);+});+</script>diff --git a/Tests/LibWeb/Text/input/display_list/window-moves-with-the-frames-of-a-scroll.html b/Tests/LibWeb/Text/input/display_list/window-moves-with-the-frames-of-a-scroll.htmlnew file mode 100644index 00000000000..00f4bb53163--- /dev/null+++ b/Tests/LibWeb/Text/input/display_list/window-moves-with-the-frames-of-a-scroll.html@@ -0,0 +1,51 @@+<!doctype html>+<html>+<script src="../include.js"></script>+<style>+ body { margin: 0; }+ body > div { height: 500px; }+ body > div:nth-child(odd) { background: #cde; }+</style>+<body>+<script>+// A frame that scrolls the page further than the window of the published recording reaches records a display list+// for a window placed where the page is now, without anything else asking for one. Each step scrolls, lets the+// frames of the scroll go by, and then changes one block and records: a block the frames recorded is copied, and+// one they left out would be recorded here.+for (let i = 0; i < 12; ++i) {+ const block = document.createElement("div");+ block.id = "b" + i;+ block.textContent = "block " + i;+ document.body.appendChild(block);+}+const frame = () => new Promise(resolve => requestAnimationFrame(() => requestAnimationFrame(resolve)));+promiseTest(async () => {+ if (document.readyState !== "complete") await new Promise(resolve => addEventListener("load", resolve, { once: true }));+ await document.fonts.ready;+ __outputElement.style.display = "none";+ await frame();+ const output = [];+ const actionOf = (trace, id) => {+ const scope = `#${id}/descendants(background-and-borders) `;+ const line = trace.split("\n").find(line => line.includes(scope));+ return line ? line.slice(line.indexOf(scope) + scope.length).trim() : "-";+ };+ const afterFramesOf = async (label, scrollTop, changedBlock) => {+ window.scrollTo(0, scrollTop);+ await frame();+ changedBlock.style.background = "red";+ internals.beginDisplayListTrace();+ // The frames of the page paint overlays, and a recording copies from one made with the same inputs.+ internals.recordDisplayListForTesting(true, false);+ const trace = internals.takeDisplayListTrace();+ output.push(`${label}: ${Array.from({ length: 12 }, (_, i) => actionOf(trace, "b" + i)).join(" ")}`);+ };++ await afterFramesOf("scrolled by 300, inside the slack, and b0 changed", 300, b0);+ await afterFramesOf("scrolled to 3000, and b6 changed", 3000, b6);+ await afterFramesOf("scrolled back to the top, and b2 changed", 0, b2);++ __outputElement.style.display = "";+ for (const line of output) println(line);+});+</script>diff --git a/Tests/LibWeb/Text/input/display_list/window-places-content-by-scrollers-and-transforms.html b/Tests/LibWeb/Text/input/display_list/window-places-content-by-scrollers-and-transforms.htmlnew file mode 100644index 00000000000..aa4a815964f--- /dev/null+++ b/Tests/LibWeb/Text/input/display_list/window-places-content-by-scrollers-and-transforms.html@@ -0,0 +1,56 @@+<!doctype html>+<html>+<script src="../include.js"></script>+<style>+ body { margin: 0; height: 6000px; position: relative; }+ #scroller { height: 300px; overflow: scroll; }+ #scroller > div { height: 500px; }+ #scroller > div:nth-child(odd) { background: #cde; }+ #pulled { position: absolute; left: 0; top: 5000px; width: 100px; height: 100px; background: green; transform: translateY(-4900px); }+ #pushed { position: absolute; left: 200px; top: 100px; width: 100px; height: 100px; background: blue; transform: translateY(8000px); }+ #stuck { position: sticky; top: 0; height: 50px; background: orange; margin-top: 4000px; }+ #pinned { position: fixed; left: 0; bottom: 0; width: 100px; height: 40px; background: purple; }+</style>+<body><div id="scroller"></div><div id="stuck">stuck</div><div id="pulled"></div><div id="pushed"></div><div id="pinned"></div>+<script>+// What a scroller holds is in the window where it shows with the scroller where it is, and what a transform moves is+// in it where the transform puts it: the box a transform pulls into view from far down the page is recorded while the+// page is at the top and left out once the page scrolls away from it, and the one it pushes far away is left out. A+// sticky box moves on its own as the page scrolls, so it is never left out, and a fixed box stays in the viewport.+for (let i = 0; i < 10; ++i) {+ const item = document.createElement("div");+ item.id = "s" + i;+ item.textContent = "item " + i;+ scroller.appendChild(item);+}+promiseTest(async () => {+ if (document.readyState !== "complete") await new Promise(resolve => addEventListener("load", resolve, { once: true }));+ await document.fonts.ready;+ __outputElement.style.display = "none";+ const output = [];+ const actionAfter = (trace, label) => {+ const line = trace.split("\n").find(line => line.includes(label));+ return line ? line.slice(line.indexOf(label) + label.length).trim() : "-";+ };+ const record = (label, cold = false) => {+ internals.beginDisplayListTrace();+ internals.recordDisplayListForTesting(false, cold);+ const trace = internals.takeDisplayListTrace();+ const items = Array.from({ length: 10 }, (_, i) => actionAfter(trace, `#s${i}/descendants(background-and-borders) `));+ const boxes = ["pulled", "pushed", "stuck", "pinned"].map(id => `${id}=${actionAfter(trace, `#${id} `)}`);+ output.push(`${label}:\n items: ${items.join(" ")}\n boxes: ${boxes.join(" ")}`);+ };++ record("at the top", true);+ scroller.scrollTop = 3000;+ record("the scroller scrolled to 3000");+ window.scrollTo(0, 5400);+ record("the page scrolled to the bottom");+ window.scrollTo(0, 0);+ scroller.scrollTop = 0;+ record("back at the top");++ __outputElement.style.display = "";+ for (const line of output) println(line);+});+</script>diff --git a/Tests/LibWeb/Text/input/visual-context/value-only-update-keeps-tree.html b/Tests/LibWeb/Text/input/visual-context/value-only-update-keeps-tree.htmlindex 78c9b6fe496..3409a325119 100644--- a/Tests/LibWeb/Text/input/visual-context/value-only-update-keeps-tree.html+++ b/Tests/LibWeb/Text/input/visual-context/value-only-update-keeps-tree.html@@ -2,7 +2,9 @@<script src="../include.js"></script><script src="../work-test.js"></script><!-- Changing the value of an effect or a transform patches the box's node in place: the tree keeps its structure, and- the recorded display list needs no new recording. -->+ the recorded display list needs no new recording. A transformed box may have moved across the edge of the window+ the published recording was made for, so a recording made after its transform changed walks down to it, and+ copies everything. --><div id="box" style="width: 100px; height: 100px; opacity: 0.5; transform: translateX(10px)"></div><div id="relative-box" style="position: relative; width: 100px; height: 100px; opacity: 0.5"></div><div id="backdrop-box" style="width: 100px; height: 100px; backdrop-filter: invert(1)"></div>@@ -11,6 +13,48 @@@canvas RECORD (empty)@viewport COPY`;+ const walkedAndCopied = `+ @canvas RECORD (empty)+ @viewport ASSEMBLE+ @viewport/preamble COPY+ @viewport/scroll-metadata COPY+ @viewport/background COPY+ @viewport/border COPY+ BlockContainer<HTML>/descendants(background-and-borders) ASSEMBLE+ @viewport/foreground COPY+ BlockContainer<HTML>/descendants(foreground) ASSEMBLE+ BlockContainer<HTML> ASSEMBLE+ BlockContainer<HTML>/preamble COPY+ BlockContainer<HTML>/scroll-metadata COPY+ BlockContainer<HTML>/background COPY+ BlockContainer<HTML>/border COPY+ BlockContainer<BODY>/descendants(background-and-borders) ASSEMBLE+ BlockContainer<BODY>/scroll-metadata COPY+ BlockContainer<BODY>/background COPY+ BlockContainer<BODY>/border COPY+ BlockContainer<DIV>#box/descendants(background-and-borders) COPY+ BlockContainer<DIV>#relative-box/descendants(background-and-borders) COPY+ BlockContainer<DIV>#backdrop-box/descendants(background-and-borders) COPY+ BlockContainer<HTML>/foreground COPY+ BlockContainer<BODY>/descendants(foreground) ASSEMBLE+ BlockContainer<BODY>/foreground COPY+ BlockContainer<DIV>#box/descendants(foreground) COPY+ BlockContainer<DIV>#relative-box/descendants(foreground) COPY+ BlockContainer<DIV>#backdrop-box/descendants(foreground) COPY+ BlockContainer<BODY>/outline COPY+ BlockContainer<BODY>/overlay COPY+ BlockContainer<DIV>#box COPY+ BlockContainer<DIV>#relative-box ASSEMBLE+ BlockContainer<DIV>#relative-box/preamble COPY+ BlockContainer<DIV>#relative-box/scroll-metadata COPY+ BlockContainer<DIV>#relative-box/background COPY+ BlockContainer<DIV>#relative-box/border COPY+ BlockContainer<DIV>#relative-box/foreground COPY+ BlockContainer<DIV>#relative-box/outline COPY+ BlockContainer<DIV>#backdrop-box COPY+ BlockContainer<HTML>/outline COPY+ @viewport/outline COPY+ `;displayListTest({steps: [{@@ -26,7 +70,7 @@div#box effects UPDATEDdiv#box transform UPDATED`,- displayList: quietRecording,+ displayList: walkedAndCopied,},},{