Skip to content

Commit 30b51b0

Browse files
kalenikaliaksandrawesomekling
authored andcommitted
LibWeb: Fix y position calculation for blocks with clearance
This change fixes problem that y position of blocks with clearance might not include border_top and padding_top by changing `place_block_level_element_in_normal_flow_vertically` to accept y position without `border_box_top` and adding it on the last step when clearance is already taken in account. Bug reproducer: ```html <style> .a { border: 10px salmon solid; width: 50px; height: 50px; float: left; } .b { clear: both; border: 20px slateblue solid; width: 50px; height: 50px; } </style> <div class="a"></div><div class="b"></div><div class="c"></div> ```
1 parent 7762c1a commit 30b51b0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ void BlockFormattingContext::layout_block_level_box(Box const& box, BlockContain
470470
margin_top = 0;
471471
}
472472

473-
place_block_level_element_in_normal_flow_vertically(box, current_y + box_state.border_box_top() + margin_top);
473+
place_block_level_element_in_normal_flow_vertically(box, current_y + margin_top);
474474
place_block_level_element_in_normal_flow_horizontally(box, available_space);
475475

476476
OwnPtr<FormattingContext> independent_formatting_context;
@@ -625,6 +625,8 @@ void BlockFormattingContext::place_block_level_element_in_normal_flow_vertically
625625
if ((computed_values.clear() == CSS::Clear::Right || computed_values.clear() == CSS::Clear::Both) && !child_box.is_flex_item())
626626
clear_floating_boxes(m_right_floats);
627627

628+
y += box_state.border_box_top();
629+
628630
box_state.set_content_offset(CSSPixelPoint { box_state.offset.x(), y.value() });
629631
}
630632

@@ -712,7 +714,7 @@ void BlockFormattingContext::layout_floating_box(Box const& box, BlockContainer
712714
auto y = line_builder->y_for_float_to_be_inserted_here(box);
713715
box_state.set_content_y(y + box_state.margin_box_top());
714716
} else {
715-
place_block_level_element_in_normal_flow_vertically(box, y + box_state.margin_box_top());
717+
place_block_level_element_in_normal_flow_vertically(box, y + box_state.margin_top);
716718
place_block_level_element_in_normal_flow_horizontally(box, available_space);
717719
}
718720

0 commit comments

Comments
 (0)