Truly independent web browser
LibWeb: Place end edges of empty inline boxes before the next item
Andreas Kling51a726c79309
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rsindex 6a5372ce7ee..0a125c712f2 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs@@ -820,7 +820,10 @@ impl<'pass> InlineContentPreparer<'pass> {fn exit_node_with_box_model_metrics(&mut self) {self.buffers.box_stack.pop().unwrap();- let event = InlineBoxEvent::leaving_innermost_box(self.inline_box_event_position());+ // NB: The walk looks one node ahead, so a box usually ends while its last item is the current node. An inline+ // box as the current node has no item of its own, so nothing in the box comes with the next item.+ let before_item = !self.current_node.is_invalid() && self.facts(self.current_node).is_fragmented_inline();+ let event = InlineBoxEvent::leaving_innermost_box(self.inline_box_event_position(), before_item);self.buffers.box_events.push(event);}@@ -1382,7 +1385,13 @@ impl<'context> RunItemResolver<'_, 'context> {self.accumulated_inline_size_for_tabs += advance;}- fn keep_inline_edge(&mut self, node: Node, sides: &used_values::RootInputCells, is_start: bool) {+ fn keep_inline_edge(+ &mut self,+ node: Node,+ sides: &used_values::RootInputCells,+ is_start: bool,+ takes_leading_metrics: bool,+ ) {let reversed = self.context().facts(node).inline_axis_is_reverse();let (margin, border, padding) = if is_start != reversed {(sides.margin_left, sides.border_left, sides.padding_left)@@ -1419,7 +1428,7 @@ impl<'context> RunItemResolver<'_, 'context> {right_to_left_end_margin,is_start,is_low: is_start != reversed,- takes_leading_metrics: is_start,+ takes_leading_metrics,});}}@@ -1433,7 +1442,7 @@ impl<'context> RunItemResolver<'_, 'context> {self.next_box_event += 1;match event.entered_box() {Some(node) => self.enter_node_with_box_model_metrics(node),- None => self.exit_node_with_box_model_metrics(),+ None => self.exit_node_with_box_model_metrics(event.leaves_before_item()),}}}@@ -1441,14 +1450,14 @@ impl<'context> RunItemResolver<'_, 'context> {fn enter_node_with_box_model_metrics(&mut self, node: Node) {self.entered_box_model_nodes.push(node);let sides = lay_out_entered_inline_box(self.context, node);- self.keep_inline_edge(node, &sides, true);+ self.keep_inline_edge(node, &sides, true, true);self.box_model_node_stack.push(node);}- fn exit_node_with_box_model_metrics(&mut self) {+ fn exit_node_with_box_model_metrics(&mut self, before_item: bool) {let node = self.box_model_node_stack.pop().unwrap();let sides = self.context().sides_of_entered_inline_box(node);- self.keep_inline_edge(node, &sides, false);+ self.keep_inline_edge(node, &sides, false, before_item);}fn negative_right_to_left_end_margin(&self, node: Node, margin_left: CssPixels) -> CssPixels {diff --git a/Libraries/LibWeb/Rust/src/layout/prepared_inline_content.rs b/Libraries/LibWeb/Rust/src/layout/prepared_inline_content.rsindex eb192ff28ed..67ffa7b7345 100644--- a/Libraries/LibWeb/Rust/src/layout/prepared_inline_content.rs+++ b/Libraries/LibWeb/Rust/src/layout/prepared_inline_content.rs@@ -135,8 +135,12 @@ pub(super) struct InlineBoxEvent {const _: () = assert!(size_of::<InlineBoxEvent>() == 8);impl InlineBoxEvent {+ const LEAVES_BEFORE_ITEM: u32 = 1 << 31;+pub(super) fn position_at(item_index: usize, within_item: bool) -> u32 {- u32::try_from(item_index << 1 | usize::from(within_item)).expect("item indices fit in 31 bits")+ let position = u32::try_from(item_index << 1 | usize::from(within_item)).expect("item indices fit in 31 bits");+ assert!(position < Self::LEAVES_BEFORE_ITEM, "item indices fit in 30 bits");+ position}pub(super) fn entering(position: u32, node: Node) -> Self {@@ -146,15 +150,20 @@ impl InlineBoxEvent {}}- pub(super) fn leaving_innermost_box(position: u32) -> Self {+ pub(super) fn leaving_innermost_box(position: u32, before_item: bool) -> Self {Self {- position,+ position: position | if before_item { Self::LEAVES_BEFORE_ITEM } else { 0 },entered_box: NodeSlotId::INVALID,}}pub(super) fn position(&self) -> u32 {- self.position+ self.position & !Self::LEAVES_BEFORE_ITEM+ }++ /// Whether the box ended before the item at this position began, instead of with that item.+ pub(super) fn leaves_before_item(&self) -> bool {+ self.position & Self::LEAVES_BEFORE_ITEM != 0}pub(super) fn entered_box(&self) -> Option<Node> {diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/inline-box-end-edges-of-empty-box.txt b/Tests/LibWeb/Layout/expected/block-and-inline/inline-box-end-edges-of-empty-box.txtindex e71c9c07941..0c65f1ac770 100644--- a/Tests/LibWeb/Layout/expected/block-and-inline/inline-box-end-edges-of-empty-box.txt+++ b/Tests/LibWeb/Layout/expected/block-and-inline/inline-box-end-edges-of-empty-box.txt@@ -4,7 +4,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <div> at [8,8] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 1, rect: [8,8 11.6875x20] baseline: 16"a"- frag 1 from TextNode start: 0, length: 1, rect: [19.6875,8 14.453125x20] baseline: 16+ frag 1 from TextNode start: 0, length: 1, rect: [39.6875,8 14.453125x20] baseline: 16"X"TextNode <#text> (not painted)InlineNode <span.margin> at [8,8] [0+0+0 0 0+0+20] [0+0+0 20 0+0+0]@@ -12,7 +12,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <div> at [8,28] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 1, rect: [8,28 11.6875x20] baseline: 16"a"- frag 1 from TextNode start: 0, length: 1, rect: [19.6875,28 14.453125x20] baseline: 16+ frag 1 from TextNode start: 0, length: 1, rect: [39.6875,28 14.453125x20] baseline: 16"X"TextNode <#text> (not painted)InlineNode <span.padding> at [8,28] [0+0+0 0 20+0+0] [0+0+0 20 0+0+0]@@ -20,7 +20,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <div> at [8,48] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 2, rect: [8,48 21.6875x20] baseline: 16"a "- frag 1 from TextNode start: 0, length: 1, rect: [29.6875,48 14.453125x20] baseline: 16+ frag 1 from TextNode start: 0, length: 1, rect: [49.6875,48 14.453125x20] baseline: 16"X"TextNode <#text> (not painted)InlineNode <span.margin> at [8,48] [0+0+0 0 0+0+20] [0+0+0 20 0+0+0]@@ -28,7 +28,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <div> at [8,68] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 2, rect: [8,68 21.6875x20] baseline: 16"a "- frag 1 from TextNode start: 1, length: 1, rect: [29.6875,68 14.453125x20] baseline: 16+ frag 1 from TextNode start: 1, length: 1, rect: [49.6875,68 14.453125x20] baseline: 16"X"TextNode <#text> (not painted)InlineNode <span.margin> at [8,68] [0+0+0 0 0+0+20] [0+0+0 20 0+0+0]@@ -36,27 +36,27 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <div> at [8,88] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 1, rect: [8,88 11.6875x20] baseline: 16"a"- frag 1 from TextNode start: 0, length: 2, rect: [19.6875,88 24.453125x20] baseline: 16+ frag 1 from TextNode start: 0, length: 2, rect: [39.6875,88 24.453125x20] baseline: 16" X"TextNode <#text> (not painted)InlineNode <span.margin> at [8,88] [0+0+0 0 0+0+20] [0+0+0 20 0+0+0]TextNode <#text> (not painted)BlockContainer <div> at [8,108] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 1, rect: [8,108 14.453125x20] baseline: 16+ frag 0 from TextNode start: 0, length: 1, rect: [28,108 14.453125x20] baseline: 16"X"InlineNode <span.margin> at [8,108] [0+0+0 0 0+0+20] [0+0+0 20 0+0+0]TextNode <#text> (not painted)BlockContainer <div> at [8,128] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 1, rect: [8,128 11.6875x20] baseline: 16"a"- frag 1 from TextNode start: 0, length: 1, rect: [19.6875,128 14.453125x20] baseline: 16+ frag 1 from TextNode start: 0, length: 1, rect: [39.6875,128 14.453125x20] baseline: 16"X"TextNode <#text> (not painted)InlineNode <span.margin> at [8,128] [0+0+0 0 0+0+20] [0+0+0 20 0+0+0]InlineNode <b> at [8,128] [0+0+0 0 0+0+0] [0+0+0 20 0+0+0]TextNode <#text> (not painted)BlockContainer <div> at [8,148] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inline- frag 0 from TextNode start: 0, length: 1, rect: [19.6875,148 14.453125x20] baseline: 16+ frag 0 from TextNode start: 0, length: 1, rect: [39.6875,148 14.453125x20] baseline: 16"X"InlineNode <span.margin> at [8,148] [0+0+0 11.6875 0+0+20] [0+0+0 20 0+0+0]frag 0 from TextNode start: 0, length: 1, rect: [8,148 11.6875x20] baseline: 16@@ -69,7 +69,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <div.shrink-to-fit> at [8,168] inline-block [0+0+0 46.140625 0+0+0] [0+0+0 20 0+0+0] [BFC] children: inlinefrag 0 from TextNode start: 0, length: 1, rect: [8,168 11.6875x20] baseline: 16"a"- frag 1 from TextNode start: 0, length: 1, rect: [19.6875,168 14.453125x20] baseline: 16+ frag 1 from TextNode start: 0, length: 1, rect: [39.6875,168 14.453125x20] baseline: 16"X"TextNode <#text> (not painted)InlineNode <span.margin> at [8,168] [0+0+0 0 0+0+20] [0+0+0 20 0+0+0]diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/inline-box-end-edges-on-collapsed-whitespace.txt b/Tests/LibWeb/Layout/expected/block-and-inline/inline-box-end-edges-on-collapsed-whitespace.txtindex 20a9c78223d..3e09ae94cf8 100644--- a/Tests/LibWeb/Layout/expected/block-and-inline/inline-box-end-edges-on-collapsed-whitespace.txt+++ b/Tests/LibWeb/Layout/expected/block-and-inline/inline-box-end-edges-on-collapsed-whitespace.txt@@ -48,7 +48,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] childrenBlockContainer <div> at [8,108] [0+0+0 784 0+0+0] [0+0+0 20 0+0+0] children: inlinefrag 0 from TextNode start: 0, length: 2, rect: [8,108 21.6875x20] baseline: 16"a "- frag 1 from TextNode start: 1, length: 1, rect: [29.6875,108 14.453125x20] baseline: 16+ frag 1 from TextNode start: 1, length: 1, rect: [49.6875,108 14.453125x20] baseline: 16"X"TextNode <#text> (not painted)InlineNode <span.margin> at [8,108] [0+0+0 0 0+0+20] [0+0+0 20 0+0+0]