Truly independent web browser
LibWeb: Make fragment link offsets physical when fragments are built
Aliaksandr Kalenikc9f80e20fd66
diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rsindex fc6d9ea8317..0f453431cc5 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_engine.rs@@ -3182,6 +3182,7 @@ impl<'pass> AbsposEngine<'pass> {resolved_anchor_insets: resolved,resolved_anchor_sizes,position_option: None,+ frame: self.pass.frame,}.without_static_position_in_axes_placed_by_own_insets();(inputs, default_scroll_shift)diff --git a/Libraries/LibWeb/Rust/src/layout/abspos_inputs.rs b/Libraries/LibWeb/Rust/src/layout/abspos_inputs.rsindex 6336da5dceb..ed9c8c62ffe 100644--- a/Libraries/LibWeb/Rust/src/layout/abspos_inputs.rs+++ b/Libraries/LibWeb/Rust/src/layout/abspos_inputs.rs@@ -200,6 +200,9 @@ pub(crate) struct AbsposLayoutInputs {pub(crate) resolved_anchor_sizes: super::style_values::ResolvedAnchorSizes,/// The position option the box is laid out with, or none for a box without position options.pub(crate) position_option: Option<PositionOptionChoice>,+ /// The frame in which the containing block lays out its contents, in which the box is laid out and its resolved+ /// anchor sizes lie.+ pub(crate) frame: super::geometry::Frame,}impl AbsposLayoutInputs {diff --git a/Libraries/LibWeb/Rust/src/layout/commit.rs b/Libraries/LibWeb/Rust/src/layout/commit.rsindex 96f321c7f60..3b8b80e4cb1 100644--- a/Libraries/LibWeb/Rust/src/layout/commit.rs+++ b/Libraries/LibWeb/Rust/src/layout/commit.rs@@ -198,6 +198,10 @@ impl<'tree> Commit<'_, 'tree> {fn meet(&mut self, link: &'tree FragmentLink, holder: &Holder) {let node = link.fragment.node;+ debug_assert!(+ link.fragment.outer_links != fragment_tree::OuterLinks::AwaitingContainingBlockSize,+ "{node:?} reaches commit with links that await the size of their containing block"+ );// NB: A partial relayout's root keeps the fragment of its parent as its holder, which the commit does not walk.let keeps_its_holder = holder.node.is_invalid() && !self.is_full_commit && node == self.root;let recorded_holder = if keeps_its_holder {@@ -495,9 +499,12 @@ impl<'tree> Commit<'_, 'tree> {}).flatten();if let Some(line_data) = merged_line_data.as_ref().or(fragment.line_data.as_ref()) {- let change = self- .paintables- .set_line_data(node, line_data, previous_fragmented_content);+ let change = self.paintables.set_line_data(+ node,+ line_data,+ previous_fragmented_content,+ link.fragment.sides.content_size,+ );line_root_changes_for_children.fragment_changed |= change.content_changed;line_root_changes_for_children.inline_content_changed |= change.content_changed;line_root_changes_for_children.inline_item_order_changed |= change.item_order_changed;diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rsindex 4106bda5f91..cd1936db15b 100644--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs@@ -4201,7 +4201,11 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {cells: root_box.cells,line_data: root_box.line_data,};- let facts_decided_by_parent = run_state::FactsDecidedByParent::of_committed_link(&committed_root_link, pass.frame);+ let facts_decided_by_parent = run_state::FactsDecidedByParent::of_committed_link(+ &committed_root_link,+ pass.frame,+ fragment_tree::committed_content_size_of(pass, committed_root_link.placement.containing_block),+ );let placement = facts_decided_by_parent.placement.expect("the root of a partial relayout keeps the placement it committed");diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rsindex baa9e2a7196..f48ba7e333b 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs@@ -8,7 +8,7 @@ use crate::css::css_enums::{overflow, positioning, writing_mode};use crate::css::css_pixels::{CssPixelPoint, CssPixelRect, CssPixels};use crate::css::display::FfiDisplay;use crate::layout::LayoutNodeArena;-use crate::layout::fragment_tree::{Fragment, FragmentLink};+use crate::layout::fragment_tree::{Fragment, FragmentLink, OuterLinks};use crate::layout::geometry::{Frame, Sides};use crate::layout::inline_content::{InlineContent, PhysicalPlane};use crate::layout::node_data::{NodeFlag, NodeKind, NodeSlotId};@@ -69,18 +69,7 @@ struct ContainedBoxesRelativeToContainerPaddingBox {impl ContainedBoxesRelativeToContainerPaddingBox {fn of(link: &FragmentLink, container: &BoxesRelativeToOwnPaddingBox) -> Self {let fragment = &link.fragment;- let frame = link.placement.frame;- let content_size_in_frame = frame.size_from_physical(fragment.sides.content_size);- let content_box = frame- .rect_to_physical(- CssPixelRect::new(- link.committed_offset.x,- link.committed_offset.y,- content_size_in_frame.width,- content_size_in_frame.height,- ),- container.content_size,- )+ let content_box = CssPixelRect::from_location_and_size(link.offset.into(), fragment.sides.content_size.into()).translated_by(container.content_box.location());let padding_box = inflated_by(content_box, fragment.sides.padding);Self {@@ -131,9 +120,7 @@ impl TransformGeometry for ContainedBoxTransformGeometry<'_> {pub(crate) fn contained_links(fragment: &Fragment) -> impl Iterator<Item = &FragmentLink> {let node = fragment.node;fragment.children.iter().flat_map(move |link| {- let outer_links = link- .fragment- .holds_links_of_outer_containing_blocks+ let outer_links = (link.fragment.outer_links != OuterLinks::None).then_some(&link.fragment.children).into_iter().flatten()@@ -698,7 +685,7 @@ impl LayoutNodeArena {.committed_fragment_link_cloned(holder.slot_index(), holder.generation())}).map(|holder_link| holder_link.fragment)- .filter(|holder_fragment| holder_fragment.holds_links_of_outer_containing_blocks);+ .filter(|holder_fragment| holder_fragment.outer_links != OuterLinks::None);let links_held_beside = holder_fragment.iter().flat_map(|holder_fragment| holder_fragment.children.iter())@@ -854,7 +841,7 @@ mod tests {let fragment = std::sync::Arc::get_mut(&mut child_link.fragment).unwrap();fragment.sides.content_size.width = CssPixels::from_integer(20);fragment.sides.content_size.height = CssPixels::from_integer(20);- child_link.committed_offset.y = CssPixels::from_integer(180).into();+ child_link.offset.y = CssPixels::from_integer(180).into();child_link.placement.containing_block = container;let overflow = scrollable_overflow_of(&arena, &container_link.fragment, std::iter::once(&child_link));assert_eq!(diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rsindex 8905114614b..9d80d2d44b8 100644--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs@@ -250,6 +250,19 @@ impl PendingPayload {}}+/// Whether a fragment holds links whose containing block is outside its box, as a table box holds the rows and cells+/// its wrapper contains, and whether their offsets are final.+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]+pub(crate) enum OuterLinks {+ #[default]+ None,+ /// The links of boxes whose containing block is that of the fragment's own box, offset as if that containing+ /// block's content box had no size, until the fragment of the containing block is built. Only a frame that reverses+ /// an axis leaves them so.+ AwaitingContainingBlockSize,+ Placed,+}+pub(crate) struct Fragment {pub(crate) identity: u64,pub(crate) node: crate::layout::node_data::NodeSlotId,@@ -259,7 +272,7 @@ pub(crate) struct Fragment {pub(crate) line_clamp: LineClampFacts,pub(crate) breaks: BreakFacts,pub(crate) scrollable_overflow: fragment_overflow::FragmentScrollableOverflow,- pub(crate) holds_links_of_outer_containing_blocks: bool,+ pub(crate) outer_links: OuterLinks,pub(crate) children: Vec<FragmentLink>,}@@ -309,8 +322,6 @@ pub(crate) struct LinkPlacement {/// The default scroll shift of a box whose anchor insets its layout resolved, which commit records for the box.pub(crate) default_scroll_shift: Option<abspos_inputs::DefaultScrollShift>,pub(crate) containing_block: crate::layout::node_data::NodeSlotId,- /// The frame the box was laid out in, in which the link and the fragment hold its geometry.- pub(crate) frame: geometry::Frame,}impl LinkPlacement {@@ -343,7 +354,6 @@ impl LinkPlacement {.map_or(crate::layout::node_data::NodeSlotId::INVALID, |placement| {placement.containing_block}),- frame,}}}@@ -351,10 +361,76 @@ impl LinkPlacement {#[derive(Clone)]pub(crate) struct FragmentLink {pub(crate) fragment: std::sync::Arc<Fragment>,- pub(crate) committed_offset: FfiCssPixelPoint,+ /// The physical offset of the content box of the fragment's box in the content box of its containing block.+ pub(crate) offset: FfiCssPixelPoint,pub(crate) placement: LinkPlacement,}+/// The physical offset of a content box of physical size `content_size` that lies at `offset_in_frame` in the content+/// box of a containing block of physical size `containing_block_size`, which lays out its contents in `frame`.+fn physical_offset(+ offset_in_frame: FfiCssPixelPoint,+ frame: geometry::Frame,+ content_size: FfiCssPixelSize,+ containing_block_size: FfiCssPixelSize,+) -> FfiCssPixelPoint {+ if frame.is_physical() {+ return offset_in_frame;+ }+ let size_in_frame = frame.size_from_physical(content_size);+ frame+ .rect_to_physical(+ CssPixelRect::new(+ offset_in_frame.x,+ offset_in_frame.y,+ size_in_frame.width,+ size_in_frame.height,+ ),+ containing_block_size,+ )+ .location()+ .into()+}++/// A link the builder holds until the physical size of its containing block is known, with its offset in `frame`, the+/// frame in which the containing block lays out its contents.+pub(crate) struct PendingLink {+ fragment: std::sync::Arc<Fragment>,+ offset_in_frame: FfiCssPixelPoint,+ frame: geometry::Frame,+ placement: LinkPlacement,+ /// The physical content size of the containing block, once the builder knows it.+ containing_block_size: Option<FfiCssPixelSize>,+}++impl PendingLink {+ fn into_link(self, containing_block_size: FfiCssPixelSize) -> FragmentLink {+ FragmentLink {+ offset: physical_offset(+ self.offset_in_frame,+ self.frame,+ self.fragment.sides.content_size,+ containing_block_size,+ ),+ fragment: self.fragment,+ placement: self.placement,+ }+ }+}++/// The physical content size `node` committed, or none for a box without a committed fragment.+pub(crate) fn committed_content_size_of(+ pass: &LayoutPass<'_>,+ node: crate::layout::node_data::NodeSlotId,+) -> FfiCssPixelSize {+ if node.is_invalid() {+ return FfiCssPixelSize::default();+ }+ crate::painting::paint_read::GeometryRead::with_committed_fragment_link(pass.arena(), node, |link| {+ link.map(|link| link.fragment.sides.content_size).unwrap_or_default()+ })+}+fn same_allocation<T>(left: Option<&std::sync::Arc<T>>, right: Option<&std::sync::Arc<T>>) -> bool {match (left, right) {(None, None) => true,@@ -415,7 +491,9 @@ impl Fragment {}fn builds_like_apart_from_overflow(&self, previous: &Fragment) -> bool {- self.has_same_box_properties(previous) && self.holds_same_contents_as(previous)+ self.has_same_box_properties(previous)+ && self.outer_links == previous.outer_links+ && self.holds_same_contents_as(previous)}pub(crate) fn with_scrollable_overflow(@@ -439,11 +517,16 @@ impl Fragment {line_clamp: self.line_clamp,breaks: self.breaks,scrollable_overflow,- holds_links_of_outer_containing_blocks: self.holds_links_of_outer_containing_blocks,+ outer_links: self.outer_links,children,}}+ /// Whether the fragment holds links of boxes whose containing block is `node`.+ fn holds_links_contained_by(&self, node: crate::layout::node_data::NodeSlotId) -> bool {+ self.outer_links != OuterLinks::None && self.children.iter().any(|link| link.placement.containing_block == node)+ }+/// Whether the fragment holds the very lines and child fragments `previous` holds, placed the same way.pub(crate) fn holds_same_contents_as(&self, previous: &Fragment) -> bool {same_allocation(self.line_data.as_ref(), previous.line_data.as_ref())@@ -524,10 +607,10 @@ impl FragmentLink {line_clamp: LineClampFacts::default(),breaks: BreakFacts::default(),scrollable_overflow: Default::default(),- holds_links_of_outer_containing_blocks: false,+ outer_links: OuterLinks::None,children: Vec::new(),}),- committed_offset: Default::default(),+ offset: Default::default(),placement: LinkPlacement {insets: geometry::Sides::default(),shown_as: ShownAs::default(),@@ -535,18 +618,41 @@ impl FragmentLink {abspos_layout_inputs: None,default_scroll_shift: None,containing_block: crate::layout::node_data::NodeSlotId::INVALID,- frame: geometry::Frame::PHYSICAL,},}}+ /// The offset of the link's content box in the content box of its containing block, read in `frame`, where the+ /// containing block's content box has the physical size `containing_block_size`.+ pub(crate) fn offset_in_frame(+ &self,+ frame: geometry::Frame,+ containing_block_size: FfiCssPixelSize,+ ) -> FfiCssPixelPoint {+ if frame.is_physical() {+ return self.offset;+ }+ frame+ .rect_from_physical(+ CssPixelRect::new(+ self.offset.x,+ self.offset.y,+ self.fragment.sides.content_size.width,+ self.fragment.sides.content_size.height,+ ),+ containing_block_size,+ )+ .location()+ .into()+ }+pub(crate) fn places_same_fragment_identically_to(&self, previous: &FragmentLink) -> bool {std::sync::Arc::ptr_eq(&self.fragment, &previous.fragment) && self.has_same_placement(previous)}pub(crate) fn has_same_placement(&self, previous: &FragmentLink) -> bool {self.fragment.node == previous.fragment.node- && self.committed_offset == previous.committed_offset+ && self.offset == previous.offset&& self.placement == previous.placement}}@@ -711,6 +817,8 @@ pub(crate) struct PlacedBoxes {struct PlacedBoxSlot {builder: u64,placement: run_state::BoxPlacement,+ /// The physical size of the box's content box, once the builder built the box's fragment.+ physical_content_size: Option<FfiCssPixelSize>,}impl Default for PlacedBoxSlot {@@ -721,6 +829,7 @@ impl Default for PlacedBoxSlot {content_offset_in_containing_block: FfiCssPixelPoint::default(),containing_block: crate::layout::node_data::NodeSlotId::INVALID,},+ physical_content_size: None,}}}@@ -760,11 +869,28 @@ impl FragmentBuilderScratch {) -> bool {self.placed_box_slots.with_row_mut(node.slot_index() as usize, |slot| {let was_placed_by_builder = slot.builder == builder;- *slot = PlacedBoxSlot { builder, placement };+ *slot = PlacedBoxSlot {+ builder,+ placement,+ physical_content_size: None,+ };was_placed_by_builder})}+ fn note_physical_content_size(+ &self,+ builder: u64,+ node: crate::layout::node_data::NodeSlotId,+ physical_content_size: FfiCssPixelSize,+ ) {+ self.placed_box_slots.with_row_mut(node.slot_index() as usize, |slot| {+ if slot.builder == builder {+ slot.physical_content_size = Some(physical_content_size);+ }+ });+ }+fn placement_by(&self,builder: u64,@@ -806,6 +932,16 @@ impl PlacementsOfBuilder<'_> {self.placement_of(node).is_some()}+ /// The physical size of the content box of `node`, where the builder placed the box and built its fragment.+ fn physical_content_size_of(&self, node: crate::layout::node_data::NodeSlotId) -> Option<FfiCssPixelSize> {+ self.scratch+ .placed_box_slots+ .with_row(node.slot_index() as usize, |slot| {+ slot.filter(|slot| slot.builder == self.builder)+ .and_then(|slot| slot.physical_content_size)+ })+ }+/// The containing block `node` is placed in, or for a box not placed in one yet, the containing block it is laid/// out in, within the run rooted at `run_root`.pub(crate) fn placement_containing_block(@@ -882,38 +1018,146 @@ impl FragmentGeometry {}}-fn snapshot_fragment(+/// How the physical offsets of boxes in a content box whose contents use `frame` move as the content box goes from+/// the physical size `from` to `to`: along each axis the frame reverses, they keep their distance from the far edge.+fn shift_of_contents(frame: geometry::Frame, from: FfiCssPixelSize, to: FfiCssPixelSize) -> FfiCssPixelPoint {+ FfiCssPixelPoint {+ x: if frame.vertical_axis_is_reversed() {+ to.width - from.width+ } else {+ CssPixels::default()+ },+ y: if frame.horizontal_axis_is_reversed() {+ to.height - from.height+ } else {+ CssPixels::default()+ },+ }+}++/// A fragment like `fragment` whose links of boxes contained by `containing_block` are moved by `shift`, and whose+/// outer links are then `outer_links`.+fn fragment_with_contained_links_moved(+ pass: &LayoutPass<'_>,+ fragment: &Fragment,+ containing_block: crate::layout::node_data::NodeSlotId,+ shift: FfiCssPixelPoint,+ outer_links: OuterLinks,+) -> std::sync::Arc<Fragment> {+ let children = fragment+ .children+ .iter()+ .map(|link| {+ let mut link = link.clone();+ if link.placement.containing_block == containing_block {+ link.offset = formatting_context::point_add(link.offset, shift);+ }+ link+ })+ .collect();+ let mut rebuilt = fragment.with_scrollable_overflow_and_children(fragment.scrollable_overflow, children);+ rebuilt.outer_links = outer_links;+ rebuilt_fragment(pass, rebuilt)+}++/// The links of the fragment `arrived` of `node`, for a fragment of the box at the physical content size+/// `content_size`. The boxes the box contains keep their offsets in the frame it lays out its contents in.+fn links_moved_to_content_size(pass: &LayoutPass<'_>,node: crate::layout::node_data::NodeSlotId,+ arrived: &Fragment,+ content_size: FfiCssPixelSize,+) -> Vec<FragmentLink> {+ let shift = shift_of_contents(+ formatting_context::frame_established_by(pass, node),+ arrived.sides.content_size,+ content_size,+ );+ if shift == FfiCssPixelPoint::default() {+ return arrived.children.clone();+ }+ arrived+ .children+ .iter()+ .map(|link| {+ let mut link = link.clone();+ if link.placement.containing_block == node {+ link.offset = formatting_context::point_add(link.offset, shift);+ }+ if link.fragment.outer_links == OuterLinks::Placed && link.fragment.holds_links_contained_by(node) {+ link.fragment =+ fragment_with_contained_links_moved(pass, &link.fragment, node, shift, OuterLinks::Placed);+ }+ link+ })+ .collect()+}++/// The links `children` of a fragment of `node` whose content box has the physical size `content_size`, where the+/// fragments of the boxes it contains place the links of its other boxes that awaited its size.+fn place_links_awaiting_size_of(+ pass: &LayoutPass<'_>,+ node: crate::layout::node_data::NodeSlotId,+ content_size: FfiCssPixelSize,mut children: Vec<FragmentLink>,+) -> Vec<FragmentLink> {+ for link in &mut children {+ if link.placement.containing_block != node+ || link.fragment.outer_links != OuterLinks::AwaitingContainingBlockSize+ {+ continue;+ }+ let shift = shift_of_contents(+ formatting_context::frame_established_by(pass, node),+ FfiCssPixelSize::default(),+ content_size,+ );+ link.fragment = fragment_with_contained_links_moved(pass, &link.fragment, node, shift, OuterLinks::Placed);+ }+ children+}++/// Builds the fragment of `node` around `children`, whose offsets are physical. Where `awaits_containing_block_size`,+/// the links it holds of boxes contained by its own containing block await that block's size.+fn snapshot_fragment(+ pass: &LayoutPass<'_>,+ node: crate::layout::node_data::NodeSlotId,+ children: Vec<FragmentLink>,geometry: FragmentGeometry,breaks: BreakFacts,payload: PendingPayload,+ awaits_containing_block_size: bool,) -> std::sync::Arc<Fragment> {let FragmentGeometry { cells, line_data } = geometry;let PendingPayload { payload, line_clamp } = payload;+ let sides = cells.box_sides().in_frame(pass.frame, geometry::Frame::PHYSICAL);+ let mut children = place_links_awaiting_size_of(pass, node, sides.content_size, children);if line_clamp.has_line_clamp_point && !breaks.continues_in_next {line_clamp_edge::clip_floats_at_block_end_content_edge(pass,node,formatting_context::frame_established_by(pass, node),- pass.frame- .size_to_physical(cells.content_inline_size, cells.content_block_size),+ sides.content_size,&mut children,);}+ let outer_links = if !fragment_overflow::holds_links_of_outer_containing_blocks(node, &children) {+ OuterLinks::None+ } else if awaits_containing_block_size {+ OuterLinks::AwaitingContainingBlockSize+ } else {+ OuterLinks::Placed+ };let mut fragment = Fragment {identity: 0,node,- sides: cells.box_sides().in_frame(pass.frame, geometry::Frame::PHYSICAL),+ sides,line_data,payload: payload.filter(|payload| !payload.holds_nothing()),line_clamp,breaks,scrollable_overflow: Default::default(),- holds_links_of_outer_containing_blocks: fragment_overflow::holds_links_of_outer_containing_blocks(- node, &children,- ),+ outer_links,children,};fragment.scrollable_overflow = fragment_overflow::scrollable_overflow_of(@@ -938,7 +1182,15 @@ pub(crate) fn fragment_with_children(fragment: &Fragment,children: Vec<FragmentLink>,) -> std::sync::Arc<Fragment> {- let mut rebuilt = fragment.with_scrollable_overflow_and_children(fragment.scrollable_overflow, children);+ rebuilt_fragment(+ pass,+ fragment.with_scrollable_overflow_and_children(fragment.scrollable_overflow, children),+ )+}++/// The committed fragment of the box of `rebuilt` where that builds identically to it, or else `rebuilt` with an+/// identity of its own.+fn rebuilt_fragment(pass: &LayoutPass<'_>, mut rebuilt: Fragment) -> std::sync::Arc<Fragment> {if let Some(previous) = previously_committed_fragment_matching(pass, &rebuilt) {return previous;}@@ -953,21 +1205,43 @@ fn fragment_of_placed_box(pass: &LayoutPass<'_>,node: crate::layout::node_data::NodeSlotId,arrived: Option<std::sync::Arc<Fragment>>,- children: Vec<FragmentLink>,+ children: Vec<PendingLink>,geometry: FragmentGeometry,breaks: BreakFacts,payload: PendingPayload,) -> std::sync::Arc<Fragment> {+ let content_size = geometry+ .cells+ .box_sides()+ .in_frame(pass.frame, geometry::Frame::PHYSICAL)+ .content_size;+ let placed_children = |children: Vec<PendingLink>| {+ children.into_iter().map(move |child| {+ debug_assert!(+ child.placement.containing_block == node,+ "a box holds the pending links of the boxes it contains"+ );+ child.into_link(content_size)+ })+ };let Some(arrived) = arrived else {- return snapshot_fragment(pass, node, children, geometry, breaks, payload);+ return snapshot_fragment(+ pass,+ node,+ placed_children(children).collect(),+ geometry,+ breaks,+ payload,+ false,+ );};let shows_box_as_placed =children.is_empty() && geometry.shows_box_of_fragment(&arrived, pass.frame) && arrived.breaks == breaks;if shows_box_as_placed {return arrived;}- let mut all_children = arrived.children.clone();- all_children.extend(children);+ let mut all_children = links_moved_to_content_size(pass, node, &arrived, content_size);+ all_children.extend(placed_children(children));snapshot_fragment(pass,node,@@ -975,6 +1249,7 @@ fn fragment_of_placed_box(geometry,breaks,PendingPayload::of_fragment(&arrived),+ arrived.outer_links == OuterLinks::AwaitingContainingBlockSize,)}@@ -1026,7 +1301,7 @@ impl PayloadsPastRun {/// whole layout pass hands its links to commit.pub(crate) struct RunContents {pub(crate) node: crate::layout::node_data::NodeSlotId,- pub(crate) scoped_descendants: Vec<FragmentLink>,+ pub(crate) scoped_descendants: Vec<PendingLink>,pub(crate) holds_links_beside_their_sealed_containing_blocks: bool,pub(crate) payloads_past_run: PayloadsPastRun,/// What the run's layout of its root hands the root's fragment.@@ -1038,32 +1313,62 @@ impl RunContents {pub(crate) fn into_run_root_fragment(self, pass: &LayoutPass<'_>, geometry: FragmentGeometry) -> RunRootFragment {let Self {node,- mut scoped_descendants,+ scoped_descendants,holds_links_beside_their_sealed_containing_blocks,payloads_past_run,root_payload,} = self;+ let content_size = geometry+ .cells+ .box_sides()+ .in_frame(pass.frame, geometry::Frame::PHYSICAL)+ .content_size;+ let mut awaits_containing_block_size = false;+ let mut links: Vec<FragmentLink> = scoped_descendants+ .into_iter()+ .map(|link| {+ let containing_block_size = match link.containing_block_size {+ Some(size) => size,+ None if effective_containing_block(pass, &link) == node => content_size,+ None => {+ // NB: A table box holds the rows and cells its wrapper contains, whose fragment is built after+ // the table box's.+ awaits_containing_block_size |= !link.placement.containing_block.is_invalid()+ && (link.frame.vertical_axis_is_reversed() || link.frame.horizontal_axis_is_reversed());+ FfiCssPixelSize::default()+ }+ };+ link.into_link(containing_block_size)+ })+ .collect();if holds_links_beside_their_sealed_containing_blocks {- fragment_overflow::include_links_held_beside_their_containing_blocks(- pass.arena(),- node,- &mut scoped_descendants,- );+ fragment_overflow::include_links_held_beside_their_containing_blocks(pass.arena(), node, &mut links);}RunRootFragment::new(snapshot_fragment(pass,node,- scoped_descendants,+ links,geometry,BreakFacts::default(),root_payload,+ awaits_containing_block_size,),payloads_past_run,)}}+/// The containing block of the box `link` places, or for a link without one, the containing block found among the+/// box's ancestors, as painting finds it.+fn effective_containing_block(pass: &LayoutPass<'_>, link: &PendingLink) -> crate::layout::node_data::NodeSlotId {+ let containing_block = link.placement.containing_block;+ if containing_block.is_invalid() {+ return pass.arena().containing_block_by_walking_ancestors(link.fragment.node);+ }+ containing_block+}+/// What a run hands its parent of its root: the root's fragment, and what goes past the run toward boxes outside it./// A box its parent takes as it was committed hands its committed fragment the same way, with nothing past it.#[derive(Clone)]@@ -1118,7 +1423,7 @@ struct PendingFragment {node: crate::layout::node_data::NodeSlotId,/// The fragment the box's layout handed its placement: the root fragment of its own run, or its committed fragment.arrived: Option<std::sync::Arc<Fragment>>,- children: Vec<FragmentLink>,+ children: Vec<PendingLink>,pending_abspos: Vec<abspos_inputs::PendingAbsposChild>,anchor_candidates: Vec<AnchorCandidate>,inline_containing_block_rects: Vec<InlineContainingBlockRect>,@@ -1156,7 +1461,7 @@ struct RunFragmentBuilderInner {abspos_containing_block_info_contributions: Vec<AbsposContainingBlockInfoContribution>,/// How many abspos containing block info contributions the run has received, whether or not they are still listed.abspos_containing_block_info_contributions_received: u64,- top_scope_links: Vec<FragmentLink>,+ top_scope_links: Vec<PendingLink>,/// What the layouts of children the run laid out but never placed handed their placements, which close() links at/// the top of the run's fragments.children_left_unplaced: Vec<ChildLeftUnplaced>,@@ -1643,7 +1948,7 @@ impl RunFragmentBuilder {inner.holds_links_beside_their_sealed_containing_blocks |=contents.holds_links_beside_their_sealed_containing_blocks;for mut link in contents.scoped_descendants {- link.committed_offset = formatting_context::point_add(link.committed_offset, offset);+ link.offset_in_frame = formatting_context::point_add(link.offset_in_frame, offset);if link.placement.containing_block == self.root_node&& let Some(line_index) = link.placement.containing_line_box_index.as_mut(){@@ -1690,7 +1995,7 @@ impl RunFragmentBuilder {.iter_mut().filter(|link| link.placement.containing_block == root){- link.committed_offset = formatting_context::point_add(link.committed_offset, offset);+ link.offset_in_frame = formatting_context::point_add(link.offset_in_frame, offset);}{let scratch = pass.fragment_builder_scratch();@@ -1851,7 +2156,7 @@ impl RunFragmentBuilder {facts: run_state::FactsDecidedByParent,abspos_layout_inputs: Option<std::sync::Arc<abspos_inputs::AbsposLayoutInputs>>,containing_line_box_index: Option<u32>,- committed_offset: FfiCssPixelPoint,+ offset_in_frame: FfiCssPixelPoint,own_anchor_candidate_border_box_rect: Option<CssPixelRect>,) -> PlacedFragment {let placement = facts.placement.expect("a box is placed before its fragment is built");@@ -1870,6 +2175,9 @@ impl RunFragmentBuilder {.remove(&slot).unwrap_or_else(|| PendingFragment::new(node));let content_size = (geometry.cells.content_inline_size, geometry.cells.content_block_size);+ let physical_content_size = pass.frame.size_to_physical(content_size.0, content_size.1);+ pass.fragment_builder_scratch()+ .note_physical_content_size(self.builder, node, physical_content_size);let link_placement = LinkPlacement::of_box(&facts,&geometry.cells,@@ -1886,10 +2194,12 @@ impl RunFragmentBuilder {facts.fragment_facts.breaks,payload,);- let link = FragmentLink {+ let link = PendingLink {fragment: fragment.clone(),- committed_offset,+ offset_in_frame,+ frame: pass.frame,placement: link_placement,+ containing_block_size: None,};self.attach(pass, &mut inner, link, containing_block);let exports_payloads = !pending_abspos_from_placed_box.is_empty()@@ -1900,10 +2210,10 @@ impl RunFragmentBuilder {let frames = exports_payloads.then(|| {let own = formatting_context::frame_established_by(pass, node);- (own != pass.frame).then(|| PlacedBoxFrames {+ (own != pass.frame).then_some(PlacedBoxFrames {own,containing_block: pass.frame,- physical_content_size: pass.frame.size_to_physical(content_size.0, content_size.1),+ physical_content_size,})}).flatten();@@ -1973,16 +2283,16 @@ impl RunFragmentBuilder {&self,pass: &LayoutPass<'_>,inner: &mut RunFragmentBuilderInner,- link: FragmentLink,+ link: PendingLink,containing_block: Option<crate::layout::node_data::NodeSlotId>,) {let Some(containing_block) = containing_block else {- inner.top_scope_links.push(link);+ self.push_to_top_scope(pass, inner, link);return;};if containing_block == self.root_node || Some(containing_block.slot_index()) == self.root_containing_block_slot{- inner.top_scope_links.push(link);+ self.push_to_top_scope(pass, inner, link);return;}if let Some(pending_fragment) = inner.pending_fragments.get_mut(&containing_block.slot_index()) {@@ -1993,7 +2303,7 @@ impl RunFragmentBuilder {if self.is_entry_accumulator || self.with_placements(pass, |placements| placements.is_placed(containing_block)){inner.holds_links_beside_their_sealed_containing_blocks |= !self.is_entry_accumulator;- inner.top_scope_links.push(link);+ self.push_to_top_scope(pass, inner, link);return;}let mut pending_fragment = PendingFragment::new(containing_block);@@ -2003,6 +2313,17 @@ impl RunFragmentBuilder {.insert(containing_block.slot_index(), pending_fragment);}+ /// Puts `link` at the top of the run's fragments, with the physical content size of its containing block where the+ /// run placed that block already.+ fn push_to_top_scope(&self, pass: &LayoutPass<'_>, inner: &mut RunFragmentBuilderInner, mut link: PendingLink) {+ if link.containing_block_size.is_none() {+ let containing_block = effective_containing_block(pass, &link);+ link.containing_block_size =+ self.with_placements(pass, |placements| placements.physical_content_size_of(containing_block));+ }+ inner.top_scope_links.push(link);+ }+pub(crate) fn take_run_contents(&self, pass: &LayoutPass<'_>) -> RunContents {debug_assert!(!self.is_entry_accumulator,@@ -2017,8 +2338,19 @@ impl RunFragmentBuilder {"an ordinary run closes into the contents of its root");let root = self.close(pass);+ // NB: A link at the top of a pass whose containing block the pass did not place, such as the containing block of+ // a partial relayout's root, keeps the containing block it committed.CompletedPassFragments {- roots: root.scoped_descendants,+ roots: root+ .scoped_descendants+ .into_iter()+ .map(|link| {+ let containing_block_size = link+ .containing_block_size+ .unwrap_or_else(|| committed_content_size_of(pass, effective_containing_block(pass, &link)));+ link.into_link(containing_block_size)+ })+ .collect(),}}@@ -2053,7 +2385,7 @@ impl RunFragmentBuilder {let node = root.fragment.node;let facts = unplaced_child.facts_decided_by_parent;let placement = LinkPlacement::of_box(&facts, &unplaced_child.geometry.cells, None, None, pass.frame);- inner.top_scope_links.push(FragmentLink {+ let link = PendingLink {fragment: fragment_of_placed_box(pass,node,@@ -2063,9 +2395,12 @@ impl RunFragmentBuilder {facts.fragment_facts.breaks,PendingPayload::default(),),- committed_offset: FfiCssPixelPoint::default(),+ offset_in_frame: FfiCssPixelPoint::default(),+ frame: pass.frame,placement,- });+ containing_block_size: None,+ };+ self.push_to_top_scope(pass, &mut inner, link);}self.with_placements(pass, |placements| {for entry in &mut payloads_past_run.pending_abspos {diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex 53291fc998c..c57c74f7c4e 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -7636,6 +7636,7 @@ mod tests {resolved_anchor_insets: None,resolved_anchor_sizes: Default::default(),position_option: Default::default(),+ frame: crate::layout::geometry::Frame::PHYSICAL,}}diff --git a/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs b/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rsindex 9842bdde2ae..ce45761d6cf 100644--- a/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs+++ b/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs@@ -90,21 +90,7 @@ impl ClampEdgeWalk<'_, '_> {let fragment = &link.fragment;let data = self.pass.arena().data(fragment.node);let style = node_facts::node_style_view(data);- let frame = link.placement.frame;- let content_size_in_frame = frame.size_from_physical(fragment.sides.content_size);- let content_box = frame- .rect_to_physical(- CssPixelRect::new(- link.committed_offset.x,- link.committed_offset.y,- content_size_in_frame.width,- content_size_in_frame.height,- ),- FfiCssPixelSize {- width: containing_block.width,- height: containing_block.height,- },- )+ let content_box = CssPixelRect::from_location_and_size(link.offset.into(), fragment.sides.content_size.into()).translated_by(containing_block.location());if node_facts::node_is_floating(data, style) {diff --git a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rsindex 5eb139af976..187ecb3253d 100644--- a/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs+++ b/Libraries/LibWeb/Rust/src/layout/partial_relayout.rs@@ -668,6 +668,7 @@ impl LayoutNodeArena {resolved_anchor_insets: None,resolved_anchor_sizes: Default::default(),position_option: Default::default(),+ frame: crate::layout::geometry::Frame::PHYSICAL,})}diff --git a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rsindex 91287a563fa..fad4729f9b2 100644--- a/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_repeatability.rs@@ -387,8 +387,8 @@ fn nodes_of(links: &[fragment_tree::FragmentLink]) -> Vec<Node> {fn describe_placement(link: &fragment_tree::FragmentLink) -> String {format!("offset ({:?}, {:?}) insets ({:?} {:?} {:?} {:?}) line box {:?} in {:?}, abspos inputs {}",- link.committed_offset.x,- link.committed_offset.y,+ link.offset.x,+ link.offset.y,link.placement.insets.top,link.placement.insets.right,link.placement.insets.bottom,diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rsindex 4041d913148..f4fb06cd52b 100644--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs@@ -245,12 +245,17 @@ pub(crate) struct FactsDecidedByParent {}impl FactsDecidedByParent {- /// What the parent decided about a box, as the committed link of the box shows it, read in `frame`.- pub(crate) fn of_committed_link(link: &fragment_tree::FragmentLink, frame: geometry::Frame) -> Self {+ /// What the parent decided about a box, as the committed link of the box shows it, read in `frame`, where the+ /// content box of the box's containing block has the physical size `containing_block_size`.+ pub(crate) fn of_committed_link(+ link: &fragment_tree::FragmentLink,+ frame: geometry::Frame,+ containing_block_size: FfiCssPixelSize,+ ) -> Self {let insets = link.placement.insets.in_frame(geometry::Frame::PHYSICAL, frame);Self {placement: Some(BoxPlacement {- content_offset_in_containing_block: link.committed_offset,+ content_offset_in_containing_block: link.offset_in_frame(frame, containing_block_size),containing_block: link.placement.containing_block,}),used_insets: UsedInsets {diff --git a/Libraries/LibWeb/Rust/src/layout/script_entries.rs b/Libraries/LibWeb/Rust/src/layout/script_entries.rsindex 988d63292b6..126fe695ae1 100644--- a/Libraries/LibWeb/Rust/src/layout/script_entries.rs+++ b/Libraries/LibWeb/Rust/src/layout/script_entries.rs@@ -798,9 +798,10 @@ pub extern "C" fn layout_script_anchor_resolved_size(}arena.with_committed_fragment_link(slot, |link| {let link = link?;- let sizes = link.placement.abspos_layout_inputs.as_ref()?.resolved_anchor_sizes;+ let inputs = link.placement.abspos_layout_inputs.as_ref()?;+ let sizes = inputs.resolved_anchor_sizes;// NB: The sizes lie in the frame the box was laid out in, whose axes a vertical writing mode transposes.- let (physical_width, physical_height) = if link.placement.frame.is_transposed() {+ let (physical_width, physical_height) = if inputs.frame.is_transposed() {((sizes.min_height, sizes.max_height), (sizes.min_width, sizes.max_width))} else {((sizes.min_width, sizes.max_width), (sizes.min_height, sizes.max_height))diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rsindex 41e6bb85e26..0f61cc48d03 100644--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs@@ -2242,7 +2242,10 @@ impl<'pass> SvgFormattingContext<'pass> {.with_current_committed_fragment_link(shape, |link| link.clone())?;let fragment = link.fragment.clone();fragment.svg()?.path.as_ref()?;- let committed_offset = link.committed_offset;+ let committed_offset = link.offset_in_frame(+ self.run.pass.frame,+ fragment_tree::committed_content_size_of(&self.run.pass, link.placement.containing_block),+ );// The transforms and the stroke's percentage basis are what the shape's facts take from outside its own// geometry.let committed = fragment.svg().map(|svg| svg.facts).unwrap_or_default();diff --git a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rsindex 171105129a3..d1d26a6979f 100644--- a/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs+++ b/Libraries/LibWeb/Rust/src/painting/paint_order_plan.rs@@ -675,7 +675,9 @@ mod tests {arena.populate_paintable_row(node);arena.refresh_paint_order_inputs(node);}- arena.paintable_rows_mut().paintable_data_mut(child).offset.x = CssPixels::from_integer(100);+ let mut moved = crate::layout::fragment_tree::FragmentLink::for_test(child);+ moved.offset.x = CssPixels::from_integer(100);+ arena.set_committed_fragment_link(child, moved, None);let after_move = PaintOrderInputs::gather(&arena.paintable_rows(), child);assert!(!arena.update_paint_order_inputs(child, after_move));arena.set_node_flag(child, NodeFlag::IsFlexItem, true);diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rsindex 7dd5c0b5d10..1dcdec24f5a 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs@@ -4,7 +4,6 @@* SPDX-License-Identifier: BSD-2-Clause*/-use crate::css::css_pixels::CssPixelRect;use crate::layout::LayoutNodeArena;use crate::layout::node_data::{DomPaintFact, NodeKind, NodeSlotId};use crate::layout::{formatting_context, fragment_tree, node_facts, used_values};@@ -153,7 +152,12 @@ impl<'a> PaintableCommit<'a> {)};let row_existed_before_this_commit = self.arena().paintable_rows().paintable_row_is_populated(node);- let previous_offset = row_existed_before_this_commit.then(|| self.arena().live_paintable_data(node).offset);+ let previous_offset = row_existed_before_this_commit+ .then(|| {+ self.arena()+ .with_committed_fragment_link(node, |link| link.map(|link| link.offset))+ })+ .flatten();if !wants_paintable {self.clear_node(node);return PreparedPaintable {@@ -235,26 +239,8 @@ impl<'a> PaintableCommit<'a> {previous_offset: Option<used_values::FfiCssPixelPoint>,) -> ReplacedCommittedFragmentLink {let fragment = &link.fragment;- let frame = link.placement.frame;let new_content_size = fragment.sides.content_size;- let content_size_in_frame = frame.size_from_physical(new_content_size);- let new_offset: used_values::FfiCssPixelPoint = if frame.is_physical() {- link.committed_offset- } else {- crate::painting::paintable_geometry::physical_content_rect_in_containing_block(- self.arena(),- frame,- self.committed_containing_block(node, Some(link)),- CssPixelRect::new(- link.committed_offset.x,- link.committed_offset.y,- content_size_in_frame.width,- content_size_in_frame.height,- ),- )- .location()- .into()- };+ let new_offset = link.offset;let mut content_size_change = None;let mut own_paint_unchanged = false;let mut child_placements_unchanged = false;@@ -361,14 +347,6 @@ impl<'a> PaintableCommit<'a> {);}self.arena_mut().note_scroll_offset_may_leave_range(node);- {- let arena = self.arena_mut();- let mut paintable_rows = arena.paintable_rows_mut();- let mut data = paintable_rows.paintable_data_mut(node);- data.set_frame(frame);- data.content_size = new_content_size;- data.offset = new_offset;- }// A layout pass bumps no epoch, so its geometry is laid out against the epoch the node has now.let epoch_of_laid_out_geometry = self.arena().data(node).fragment_cache_epoch;self.arena_mut()@@ -494,6 +472,7 @@ impl<'a> PaintableCommit<'a> {slot: NodeSlotId,line_data: &std::sync::Arc<crate::layout::inline_content::InlineContent>,previous_fragmented_content: Option<std::sync::Arc<crate::layout::inline_content::InlineContent>>,+ content_size: used_values::FfiCssPixelSize,) -> LineDataChange {if !node_painting::has_lines(self.arena(), slot) {self.clear_line_data(slot);@@ -504,7 +483,6 @@ impl<'a> PaintableCommit<'a> {let line_data = if writing_mode == crate::css::css_enums::writing_mode::HORIZONTAL_TB {line_data} else {- let content_size = self.arena().live_paintable_data(slot).content_size;physical_line_data = std::sync::Arc::new(line_data.in_physical_plane(writing_mode, content_size));&physical_line_data};diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs b/Libraries/LibWeb/Rust/src/painting/paintable_data.rsindex 005905e2a83..10f751c3190 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_data.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_data.rs@@ -19,10 +19,6 @@ pub enum PaintableFlag {HasLaterBoxFragments = 1 << 4,}-/// The flag bits that hold the writing mode of the frame a box was laid out in.-const FRAME_WRITING_MODE_SHIFT: u32 = 5;-const FRAME_WRITING_MODE_MASK: u32 = 0b111;-#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]#[repr(C)]pub struct FfiPixelBox {@@ -58,9 +54,6 @@ pub struct PaintableData {pub slot_generation: u8,pub flags: u32,- pub offset: used_values::FfiCssPixelPoint,- pub content_size: used_values::FfiCssPixelSize,-pub establishes_stacking_context: bool,pub own_scroll_node_index: SpatialNodeIndex,@@ -77,8 +70,6 @@ impl Default for PaintableData {selection_state: 0,slot_generation: 0,flags: 0,- offset: used_values::FfiCssPixelPoint::default(),- content_size: used_values::FfiCssPixelSize::default(),establishes_stacking_context: false,own_scroll_node_index: SpatialNodeIndex::default(),node_identity: 0,@@ -94,16 +85,6 @@ impl PaintableData {self.flags & flag as u32 != 0}- /// The writing mode of the frame the box was laid out in: that of its containing block.- pub(crate) fn frame(&self) -> crate::layout::geometry::Frame {- crate::layout::geometry::Frame::of(((self.flags >> FRAME_WRITING_MODE_SHIFT) & FRAME_WRITING_MODE_MASK) as u8)- }-- pub(crate) fn set_frame(&mut self, frame: crate::layout::geometry::Frame) {- self.flags = (self.flags & !(FRAME_WRITING_MODE_MASK << FRAME_WRITING_MODE_SHIFT))- | ((u32::from(frame.writing_mode()) & FRAME_WRITING_MODE_MASK) << FRAME_WRITING_MODE_SHIFT);- }-pub fn set_flag(&mut self, flag: PaintableFlag, value: bool) {if value {self.flags |= flag as u32;diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rsindex c46a2489cb8..df3c74c5a1b 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs@@ -6,7 +6,6 @@use crate::css::css_pixels::CssPixels;use crate::css::css_pixels::{CssPixelPoint, CssPixelRect};-use crate::layout::geometry::Frame;use crate::layout::node_data::NodeSlotId;use crate::layout::{formatting_context, grid_formatting_context, svg_formatting_context, table_formatting_context, used_values,@@ -15,36 +14,6 @@ use crate::painting::node_painting;use crate::painting::paint_read::GeometryRead;use crate::painting::paintable_data::*;-/// The physical rect of a box's content box within its containing block's content box, from the rect its fragment-/// link holds in the frame the box was laid out in.-pub(crate) fn physical_content_rect_in_containing_block(- arena: &impl GeometryRead,- frame: Frame,- containing_block: NodeSlotId,- rect_in_frame: CssPixelRect,-) -> CssPixelRect {- if frame.is_physical() {- return rect_in_frame;- }- let containing_block_size = if containing_block.is_invalid() || !arena.paintable_row_is_populated(containing_block)- {- used_values::FfiCssPixelSize::default()- } else {- committed_content_size(arena, containing_block)- };- frame.rect_to_physical(rect_in_frame, containing_block_size)-}--fn link_content_rect(link: &crate::layout::fragment_tree::FragmentLink, frame: Frame) -> CssPixelRect {- let content_size_in_frame = frame.size_from_physical(link.fragment.sides.content_size);- CssPixelRect::new(- link.committed_offset.x,- link.committed_offset.y,- content_size_in_frame.width,- content_size_in_frame.height,- )-}-pub(crate) fn committed_offset(arena: &impl GeometryRead, slot: NodeSlotId) -> used_values::FfiCssPixelPoint {// NB: An inline box without pieces keeps the geometry its link gives it.if node_painting::is_fragmented_inline(arena, slot)@@ -52,20 +21,8 @@ pub(crate) fn committed_offset(arena: &impl GeometryRead, slot: NodeSlotId) -> u{return unions.content.location().into();}- let data = arena.paintable_data(slot);- let frame = data.frame();- if !frame.is_physical() {- let containing_block = data.containing_block;- return arena- .with_committed_fragment_link(slot, |link| link.map(|link| link_content_rect(link, frame)))- .map_or_else(used_values::FfiCssPixelPoint::default, |rect| {- physical_content_rect_in_containing_block(arena, frame, containing_block, rect)- .location()- .into()- });- }arena.with_committed_fragment_link(slot, |link| {- link.map_or_else(used_values::FfiCssPixelPoint::default, |link| link.committed_offset)+ link.map_or_else(used_values::FfiCssPixelPoint::default, |link| link.offset)})}@@ -380,12 +337,7 @@ pub(crate) fn absolute_fragment_rect(arena: &impl GeometryRead, slot: NodeSlotIdlet Some((rect, containing_block_fragment)) = with_later_box_fragment(arena, slot, index, |fragment| {let link = &fragment.link;(- CssPixelRect::new(- link.committed_offset.x,- link.committed_offset.y,- link.fragment.sides.content_size.width,- link.fragment.sides.content_size.height,- ),+ CssPixelRect::from_location_and_size(link.offset.into(), link.fragment.sides.content_size.into()),fragment.containing_block_fragment,)}) else {diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rsindex 702621e22bc..c59a9c26e13 100644--- a/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs+++ b/Libraries/LibWeb/Rust/src/painting/paintable_rows.rs@@ -51,7 +51,7 @@ mod tests {assert!(slot_with(link.clone()) == slot_with(link.clone()));let mut moved = link.clone();- moved.committed_offset.x = crate::css::css_pixels::CssPixels::from_integer(10);+ moved.offset.x = crate::css::css_pixels::CssPixels::from_integer(10);assert!(slot_with(link.clone()) != slot_with(moved));// An equal fragment laid out again is a different fragment.diff --git a/Libraries/LibWeb/Rust/src/painting/published_frame.rs b/Libraries/LibWeb/Rust/src/painting/published_frame.rsindex 837c20b057f..343cf8407d4 100644--- a/Libraries/LibWeb/Rust/src/painting/published_frame.rs+++ b/Libraries/LibWeb/Rust/src/painting/published_frame.rs@@ -308,28 +308,22 @@ mod tests {let mut link = fragment_tree::FragmentLink::for_test(node);link.placement.insets.left = CssPixels::from_integer(10);arena.set_committed_fragment_link(node, link.clone(), None);- arena.paintable_rows_mut().paintable_data_mut(node).offset.x = CssPixels::from_integer(10).into();+ arena.paintable_rows_mut().paintable_data_mut(node).node_identity = 10;arena.committed_side_data_mut(node).inline_content = Some(Default::default());let published = arena.publish_rows();link.placement.insets.left = CssPixels::from_integer(20);arena.set_committed_fragment_link(node, link, None);- arena.paintable_rows_mut().paintable_data_mut(node).offset.x = CssPixels::from_integer(20).into();+ arena.paintable_rows_mut().paintable_data_mut(node).node_identity = 20;arena.committed_side_data_mut(node).inline_content = None;- assert_eq!(- published.paintable_data(node).offset.x,- CssPixels::from_integer(10).into()- );+ assert_eq!(published.paintable_data(node).node_identity, 10);assert_eq!(published.with_committed_fragment_link(node, |link| link.map(|link| link.placement.insets.left)),Some(CssPixels::from_integer(10)));assert!(published.committed_side_data(node).inline_content.is_some());- assert_eq!(- arena.live_paintable_data(node).offset.x,- CssPixels::from_integer(20).into()- );+ assert_eq!(arena.live_paintable_data(node).node_identity, 20);assert_eq!(arena.with_committed_fragment_link(node, |link| link.map(|link| link.placement.insets.left)),Some(CssPixels::from_integer(20))@@ -362,7 +356,7 @@ mod tests {continue;}arena.populate_paintable_row(node);- arena.paintable_rows_mut().paintable_data_mut(node).offset.x = CssPixels::from_integer(index as i64).into();+ arena.paintable_rows_mut().paintable_data_mut(node).node_identity = index as i64;if index % 2 == 0 {let mut link = fragment_tree::FragmentLink::for_test(node);link.placement.insets.top = CssPixels::from_integer(index as i64);diff --git a/Tests/LibWeb/Text/expected/display_list/vertical-rl-container-width-change-rerecords-children.txt b/Tests/LibWeb/Text/expected/display_list/vertical-rl-container-width-change-rerecords-children.txtnew file mode 100644index 00000000000..452469a64dc--- /dev/null+++ b/Tests/LibWeb/Text/expected/display_list/vertical-rl-container-width-change-rerecords-children.txt@@ -0,0 +1,2 @@+#vertical-rl-child background re-recorded: true+#sideways-rl-child background re-recorded: truediff --git a/Tests/LibWeb/Text/expected/hit_testing/vertical-rl-container-width-change-moves-child.txt b/Tests/LibWeb/Text/expected/hit_testing/vertical-rl-container-width-change-moves-child.txtnew file mode 100644index 00000000000..487b7aa620d--- /dev/null+++ b/Tests/LibWeb/Text/expected/hit_testing/vertical-rl-container-width-change-moves-child.txt@@ -0,0 +1,3 @@+Before: (260, 10) hits <DIV id="child">+After: (160, 10) hits <DIV id="child">+After: (260, 10) hits <BODY>diff --git a/Tests/LibWeb/Text/input/display_list/vertical-rl-container-width-change-rerecords-children.html b/Tests/LibWeb/Text/input/display_list/vertical-rl-container-width-change-rerecords-children.htmlnew file mode 100644index 00000000000..4f7b083a9cb--- /dev/null+++ b/Tests/LibWeb/Text/input/display_list/vertical-rl-container-width-change-rerecords-children.html@@ -0,0 +1,52 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ }++ .container {+ width: 300px;+ height: 100px;+ background: lightgray;+ }++ #vertical-rl {+ writing-mode: vertical-rl;+ }++ #sideways-rl {+ writing-mode: sideways-rl;+ }++ .child {+ width: 50px;+ height: 50px;+ background: green;+ }+</style>+<div class="container" id="vertical-rl"><div class="child" id="vertical-rl-child"></div></div>+<div class="container" id="sideways-rl"><div class="child" id="sideways-rl-child"></div></div>+<script>+ // The block axes of both containers run right to left, so narrowing them moves their children left, while the+ // children keep their offsets in the containers' writing modes. The recording has to paint them where they moved.+ asyncTest(async done => {+ __outputElement.style.display = "none";+ await animationFrame();+ await animationFrame();+ internals.recordDisplayListForTesting(false, false);+ for (const container of document.querySelectorAll(".container"))+ container.style.width = "200px";+ internals.beginDisplayListTrace();+ internals.recordDisplayListForTesting(false, false);+ const trace = internals.takeDisplayListTrace();+ __outputElement.style.display = "";+ for (const child of document.querySelectorAll(".child")) {+ const rerecorded = trace+ .split("\n")+ .some(line => line.includes(`#${child.id}.`) && line.includes("/background RECORD"));+ println(`#${child.id} background re-recorded: ${rerecorded}`);+ }+ done();+ });+</script>diff --git a/Tests/LibWeb/Text/input/hit_testing/vertical-rl-container-width-change-moves-child.html b/Tests/LibWeb/Text/input/hit_testing/vertical-rl-container-width-change-moves-child.htmlnew file mode 100644index 00000000000..3cbb9d66666--- /dev/null+++ b/Tests/LibWeb/Text/input/hit_testing/vertical-rl-container-width-change-moves-child.html@@ -0,0 +1,42 @@+<!DOCTYPE html>+<script src="../include.js"></script>+<style>+ body {+ margin: 0;+ }++ #container {+ writing-mode: vertical-rl;+ width: 300px;+ height: 200px;+ background: lightgray;+ }++ #child {+ width: 50px;+ height: 50px;+ background: green;+ }+</style>+<div id="container"><div id="child"></div></div>+<script>+ function describe(node) {+ return node.id ? `<${node.nodeName} id="${node.id}">` : `<${node.nodeName}>`;+ }++ asyncTest(async done => {+ // NB: Printing adds text to the page, so the output waits until every point is hit tested.+ const lines = [];+ await animationFrame();+ await animationFrame();+ lines.push(`Before: (260, 10) hits ${describe(internals.hitTest(260, 10).node)}`);+ container.style.width = "200px";+ await animationFrame();+ await animationFrame();+ lines.push(`After: (160, 10) hits ${describe(internals.hitTest(160, 10).node)}`);+ lines.push(`After: (260, 10) hits ${describe(internals.hitTest(260, 10).node)}`);+ for (const line of lines)+ println(line);+ done();+ });+</script>