Skip to content

Commit

Permalink
Correct baseline positioning of display: inline-block
Browse files Browse the repository at this point in the history
  • Loading branch information
mrobinson committed Dec 19, 2023
1 parent eab96ed commit 1a0037e
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions components/layout_2020/flow/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ impl<'a, 'b> InlineFormattingContextState<'a, 'b> {
inline_box,
&self.containing_block,
self.layout_context,
Some(self.current_inline_container_state()),
self.current_inline_container_state(),
inline_box.is_last_fragment,
);

Expand Down Expand Up @@ -1511,6 +1511,7 @@ impl InlineFormattingContext {
containing_block.style.to_arc(),
layout_context,
None, /* parent_container */
self.text_decoration_line,
layout_context.style_context.quirks_mode() == QuirksMode::NoQuirks, /* create_strut */
),
linebreaker: None,
Expand Down Expand Up @@ -1586,8 +1587,8 @@ impl InlineFormattingContext {

let mut collapsible_margins_in_children = CollapsedBlockMargins::zero();
let content_block_size = ifc.current_line.start_position.block;
collapsible_margins_in_children.collapsed_through =
!ifc.had_inflow_content && content_block_size == Length::zero() &&
collapsible_margins_in_children.collapsed_through = !ifc.had_inflow_content &&
content_block_size == Length::zero() &&
collapsible_with_parent_start_margin.0;

return FlowLayout {
Expand Down Expand Up @@ -1627,18 +1628,17 @@ impl InlineContainerState {
style: Arc<ComputedValues>,
layout_context: &LayoutContext,
parent_container: Option<&InlineContainerState>,
parent_text_decoration_line: TextDecorationLine,
create_strut: bool,
) -> Self {
let text_decoration_line = parent_text_decoration_line | style.clone_text_decoration_line();
let font_metrics = font_metrics_from_style(layout_context, &style);
let mut text_decoration_line = style.clone_text_decoration_line();
let line_height = line_height(&style, &font_metrics);

let mut baseline_offset = Au::zero();
let mut strut_block_sizes =
Self::get_block_sizes_with_style(&style, &font_metrics, line_height);
if let Some(parent_container) = parent_container {
text_decoration_line |= parent_container.text_decoration_line;

// The baseline offset from `vertical-align` might adjust where our block size contribution is
// within the line.
baseline_offset = parent_container.get_cumulative_baseline_offset_for_child(
Expand Down Expand Up @@ -1797,7 +1797,7 @@ impl InlineBoxContainerState {
inline_box: &InlineBox,
containing_block: &ContainingBlock,
layout_context: &LayoutContext,
parent_container: Option<&InlineContainerState>,
parent_container: &InlineContainerState,
is_last_fragment: bool,
) -> Self {
let style = inline_box.style.clone();
Expand All @@ -1808,7 +1808,14 @@ impl InlineBoxContainerState {
create_strut = create_strut ||
(style.writing_mode.is_horizontal() && !pbm.padding_border_sums.inline.is_zero());

let base = InlineContainerState::new(style, layout_context, parent_container, create_strut);
let parent_text_decoration_line = parent_container.text_decoration_line;
let base = InlineContainerState::new(
style,
layout_context,
Some(parent_container),
parent_text_decoration_line,
create_strut,
);
Self {
base,
base_fragment_info: inline_box.base_fragment_info,
Expand Down Expand Up @@ -1863,7 +1870,6 @@ impl IndependentFormattingContext {
size,
};

let baseline_offset = content_rect.max_block_position();
(
BoxFragment::new(
replaced.base_fragment_info,
Expand All @@ -1877,7 +1883,7 @@ impl IndependentFormattingContext {
None, /* last_inflow_baseline_offset */
CollapsedBlockMargins::zero(),
),
baseline_offset,
None,
)
},
IndependentFormattingContext::NonReplaced(non_replaced) => {
Expand Down Expand Up @@ -1957,8 +1963,8 @@ impl IndependentFormattingContext {
non_replaced.style.get_box().overflow_x,
independent_layout.last_inflow_baseline_offset,
) {
(Overflow::Visible, Some(baseline)) => baseline,
_ => block_size,
(Overflow::Visible, Some(baseline)) => Some(baseline),
_ => None,
};

(
Expand Down Expand Up @@ -1987,8 +1993,12 @@ impl IndependentFormattingContext {
ifc.process_soft_wrap_opportunity();
}

let baseline_offset = Au::from_f32_px((baseline_offset + pbm_sums.block_start).px());
let size = &pbm_sums.sum() + &fragment.content_rect.size;
let baseline_offset = baseline_offset
.map(|baseline_offset| baseline_offset + pbm_sums.block_start)
.unwrap_or(size.block);
let baseline_offset = Au::from_f32_px(baseline_offset.px());

let (block_sizes, baseline_offset_in_parent) =
self.get_block_sizes_and_baseline_offset(ifc, size.block, baseline_offset);
ifc.push_content_line_item_to_unbreakable_segment(
Expand Down

0 comments on commit 1a0037e

Please sign in to comment.