Skip to content

Truly independent web browser

LibWeb: Place inline end edges after an out-of-flow last child

Andreas Kling28b1c23eec7c
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index e2c03049c80..c9db2bd6fbe 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -569,6 +569,18 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
.unwrap_or(line_box_fragment::GLYPH_TEXT_TYPE_CONTEXT_DEPENDENT)
}
+ /// The end edges of inline boxes that end right after an out-of-flow box are pending when the iterator reaches
+ /// that box. It takes no edges itself, so they precede the next item rather than follow its content.
+ fn carry_trailing_metrics_past_out_of_flow_box(&mut self) {
+ let Some(trailing) = self.extra_trailing_metrics.take() else {
+ return;
+ };
+ let leading = self.extra_leading_metrics.get_or_insert_default();
+ leading.margin += trailing.margin;
+ leading.border += trailing.border;
+ leading.padding += trailing.padding;
+ }
+
fn add_extra_box_model_metrics_to_item(
&mut self,
item: &mut Item,
@@ -738,12 +750,14 @@ impl<'iterator, 'context> InlineLevelIteratorGenerator<'iterator, 'context> {
|| extra.border != CssPixels::default()
|| extra.padding != CssPixels::default()
});
+ self.carry_trailing_metrics_past_out_of_flow_box();
self.skip_to_next();
let mut item = Item::new(ItemType::AbsolutelyPositionedElement, node);
item.preceded_by_unattached_inline_start_edges = preceded;
return Some(item);
}
if facts.is_floating() {
+ self.carry_trailing_metrics_past_out_of_flow_box();
self.skip_to_next();
return Some(Item::new(ItemType::FloatingElement, node));
}
diff --git a/Tests/LibWeb/Layout/expected/abspos-inline-containing-block-first-last-line-rule.txt b/Tests/LibWeb/Layout/expected/abspos-inline-containing-block-first-last-line-rule.txt
index 926f95006a6..12cdbb31d74 100644
--- a/Tests/LibWeb/Layout/expected/abspos-inline-containing-block-first-last-line-rule.txt
+++ b/Tests/LibWeb/Layout/expected/abspos-inline-containing-block-first-last-line-rule.txt
@@ -42,7 +42,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <div.frame> at [8,164] [8+0+0 300 0+0+492] [8+0+0 20 0+0+8] children: inline
frag 0 from TextNode start: 5, length: 3, rect: [8,166 26.6875x16] baseline: 12.796875
"aa "
- frag 1 from TextNode start: 0, length: 3, rect: [83.40625,166 23.71875x16] baseline: 12.796875
+ frag 1 from TextNode start: 0, length: 3, rect: [91.40625,166 23.71875x16] baseline: 12.796875
" dd"
TextNode <#text> (not painted)
InlineNode <span.rel> at [38.6875,166] [0+4+0 44.71875 0+8+0] [0+0+0 16 0+0+0]
@@ -57,7 +57,7 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <div.frame> at [8,192] [8+0+0 300 0+0+492] [8+0+0 20 0+0+8] children: inline
frag 0 from TextNode start: 5, length: 3, rect: [200.875,194 26.6875x16] baseline: 12.796875
"aa "
- frag 1 from TextNode start: 0, length: 3, rect: [276.28125,194 23.71875x16] baseline: 12.796875
+ frag 1 from TextNode start: 0, length: 3, rect: [284.28125,194 23.71875x16] baseline: 12.796875
" dd"
TextNode <#text> (not painted)
InlineNode <span.rel> at [231.5625,194] [0+4+0 44.71875 0+8+0] [0+0+0 16 0+0+0]
diff --git a/Tests/LibWeb/Ref/expected/inline-end-edges-after-out-of-flow-last-child-ref.html b/Tests/LibWeb/Ref/expected/inline-end-edges-after-out-of-flow-last-child-ref.html
new file mode 100644
index 00000000000..0ea8ff3cbfb
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/inline-end-edges-after-out-of-flow-last-child-ref.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<style>
+ div {
+ margin: 10px;
+ }
+ .inline {
+ padding: 0 30px 0 20px;
+ }
+ .box {
+ display: inline-block;
+ width: 50px;
+ height: 10px;
+ background: blue;
+ }
+ .out-of-flow {
+ width: 10px;
+ height: 10px;
+ background: green;
+ }
+ .absolute {
+ position: absolute;
+ }
+ .float {
+ float: left;
+ }
+</style>
+<!-- A zero-width space after each out-of-flow box ends the inline boxes with in-flow content. -->
+<div><span class="inline"><span class="box"></span><span class="out-of-flow absolute"></span>&#8203;</span><span class="box"></span></div>
+<div><span class="inline"><span class="box"></span><span class="out-of-flow float"></span>&#8203;</span><span class="box"></span></div>
+<div><span class="inline"><span class="box"></span><span class="out-of-flow float"></span>&#8203;</span><span class="box"></span></div>
diff --git a/Tests/LibWeb/Ref/input/inline-end-edges-after-out-of-flow-last-child.html b/Tests/LibWeb/Ref/input/inline-end-edges-after-out-of-flow-last-child.html
new file mode 100644
index 00000000000..d1f99005340
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/inline-end-edges-after-out-of-flow-last-child.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<link rel="match" href="../expected/inline-end-edges-after-out-of-flow-last-child-ref.html">
+<style>
+ div {
+ margin: 10px;
+ }
+ .inline {
+ padding: 0 30px 0 20px;
+ }
+ .box {
+ display: inline-block;
+ width: 50px;
+ height: 10px;
+ background: blue;
+ }
+ .out-of-flow {
+ width: 10px;
+ height: 10px;
+ background: green;
+ }
+ .absolute {
+ position: absolute;
+ }
+ .float {
+ float: left;
+ }
+ .float-after::after {
+ content: "";
+ float: left;
+ width: 10px;
+ height: 10px;
+ background: green;
+ }
+</style>
+<div><span class="inline"><span class="box"></span><span class="out-of-flow absolute"></span></span><span class="box"></span></div>
+<div><span class="inline"><span class="box"></span><span class="out-of-flow float"></span></span><span class="box"></span></div>
+<div><span class="inline float-after"><span class="box"></span></span><span class="box"></span></div>