diff options
author | Andreas Kling <kling@serenityos.org> | 2020-08-14 19:38:48 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-08-15 00:05:45 +0200 |
commit | 7698feb8ce0e18d1a931d38ffa35ef1f449e097e (patch) | |
tree | 80fbaa648f16bd0543ed86e923b1904afd9697ee /Libraries/LibWeb | |
parent | a37331e236022f2b7a118ed3deb3d877890f4a55 (diff) | |
download | serenity-7698feb8ce0e18d1a931d38ffa35ef1f449e097e.zip |
LibWeb: Add NonDocumentTypeChildNode::next_element_in_pre_order()
This is handy for traversing only the elements in a document.
Diffstat (limited to 'Libraries/LibWeb')
-rw-r--r-- | Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h b/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h index 720edd2429..2e3b3996d9 100644 --- a/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h +++ b/Libraries/LibWeb/DOM/NonDocumentTypeChildNode.h @@ -53,8 +53,18 @@ public: return nullptr; } + Element* next_element_in_pre_order() + { + for (auto* node = static_cast<NodeType*>(this)->next_in_pre_order(); node; node = node->next_in_pre_order()) { + if (is<Element>(*node)) + return downcast<Element>(node); + } + return nullptr; + } + const Element* previous_element_sibling() const { return const_cast<NonDocumentTypeChildNode*>(this)->previous_element_sibling(); } const Element* next_element_sibling() const { return const_cast<NonDocumentTypeChildNode*>(this)->next_element_sibling(); } + const Element* next_element_in_pre_order() const { return const_cast<NonDocumentTypeChildNode*>(this)->next_element_in_pre_order(); } protected: NonDocumentTypeChildNode() { } |