Skip to content

Commit

Permalink
LibWeb: Use contained_children instead of abspos_children
Browse files Browse the repository at this point in the history
  • Loading branch information
ebanner committed Oct 31, 2024
1 parent d244c14 commit 1be2641
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 24 deletions.
11 changes: 1 addition & 10 deletions Userland/Libraries/LibWeb/DOM/Document.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1166,13 +1166,10 @@ void Document::update_layout()

// Assign each box that establishes a formatting context a list of absolutely positioned children it should take care of during layout
m_layout_root->for_each_in_inclusive_subtree_of_type<Layout::Box>([&](auto& child) {
child.clear_contained_abspos_children();
child.clear_contained_children();
return TraversalDecision::Continue;
});
m_layout_root->for_each_in_inclusive_subtree([&](auto& child) {
if (!child.is_absolutely_positioned())
return TraversalDecision::Continue;
if (auto* containing_block = child.containing_block()) {
auto* closest_box_that_establishes_formatting_context = containing_block;
while (closest_box_that_establishes_formatting_context) {
Expand All @@ -1184,17 +1181,11 @@ void Document::update_layout()
closest_box_that_establishes_formatting_context = closest_box_that_establishes_formatting_context->containing_block();
}
VERIFY(closest_box_that_establishes_formatting_context);
closest_box_that_establishes_formatting_context->add_contained_abspos_child(child);
closest_box_that_establishes_formatting_context->add_contained_child(child);
}
return TraversalDecision::Continue;
});

m_layout_root->for_each_in_inclusive_subtree([&](auto& child) {
if (auto* containing_block = child.containing_block())
containing_block->add_contained_child(child);
return TraversalDecision::Continue;
});

Layout::LayoutState layout_state;

{
Expand Down
6 changes: 4 additions & 2 deletions Userland/Libraries/LibWeb/Layout/BlockFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ void BlockFormattingContext::parent_context_did_dimension_child_root_box()

if (m_layout_mode == LayoutMode::Normal) {
// We can also layout absolutely positioned boxes within this BFC.
for (auto& child : root().contained_abspos_children()) {
auto& box = verify_cast<Box>(*child);
for (auto& child : root().contained_children()) {
if (!child.is_absolutely_positioned())
continue;
auto& box = verify_cast<Box>(child);
auto& cb_state = m_state.get(*box.containing_block());
auto available_width = AvailableSize::make_definite(cb_state.content_width() + cb_state.padding_left + cb_state.padding_right);
auto available_height = AvailableSize::make_definite(cb_state.content_height() + cb_state.padding_top + cb_state.padding_bottom);
Expand Down
1 change: 0 additions & 1 deletion Userland/Libraries/LibWeb/Layout/Box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Box::~Box()
void Box::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_contained_abspos_children);
}

JS::GCPtr<Painting::Paintable> Box::create_paintable() const
Expand Down
4 changes: 0 additions & 4 deletions Userland/Libraries/LibWeb/Layout/Box.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ class Box : public NodeWithStyleAndBoxModelMetrics {

virtual JS::GCPtr<Painting::Paintable> create_paintable() const override;

void add_contained_abspos_child(JS::NonnullGCPtr<Node> child) { m_contained_abspos_children.append(child); }
void clear_contained_abspos_children() { m_contained_abspos_children.clear(); }
Vector<JS::NonnullGCPtr<Node>> const& contained_abspos_children() const { return m_contained_abspos_children; }

virtual void visit_edges(Cell::Visitor&) override;

Expand All @@ -65,7 +62,6 @@ class Box : public NodeWithStyleAndBoxModelMetrics {
Optional<CSSPixels> m_natural_height;
Optional<CSSPixelFraction> m_natural_aspect_ratio;

Vector<JS::NonnullGCPtr<Node>> m_contained_abspos_children;
};

template<>
Expand Down
6 changes: 4 additions & 2 deletions Userland/Libraries/LibWeb/Layout/FlexFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ void FlexFormattingContext::parent_context_did_dimension_child_root_box()
return IterationDecision::Continue;
});

for (auto& child : flex_container().contained_abspos_children()) {
auto& box = verify_cast<Box>(*child);
for (auto& child : flex_container().contained_children()) {
if (!child.is_absolutely_positioned())
continue;
auto& box = verify_cast<Box>(child);
auto& cb_state = m_state.get(*box.containing_block());
auto available_width = AvailableSize::make_definite(cb_state.content_width() + cb_state.padding_left + cb_state.padding_right);
auto available_height = AvailableSize::make_definite(cb_state.content_height() + cb_state.padding_top + cb_state.padding_bottom);
Expand Down
6 changes: 4 additions & 2 deletions Userland/Libraries/LibWeb/Layout/GridFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2208,8 +2208,10 @@ void GridFormattingContext::parent_context_did_dimension_child_root_box()
return IterationDecision::Continue;
});

for (auto const& child : grid_container().contained_abspos_children()) {
auto const& box = verify_cast<Box>(*child);
for (auto const& child : grid_container().contained_children()) {
if (!child.is_absolutely_positioned())
continue;
auto const& box = verify_cast<Box>(child);
layout_absolutely_positioned_element(box);
}
}
Expand Down
5 changes: 4 additions & 1 deletion Userland/Libraries/LibWeb/Layout/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ Node::Node(DOM::Document& document, DOM::Node* node)
node->set_layout_node({}, *this);
}

Node::~Node() = default;
Node::~Node() {
if (m_sibling_contained_node.is_in_list())
m_sibling_contained_node.remove();
}

void Node::visit_edges(Cell::Visitor& visitor)
{
Expand Down
6 changes: 4 additions & 2 deletions Userland/Libraries/LibWeb/Layout/TableFormattingContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1633,8 +1633,10 @@ void TableFormattingContext::parent_context_did_dimension_child_root_box()
return TraversalDecision::Continue;
});

for (auto& child : context_box().contained_abspos_children()) {
auto& box = verify_cast<Box>(*child);
for (auto& child : context_box().contained_children()) {
if (!child.is_absolutely_positioned())
continue;
auto& box = verify_cast<Box>(child);
auto& cb_state = m_state.get(*box.containing_block());
auto available_width = AvailableSize::make_definite(cb_state.content_width() + cb_state.padding_left + cb_state.padding_right);
auto available_height = AvailableSize::make_definite(cb_state.content_height() + cb_state.padding_top + cb_state.padding_bottom);
Expand Down

0 comments on commit 1be2641

Please sign in to comment.