diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp index a7f1871322..778a1cf00c 100644 --- a/Libraries/LibWeb/DOM/Node.cpp +++ b/Libraries/LibWeb/DOM/Node.cpp @@ -155,4 +155,30 @@ void Node::dispatch_event(NonnullRefPtr event) parent()->dispatch_event(move(event)); } +String Node::child_text_content() const +{ + if (!is(*this)) + return String::empty(); + + StringBuilder builder; + to(*this).for_each_child([&](auto& child) { + if (is(child)) + builder.append(to(child).text_content()); + }); + return builder.build(); +} + +const Node* Node::root() const +{ + const Node* root = this; + while (root->parent()) + root = root->parent(); + return root; +} + +bool Node::is_connected() const +{ + return root() && root()->is_document(); +} + } diff --git a/Libraries/LibWeb/DOM/Node.h b/Libraries/LibWeb/DOM/Node.h index 479ec8960f..771a87f78d 100644 --- a/Libraries/LibWeb/DOM/Node.h +++ b/Libraries/LibWeb/DOM/Node.h @@ -94,8 +94,13 @@ public: const HTMLAnchorElement* enclosing_link_element() const; const HTMLElement* enclosing_html_element() const; + String child_text_content() const; + virtual bool is_html_element() const { return false; } + const Node* root() const; + bool is_connected() const; + template const T* first_child_of_type() const;