Skip to content

Truly independent web browser

LibWeb: Preserve decorated inline edges around block children

sideshowbarkerd67314413177
diff --git a/Libraries/LibWeb/DOM/Element.cpp b/Libraries/LibWeb/DOM/Element.cpp
index 7b568f328d9..dad29df7d76 100644
--- a/Libraries/LibWeb/DOM/Element.cpp
+++ b/Libraries/LibWeb/DOM/Element.cpp
@@ -2933,7 +2933,7 @@ int Element::client_width() const
// 1. If the element has no associated CSS layout box or if the CSS layout box is inline, return zero.
auto const* layout_node = this->layout_node(read);
- if (!layout_node || !Painting::has_committed_box(*layout_node))
+ if (!layout_node || layout_node->is_fragmented_inline() || !Painting::has_committed_box(*layout_node))
return 0;
// 3. Return the width of the padding edge excluding the width of any rendered scrollbar between the padding edge and the border edge,
@@ -2961,7 +2961,7 @@ int Element::client_height() const
// 1. If the element has no associated CSS layout box or if the CSS layout box is inline, return zero.
auto const* layout_node = this->layout_node(read);
- if (!layout_node || !Painting::has_committed_box(*layout_node))
+ if (!layout_node || layout_node->is_fragmented_inline() || !Painting::has_committed_box(*layout_node))
return 0;
// 3. Return the height of the padding edge excluding the height of any rendered scrollbar between the padding edge and the border edge,
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index a96d3c3811e..7d5e126384b 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -556,7 +556,7 @@ pub(crate) fn compute(
let mut direct = true;
let mut previous: Option<usize> = None;
- let mut ancestor = context.nearest_fragmented_inline_ancestor(fragment.layout_node);
+ let mut ancestor = context.inline_box_for_fragment(fragment.layout_node);
while !ancestor.is_invalid() {
let node_index = if let Some(index) = node_to_index.get(&ancestor) {
*index
@@ -1316,7 +1316,7 @@ impl<'context> InlineFormattingContext<'context> {
fn fragmented_inline_ancestors(&self, node: Node) -> Vec<Node> {
let mut ancestors = Vec::new();
- let mut ancestor = self.nearest_fragmented_inline_ancestor(node);
+ let mut ancestor = self.inline_box_for_fragment(node);
while !ancestor.is_invalid() {
ancestors.push(ancestor);
ancestor = self.nearest_fragmented_inline_ancestor(ancestor);
@@ -1331,6 +1331,14 @@ impl<'context> InlineFormattingContext<'context> {
ancestors
}
+ fn inline_box_for_fragment(&self, node: Node) -> Node {
+ if !node.is_invalid() && self.facts(node).is_fragmented_inline() {
+ node
+ } else {
+ self.nearest_fragmented_inline_ancestor(node)
+ }
+ }
+
pub(crate) fn nearest_fragmented_inline_ancestor(&self, node: Node) -> Node {
let mut ancestor = self.parent_node(node);
while !ancestor.is_invalid() {
@@ -2080,6 +2088,12 @@ impl<'context> InlineFormattingContext<'context> {
leading_padding = CssPixels::default();
match item.type_ {
+ inline_level_iterator::ItemType::InlineEdge => {
+ if self.stops_at_line_clamp_point(line_builder, &mut state_at_clamp_point) {
+ break;
+ }
+ line_builder.append_inline_edge(&item);
+ }
inline_level_iterator::ItemType::ForcedBreak => {
self.current_line_start.set(fragmentation::LinePosition {
item_index: item_index + 1,
@@ -2954,7 +2968,11 @@ impl<'context> InlineFormattingContext<'context> {
.chain(childless_inline_boxes)
.filter(|node| !node.is_invalid())
{
- let mut ancestor = self.callbacks.parent(node);
+ let mut ancestor = if self.facts(node).is_fragmented_inline() {
+ node
+ } else {
+ self.callbacks.parent(node)
+ };
while !ancestor.is_invalid() && ancestor != self.containing_block && walked.insert(ancestor) {
present.insert(ancestor);
ancestor = self.callbacks.parent(ancestor);
@@ -2988,7 +3006,12 @@ impl<'context> InlineFormattingContext<'context> {
// NB: Fragments that text-overflow elided keep their shift too, since the elided content still extends
// the scrollable overflow.
for fragment in &mut line.fragments {
- fragment.relpos_delta = accumulated_relative_offset_from(self.callbacks.parent(fragment.layout_node));
+ let first_ancestor = if self.facts(fragment.layout_node).is_fragmented_inline() {
+ fragment.layout_node
+ } else {
+ self.callbacks.parent(fragment.layout_node)
+ };
+ fragment.relpos_delta = accumulated_relative_offset_from(first_ancestor);
}
}
for piece in &mut data.inline_box_pieces {
@@ -3306,6 +3329,9 @@ impl ContentSizingLines {
);
match item.type_ {
inline_level_iterator::ItemType::ForcedBreak => self.lines.force_break(),
+ inline_level_iterator::ItemType::InlineEdge => {
+ self.lines.append(border_box_inline_size, false, CssPixels::default());
+ }
inline_level_iterator::ItemType::Element => {
self.lines
.append_atomic_inline(border_box_inline_size, self.container_wraps);
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index aed91575f5a..71a0ad9ecc2 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -17,6 +17,7 @@ pub(crate) enum ItemType {
ForcedBreak,
AbsolutelyPositionedElement,
FloatingElement,
+ InlineEdge,
}
impl ItemType {
@@ -25,7 +26,7 @@ impl ItemType {
pub(crate) fn stays_on_lines(self) -> bool {
matches!(
self,
- Self::Text | Self::Element | Self::ForcedBreak | Self::AbsolutelyPositionedElement
+ Self::Text | Self::Element | Self::InlineEdge | Self::ForcedBreak | Self::AbsolutelyPositionedElement
)
}
}
@@ -493,6 +494,25 @@ struct ExtraBoxMetrics {
padding: CssPixels,
}
+#[derive(Clone, Copy)]
+enum InlineEdgeBoundary {
+ BeforeBlock(Node),
+ BeforeBreak(Option<Node>),
+ Closing(Node, Option<Node>),
+ End,
+}
+
+struct PendingInlineEdge {
+ node: Node,
+ margin: CssPixels,
+ border: CssPixels,
+ padding: CssPixels,
+ physical: ExtraBoxMetrics,
+ is_start: bool,
+ is_low: bool,
+ takes_leading_metrics: bool,
+}
+
struct TextNodeContext<'pass> {
chunks: std::sync::Arc<super::rendered_text::CachedTextChunks>,
text: &'pass [u16],
@@ -554,14 +574,14 @@ impl PreparedInlineContent {
context,
prepared: self,
atomic_sizing,
- extra_leading_metrics: None,
- extra_trailing_metrics: None,
+ pending_inline_edges: Vec::new(),
box_model_node_stack: Vec::new(),
entered_box_model_nodes: Vec::new(),
accumulated_inline_size_for_tabs: CssPixels::default(),
next_box_event: 0,
next_tab_stop: 0,
fonts_taken: 0,
+ forced_break_owner: NodeSlotId::INVALID,
}
.resolve()
}
@@ -680,17 +700,14 @@ impl<'pass> InlineContentPreparer<'pass> {
let mut node = current;
loop {
+ if self.buffers.box_stack.last().copied() == Some(node) {
+ self.exit_node_with_box_model_metrics();
+ }
let next = self.pass.next_sibling(node);
if !next.is_invalid() {
- if self.buffers.box_stack.last().copied() == Some(node) {
- self.exit_node_with_box_model_metrics();
- }
return next;
}
node = self.pass.parent(node);
- if self.buffers.box_stack.last().copied() == Some(node) {
- self.exit_node_with_box_model_metrics();
- }
if node.is_invalid() || node == stay_within {
return NodeSlotId::INVALID;
}
@@ -884,7 +901,7 @@ impl<'pass> InlineContentPreparer<'pass> {
}
if text_context.should_respect_linebreaks && chunk.has_breaking_newline {
self.text_node_context = Some(text_context);
- return Some(PreparedItem::new(ItemType::ForcedBreak, NodeSlotId::INVALID, 0));
+ return Some(PreparedItem::new(ItemType::ForcedBreak, text_node, 0));
}
let full_text = text_context.text;
@@ -1074,14 +1091,14 @@ struct RunItemResolver<'resolver, 'context> {
context: &'resolver mut inline_formatting_context::InlineFormattingContext<'context>,
prepared: &'resolver PreparedInlineContent,
atomic_sizing: AtomicInlineSizing,
- extra_leading_metrics: Option<ExtraBoxMetrics>,
- extra_trailing_metrics: Option<ExtraBoxMetrics>,
+ pending_inline_edges: Vec<PendingInlineEdge>,
box_model_node_stack: Vec<Node>,
entered_box_model_nodes: Vec<Node>,
accumulated_inline_size_for_tabs: CssPixels,
next_box_event: usize,
next_tab_stop: usize,
fonts_taken: usize,
+ forced_break_owner: Node,
}
impl<'context> RunItemResolver<'_, 'context> {
@@ -1091,18 +1108,63 @@ impl<'context> RunItemResolver<'_, 'context> {
fn resolve(mut self) -> InlineLevelIterator {
let prepared = self.prepared;
- let mut items = Vec::with_capacity(prepared.items.len());
+ let mut items: Vec<Item> = Vec::with_capacity(prepared.items.len());
+ let mut next_non_whitespace = 0;
for (index, prepared_item) in prepared.items.iter().enumerate() {
self.apply_inline_box_events_at(index, false);
+ if !self.pending_inline_edges.is_empty()
+ && prepared_item.type_() == ItemType::Text
+ && prepared_item.has(PreparedItem::COLLAPSIBLE_WHITESPACE)
+ {
+ if next_non_whitespace <= index {
+ next_non_whitespace = index + 1;
+ while let Some(next) = prepared.items.get(next_non_whitespace)
+ && next.type_() == ItemType::Text
+ && next.has(PreparedItem::COLLAPSIBLE_WHITESPACE)
+ {
+ next_non_whitespace += 1;
+ }
+ }
+ if prepared
+ .items
+ .get(next_non_whitespace)
+ .is_none_or(|next| matches!(next.type_(), ItemType::BlockLevelBox | ItemType::ForcedBreak))
+ {
+ // Whitespace at a line end disappears, but its inline box edges still belong on that line.
+ self.fonts_taken += usize::from(prepared_item.has(PreparedItem::TAKES_NEXT_FONT));
+ continue;
+ }
+ }
+ if let Some(last) = items.last()
+ && last.type_ == ItemType::ForcedBreak
+ {
+ let boundary = InlineEdgeBoundary::Closing(self.forced_break_owner, Some(prepared_item.node()));
+ self.append_unattached_edges(&mut items, boundary);
+ }
+ if prepared_item.type_() == ItemType::BlockLevelBox {
+ self.append_unattached_edges(&mut items, InlineEdgeBoundary::BeforeBlock(prepared_item.node()));
+ } else if prepared_item.type_() == ItemType::ForcedBreak {
+ let next = prepared.items.get(index + 1).map(PreparedItem::node);
+ self.append_unattached_edges(&mut items, InlineEdgeBoundary::BeforeBreak(next));
+ }
let item = self.resolve_item(index, prepared_item);
if matches!(item.type_, ItemType::ForcedBreak | ItemType::BlockLevelBox) {
self.accumulated_inline_size_for_tabs = CssPixels::default();
} else if item.type_ != ItemType::FloatingElement {
self.accumulated_inline_size_for_tabs += item.border_box_inline_size();
}
+ let closes_boundary = matches!(item.type_, ItemType::BlockLevelBox | ItemType::ForcedBreak);
+ if item.type_ == ItemType::ForcedBreak {
+ self.forced_break_owner = prepared_item.node();
+ }
items.push(item);
+ if closes_boundary {
+ let next = prepared.items.get(index + 1).map(PreparedItem::node);
+ self.append_unattached_edges(&mut items, InlineEdgeBoundary::Closing(prepared_item.node(), next));
+ }
}
- self.apply_inline_box_events_at(items.len(), false);
+ self.apply_inline_box_events_at(prepared.items.len(), false);
+ self.append_unattached_edges(&mut items, InlineEdgeBoundary::End);
debug_assert_eq!(self.next_box_event, prepared.box_events.len());
InlineLevelIterator {
entered_box_model_nodes: self.entered_box_model_nodes,
@@ -1111,6 +1173,113 @@ impl<'context> RunItemResolver<'_, 'context> {
}
}
+ fn append_unattached_edges(&mut self, items: &mut Vec<Item>, boundary: InlineEdgeBoundary) {
+ // Nonzero inline-axis edges keep a line box even when it contains no text. Preserve their presence
+ // independently of their sum, since negative margins can cancel other margins, borders, or padding.
+ // https://drafts.csswg.org/css-inline-3/#invisible-line-boxes
+ let context = &*self.context;
+ let is_ancestor = |ancestor: Node, mut node: Node| {
+ while !node.is_invalid() {
+ node = context.parent_node(node);
+ if node == ancestor {
+ return true;
+ }
+ }
+ false
+ };
+ let closing_prefix = if let InlineEdgeBoundary::Closing(node, next) = boundary {
+ self.pending_inline_edges.iter().rposition(|edge| {
+ !edge.is_start && is_ancestor(edge.node, node) && next.is_none_or(|next| !is_ancestor(edge.node, next))
+ })
+ } else {
+ None
+ };
+ let mut edge_index = 0;
+ let mut advance = CssPixels::default();
+ self.pending_inline_edges.retain(|edge| {
+ let emit = match boundary {
+ InlineEdgeBoundary::End => true,
+ InlineEdgeBoundary::BeforeBlock(node) => edge.is_start || !is_ancestor(edge.node, node),
+ InlineEdgeBoundary::BeforeBreak(next) => {
+ edge.is_start || next.is_none_or(|next| !is_ancestor(edge.node, next))
+ }
+ InlineEdgeBoundary::Closing(_, _) => closing_prefix.is_some_and(|last| edge_index <= last),
+ };
+ edge_index += 1;
+ if !emit {
+ return true;
+ }
+ if edge.margin == CssPixels::default()
+ && edge.border == CssPixels::default()
+ && edge.padding == CssPixels::default()
+ {
+ return false;
+ }
+ let mut item = Item::new(ItemType::InlineEdge, edge.node);
+ if edge.is_low {
+ item.margin_start = edge.margin;
+ item.border_start = edge.border;
+ item.padding_start = edge.padding;
+ } else {
+ item.margin_end = edge.margin;
+ item.border_end = edge.border;
+ item.padding_end = edge.padding;
+ }
+ if !edge.is_start
+ && items.last().is_some_and(|last| {
+ last.type_ == ItemType::ForcedBreak && is_ancestor(edge.node, self.forced_break_owner)
+ })
+ {
+ items.insert(items.len() - 1, item);
+ } else {
+ advance += item.border_box_inline_size();
+ items.push(item);
+ }
+ false
+ });
+ self.accumulated_inline_size_for_tabs += advance;
+ }
+
+ fn keep_inline_edge(&mut self, node: Node, sides: &used_values::RootInputCells, is_start: 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)
+ } else {
+ (sides.margin_right, sides.border_right, sides.padding_right)
+ };
+ let physical = if is_start {
+ ExtraBoxMetrics {
+ margin: sides.margin_left,
+ border: sides.border_left,
+ padding: sides.padding_left,
+ }
+ } else {
+ ExtraBoxMetrics {
+ margin: sides.margin_right,
+ border: sides.border_right,
+ padding: sides.padding_right,
+ }
+ };
+ if margin != CssPixels::default()
+ || border != CssPixels::default()
+ || padding != CssPixels::default()
+ || physical.margin != CssPixels::default()
+ || physical.border != CssPixels::default()
+ || physical.padding != CssPixels::default()
+ {
+ self.pending_inline_edges.push(PendingInlineEdge {
+ node,
+ margin,
+ border,
+ padding,
+ physical,
+ is_start,
+ is_low: is_start != reversed,
+ takes_leading_metrics: is_start,
+ });
+ }
+ }
+
fn apply_inline_box_events_at(&mut self, item_index: usize, within_item: bool) {
let position = InlineBoxEvent::position_at(item_index, within_item);
let prepared = self.prepared;
@@ -1128,35 +1297,22 @@ 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);
- let leading = self.extra_leading_metrics.get_or_insert_default();
- leading.margin += sides.margin_left;
- leading.border += sides.border_left;
- leading.padding += sides.padding_left;
+ self.keep_inline_edge(node, &sides, true);
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 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;
- trailing.padding += padding;
+ self.keep_inline_edge(node, &sides, false);
}
/// The end edges of inline boxes that end right after an out-of-flow box are pending when the resolver 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;
+ for edge in &mut self.pending_inline_edges {
+ edge.takes_leading_metrics = true;
+ }
}
fn add_extra_box_model_metrics_to_item(
@@ -1165,32 +1321,53 @@ impl<'context> RunItemResolver<'_, 'context> {
add_leading_metrics: bool,
add_trailing_metrics: bool,
) {
- if add_leading_metrics && let Some(extra) = self.extra_leading_metrics.take() {
- item.margin_start += extra.margin;
- item.border_start += extra.border;
- item.padding_start += extra.padding;
- }
- if add_trailing_metrics && let Some(extra) = self.extra_trailing_metrics.take() {
- item.margin_end += extra.margin;
- item.border_end += extra.border;
- item.padding_end += extra.padding;
- }
+ self.pending_inline_edges.retain(|edge| {
+ if edge.takes_leading_metrics && add_leading_metrics {
+ item.margin_start += edge.physical.margin;
+ item.border_start += edge.physical.border;
+ item.padding_start += edge.physical.padding;
+ false
+ } else if !edge.takes_leading_metrics && add_trailing_metrics {
+ item.margin_end += edge.physical.margin;
+ item.border_end += edge.physical.border;
+ item.padding_end += edge.physical.padding;
+ false
+ } else {
+ true
+ }
+ });
}
fn resolve_item(&mut self, item_index: usize, prepared_item: &PreparedItem) -> Item {
let node = prepared_item.node();
match prepared_item.type_() {
+ ItemType::InlineEdge => unreachable!("unattached inline edges are emitted while resolving items"),
ItemType::Text => self.resolve_text_item(prepared_item),
ItemType::ForcedBreak => {
self.apply_inline_box_events_at(item_index, true);
- Item::new(ItemType::ForcedBreak, node)
+ Item::new(
+ ItemType::ForcedBreak,
+ if self.context().facts(node).is_text_node() {
+ NodeSlotId::INVALID
+ } else {
+ node
+ },
+ )
}
ItemType::AbsolutelyPositionedElement => {
- let preceded = self.extra_leading_metrics.is_some_and(|extra| {
- extra.margin != CssPixels::default()
- || extra.border != CssPixels::default()
- || extra.padding != CssPixels::default()
- });
+ let leading = self
+ .pending_inline_edges
+ .iter()
+ .filter(|edge| edge.takes_leading_metrics)
+ .fold(ExtraBoxMetrics::default(), |mut sum, edge| {
+ sum.margin += edge.physical.margin;
+ sum.border += edge.physical.border;
+ sum.padding += edge.physical.padding;
+ sum
+ });
+ let preceded = leading.margin != CssPixels::default()
+ || leading.border != CssPixels::default()
+ || leading.padding != CssPixels::default();
self.carry_trailing_metrics_past_out_of_flow_box();
self.apply_inline_box_events_at(item_index, true);
let mut item = Item::new(ItemType::AbsolutelyPositionedElement, node);
diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
index 708dfe85798..733456754e4 100644
--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
@@ -458,6 +458,31 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
self.max_block_size_on_current_line = self.max_block_size_on_current_line.max(margin_block_size);
}
+ pub(crate) fn append_inline_edge(&mut self, item: &inline_level_iterator::Item) {
+ self.prepare_to_append_inline_content();
+ let line_index = self.ensure_last_line_index();
+ let facts = self.fragment_facts(item.node);
+ let block_size = TextLayoutBounds::new(self.style(facts.style_source), None).block_size();
+ self.line_mut(line_index).add_fragment(
+ item.node,
+ 0,
+ 0,
+ item.border_start + item.padding_start,
+ item.border_end + item.padding_end,
+ item.margin_start,
+ item.margin_end,
+ CssPixels::default(),
+ block_size,
+ CssPixels::default(),
+ CssPixels::default(),
+ None,
+ facts,
+ false,
+ line_box_fragment::TrailingWhitespace::default(),
+ );
+ self.max_block_size_on_current_line = self.max_block_size_on_current_line.max(block_size);
+ }
+
pub(crate) fn append_text_item(&mut self, item: &mut inline_level_iterator::Item, style: StyleValues) {
let glyphs = item.glyphs.take().unwrap();
let content_block_size = TextLayoutBounds::new(style, Some(&glyphs.font)).block_size();
@@ -858,19 +883,20 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
)
};
let style = self.style(style_source);
- let fragment_baseline = if is_block_ellipsis || self.facts(node).is_text_node() {
- self.text_fragment_layout_bounds(line_index, fragment_index, style)
- .ascent
- } else {
- let box_cells = box_cells.expect("the fragment of an element item carries the cells of its box");
- formatting_context::inline_box_baseline(
- &self.context().callbacks,
- node,
- &box_cells,
- content_baselines
- .expect("the fragment of an element item carries the content baselines of its box"),
- )
- };
+ let fragment_baseline =
+ if is_block_ellipsis || self.facts(node).is_text_node() || self.facts(node).is_fragmented_inline() {
+ self.text_fragment_layout_bounds(line_index, fragment_index, style)
+ .ascent
+ } else {
+ let box_cells = box_cells.expect("the fragment of an element item carries the cells of its box");
+ formatting_context::inline_box_baseline(
+ &self.context().callbacks,
+ node,
+ &box_cells,
+ content_baselines
+ .expect("the fragment of an element item carries the content baselines of its box"),
+ )
+ };
self.line_mut(line_index).fragments[fragment_index].baseline = fragment_baseline;
if has_line_relative_aligned_subtree && self.line_relative_aligned_subtree_root(style_source).is_some() {
continue;
@@ -1284,7 +1310,8 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
}
let is_text_node = self.line(line_index).fragments[fragment_index].is_block_ellipsis
- || self.facts(snapshot.layout_node).is_text_node();
+ || self.facts(snapshot.layout_node).is_text_node()
+ || self.facts(snapshot.layout_node).is_fragmented_inline();
if is_text_node {
let font_box_size = normal_line_height(style);
let font_baseline = Self::baseline_for_style(style, font_box_size);
diff --git a/Tests/LibWeb/Layout/expected/abspos-element-with-inline-as-abspos-containing-block.txt b/Tests/LibWeb/Layout/expected/abspos-element-with-inline-as-abspos-containing-block.txt
index ae3b492c6b6..5371025dfe6 100644
--- a/Tests/LibWeb/Layout/expected/abspos-element-with-inline-as-abspos-containing-block.txt
+++ b/Tests/LibWeb/Layout/expected/abspos-element-with-inline-as-abspos-containing-block.txt
@@ -1,6 +1,7 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline
BlockContainer <body> at [8,8] positioned [8+0+0 300 0+0+8] [8+0+0 300 0+0+8] [BFC] children: inline
+ frag 0 from InlineNode start: 0, length: 0, rect: [82.125,8 0x16] baseline: 12.796875
InlineNode <span.span1> at [8,8] [0+0+0 74.125 16+0+0] [0+0+0 16 0+0+0]
frag 0 from TextNode start: 0, length: 8, rect: [8,8 74.125x16] baseline: 12.796875
"Features"
diff --git a/Tests/LibWeb/Layout/expected/abspos-pseudo-element-with-inline-as-abspos-containing-block.txt b/Tests/LibWeb/Layout/expected/abspos-pseudo-element-with-inline-as-abspos-containing-block.txt
index f9e7f2f91f9..3a6acdc0fed 100644
--- a/Tests/LibWeb/Layout/expected/abspos-pseudo-element-with-inline-as-abspos-containing-block.txt
+++ b/Tests/LibWeb/Layout/expected/abspos-pseudo-element-with-inline-as-abspos-containing-block.txt
@@ -1,6 +1,7 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 32 0+0+0] [BFC] children: not-inline
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 16 0+0+8] children: inline
+ frag 0 from InlineNode start: 0, length: 0, rect: [82.125,8 0x16] baseline: 12.796875
InlineNode <span> at [8,8] [0+0+0 74.125 16+0+0] [0+0+0 16 0+0+0]
frag 0 from TextNode start: 0, length: 8, rect: [8,8 74.125x16] baseline: 12.796875
"Features"
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/abspos-only-child-of-span.txt b/Tests/LibWeb/Layout/expected/block-and-inline/abspos-only-child-of-span.txt
index e196cc00be9..eff61c5805e 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/abspos-only-child-of-span.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/abspos-only-child-of-span.txt
@@ -1,12 +1,14 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
- BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline
- BlockContainer <body> at [0,0] [0+0+0 800 0+0+0] [0+0+0 0 0+0+0] children: not-inline
- BlockContainer <div> at [0,0] positioned [0+0+0 800 0+0+0] [0+0+0 0 0+0+0] children: inline
- InlineNode <span> at [0,0] [0+0+5 0 5+0+0] [0+0+5 20 5+0+0]
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 20 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [0,0] [0+0+0 800 0+0+0] [0+0+0 20 0+0+0] children: not-inline
+ BlockContainer <div> at [0,0] positioned [0+0+0 800 0+0+0] [0+0+0 20 0+0+0] children: inline
+ frag 0 from InlineNode start: 0, length: 0, rect: [5,5 0x10] baseline: 8
+ frag 1 from InlineNode start: 0, length: 0, rect: [5,5 0x10] baseline: 8
+ InlineNode <span> at [5,5] [0+0+5 0 5+0+0] [0+0+5 10 5+0+0]
BlockContainer <b> at [0,0] positioned [0+0+0 10 0+0+0] [0+0+0 20 0+0+0] [BFC] children: inline
frag 0 from TextNode start: 0, length: 1, rect: [0,5 10x10] baseline: 8
"X"
TextNode <#text> (not painted)
SC for Viewport<#document> [0,0 800x600] (z-index: auto)
- SC for BlockContainer<HTML> [0,0 800x0] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x20] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/inline-start-padding-attaches-after-interrupting-block.txt b/Tests/LibWeb/Layout/expected/block-and-inline/inline-start-padding-attaches-after-interrupting-block.txt
deleted file mode 100644
index 5f227ed6057..00000000000
--- a/Tests/LibWeb/Layout/expected/block-and-inline/inline-start-padding-attaches-after-interrupting-block.txt
+++ /dev/null
@@ -1,17 +0,0 @@
-Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
- BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 30 0+0+0] [BFC] children: not-inline
- BlockContainer <body> at [0,0] [0+0+0 800 0+0+0] [0+0+0 30 0+0+0] children: not-inline
- BlockContainer <div> at [0,0] [0+0+0 800 0+0+0] [0+0+0 30 0+0+0] children: inline
- InlineNode <span> at [50,15] [0+0+50 40 0+0+0] [0+0+0 10 0+0+0]
- frag 0 from BlockContainer start: 0, length: 0, rect: [0,0 800x10] baseline: 0
- frag 0 from TextNode start: 0, length: 4, rect: [50,15 40x10] baseline: 8
- "text"
- TextNode <#text> (not painted)
- BlockContainer <div> at [0,0] [0+0+0 800 0+0+0] [0+0+0 10 0+0+0] children: inline
- frag 0 from TextNode start: 0, length: 5, rect: [0,5 50x10] baseline: 8
- "block"
- TextNode <#text> (not painted)
- TextNode <#text> (not painted)
-
-SC for Viewport<#document> [0,0 800x600] (z-index: auto)
- SC for BlockContainer<HTML> [0,0 800x30] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/inline-start-padding-before-interrupting-block.txt b/Tests/LibWeb/Layout/expected/block-and-inline/inline-start-padding-before-interrupting-block.txt
new file mode 100644
index 00000000000..909c579028e
--- /dev/null
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/inline-start-padding-before-interrupting-block.txt
@@ -0,0 +1,18 @@
+Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 50 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [0,0] [0+0+0 800 0+0+0] [0+0+0 50 0+0+0] children: not-inline
+ BlockContainer <div> at [0,0] [0+0+0 800 0+0+0] [0+0+0 50 0+0+0] children: inline
+ frag 0 from InlineNode start: 0, length: 0, rect: [50,5 0x10] baseline: 8
+ InlineNode <span> at [0,35] [0+0+50 40 0+0+0] [0+0+0 10 0+0+0]
+ frag 0 from BlockContainer start: 0, length: 0, rect: [0,20 800x10] baseline: 0
+ frag 0 from TextNode start: 0, length: 4, rect: [0,35 40x10] baseline: 8
+ "text"
+ TextNode <#text> (not painted)
+ BlockContainer <div> at [0,20] [0+0+0 800 0+0+0] [0+0+0 10 0+0+0] children: inline
+ frag 0 from TextNode start: 0, length: 5, rect: [0,25 50x10] baseline: 8
+ "block"
+ TextNode <#text> (not painted)
+ TextNode <#text> (not painted)
+
+SC for Viewport<#document> [0,0 800x600] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x50] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt b/Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt
index 7c53af8f3b0..bb075c7c206 100644
--- a/Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt
+++ b/Tests/LibWeb/Layout/expected/block-and-inline/leading-margin-on-inline-content-that-starts-with-collapsible-whitespace.txt
@@ -1,6 +1,7 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 32 0+0+0] [BFC] children: not-inline
BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 16 0+0+8] children: inline
+ frag 0 from InlineNode start: 0, length: 0, rect: [189.6875,8 0x16] baseline: 12.796875
InlineNode <div> at [28,8] [20+0+0 82.125 0+0+20] [0+0+0 16 0+0+0]
frag 0 from TextNode start: 1, length: 9, rect: [28,8 82.125x16] baseline: 12.796875
"Download "
diff --git a/Tests/LibWeb/Layout/expected/inline-fragment-ordering-flakiness.txt b/Tests/LibWeb/Layout/expected/inline-fragment-ordering-flakiness.txt
index 053eb955296..412a926cbb6 100644
--- a/Tests/LibWeb/Layout/expected/inline-fragment-ordering-flakiness.txt
+++ b/Tests/LibWeb/Layout/expected/inline-fragment-ordering-flakiness.txt
@@ -1,5 +1,6 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 16 0+0+0] [BFC] children: inline
+ frag 0 from InlineNode start: 0, length: 0, rect: [44.84375,0 0x16] baseline: 12.796875
InlineNode <body> at [8,0] [8+0+0 36.84375 0+0+8] [8+0+0 16 0+0+8]
frag 0 from BlockContainer start: 0, length: 0, rect: [8,0 36.84375x16] baseline: 12.796875
BlockContainer <main> at [8,0] inline-block [0+0+0 36.84375 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
diff --git a/Tests/LibWeb/Layout/expected/leading-metrics.txt b/Tests/LibWeb/Layout/expected/leading-metrics.txt
index ad5a05735fa..5d3460a13d2 100644
--- a/Tests/LibWeb/Layout/expected/leading-metrics.txt
+++ b/Tests/LibWeb/Layout/expected/leading-metrics.txt
@@ -5,10 +5,12 @@ Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children
BlockContainer <pre> at [8,13] [0+0+0 784 0+0+0] [13+0+0 39 0+0+13] children: inline
frag 0 from TextNode start: 0, length: 5, rect: [8,13 29.921875x13] baseline: 10.390625
"hello"
- frag 1 from TextNode start: 1, length: 1, rect: [8,39 6.5x13] baseline: 10.390625
+ frag 1 from InlineNode start: 0, length: 0, rect: [18,26 0x13] baseline: 10.390625
+ frag 2 from InlineNode start: 0, length: 0, rect: [18,26 0x13] baseline: 10.390625
+ frag 3 from TextNode start: 1, length: 1, rect: [8,39 6.5x13] baseline: 10.390625
" "
TextNode <#text> (not painted)
- InlineNode <code> at [8,13] [0+10+0 0 0+10+0] [0+10+0 13 0+10+0]
+ InlineNode <code> at [18,26] [0+10+0 0 0+10+0] [0+10+0 13 0+10+0]
TextNode <#text> (not painted)
SC for Viewport<#document> [0,0 800x600] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/expected/table/inline-after-table-cell.txt b/Tests/LibWeb/Layout/expected/table/inline-after-table-cell.txt
index 62d5e2974a7..21fd48213e6 100644
--- a/Tests/LibWeb/Layout/expected/table/inline-after-table-cell.txt
+++ b/Tests/LibWeb/Layout/expected/table/inline-after-table-cell.txt
@@ -1,14 +1,16 @@
Viewport <#document> at [0,0] [0+0+0 800 0+0+0] [0+0+0 600 0+0+0] [BFC] children: not-inline
- BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 16 0+0+0] [BFC] children: not-inline
- BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 0 0+0+8] children: not-inline
+ BlockContainer <html> at [0,0] [0+0+0 800 0+0+0] [0+0+0 32 0+0+0] [BFC] children: not-inline
+ BlockContainer <body> at [8,8] [8+0+0 784 0+0+8] [8+0+0 16 0+0+8] children: not-inline
TableWrapper <(anonymous)> at [8,8] [0+0+0 0 0+0+784] [0+0+0 0 0+0+0] [BFC] children: not-inline
Box <(anonymous)> at [8,8] table-box [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [TFC] children: not-inline
Box <(anonymous)> at [8,8] table-row [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] children: not-inline
BlockContainer <div> at [8,8] table-cell [0+0+0 0 0+0+0] [0+0+0 0 0+0+0] [BFC] children: not-inline
- BlockContainer <(anonymous)> at [8,8] [0+0+0 784 0+0+0] [0+0+0 0 0+0+0] children: inline
+ BlockContainer <(anonymous)> at [8,8] [0+0+0 784 0+0+0] [0+0+0 16 0+0+0] children: inline
+ frag 0 from InlineNode start: 0, length: 0, rect: [11,8 0x16] baseline: 12.796875
+ frag 1 from InlineNode start: 0, length: 0, rect: [11,8 0x16] baseline: 12.796875
TextNode <#text> (not painted)
- InlineNode <span> at [8,8] [0+3+0 0 0+3+0] [0+3+0 16 0+3+0]
+ InlineNode <span> at [11,8] [0+3+0 0 0+3+0] [0+3+0 16 0+3+0]
TextNode <#text> (not painted)
SC for Viewport<#document> [0,0 800x600] (z-index: auto)
- SC for BlockContainer<HTML> [0,0 800x16] (z-index: auto)
+ SC for BlockContainer<HTML> [0,0 800x32] (z-index: auto)
diff --git a/Tests/LibWeb/Layout/input/block-and-inline/inline-start-padding-attaches-after-interrupting-block.html b/Tests/LibWeb/Layout/input/block-and-inline/inline-start-padding-before-interrupting-block.html
similarity index 100%
rename from Tests/LibWeb/Layout/input/block-and-inline/inline-start-padding-attaches-after-interrupting-block.html
rename to Tests/LibWeb/Layout/input/block-and-inline/inline-start-padding-before-interrupting-block.html
diff --git a/Tests/LibWeb/Text/expected/block-in-inline-decorated-edges.txt b/Tests/LibWeb/Text/expected/block-in-inline-decorated-edges.txt
new file mode 100644
index 00000000000..d5c2dd6364d
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/block-in-inline-decorated-edges.txt
@@ -0,0 +1,57 @@
+ltr div no edges: PASS
+ltr div margins: PASS
+ltr div start margin: PASS
+ltr div end margin: PASS
+ltr div negative margins: PASS
+ltr div padding: PASS
+ltr div borders: PASS
+ltr div canceling edges: PASS
+ltr div block-axis edges: PASS
+ltr svg no edges: PASS
+ltr svg margins: PASS
+ltr svg start margin: PASS
+ltr svg end margin: PASS
+ltr svg negative margins: PASS
+ltr svg padding: PASS
+ltr svg borders: PASS
+ltr svg canceling edges: PASS
+ltr svg block-axis edges: PASS
+rtl div no edges: PASS
+rtl div margins: PASS
+rtl div start margin: PASS
+rtl div end margin: PASS
+rtl div negative margins: PASS
+rtl div padding: PASS
+rtl div borders: PASS
+rtl div canceling edges: PASS
+rtl div block-axis edges: PASS
+rtl svg no edges: PASS
+rtl svg margins: PASS
+rtl svg start margin: PASS
+rtl svg end margin: PASS
+rtl svg negative margins: PASS
+rtl svg padding: PASS
+rtl svg borders: PASS
+rtl svg canceling edges: PASS
+rtl svg block-axis edges: PASS
+collapsed whitespace: PASS
+nested canceling margins: PASS
+nested line heights: PASS
+consecutive blocks: PASS
+start edge before break: PASS
+end edge after break: PASS
+start edge before newline: PASS
+end edge before newline: PASS
+multiline text: PASS
+space after break: PASS
+new end edge after break: PASS
+new start edge after break: PASS
+empty inline min-content width: 16
+RTL text padding: 20
+ltr start edge rectangle: 0,8
+ltr inline client size: 0,0
+rtl start edge rectangle: 192,8
+rtl inline client size: 0,0
+empty sibling rectangle: 0,16
+tab after closing edge: PASS
+column start edge rectangle: 0,8
diff --git a/Tests/LibWeb/Text/expected/css/abspos-only-child-of-span-geometry.txt b/Tests/LibWeb/Text/expected/css/abspos-only-child-of-span-geometry.txt
index 3770ac60472..be8efcc5d53 100644
--- a/Tests/LibWeb/Text/expected/css/abspos-only-child-of-span-geometry.txt
+++ b/Tests/LibWeb/Text/expected/css/abspos-only-child-of-span-geometry.txt
@@ -1,3 +1,3 @@
-target rect: 0,10 10x10
+target rect: 0,0 10x10
elementFromPoint hits target: true
host rect count: 1
diff --git a/Tests/LibWeb/Text/expected/multicol-inline-box-without-fragments.txt b/Tests/LibWeb/Text/expected/multicol-inline-box-without-fragments.txt
index 6e0129198de..0a509358608 100644
--- a/Tests/LibWeb/Text/expected/multicol-inline-box-without-fragments.txt
+++ b/Tests/LibWeb/Text/expected/multicol-inline-box-without-fragments.txt
@@ -1,4 +1,4 @@
break-only: 12x26, padding-left 3px
collapsed-whitespace: 12x26, padding-left 3px
starts-after-break: 210 150
-starts-with-break: 220 70
+starts-with-break: 60 10 | 220 60
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/client-props-inline-list-item.txt b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/client-props-inline-list-item.txt
index 9644feb5f78..a2155526c10 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/client-props-inline-list-item.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/cssom-view/client-props-inline-list-item.txt
@@ -2,5 +2,5 @@ Harness status: OK
Found 1 tests
-1 Fail
-Fail client* returns the same for non-replaced inlines regardless of list-item-ness
\ No newline at end of file
+1 Pass
+Pass client* returns the same for non-replaced inlines regardless of list-item-ness
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/href-click-004.txt b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/href-click-004.txt
index 110f770a0e2..e6f69002a55 100644
--- a/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/href-click-004.txt
+++ b/Tests/LibWeb/Text/expected/wpt-import/mathml/relations/html5-tree/href-click-004.txt
@@ -2,10 +2,9 @@ Harness status: OK
Found 28 tests
-26 Pass
-2 Fail
-Fail annotation with href attribute does not react to click.
-Fail annotation-xml with href attribute does not react to click.
+28 Pass
+Pass annotation with href attribute does not react to click.
+Pass annotation-xml with href attribute does not react to click.
Pass maction with href attribute does not react to click.
Pass menclose with href attribute does not react to click.
Pass merror with href attribute does not react to click.
diff --git a/Tests/LibWeb/Text/input/block-in-inline-decorated-edges.html b/Tests/LibWeb/Text/input/block-in-inline-decorated-edges.html
new file mode 100644
index 00000000000..6c5f161a6fe
--- /dev/null
+++ b/Tests/LibWeb/Text/input/block-in-inline-decorated-edges.html
@@ -0,0 +1,129 @@
+<!doctype html>
+<link rel="help" href="https://drafts.csswg.org/css-inline-3/#invisible-line-boxes">
+<script src="include.js"></script>
+<style>
+ .container { font: 16px/16px monospace; width: 200px; }
+ .child { display: block; width: 30px; height: 30px; }
+</style>
+<script>
+ test(() => {
+ const cases = [
+ ["no edges", "", 30, 0],
+ ["margins", "margin-inline: 8px", 62, 16],
+ ["start margin", "margin-inline-start: 8px", 46, 16],
+ ["end margin", "margin-inline-end: 8px", 46, 0],
+ ["negative margins", "margin-inline: -8px", 62, 16],
+ ["padding", "padding-inline: 8px", 62, 16],
+ ["borders", "border-inline: 2px solid", 62, 16],
+ ["canceling edges", "margin-inline: -8px; padding-inline: 8px", 62, 16],
+ ["block-axis edges", "margin-block: 8px; padding-block: 8px", 30, 0],
+ ];
+ for (const direction of ["ltr", "rtl"]) {
+ for (const tag of ["div", "svg"]) {
+ for (const [name, declarations, height, offset] of cases) {
+ const container = document.createElement("div");
+ container.className = "container";
+ container.dir = direction;
+ const link = document.createElement("a");
+ link.style.cssText = declarations;
+ const child = tag === "svg"
+ ? document.createElementNS("http://www.w3.org/2000/svg", "svg")
+ : document.createElement("div");
+ child.classList.add("child");
+ link.append(child);
+ container.append(link);
+ document.body.append(container);
+ const outer = container.getBoundingClientRect();
+ const inner = child.getBoundingClientRect();
+ const actual = [outer.height, inner.top - outer.top];
+ println(`${direction} ${tag} ${name}: ${actual[0] === height && actual[1] === offset ? "PASS" : `${actual} != ${height},${offset}`}`);
+ container.remove();
+ }
+ }
+ }
+ const fixtures = [
+ ["collapsed whitespace", '<a style="margin-inline:8px"> <div class="child"></div> </a>', 62, "16"],
+ ["nested canceling margins", '<a style="margin-inline:8px"><span style="margin-inline:-8px"><div class="child"></div></span></a>', 62, "16"],
+ ["nested line heights", '<a style="margin-inline:8px;line-height:32px"><span style="margin-inline:8px;line-height:16px"><div class="child"></div></span></a>', 94, "32"],
+ ["consecutive blocks", '<a style="margin-inline:8px"><div class="child"></div><div class="child"></div></a>', 92, "16,46"],
+ ["start edge before break", '<a style="margin-inline-start:8px"><br></a>', 16, ""],
+ ["end edge after break", '<a style="margin-inline-end:8px"><br></a>', 16, ""],
+ ["start edge before newline", '<a style="margin-inline-start:8px;white-space:pre">\n</a>', 16, ""],
+ ["end edge before newline", '<a style="padding-inline-end:8px;white-space:pre">\n</a>', 16, ""],
+ ["multiline text", '<a style="padding-inline-end:8px;white-space:pre">\nX</a>', 32, ""],
+ ["space after break", '<a style="margin-inline:8px"><br> </a>', 16, ""],
+ ["new end edge after break", '<br><a style="margin-inline-end:8px"></a>', 32, ""],
+ ["new start edge after break", '<br><a style="margin-inline-start:8px"></a>', 32, ""],
+ ];
+ for (const [name, html, height, offsets] of fixtures) {
+ const container = document.createElement("div");
+ container.className = "container";
+ container.innerHTML = html;
+ document.body.append(container);
+ const outer = container.getBoundingClientRect();
+ const actual = [...container.querySelectorAll(".child")].map(child => child.getBoundingClientRect().top - outer.top).join(",");
+ println(`${name}: ${outer.height === height && actual === offsets ? "PASS" : `${outer.height};${actual} != ${height};${offsets}`}`);
+ container.remove();
+ }
+ const sizing = document.createElement("div");
+ sizing.className = "container";
+ sizing.style.width = "min-content";
+ sizing.innerHTML = '<span style="padding-inline:8px"></span>';
+ document.body.append(sizing);
+ println(`empty inline min-content width: ${sizing.getBoundingClientRect().width}`);
+ sizing.remove();
+
+ const rtl = document.createElement("div");
+ rtl.className = "container";
+ rtl.innerHTML = '<span dir="rtl" style="padding-left:20px">abc</span>';
+ document.body.append(rtl);
+ const range = document.createRange();
+ range.selectNodeContents(rtl.firstChild);
+ println(`RTL text padding: ${range.getBoundingClientRect().left - rtl.firstChild.getBoundingClientRect().left}`);
+ rtl.remove();
+
+ for (const direction of ["ltr", "rtl"]) {
+ const container = document.createElement("div");
+ container.className = "container";
+ container.dir = direction;
+ container.innerHTML = '<a style="padding-inline-start:8px"><div class="child"></div></a>';
+ document.body.append(container);
+ const rect = container.firstChild.getClientRects()[0];
+ println(`${direction} start edge rectangle: ${rect.left - container.getBoundingClientRect().left},${rect.width}`);
+ println(`${direction} inline client size: ${container.firstChild.clientWidth},${container.firstChild.clientHeight}`);
+ container.remove();
+ }
+
+ const sibling = document.createElement("div");
+ sibling.className = "container";
+ sibling.innerHTML = '<a style="margin-right:8px"><div class="child"></div><span id="empty" style="padding-inline:8px"></span></a>';
+ document.body.append(sibling);
+ const siblingRect = sibling.querySelector("#empty").getBoundingClientRect();
+ println(`empty sibling rectangle: ${siblingRect.left - sibling.getBoundingClientRect().left},${siblingRect.width}`);
+ sibling.remove();
+
+ const tabPositions = [];
+ for (const padding of [0, 8]) {
+ const container = document.createElement("div");
+ container.className = "container";
+ container.innerHTML = `<a style="padding-right:${padding}px"><br></a><span style="white-space:pre">\tX</span>`;
+ document.body.append(container);
+ const range = document.createRange();
+ range.setStart(container.lastChild.firstChild, 1);
+ range.setEnd(container.lastChild.firstChild, 2);
+ tabPositions.push(range.getBoundingClientRect().left - container.getBoundingClientRect().left);
+ container.remove();
+ }
+ println(`tab after closing edge: ${tabPositions[0] === tabPositions[1] ? "PASS" : tabPositions.join(",")}`);
+
+ const columns = document.createElement("div");
+ columns.className = "container";
+ columns.style.cssText = "columns:2;column-gap:0;column-fill:auto;height:32px";
+ columns.innerHTML = '<a style="padding-inline:8px"><div class="child" style="break-inside:avoid"></div></a>';
+ document.body.append(columns);
+ const columnRect = columns.getBoundingClientRect();
+ const edgeRect = columns.firstChild.getClientRects()[0];
+ println(`column start edge rectangle: ${edgeRect.left - columnRect.left},${edgeRect.width}`);
+ columns.remove();
+ });
+</script>