Skip to content

Commit 89ba003

Browse files
committed
LibWeb: Account for negative margins when calculating float intrusion
If a box has a negative margin-left, it may have a negative effective offset within its parent BFC root coordinate system. We can account for this when calculating the amount of left-side float intrusion by flooring the X offset at 0.
1 parent 0e5ec8c commit 89ba003

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Viewport <#document> at (0,0) content-size 800x600 children: not-inline
2+
BlockContainer <html> at (1,1) content-size 798x55.40625 [BFC] children: not-inline
3+
BlockContainer <body> at (110,10) content-size 300x37.40625 positioned children: not-inline
4+
BlockContainer <div> at (61,11) content-size 200x35.40625 children: inline
5+
line 0 width: 159.859375, height: 17.46875, bottom: 17.46875, baseline: 13.53125
6+
frag 0 from TextNode start: 0, length: 19, rect: [61,11 159.859375x17.46875]
7+
"there are no floats"
8+
line 1 width: 163.875, height: 17.9375, bottom: 35.40625, baseline: 13.53125
9+
frag 0 from TextNode start: 20, length: 21, rect: [61,28 163.875x17.46875]
10+
"intruding on this div"
11+
TextNode <#text>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!doctype html><style>
2+
* { border: 1px solid black; }
3+
html { background: white; }
4+
body {
5+
position: relative;
6+
left: 100px;
7+
background: pink;
8+
width: 300px;
9+
}
10+
div {
11+
margin-left: -50px;
12+
background: orange;
13+
width: 200px;
14+
}
15+
</style><body><div>there are no floats intruding on this div

Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ FormattingContext::SpaceUsedByFloats BlockFormattingContext::intrusion_by_floats
10661066
CSSPixels y_in_root = box_in_root_rect.y() + y_in_box;
10671067
auto space_used_by_floats_in_root = space_used_by_floats(y_in_root);
10681068

1069-
auto left_intrusion = max(CSSPixels(0), space_used_by_floats_in_root.left - box_in_root_rect.x());
1069+
auto left_intrusion = max(CSSPixels(0), space_used_by_floats_in_root.left - max(CSSPixels(0), box_in_root_rect.x()));
10701070

10711071
CSSPixels offset_from_containing_block_chain_margins_between_here_and_root = 0;
10721072
for (auto const* containing_block = static_cast<Box const*>(&box); containing_block && containing_block != &root(); containing_block = containing_block->containing_block()) {

Userland/Libraries/LibWeb/Layout/InlineFormattingContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ CSSPixels InlineFormattingContext::leftmost_x_offset_at(CSSPixels y) const
5151
}
5252
// The left edge of the containing block is to the left of the rightmost left-side float.
5353
// We adjust the inline content insertion point by the overlap between the containing block and the float.
54-
return space.left - box_in_root_rect.x();
54+
return space.left - max(CSSPixels(0), box_in_root_rect.x());
5555
}
5656

5757
CSSPixels InlineFormattingContext::available_space_for_line(CSSPixels y) const

0 commit comments

Comments
 (0)