Skip to content

Truly independent web browser

LibWeb: Keep the inline boxes a line layout entered in a table

Aliaksandr Kalenikcb2bae7eeba0
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 6459bf04164..e82ac214b00 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -627,7 +627,7 @@ pub(crate) fn compute(
std::mem::take(&mut per_node.lines),
)
};
- let used = context.used(node);
+ let sides = context.sides_of_entered_inline_box(node);
let reversed = context.facts(node).inline_axis_is_reverse();
let (
border_padding_low,
@@ -637,12 +637,12 @@ pub(crate) fn compute(
margin_low,
margin_high,
) = (
- used.border_box_left(false),
- used.border_box_right(false),
- used.border_box_top(false),
- used.border_box_bottom(false),
- used.margin_left.get(),
- used.margin_right.get(),
+ sides.border_box_left(false),
+ sides.border_box_right(false),
+ sides.border_box_top(false),
+ sides.border_box_bottom(false),
+ sides.margin_left,
+ sides.margin_right,
);
let node_is_inline_containing_block = collect_inline_containing_block_rects
@@ -785,7 +785,7 @@ pub(crate) fn compute(
if node_is_inline_containing_block
&& let Some(rect) = padding_box_rect_spanning_first_and_last_content_lines(
&corners,
- used,
+ &sides,
reversed,
container_inline_axis_is_reverse,
)
@@ -798,7 +798,10 @@ pub(crate) fn compute(
}
for (index, node) in without_fragments.into_iter().enumerate() {
- context.used(node);
+ assert!(
+ context.entered_inline_box(node).is_some(),
+ "a fragmented inline without fragments is an inline box the context entered"
+ );
let line_height = context.style(node).line_height();
let placeholder_rect = FfiCssPixelRect {
height: line_height,
@@ -845,7 +848,7 @@ pub(crate) fn compute(
fn padding_box_rect_spanning_first_and_last_content_lines(
corners: &FirstAndLastContentLineCorners,
- used: &UsedValues,
+ sides: &used_values::RootInputCells,
inline_axis_is_reverse: bool,
container_inline_axis_is_reverse: bool,
) -> Option<CssPixelRect> {
@@ -853,10 +856,10 @@ fn padding_box_rect_spanning_first_and_last_content_lines(
let last = corners.last?;
let (border_inline_low, border_inline_high, border_block_low, border_block_high) = (
- used.border_left.get(),
- used.border_right.get(),
- used.border_top.get(),
- used.border_bottom.get(),
+ sides.border_left,
+ sides.border_right,
+ sides.border_top,
+ sides.border_bottom,
);
let direction_matches = inline_axis_is_reverse == container_inline_axis_is_reverse;
let (contracted_inline_low, contracted_inline_high) = if direction_matches {
@@ -988,6 +991,8 @@ pub(crate) struct InlineFormattingContext<'context> {
/// Whether margins collapse through each block-level box this context interrupted its lines for, as the layout of
/// the box found.
margins_collapse_through_interrupting_blocks: RefCell<HashMap<Node, bool>>,
+ /// The sizes and box sides of each inline box this context entered, as it resolved them on entering the box.
+ sides_of_entered_inline_boxes: RefCell<HashMap<Node, used_values::RootInputCells>>,
}
impl<'context> InlineFormattingContext<'context> {
@@ -1017,6 +1022,7 @@ impl<'context> InlineFormattingContext<'context> {
fragmentainer_stop_token: RefCell::new(None),
lines_are_unbreakable: Cell::new(false),
margins_collapse_through_interrupting_blocks: RefCell::new(HashMap::default()),
+ sides_of_entered_inline_boxes: RefCell::new(HashMap::default()),
}
}
@@ -1184,6 +1190,21 @@ impl<'context> InlineFormattingContext<'context> {
self.run.records.create_used_values(&self.callbacks, node, constraints)
}
+ pub(crate) fn keep_sides_of_entered_inline_box(&self, node: Node, sides: used_values::RootInputCells) {
+ self.sides_of_entered_inline_boxes.borrow_mut().insert(node, sides);
+ }
+
+ fn entered_inline_box(&self, node: Node) -> Option<used_values::RootInputCells> {
+ self.sides_of_entered_inline_boxes.borrow().get(&node).copied()
+ }
+
+ /// The sizes and box sides of `node`, an inline box this context entered.
+ #[track_caller]
+ pub(crate) fn sides_of_entered_inline_box(&self, node: Node) -> used_values::RootInputCells {
+ self.entered_inline_box(node)
+ .expect("the inline formatting context entered the inline box")
+ }
+
/// Starts holding `node`, an atomic inline-level box: kept for its run where it has a formatting context of its
/// own, or with a record where this context lays it out itself.
pub(crate) fn hold_atomic_inline(&self, node: Node) {
@@ -2313,11 +2334,17 @@ impl<'context> InlineFormattingContext<'context> {
if let Some(collapses_through) = interrupting_block_collapses_through {
return collapses_through;
}
- if !self.run.records.holds_box(child) {
+ let entered_inline_box = self.entered_inline_box(child);
+ if entered_inline_box.is_none() && !self.run.records.holds_box(child) {
return true;
}
block_formatting_context::margins_can_collapse_through_box_itself(facts, self.style(child), || {
- self.used(child).border_box_block_size(false)
+ match entered_inline_box {
+ Some(sides) => sides.border_box_block_size(false),
+ // NB: A box this context holds as an atomic inline-level box, which has a record where it has no
+ // formatting context of its own.
+ None => self.used(child).border_box_block_size(false),
+ }
}) && self.children_let_margins_collapse_through(child)
})
}
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index 3c7ce6b675f..c6119951279 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -552,20 +552,20 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
fn enter_node_with_box_model_metrics(&mut self, node: Node) {
self.entered_box_model_nodes.push(node);
- let used = record_entered_inline_box(self.context, node);
+ let sides = record_entered_inline_box(self.context, node);
let leading = self.extra_leading_metrics.get_or_insert_default();
- leading.margin += used.margin_left.get();
- leading.border += used.border_left.get();
- leading.padding += used.padding_left.get();
+ leading.margin += sides.margin_left;
+ leading.border += sides.border_left;
+ leading.padding += sides.padding_left;
self.box_model_node_stack.push(node);
}
fn exit_node_with_box_model_metrics(&mut self) {
let node = self.box_model_node_stack.pop().unwrap();
- let used = self.context().used(node);
- let margin = used.margin_right.get();
- let border = used.border_right.get();
- let padding = used.padding_right.get();
+ let sides = self.context().sides_of_entered_inline_box(node);
+ let margin = sides.margin_right;
+ let border = sides.border_right;
+ let padding = sides.padding_right;
let trailing = self.extra_trailing_metrics.get_or_insert_default();
trailing.margin += margin;
trailing.border += border;
@@ -990,20 +990,23 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
}
}
-fn record_entered_inline_box<'context>(
- context: &inline_formatting_context::InlineFormattingContext<'context>,
+/// Registers `node`, an inline box the context enters, resolves its box sides and returns them.
+fn record_entered_inline_box(
+ context: &inline_formatting_context::InlineFormattingContext<'_>,
node: Node,
-) -> &'context UsedValues {
+) -> used_values::RootInputCells {
let constraints = context.input.containing_block_constraints;
let used = context.create_used_values(node, constraints);
let style = context.style(node);
let basis = constraints.inline_basis();
used.resolve_box_model(&style, basis);
context.compute_inset(node);
+ let sides = used_values::RootInputCells::capture(used);
+ context.keep_sides_of_entered_inline_box(node, sides);
if context.run.fragments.is_some() && context.run.fragmentainer.is_none() {
formatting_context::place_child(context.run, node, FfiCssPixelPoint::default(), None);
}
- used
+ sides
}
/// The inline items a block container generated, kept for the later runs of the container in the same pass. Their
diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
index edf7502a0cb..af6fa2da35a 100644
--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
@@ -748,12 +748,12 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
fn inline_box_alignment_metrics(&self, node: Node) -> VerticalAlignMetrics {
let style = self.style(node);
- let used = self.context().used(node);
+ let sides = self.context().sides_of_entered_inline_box(node);
VerticalAlignMetrics {
baseline: Self::baseline_for_style(style, style.line_height()),
block_size: style.line_height(),
- effective_box_block_start_offset: used.border_box_top(false),
- effective_box_block_end_offset: used.border_box_bottom(false),
+ effective_box_block_start_offset: sides.border_box_top(false),
+ effective_box_block_end_offset: sides.border_box_bottom(false),
line_height: style.line_height(),
}
}