mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 05:57:44 +00:00
LibWeb: Simplify Layout::Node::containing_block()
Use first_ancestor_of_type<BlockContainer>() instead of implementing a custom traversal lambda.
This commit is contained in:
parent
6625edb5d2
commit
60c781ebc7
1 changed files with 2 additions and 9 deletions
|
@ -40,15 +40,8 @@ bool Node::can_contain_boxes_with_position_absolute() const
|
||||||
|
|
||||||
const BlockContainer* Node::containing_block() const
|
const BlockContainer* Node::containing_block() const
|
||||||
{
|
{
|
||||||
auto nearest_block_ancestor = [this] {
|
|
||||||
auto* ancestor = parent();
|
|
||||||
while (ancestor && !is<BlockContainer>(*ancestor))
|
|
||||||
ancestor = ancestor->parent();
|
|
||||||
return static_cast<const BlockContainer*>(ancestor);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (is<TextNode>(*this))
|
if (is<TextNode>(*this))
|
||||||
return nearest_block_ancestor();
|
return first_ancestor_of_type<BlockContainer>();
|
||||||
|
|
||||||
auto position = computed_values().position();
|
auto position = computed_values().position();
|
||||||
|
|
||||||
|
@ -64,7 +57,7 @@ const BlockContainer* Node::containing_block() const
|
||||||
if (position == CSS::Position::Fixed)
|
if (position == CSS::Position::Fixed)
|
||||||
return &root();
|
return &root();
|
||||||
|
|
||||||
return nearest_block_ancestor();
|
return first_ancestor_of_type<BlockContainer>();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Node::establishes_stacking_context() const
|
bool Node::establishes_stacking_context() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue