Skip to content

Commit

Permalink
LibWeb: Use the margin box of floating elements for flowing around
Browse files Browse the repository at this point in the history
Inline content flows around the entire margin box of floating elements,
not just the content box.
  • Loading branch information
awesomekling committed Dec 12, 2020
1 parent 66e9dde commit 2b8c7fa
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
17 changes: 17 additions & 0 deletions Base/res/html/misc/float-2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<style>
#b {
border: 1px solid red;
width: 50px;
height: 50px;
float: left;
}
</style>
</head>
<body>
<div id=b></div>
<div id=a>Text</div>
</body>
</html>
16 changes: 16 additions & 0 deletions Libraries/LibWeb/Layout/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ class Box : public NodeWithStyleAndBoxModelMetrics {
return width() + border_box.left + border_box.right;
}

Gfx::FloatRect content_box_as_relative_rect() const
{
return { m_offset, m_size };
}

Gfx::FloatRect margin_box_as_relative_rect() const
{
auto rect = content_box_as_relative_rect();
auto margin_box = box_model().margin_box(*this);
rect.set_x(rect.x() - margin_box.left);
rect.set_width(rect.width() + margin_box.left + margin_box.right);
rect.set_y(rect.y() - margin_box.top);
rect.set_height(rect.height() + margin_box.top + margin_box.bottom);
return rect;
}

float absolute_x() const { return absolute_rect().x(); }
float absolute_y() const { return absolute_rect().y(); }
Gfx::FloatPoint absolute_position() const { return absolute_rect().location(); }
Expand Down
4 changes: 2 additions & 2 deletions Libraries/LibWeb/Layout/InlineFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static AvailableSpaceForLineInfo available_space_for_line(const InlineFormatting

for (ssize_t i = bfc.left_floating_boxes().size() - 1; i >= 0; --i) {
auto& floating_box = *bfc.left_floating_boxes().at(i);
Gfx::FloatRect rect { floating_box.effective_offset(), floating_box.size() };
auto rect = floating_box.margin_box_as_relative_rect();
if (rect.contains_vertically(y)) {
info.left = rect.right() + 1;
break;
Expand All @@ -73,7 +73,7 @@ static AvailableSpaceForLineInfo available_space_for_line(const InlineFormatting

for (ssize_t i = bfc.right_floating_boxes().size() - 1; i >= 0; --i) {
auto& floating_box = *bfc.right_floating_boxes().at(i);
Gfx::FloatRect rect { floating_box.effective_offset(), floating_box.size() };
auto rect = floating_box.margin_box_as_relative_rect();
if (rect.contains_vertically(y)) {
info.right = rect.left() - 1;
break;
Expand Down

0 comments on commit 2b8c7fa

Please sign in to comment.