LibWeb: Refactor out-of-flow and in-flow into functions
The concept of out-of-flow and in-flow elements is used in a few places in the layout code. This change refactors these concepts into functions.
This commit is contained in:
parent
9c80326053
commit
196922ae5b
Notes:
sideshowbarker
2024-07-17 11:29:41 +09:00
Author: https://github.com/arthurc Commit: https://github.com/LadybirdBrowser/ladybird/commit/196922ae5b Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/443
2 changed files with 13 additions and 9 deletions
Userland/Libraries/LibWeb/Layout
|
@ -164,6 +164,14 @@ public:
|
|||
u32 initial_quote_nesting_level() const { return m_initial_quote_nesting_level; }
|
||||
void set_initial_quote_nesting_level(u32 value) { m_initial_quote_nesting_level = value; }
|
||||
|
||||
// An element is called out of flow if it is floated, absolutely positioned, or is the root element.
|
||||
// https://www.w3.org/TR/CSS22/visuren.html#positioning-scheme
|
||||
bool is_out_of_flow() const { return is_floating() || is_absolutely_positioned(); }
|
||||
|
||||
// An element is called in-flow if it is not out-of-flow.
|
||||
// https://www.w3.org/TR/CSS22/visuren.html#positioning-scheme
|
||||
bool is_in_flow() const { return !is_out_of_flow(); }
|
||||
|
||||
protected:
|
||||
Node(DOM::Document&, DOM::Node*);
|
||||
|
||||
|
|
|
@ -42,9 +42,7 @@ TreeBuilder::TreeBuilder() = default;
|
|||
static bool has_inline_or_in_flow_block_children(Layout::Node const& layout_node)
|
||||
{
|
||||
for (auto child = layout_node.first_child(); child; child = child->next_sibling()) {
|
||||
if (child->is_inline())
|
||||
return true;
|
||||
if (!child->is_floating() && !child->is_absolutely_positioned())
|
||||
if (child->is_inline() || child->is_in_flow())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -57,7 +55,7 @@ static bool has_in_flow_block_children(Layout::Node const& layout_node)
|
|||
for (auto child = layout_node.first_child(); child; child = child->next_sibling()) {
|
||||
if (child->is_inline())
|
||||
continue;
|
||||
if (!child->is_floating() && !child->is_absolutely_positioned())
|
||||
if (child->is_in_flow())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -98,9 +96,7 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
|
|||
return layout_parent;
|
||||
}
|
||||
|
||||
bool is_out_of_flow = layout_node.is_absolutely_positioned() || layout_node.is_floating();
|
||||
|
||||
if (is_out_of_flow
|
||||
if (layout_node.is_out_of_flow()
|
||||
&& !layout_parent.display().is_flex_inside()
|
||||
&& !layout_parent.display().is_grid_inside()
|
||||
&& layout_parent.last_child()->is_anonymous()
|
||||
|
@ -115,7 +111,7 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
|
|||
return layout_parent;
|
||||
}
|
||||
|
||||
if (is_out_of_flow) {
|
||||
if (layout_node.is_out_of_flow()) {
|
||||
// Block is out-of-flow, it can have inline siblings if necessary.
|
||||
return layout_parent;
|
||||
}
|
||||
|
@ -128,7 +124,7 @@ static Layout::Node& insertion_parent_for_block_node(Layout::NodeWithStyle& layo
|
|||
for (JS::GCPtr<Layout::Node> child = layout_parent.first_child(); child; child = next) {
|
||||
next = child->next_sibling();
|
||||
// NOTE: We let out-of-flow children stay in the parent, to preserve tree structure.
|
||||
if (child->is_floating() || child->is_absolutely_positioned())
|
||||
if (child->is_out_of_flow())
|
||||
continue;
|
||||
layout_parent.remove_child(*child);
|
||||
children.append(*child);
|
||||
|
|
Loading…
Add table
Reference in a new issue