|
@@ -155,4 +155,30 @@ void Node::dispatch_event(NonnullRefPtr<Event> event)
|
|
|
parent()->dispatch_event(move(event));
|
|
|
}
|
|
|
|
|
|
+String Node::child_text_content() const
|
|
|
+{
|
|
|
+ if (!is<ParentNode>(*this))
|
|
|
+ return String::empty();
|
|
|
+
|
|
|
+ StringBuilder builder;
|
|
|
+ to<ParentNode>(*this).for_each_child([&](auto& child) {
|
|
|
+ if (is<Text>(child))
|
|
|
+ builder.append(to<Text>(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();
|
|
|
+}
|
|
|
+
|
|
|
}
|