diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index d54853fa7df..b9bbe5ddd6e 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -2158,17 +2158,35 @@ impl Fragment { let block_flow = flow.as_block(); let start_margin = block_flow.fragment.margin.block_start; let end_margin = block_flow.fragment.margin.block_end; - if style.get_box().overflow_y == overflow_x::T::visible { - if let Some(baseline_offset) = flow.baseline_offset_of_last_line_box_in_flow() { - let ascent = baseline_offset + start_margin; - let space_below_baseline = block_flow.fragment.border_box.size.block - - baseline_offset + end_margin; - return InlineMetrics::new(ascent, space_below_baseline, baseline_offset) - } - } - let ascent = block_flow.fragment.border_box.size.block + end_margin; - let space_above_baseline = start_margin + ascent; - InlineMetrics::new(space_above_baseline, Au(0), ascent) + let border_box_block_size = block_flow.fragment.border_box.size.block; + + // -------- + // margin + // top -------- + + + // | | + // | | + // A ..pogo.. | + baseline_offset_of_last_line_box_in_flow() + // | + // -------- + border_box_block_size + // margin + // B -------- + // + // ยง 10.8.1 says that the baseline (and thus ascent, which is the + // distance from the baseline to the top) should be A if it has an + // in-flow line box and if overflow: visible, and B otherwise. + let ascent = + match (flow.baseline_offset_of_last_line_box_in_flow(), + style.get_box().overflow_y) { + // Case A + (Some(baseline_offset), overflow_x::T::visible) => baseline_offset, + // Case B + _ => border_box_block_size + end_margin, + }; + + let space_below_baseline = border_box_block_size + end_margin - ascent; + let space_above_baseline = ascent + start_margin; + + InlineMetrics::new(space_above_baseline, space_below_baseline, ascent) } }