1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 23:57:43 +00:00

LibWeb: Make sure collapsed margins are not ignored if box creates FC

Fixes a bug that if box creates new formatting context then all already
collapsed margins are ignored and only margin_top is used.
This commit is contained in:
Aliaksandr Kalenik 2023-05-22 13:03:00 +03:00 committed by Andreas Kling
parent 668578ddc0
commit 76aa17be86
3 changed files with 30 additions and 12 deletions

View file

@ -553,23 +553,20 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain
m_margin_state.reset();
}
CSSPixels margin_top = 0;
auto independent_formatting_context = create_independent_formatting_context_if_needed(m_state, box);
m_margin_state.add_margin(box_state.margin_top);
m_margin_state.update_block_waiting_for_final_y_position();
CSSPixels margin_top = m_margin_state.current_collapsed_margin();
if (m_margin_state.has_block_container_waiting_for_final_y_position()) {
// If first child margin top will collapse with margin-top of containing block then margin-top of child is 0
margin_top = 0;
}
if (independent_formatting_context) {
// Margins of elements that establish new formatting contexts do not collapse with their in-flow children
m_margin_state.reset();
margin_top = box_state.margin_top;
} else {
m_margin_state.add_margin(box_state.margin_top);
m_margin_state.update_block_waiting_for_final_y_position();
margin_top = m_margin_state.current_collapsed_margin();
if (m_margin_state.has_block_container_waiting_for_final_y_position()) {
// If first child margin top will collapse with margin-top of containing block then margin-top of child is 0
margin_top = 0;
}
}
place_block_level_element_in_normal_flow_vertically(box, y + margin_top);