summaryrefslogtreecommitdiff
path: root/Libraries/LibWeb/DOM
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-10 20:43:54 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-10 22:32:12 +0200
commit0e60e7aef0303263fe9b757e7454f93425884c75 (patch)
tree0c035c149f21f9b1f8c0225e4743385ffa53d4dd /Libraries/LibWeb/DOM
parent9d7ab13b3208b642c179d29632b748fb77ecd0c0 (diff)
downloadserenity-0e60e7aef0303263fe9b757e7454f93425884c75.zip
LibWeb: Add Document create_element() and create_text_node() helpers
Diffstat (limited to 'Libraries/LibWeb/DOM')
-rw-r--r--Libraries/LibWeb/DOM/Document.cpp15
-rw-r--r--Libraries/LibWeb/DOM/Document.h3
2 files changed, 16 insertions, 2 deletions
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 4815013292..1507472598 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -46,6 +46,7 @@
#include <LibWeb/DOM/HTMLHeadElement.h>
#include <LibWeb/DOM/HTMLHtmlElement.h>
#include <LibWeb/DOM/HTMLTitleElement.h>
+#include <LibWeb/DOM/Text.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Dump.h>
#include <LibWeb/Frame.h>
@@ -112,8 +113,8 @@ void Document::fixup()
if (is<HTMLHtmlElement>(first_child()->next_sibling()))
return;
- auto body = create_element(*this, "body");
- auto html = create_element(*this, "html");
+ auto body = create_element("body");
+ auto html = create_element("html");
html->append_child(body);
this->donate_all_children_to(body);
this->append_child(html);
@@ -384,4 +385,14 @@ JS::Value Document::run_javascript(const StringView& source)
return document().interpreter().run(*program);
}
+NonnullRefPtr<Element> Document::create_element(const String& tag_name)
+{
+ return Web::create_element(*this, tag_name);
+}
+
+NonnullRefPtr<Text> Document::create_text_node(const String& data)
+{
+ return adopt(*new Text(*this, data));
+}
+
}
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 66161a8742..601dbf7bd9 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -125,6 +125,9 @@ public:
JS::Value run_javascript(const StringView&);
+ NonnullRefPtr<Element> create_element(const String& tag_name);
+ NonnullRefPtr<Text> create_text_node(const String& data);
+
private:
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;