item
\ No newline at end of file
diff --git a/Tests/LibWeb/Layout/input/block-and-inline/grid-container-should-avoid-overlapping-floats.html b/Tests/LibWeb/Layout/input/block-and-inline/grid-container-should-avoid-overlapping-floats.html
new file mode 100644
index 0000000000..dbacfe71be
--- /dev/null
+++ b/Tests/LibWeb/Layout/input/block-and-inline/grid-container-should-avoid-overlapping-floats.html
@@ -0,0 +1,13 @@
+
right
\ No newline at end of file
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
index 432ebf3138..ff101f941e 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
@@ -117,6 +117,19 @@ void BlockFormattingContext::parent_context_did_dimension_child_root_box()
}
}
+bool BlockFormattingContext::box_should_avoid_floats_because_it_establishes_fc(Box const& box)
+{
+ if (auto formatting_context_type = formatting_context_type_created_by_box(box); formatting_context_type.has_value()) {
+ if (formatting_context_type.value() == Type::Block)
+ return true;
+ if (formatting_context_type.value() == Type::Flex)
+ return true;
+ if (formatting_context_type.value() == Type::Grid)
+ return true;
+ }
+ return false;
+}
+
void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const& available_space, LayoutMode)
{
if (box.is_absolutely_positioned()) {
@@ -125,7 +138,9 @@ void BlockFormattingContext::compute_width(Box const& box, AvailableSpace const&
}
auto remaining_available_space = available_space;
- if (available_space.width.is_definite() && creates_block_formatting_context(box)) {
+ if (available_space.width.is_definite() && box_should_avoid_floats_because_it_establishes_fc(box)) {
+ // NOTE: Although CSS 2.2 specification says that only block formatting contexts should avoid floats,
+ // we also do this for flex and grid formatting contexts, because that how other engines behave.
// 9.5 Floats
// The border box of a table, a block-level replaced element, or an element in the normal flow that establishes a
// new block formatting context (such as an element with 'overflow' other than 'visible') must not overlap the margin
diff --git a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
index a2014cc56b..eec02a897b 100644
--- a/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
+++ b/Userland/Libraries/LibWeb/Layout/BlockFormattingContext.h
@@ -29,6 +29,7 @@ public:
auto const& left_side_floats() const { return m_left_floats; }
auto const& right_side_floats() const { return m_right_floats; }
+ bool box_should_avoid_floats_because_it_establishes_fc(Box const&);
void compute_width(Box const&, AvailableSpace const&, LayoutMode = LayoutMode::Normal);
// https://www.w3.org/TR/css-display/#block-formatting-context-root