Skip to content

Truly independent web browser

LibWeb: Store fragment and link box sides in physical coordinates

Aliaksandr Kalenik77f48eac8379
diff --git a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
index c9ff6c8ba58..e6b1e81e5c3 100644
--- a/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fc_run_cache.rs
@@ -291,8 +291,9 @@ impl FcRunCacheEntry {
if std::sync::Arc::ptr_eq(committed, &root.fragment) {
return true;
}
- committed.sides.content_size.width == content_inline_size
- && (committed.sides.content_size.height == content_block_size
+ let committed_content_size = self.key.parent_frame.size_from_physical(committed.sides.content_size);
+ committed_content_size.width == content_inline_size
+ && (committed_content_size.height == content_block_size
|| self.outputs.inputs_never_observed.own_block_size
== formatting_context::OwnBlockSizeObservation::Unobserved)
&& same_allocation(
diff --git a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
index c53e8740051..4106bda5f91 100644
--- a/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/formatting_context.rs
@@ -4158,7 +4158,7 @@ fn layout_subtree_with_frozen_root_geometry(run: &FormattingContextRun<'_>) {
let committed_root_link = pass
.committed_fragment_link(root)
.expect("partial relayout root must have committed geometry");
- let root_cells = used_values::RootInputCells::of_committed_fragment_link(&committed_root_link);
+ let root_cells = used_values::RootInputCells::of_committed_fragment_link(&committed_root_link, pass.frame);
let fragments = run.fragments.expect("partial relayout must build fragments");
let input = LayoutInput::new(
AvailableSpace {
@@ -4201,7 +4201,7 @@ 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);
+ let facts_decided_by_parent = run_state::FactsDecidedByParent::of_committed_link(&committed_root_link, pass.frame);
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.rs
index 9562faf4fc2..baa9e2a7196 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_overflow.rs
@@ -9,14 +9,12 @@ 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::geometry::Frame;
+use crate::layout::geometry::{Frame, Sides};
use crate::layout::inline_content::{InlineContent, PhysicalPlane};
use crate::layout::node_data::{NodeFlag, NodeKind, NodeSlotId};
use crate::layout::node_facts::{self, NodeShape};
-use crate::layout::used_values::{self, FfiCssPixelSize};
+use crate::layout::used_values::FfiCssPixelSize;
use crate::painting::paint_read::{GeometryRead, PaintRead, PaintRow};
-use crate::painting::paintable_data::FfiPixelBox;
-use crate::painting::paintable_geometry::sides_to_physical;
use crate::painting::scrollable_overflow::physical_overflow_directions_of_style;
use crate::painting::visual_context::node_values::{self, TransformGeometry};
use crate::painting::{node_painting, scroll_snap, style_queries};
@@ -28,43 +26,15 @@ pub(crate) struct FragmentScrollableOverflow {
pub(crate) has_scrollable_overflow: bool,
}
-pub(crate) fn physical_content_size(fragment: &Fragment, frame: Frame) -> FfiCssPixelSize {
- let size = fragment.sides.content_size;
- frame.size_to_physical(size.width, size.height)
-}
-
-pub(crate) fn physical_padding(fragment: &Fragment, frame: Frame) -> FfiPixelBox {
- sides_to_physical(frame, fragment.sides.padding.into())
-}
-
-fn physical_border(fragment: &Fragment, frame: Frame) -> FfiPixelBox {
- sides_to_physical(frame, fragment.sides.border.into())
-}
-
-fn physical_border_box_edges(fragment: &Fragment, frame: Frame) -> FfiPixelBox {
- let border = physical_border(fragment, frame);
- if !fragment.sides.collapsing.uses_collapsing_borders_model() {
- return border;
- }
- let is_table_box = fragment.sides.collapsing.is_collapsed_borders_table_box();
- FfiPixelBox {
- top: used_values::collapsed_border_share(border.top, true, is_table_box),
- right: used_values::collapsed_border_share(border.right, false, is_table_box),
- bottom: used_values::collapsed_border_share(border.bottom, false, is_table_box),
- left: used_values::collapsed_border_share(border.left, true, is_table_box),
- }
-}
-
-fn inflated_by(rect: CssPixelRect, sides: FfiPixelBox) -> CssPixelRect {
+fn inflated_by(rect: CssPixelRect, sides: Sides) -> CssPixelRect {
rect.inflated(sides.top, sides.right, sides.bottom, sides.left)
}
-/// The physical border box of `fragment` around its physical content box `content_box`, where the fragment holds its
-/// geometry in `frame`.
-pub(crate) fn physical_border_box_around(content_box: CssPixelRect, fragment: &Fragment, frame: Frame) -> CssPixelRect {
+/// The physical border box of `fragment` around its physical content box `content_box`.
+pub(crate) fn physical_border_box_around(content_box: CssPixelRect, fragment: &Fragment) -> CssPixelRect {
inflated_by(
- inflated_by(content_box, physical_padding(fragment, frame)),
- physical_border_box_edges(fragment, frame),
+ inflated_by(content_box, fragment.sides.padding),
+ fragment.sides.border_box_edges(),
)
}
@@ -76,16 +46,16 @@ struct BoxesRelativeToOwnPaddingBox {
}
impl BoxesRelativeToOwnPaddingBox {
- fn of(fragment: &Fragment, frame: Frame) -> Self {
- let content_size = physical_content_size(fragment, frame);
- let padding = physical_padding(fragment, frame);
+ fn of(fragment: &Fragment) -> Self {
+ let content_size = fragment.sides.content_size;
+ let padding = fragment.sides.padding;
let content_box = CssPixelRect::new(padding.left, padding.top, content_size.width, content_size.height);
let padding_box = inflated_by(content_box, padding);
Self {
content_size,
padding_box,
content_box,
- border_box: inflated_by(padding_box, physical_border_box_edges(fragment, frame)),
+ border_box: inflated_by(padding_box, fragment.sides.border_box_edges()),
}
}
}
@@ -99,24 +69,24 @@ struct ContainedBoxesRelativeToContainerPaddingBox {
impl ContainedBoxesRelativeToContainerPaddingBox {
fn of(link: &FragmentLink, container: &BoxesRelativeToOwnPaddingBox) -> Self {
let fragment = &link.fragment;
- let content_box = link
- .placement
- .frame
+ 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,
- fragment.sides.content_size.width,
- fragment.sides.content_size.height,
+ content_size_in_frame.width,
+ content_size_in_frame.height,
),
container.content_size,
)
.translated_by(container.content_box.location());
- let padding_box = inflated_by(content_box, physical_padding(fragment, link.placement.frame));
+ let padding_box = inflated_by(content_box, fragment.sides.padding);
Self {
content_box,
padding_box,
- border_box: inflated_by(padding_box, physical_border_box_edges(fragment, link.placement.frame)),
+ border_box: inflated_by(padding_box, fragment.sides.border_box_edges()),
}
}
}
@@ -197,7 +167,6 @@ pub(crate) fn include_links_held_beside_their_containing_blocks(
let overflow = scrollable_overflow_of(
arena,
fragment,
- links[index].placement.frame,
contained_links(fragment).chain(held_beside_indices.iter().map(|&held| &links[held])),
);
if overflow != fragment.scrollable_overflow {
@@ -257,8 +226,8 @@ fn inline_box_unions(
link: &FragmentLink,
content_origin: CssPixelPoint,
) -> Option<InlineBoxUnions> {
- let padding_widths = physical_padding(&link.fragment, link.placement.frame);
- let border_widths = physical_border(&link.fragment, link.placement.frame);
+ let padding_widths = link.fragment.sides.padding;
+ let border_widths = link.fragment.sides.border;
let unite = |union: &mut Option<CssPixelRect>, rect: CssPixelRect| match union {
None => *union = Some(rect),
Some(_) if rect.is_empty() => {}
@@ -282,7 +251,7 @@ fn inline_box_unions(
};
unite(
&mut padding_union,
- physical_piece.shrunken_by_present_edges(border_rect, border_widths),
+ physical_piece.shrunken_by_present_edges(border_rect, border_widths.into()),
);
unite(&mut border_union, border_rect);
}
@@ -296,11 +265,10 @@ fn inline_box_unions(
pub(crate) fn scrollable_overflow_of<'link>(
arena: &LayoutNodeArena,
fragment: &Fragment,
- frame: Frame,
contained_links: impl Iterator<Item = &'link FragmentLink>,
) -> FragmentScrollableOverflow {
let node = fragment.node;
- let own = BoxesRelativeToOwnPaddingBox::of(fragment, frame);
+ let own = BoxesRelativeToOwnPaddingBox::of(fragment);
let Some(row) = GeometryRead::node(arena, node) else {
return FragmentScrollableOverflow {
rect_relative_to_padding_box: own.padding_box,
@@ -458,7 +426,7 @@ pub(crate) fn scrollable_overflow_of<'link>(
if box_is_scroll_container && (child_is_in_flow || child_is_floating) {
let mut normal_flow_border_box = untransformed_child_border_box;
if child_position == positioning::RELATIVE {
- let inset = sides_to_physical(link.placement.frame, link.placement.insets.into());
+ let inset = link.placement.insets;
normal_flow_border_box = normal_flow_border_box.translated(-inset.left, -inset.top);
}
// INTEROP: The edges of in-flow and floated content, after which the container's end padding comes,
@@ -609,8 +577,10 @@ pub(crate) fn scrollable_overflow_of<'link>(
if box_is_scroll_container {
// NB: The box's own padding surrounds its in-flow and floated content. Whatever of it falls inside the padding
// box, or in the unreachable scrollable overflow region, adds nothing. This matches Blink.
- let padding = physical_padding(fragment, frame);
- scrollable_overflow_rect.unite(inflated_by(clip_in_flow(in_flow_and_floated_content_bounds), padding));
+ scrollable_overflow_rect.unite(inflated_by(
+ clip_in_flow(in_flow_and_floated_content_bounds),
+ fragment.sides.padding,
+ ));
}
let mut has_scrollable_overflow =
@@ -747,7 +717,7 @@ impl LayoutNodeArena {
self.committed_links_in_containing_block_fragment(candidate, fragment_index, &mut contained);
}
}
- scrollable_overflow_of(self, &link.fragment, link.placement.frame, contained.iter())
+ scrollable_overflow_of(self, &link.fragment, contained.iter())
}
fn has_scrollable_overflow_in_any_fragment(&self, node: NodeSlotId) -> bool {
@@ -886,12 +856,7 @@ mod tests {
fragment.sides.content_size.height = CssPixels::from_integer(20);
child_link.committed_offset.y = CssPixels::from_integer(180).into();
child_link.placement.containing_block = container;
- let overflow = scrollable_overflow_of(
- &arena,
- &container_link.fragment,
- Frame::PHYSICAL,
- std::iter::once(&child_link),
- );
+ let overflow = scrollable_overflow_of(&arena, &container_link.fragment, std::iter::once(&child_link));
assert_eq!(
overflow.rect_relative_to_padding_box.bottom(),
CssPixels::from_integer(expected_bottom),
diff --git a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
index 23347de34b1..8905114614b 100644
--- a/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
+++ b/Libraries/LibWeb/Rust/src/layout/fragment_tree.rs
@@ -36,7 +36,7 @@ impl CollapsingBorders {
}
}
-/// The content size, borders and paddings a fragment shows of its box.
+/// The content size, borders and paddings a fragment shows of its box, in the physical plane.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) struct BoxSides {
pub(crate) content_size: FfiCssPixelSize,
@@ -45,6 +45,45 @@ pub(crate) struct BoxSides {
pub(crate) collapsing: CollapsingBorders,
}
+impl BoxSides {
+ /// The sides, which frame `from` holds, as frame `to` holds them.
+ pub(crate) fn in_frame(self, from: geometry::Frame, to: geometry::Frame) -> Self {
+ if from == to {
+ return self;
+ }
+ let content_size = if from.is_orthogonal_to(to) {
+ FfiCssPixelSize {
+ width: self.content_size.height,
+ height: self.content_size.width,
+ }
+ } else {
+ self.content_size
+ };
+ Self {
+ content_size,
+ border: self.border.in_frame(from, to),
+ padding: self.padding.in_frame(from, to),
+ collapsing: self.collapsing,
+ }
+ }
+
+ /// The widths of the borders that lie within the border box. In the collapsing borders model, a collapsed border is
+ /// centered on the grid line between two boxes, so only a part of it belongs to each (see
+ /// `used_values::collapsed_border_share`).
+ pub(crate) fn border_box_edges(&self) -> geometry::Sides {
+ if !self.collapsing.uses_collapsing_borders_model() {
+ return self.border;
+ }
+ let is_table_box = self.collapsing.is_collapsed_borders_table_box();
+ geometry::Sides {
+ top: used_values::collapsed_border_share(self.border.top, true, is_table_box),
+ right: used_values::collapsed_border_share(self.border.right, false, is_table_box),
+ bottom: used_values::collapsed_border_share(self.border.bottom, false, is_table_box),
+ left: used_values::collapsed_border_share(self.border.left, true, is_table_box),
+ }
+ }
+}
+
/// Whether fragmentation broke the box, so that its fragment continues one in an earlier fragmentainer, or continues
/// in a later one.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
@@ -258,7 +297,7 @@ pub(crate) struct ShownAs {
pub(crate) facts: ParentShowFacts,
}
-/// Where and how a link places its fragment, apart from its offset.
+/// Where and how a link places its fragment, apart from its offset. Its insets and margins are physical.
#[derive(Clone, PartialEq)]
pub(crate) struct LinkPlacement {
pub(crate) insets: geometry::Sides,
@@ -275,6 +314,7 @@ pub(crate) struct LinkPlacement {
}
impl LinkPlacement {
+ /// The placement of a box that `facts` and `cells` describe in `frame`.
fn of_box(
facts: &run_state::FactsDecidedByParent,
cells: &used_values::RootInputCells,
@@ -289,9 +329,10 @@ impl LinkPlacement {
right: insets.right,
bottom: insets.bottom,
left: insets.left,
- },
+ }
+ .in_frame(frame, geometry::Frame::PHYSICAL),
shown_as: ShownAs {
- margins: cells.margins(),
+ margins: cells.margins().in_frame(frame, geometry::Frame::PHYSICAL),
facts: facts.fragment_facts.show,
},
containing_line_box_index,
@@ -834,8 +875,9 @@ pub(crate) struct FragmentGeometry {
}
impl FragmentGeometry {
- pub(crate) fn shows_box_of_fragment(&self, fragment: &Fragment) -> bool {
- fragment.sides == self.cells.box_sides()
+ /// Whether `fragment` shows the box as these cells, which `frame` holds, and lines do.
+ pub(crate) fn shows_box_of_fragment(&self, fragment: &Fragment, frame: geometry::Frame) -> bool {
+ fragment.sides == self.cells.box_sides().in_frame(frame, geometry::Frame::PHYSICAL)
&& same_allocation(self.line_data.as_ref(), fragment.line_data.as_ref())
}
}
@@ -863,7 +905,7 @@ fn snapshot_fragment(
let mut fragment = Fragment {
identity: 0,
node,
- sides: cells.box_sides(),
+ sides: cells.box_sides().in_frame(pass.frame, geometry::Frame::PHYSICAL),
line_data,
payload: payload.filter(|payload| !payload.holds_nothing()),
line_clamp,
@@ -877,7 +919,6 @@ fn snapshot_fragment(
fragment.scrollable_overflow = fragment_overflow::scrollable_overflow_of(
pass.arena(),
&fragment,
- pass.frame,
fragment_overflow::contained_links(&fragment),
);
if let Some(previous) = previously_committed_fragment_like(pass, &fragment) {
@@ -921,7 +962,7 @@ fn fragment_of_placed_box(
return snapshot_fragment(pass, node, children, geometry, breaks, payload);
};
let shows_box_as_placed =
- children.is_empty() && geometry.shows_box_of_fragment(&arrived) && arrived.breaks == breaks;
+ children.is_empty() && geometry.shows_box_of_fragment(&arrived, pass.frame) && arrived.breaks == breaks;
if shows_box_as_placed {
return arrived;
}
diff --git a/Libraries/LibWeb/Rust/src/layout/geometry.rs b/Libraries/LibWeb/Rust/src/layout/geometry.rs
index 3878eac6f9f..8ed8999c584 100644
--- a/Libraries/LibWeb/Rust/src/layout/geometry.rs
+++ b/Libraries/LibWeb/Rust/src/layout/geometry.rs
@@ -58,6 +58,20 @@ pub(crate) struct Sides {
pub(crate) left: CssPixels,
}
+impl Sides {
+ /// The sides, which frame `from` holds, as frame `to` holds them.
+ #[inline]
+ pub(crate) fn in_frame(self, from: Frame, to: Frame) -> Self {
+ let [top, right, bottom, left] = from.sides_in([self.top, self.right, self.bottom, self.left], to);
+ Self {
+ top,
+ right,
+ bottom,
+ left,
+ }
+ }
+}
+
/// The frame of a writing mode.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct Frame(u8);
@@ -197,6 +211,12 @@ impl Frame {
)
}
+ /// Maps a physical size to this frame.
+ #[inline]
+ pub(crate) fn size_from_physical(self, size: FfiCssPixelSize) -> FfiCssPixelSize {
+ self.size_to_physical(size.width, size.height)
+ }
+
/// Maps a size in this frame to the physical plane.
#[inline]
pub(crate) fn size_to_physical(self, width: CssPixels, height: CssPixels) -> FfiCssPixelSize {
diff --git a/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs b/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs
index 66bf0885d63..9842bdde2ae 100644
--- a/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs
+++ b/Libraries/LibWeb/Rust/src/layout/line_clamp_edge.rs
@@ -90,15 +90,15 @@ impl ClampEdgeWalk<'_, '_> {
let fragment = &link.fragment;
let data = self.pass.arena().data(fragment.node);
let style = node_facts::node_style_view(data);
- let content_box = link
- .placement
- .frame
+ 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,
- fragment.sides.content_size.width,
- fragment.sides.content_size.height,
+ content_size_in_frame.width,
+ content_size_in_frame.height,
),
FfiCssPixelSize {
width: containing_block.width,
@@ -108,7 +108,7 @@ impl ClampEdgeWalk<'_, '_> {
.translated_by(containing_block.location());
if node_facts::node_is_floating(data, style) {
- let border_box = fragment_overflow::physical_border_box_around(content_box, fragment, link.placement.frame);
+ let border_box = fragment_overflow::physical_border_box_around(content_box, fragment);
let clip = Some(self.area_before_block_end_edge.translated(-border_box.x, -border_box.y));
if link.placement.shown_as.facts.clip_decided_by_parent == clip {
return LinkOutcome::Unchanged;
diff --git a/Libraries/LibWeb/Rust/src/layout/run_state.rs b/Libraries/LibWeb/Rust/src/layout/run_state.rs
index 80fb87afe17..4041d913148 100644
--- a/Libraries/LibWeb/Rust/src/layout/run_state.rs
+++ b/Libraries/LibWeb/Rust/src/layout/run_state.rs
@@ -245,9 +245,9 @@ pub(crate) struct FactsDecidedByParent {
}
impl FactsDecidedByParent {
- /// What the parent decided about a box, as the committed link of the box shows it in the frame of the link.
- pub(crate) fn of_committed_link(link: &fragment_tree::FragmentLink) -> Self {
- let insets = link.placement.insets;
+ /// 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 {
+ let insets = link.placement.insets.in_frame(geometry::Frame::PHYSICAL, frame);
Self {
placement: Some(BoxPlacement {
content_offset_in_containing_block: link.committed_offset,
diff --git a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
index 2960608c2da..983e915a272 100644
--- a/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/sizing_context.rs
@@ -2271,7 +2271,7 @@ impl<'pass, 'container> SizingContext<'pass, 'container> {
self.pass
.arena()
.with_current_committed_fragment_link(node, |link| {
- used.update_cells(|cells| cells.take_box_metrics_of_committed_link(link));
+ used.update_cells(|cells| cells.take_box_metrics_of_committed_link(link, sized_cells.frame));
})
.is_some()
}
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index b5610e71ca4..41e6bb85e26 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -2254,7 +2254,7 @@ impl<'pass> SvgFormattingContext<'pass> {
return None;
}
cells.update_cells(|cells| {
- cells.take_box_metrics_of_committed_link(&link);
+ cells.take_box_metrics_of_committed_link(&link, self.run.pass.frame);
cells.has_definite_block_size = true;
});
self.place_laid_out_child(
diff --git a/Libraries/LibWeb/Rust/src/layout/used_values.rs b/Libraries/LibWeb/Rust/src/layout/used_values.rs
index f78d10deee1..aaa74d0c40c 100644
--- a/Libraries/LibWeb/Rust/src/layout/used_values.rs
+++ b/Libraries/LibWeb/Rust/src/layout/used_values.rs
@@ -239,20 +239,28 @@ impl RootInputCells {
}
}
- /// The sizes and box sides `link` and its fragment show, with both sizes definite.
- pub(crate) fn of_committed_fragment_link(link: &fragment_tree::FragmentLink) -> Self {
+ /// The sizes and box sides `link` and its fragment show, read in `frame`, with both sizes definite.
+ pub(crate) fn of_committed_fragment_link(link: &fragment_tree::FragmentLink, frame: geometry::Frame) -> Self {
let mut cells = Self {
has_definite_block_size: true,
..Self::default()
};
- cells.take_box_metrics_of_committed_link(link);
+ cells.take_box_metrics_of_committed_link(link, frame);
cells
}
- /// Takes the sizes and box sides `link` and its fragment show.
- pub(crate) fn take_box_metrics_of_committed_link(&mut self, link: &fragment_tree::FragmentLink) {
- let sides = &link.fragment.sides;
- let margins = link.placement.shown_as.margins;
+ /// Takes the sizes and box sides `link` and its fragment show, read in `frame`.
+ pub(crate) fn take_box_metrics_of_committed_link(
+ &mut self,
+ link: &fragment_tree::FragmentLink,
+ frame: geometry::Frame,
+ ) {
+ let sides = link.fragment.sides.in_frame(geometry::Frame::PHYSICAL, frame);
+ let margins = link
+ .placement
+ .shown_as
+ .margins
+ .in_frame(geometry::Frame::PHYSICAL, frame);
self.set_content_inline_size(sides.content_size.width);
self.set_content_block_size(sides.content_size.height);
self.margin_left = margins.left;
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
index fd5607ff126..7dd5c0b5d10 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_build.rs
@@ -236,8 +236,8 @@ impl<'a> PaintableCommit<'a> {
) -> ReplacedCommittedFragmentLink {
let fragment = &link.fragment;
let frame = link.placement.frame;
- let new_content_size =
- frame.size_to_physical(fragment.sides.content_size.width, fragment.sides.content_size.height);
+ 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 {
@@ -248,8 +248,8 @@ impl<'a> PaintableCommit<'a> {
CssPixelRect::new(
link.committed_offset.x,
link.committed_offset.y,
- fragment.sides.content_size.width,
- fragment.sides.content_size.height,
+ content_size_in_frame.width,
+ content_size_in_frame.height,
),
)
.location()
@@ -288,13 +288,7 @@ impl<'a> PaintableCommit<'a> {
}
own_paint_unchanged &= old_link.has_same_placement(link);
link_shows_box_the_same = link.placement.shown_as == old_link.placement.shown_as;
- (
- old_link.fragment.identity,
- frame.size_to_physical(
- old_link.fragment.sides.content_size.width,
- old_link.fragment.sides.content_size.height,
- ),
- )
+ (old_link.fragment.identity, old_link.fragment.sides.content_size)
})
});
if old_content_size != new_content_size {
diff --git a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
index 911f4a74c85..c46a2489cb8 100644
--- a/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
+++ b/Libraries/LibWeb/Rust/src/painting/paintable_geometry.rs
@@ -15,11 +15,6 @@ use crate::painting::node_painting;
use crate::painting::paint_read::GeometryRead;
use crate::painting::paintable_data::*;
-/// The frame the box was laid out in, in which its committed fragment holds its geometry.
-pub(crate) fn committed_frame(arena: &impl GeometryRead, slot: NodeSlotId) -> Frame {
- arena.paintable_data(slot).frame()
-}
-
/// 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(
@@ -40,12 +35,13 @@ pub(crate) fn physical_content_rect_in_containing_block(
frame.rect_to_physical(rect_in_frame, containing_block_size)
}
-fn link_content_rect(link: &crate::layout::fragment_tree::FragmentLink) -> CssPixelRect {
+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,
- link.fragment.sides.content_size.width,
- link.fragment.sides.content_size.height,
+ content_size_in_frame.width,
+ content_size_in_frame.height,
)
}
@@ -61,7 +57,7 @@ pub(crate) fn committed_offset(arena: &impl GeometryRead, slot: NodeSlotId) -> u
if !frame.is_physical() {
let containing_block = data.containing_block;
return arena
- .with_committed_fragment_link(slot, |link| link.map(link_content_rect))
+ .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()
@@ -79,67 +75,34 @@ pub(crate) fn committed_content_size(arena: &impl GeometryRead, slot: NodeSlotId
{
return unions.content.size().into();
}
- let data = arena.paintable_data(slot);
- let frame = data.frame();
arena.with_committed_fragment_link(slot, |link| {
link.map_or_else(used_values::FfiCssPixelSize::default, |link| {
- let size = link.fragment.sides.content_size;
- frame.size_to_physical(size.width, size.height)
+ link.fragment.sides.content_size
})
})
}
-pub(crate) fn sides_to_physical(frame: Frame, sides: FfiPixelBox) -> FfiPixelBox {
- if frame.is_physical() {
- return sides;
- }
- let [top, right, bottom, left] =
- frame.sides_in([sides.top, sides.right, sides.bottom, sides.left], Frame::PHYSICAL);
- FfiPixelBox {
- top,
- right,
- bottom,
- left,
- }
-}
-
pub(crate) fn committed_margin(arena: &impl GeometryRead, slot: NodeSlotId) -> FfiPixelBox {
- let frame = committed_frame(arena, slot);
arena.with_committed_fragment_link(slot, |link| {
- link.map_or_else(FfiPixelBox::default, |link| {
- sides_to_physical(frame, link.placement.shown_as.margins.into())
- })
+ link.map_or_else(FfiPixelBox::default, |link| link.placement.shown_as.margins.into())
})
}
-fn border_of(fragment: &crate::layout::fragment_tree::Fragment, frame: Frame) -> FfiPixelBox {
- sides_to_physical(frame, fragment.sides.border.into())
-}
-
-fn padding_of(fragment: &crate::layout::fragment_tree::Fragment, frame: Frame) -> FfiPixelBox {
- sides_to_physical(frame, fragment.sides.padding.into())
-}
-
pub(crate) fn committed_border(arena: &impl GeometryRead, slot: NodeSlotId) -> FfiPixelBox {
- let frame = committed_frame(arena, slot);
arena.with_committed_fragment_link(slot, |link| {
- link.map_or_else(FfiPixelBox::default, |link| border_of(&link.fragment, frame))
+ link.map_or_else(FfiPixelBox::default, |link| link.fragment.sides.border.into())
})
}
pub(crate) fn committed_padding(arena: &impl GeometryRead, slot: NodeSlotId) -> FfiPixelBox {
- let frame = committed_frame(arena, slot);
arena.with_committed_fragment_link(slot, |link| {
- link.map_or_else(FfiPixelBox::default, |link| padding_of(&link.fragment, frame))
+ link.map_or_else(FfiPixelBox::default, |link| link.fragment.sides.padding.into())
})
}
pub(crate) fn committed_inset(arena: &impl GeometryRead, slot: NodeSlotId) -> FfiPixelBox {
- let frame = committed_frame(arena, slot);
arena.with_committed_fragment_link(slot, |link| {
- link.map_or_else(FfiPixelBox::default, |link| {
- sides_to_physical(frame, link.placement.insets.into())
- })
+ link.map_or_else(FfiPixelBox::default, |link| link.placement.insets.into())
})
}
@@ -491,7 +454,7 @@ pub(crate) fn committed_fragment_padding(arena: &impl GeometryRead, slot: NodeSl
return committed_padding(arena, slot);
}
with_later_box_fragment(arena, slot, index, |fragment| {
- padding_of(&fragment.link.fragment, committed_frame(arena, slot))
+ fragment.link.fragment.sides.padding.into()
})
.unwrap_or_default()
}
@@ -501,7 +464,7 @@ pub(crate) fn committed_fragment_border(arena: &impl GeometryRead, slot: NodeSlo
return committed_border_box_edges(arena, slot);
}
with_later_box_fragment(arena, slot, index, |fragment| {
- border_of(&fragment.link.fragment, committed_frame(arena, slot))
+ fragment.link.fragment.sides.border.into()
})
.unwrap_or_default()
}
@@ -650,21 +613,11 @@ pub(crate) fn first_fragment_padding_box_rect(arena: &impl GeometryRead, slot: N
/// The border is split the same way layout splits it when placing the boxes (`BoxMetricCells::border_left_collapsed`):
/// the part before the grid line goes to the box before the line, the part after it to the box after the line.
pub(crate) fn committed_border_box_edges(arena: &impl GeometryRead, slot: NodeSlotId) -> FfiPixelBox {
- let border = committed_border(arena, slot);
- let Some(is_table_box) = arena.with_committed_fragment_link(slot, |link| {
- let collapsing = link?.fragment.sides.collapsing;
- collapsing
- .uses_collapsing_borders_model()
- .then(|| collapsing.is_collapsed_borders_table_box())
- }) else {
- return border;
- };
- FfiPixelBox {
- top: used_values::collapsed_border_share(border.top, true, is_table_box),
- right: used_values::collapsed_border_share(border.right, false, is_table_box),
- bottom: used_values::collapsed_border_share(border.bottom, false, is_table_box),
- left: used_values::collapsed_border_share(border.left, true, is_table_box),
- }
+ arena.with_committed_fragment_link(slot, |link| {
+ link.map_or_else(FfiPixelBox::default, |link| {
+ link.fragment.sides.border_box_edges().into()
+ })
+ })
}
pub(crate) fn absolute_border_box_rect(arena: &impl GeometryRead, slot: NodeSlotId) -> CssPixelRect {