LibWeb: Don't mess up the order of nodes when wrapping inline contents

Whenever we introduce a block element in a container that at that point
has only had inline children, we create an anonymous wrapper for all the
inline elements so we can keep the invariant that each container
contains either inline or non-inline children. For some reason, we
ignore all the out-of-flow nodes since they are layed out separately and
it was thought that this shouldn't matter.

However, if we are dealing with inline blocks and floating blocks, the
order of the inline contents _including_ out-of-flow nodes becomes very
important: floating blocks need to take the order of nodes into account
when positioning themselves.

Fix this by simply hoisting the out-of-flow nodes into the anonymous
wrapper as well.

Fixes the order of blocks in #4212. The gap is still not present.
This commit is contained in:
Jelle Raaijmakers 2025-04-23 22:26:45 +02:00 committed by Andreas Kling
commit 6f800caeaa
Notes: github-actions[bot] 2025-04-24 17:13:52 +00:00
14 changed files with 112 additions and 52 deletions

View file

@ -19,8 +19,6 @@
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/Dump.h>
#include <LibWeb/HTML/HTMLInputElement.h>
#include <LibWeb/HTML/HTMLLIElement.h>
#include <LibWeb/HTML/HTMLOListElement.h>
#include <LibWeb/HTML/HTMLSlotElement.h>
#include <LibWeb/Layout/FieldSetBox.h>
#include <LibWeb/Layout/ListItemBox.h>
@ -128,12 +126,8 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
// Parent block has inline-level children (our siblings); wrap these siblings into an anonymous wrapper block.
Vector<GC::Ref<Node>> children;
for (GC::Ptr<Node> child = layout_parent.first_child(); child; child = child->next_sibling()) {
// NOTE: We let out-of-flow children stay in the parent, to preserve tree structure.
if (child->is_out_of_flow())
continue;
for (GC::Ptr<Node> child = layout_parent.first_child(); child; child = child->next_sibling())
children.append(*child);
}
auto wrapper = layout_parent.create_anonymous_wrapper();
wrapper->set_children_are_inline(true);