Truly independent web browser
LibWeb: Paint inline boxes that are empty on their line
sideshowbarker0c945f0dd7e7
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_content.rs b/Libraries/LibWeb/Rust/src/layout/inline_content.rsindex 08d4017a623..b95a7eff516 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_content.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_content.rs@@ -702,8 +702,9 @@ impl InlineContent {}fn drop_repeated_placeholder_pieces(&mut self) {- let is_placeholder =- |piece: &InlineBoxPieceRecord| piece.is_geometry_only_placeholder && piece.fragment_count == 0;+ // NB: An inline box that's empty within one fragment has a piece there with no fragment of its content,+ // which is a placeholder unless the box is empty in every fragment it's laid out in.+ let is_placeholder = |piece: &InlineBoxPieceRecord| piece.fragment_count == 0;if !self.inline_box_pieces.iter().any(is_placeholder) {return;}@@ -717,15 +718,21 @@ impl InlineContent {let mut kept_count = 0u32;self.inline_box_pieces.retain(|piece| {let keep = !is_placeholder(piece) || nodes_with_pieces.insert(piece.node);- new_indices.push(kept_count);+ new_indices.push(keep.then_some(kept_count));kept_count += u32::from(keep);keep});- for item in &mut self.items {- if let InlineItem::BoxPiece(index) = item {- *index = new_indices[*index as usize];- }- }+ // NB: A dropped piece that isn't a geometry-only placeholder is painted, so its item goes too.+ self.items.retain_mut(|item| match item {+ InlineItem::BoxPiece(index) => match new_indices[*index as usize] {+ Some(new_index) => {+ *index = new_index;+ true+ }+ None => false,+ },+ _ => true,+ });}fn append_translated(diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rsindex da2e85dcfef..528fb31c7c8 100644--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs@@ -1018,6 +1018,12 @@ pub(crate) fn compute(// stand in for it only where it has no other lines.let mut corners_from_block_lines = FirstAndLastContentLineCorners::default();+ // NB: A box with content on some line, in this fragment or another, has its edges where that content is, so+ // only an empty box is on the line that holds its strut alone, for its background, borders, and outline+ // to be painted there and its border box to be hit there. Elsewhere, such a line holds a placeholder piece.+ let holds_content = lines.iter().any(|line| line.first_fragment_index.is_some())+ || context.inline_boxes_continued_from_previous_fragment.contains(&node)+ || context.inline_boxes_continued_in_next_fragment.borrow().contains(&node);for line in lines {let inline_box_anchor = || {let line_data = context.line_data();@@ -1090,7 +1096,8 @@ pub(crate) fn compute(let border_block_start = content_block_start - border_padding_block_low;let border_block_length = content_block_length + border_padding_block_low + border_padding_block_high;// NB: A placeholder piece holds the content box of its inline box.- let rect = if line.is_strut {+ let is_placeholder = line.is_strut && holds_content;+ let rect = if is_placeholder {FfiCssPixelRect {x: contributions_inline_start,y: content_block_start,@@ -1116,7 +1123,7 @@ pub(crate) fn compute(baseline: inline_box_baseline,accumulated_vertical_shift: inline_box_vertical_shift,present_edges: edge_bits(has_low_edge, has_high_edge),- is_geometry_only_placeholder: line.is_strut,+ is_geometry_only_placeholder: is_placeholder,},depth,discovery_index: node_index,diff --git a/Libraries/LibWeb/Rust/src/layout/query/inline_cursor.rs b/Libraries/LibWeb/Rust/src/layout/query/inline_cursor.rsindex 09a50996d0a..172fc70950f 100644--- a/Libraries/LibWeb/Rust/src/layout/query/inline_cursor.rs+++ b/Libraries/LibWeb/Rust/src/layout/query/inline_cursor.rs@@ -382,7 +382,7 @@ impl<'a, A: PaintRead> InlineCursor<'a, A> {if node_painting::is_fragmented_inline(arena, node) {let mut has_content = paint_order::first_paint_child(arena, node).is_some();with_inline_pieces(arena, node, |piece| {- has_content |= !piece.is_geometry_only_placeholder;+ has_content |= !piece.is_geometry_only_placeholder && piece.fragment_count != 0;!has_content});if has_content {diff --git a/Libraries/LibWeb/Rust/src/painting/hit_test/items.rs b/Libraries/LibWeb/Rust/src/painting/hit_test/items.rsindex 9f92ed006e8..8be1742a1a1 100644--- a/Libraries/LibWeb/Rust/src/painting/hit_test/items.rs+++ b/Libraries/LibWeb/Rust/src/painting/hit_test/items.rs@@ -419,7 +419,10 @@ impl<'a, R: PaintRead, S: HitTestItemSink> HitTestItems<'a, R, S> {.committed_side_data(root).inline_box_piece_indices(paintable).iter()- .any(|piece_index| !self.piece_of(root, *piece_index).is_geometry_only_placeholder)+ .any(|piece_index| {+ let piece = self.piece_of(root, *piece_index);+ !piece.is_geometry_only_placeholder && piece.fragment_count != 0+ })});has_content_pieces || crate::painting::paint_order::first_paint_child(self.rows, paintable).is_some()}diff --git a/Tests/LibWeb/Ref/expected/empty-inline-box-backgrounds-and-borders-ref.html b/Tests/LibWeb/Ref/expected/empty-inline-box-backgrounds-and-borders-ref.htmlnew file mode 100644index 00000000000..ccbe3843710--- /dev/null+++ b/Tests/LibWeb/Ref/expected/empty-inline-box-backgrounds-and-borders-ref.html@@ -0,0 +1,28 @@+<!DOCTYPE html>+<style>+@font-face {+ font-family: Ahem;+ src: url("../data/fonts/Ahem.ttf");+}+body {+ margin: 0;+ font: 20px/40px Ahem;+}+.box {+ display: inline-block;+ width: 16px;+ height: 20px;+ vertical-align: -4px;+ background: green;+}+.tall {+ height: 30px;+ vertical-align: -9px;+ outline: 2px solid blue;+}+</style>+<div><span class="box"></span>x</div>+<div>x<span class="box"></span>x</div>+<div>x<span class="box"></span></div>+<div><span class="box"></span>x</div>+<div>x<span class="box tall"></span></div>diff --git a/Tests/LibWeb/Ref/input/empty-inline-box-backgrounds-and-borders.html b/Tests/LibWeb/Ref/input/empty-inline-box-backgrounds-and-borders.htmlnew file mode 100644index 00000000000..60497081bf2--- /dev/null+++ b/Tests/LibWeb/Ref/input/empty-inline-box-backgrounds-and-borders.html@@ -0,0 +1,29 @@+<!DOCTYPE html>+<link rel="match" href="../expected/empty-inline-box-backgrounds-and-borders-ref.html">+<style>+@font-face {+ font-family: Ahem;+ src: url("../data/fonts/Ahem.ttf");+}+body {+ margin: 0;+ font: 20px/40px Ahem;+}+.padded {+ padding-left: 16px;+ background: green;+}+.bordered {+ border-left: 16px solid green;+}+.tall {+ padding: 5px 8px;+ background: green;+ outline: 2px solid blue;+}+</style>+<div><span class="padded"></span>x</div>+<div>x<span class="padded"></span>x</div>+<div>x<span class="padded"></span></div>+<div><span class="bordered"></span>x</div>+<div>x<span class="tall"></span></div>