mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +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:
parent
cad326f323
commit
5a6c36dc91
Notes:
sideshowbarker
2024-07-19 11:46:41 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/5a6c36dc917
2 changed files with 22 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ enum class NodeType : unsigned {
|
|||
};
|
||||
|
||||
class Document;
|
||||
class Element;
|
||||
class HTMLElement;
|
||||
class HTMLAnchorElement;
|
||||
class ParentNode;
|
||||
|
@ -63,6 +64,9 @@ public:
|
|||
|
||||
void set_layout_node(Badge<LayoutNode>, LayoutNode* layout_node) const { m_layout_node = layout_node; }
|
||||
|
||||
const Element* previous_element_sibling() const;
|
||||
const Element* next_element_sibling() const;
|
||||
|
||||
protected:
|
||||
Node(Document&, NodeType);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue