mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-25 19:04:58 +00:00
LibHTML: Add Node::{next,previous}_element_sibling()
These helpers return the next/previous sibling Node that's actually an element. This will be useful in the CSS engine since CSS doesn't care about text nodes.
This commit is contained in:
@@ -83,3 +83,21 @@ String Node::text_content() const
|
||||
builder.trim(1);
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
const Element* Node::next_element_sibling() const
|
||||
{
|
||||
for (auto* node = next_sibling(); node; node = node->next_sibling()) {
|
||||
if (node->is_element())
|
||||
return static_cast<const Element*>(node);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const Element* Node::previous_element_sibling() const
|
||||
{
|
||||
for (auto* node = previous_sibling(); node; node = node->previous_sibling()) {
|
||||
if (node->is_element())
|
||||
return static_cast<const Element*>(node);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user