diff options
-rw-r--r-- | Libraries/LibHTML/DOM/Node.cpp | 18 | ||||
-rw-r--r-- | Libraries/LibHTML/DOM/Node.h | 4 |
2 files changed, 22 insertions, 0 deletions
diff --git a/Libraries/LibHTML/DOM/Node.cpp b/Libraries/LibHTML/DOM/Node.cpp index 700a26bcd7..ca9f874780 100644 --- a/Libraries/LibHTML/DOM/Node.cpp +++ b/Libraries/LibHTML/DOM/Node.cpp @@ -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; +} diff --git a/Libraries/LibHTML/DOM/Node.h b/Libraries/LibHTML/DOM/Node.h index e43aa3b2f0..e9771eeb99 100644 --- a/Libraries/LibHTML/DOM/Node.h +++ b/Libraries/LibHTML/DOM/Node.h @@ -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); |