summaryrefslogtreecommitdiff
path: root/Libraries
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-08-03 13:30:18 +0200
committerAndreas Kling <kling@serenityos.org>2020-08-03 13:30:18 +0200
commite27726dc921bbaf75dca663cf393f667a83f39c0 (patch)
tree702f8ceb4af65437a47404399dfb640970dc1725 /Libraries
parent64a82100bd0c480f1d85cad3782312946443e088 (diff)
downloadserenity-e27726dc921bbaf75dca663cf393f667a83f39c0.zip
LibWeb: Add the Document.documentElement API
Also change DOM::Document::document_element() to return an Element* and not an HTML::HTMLHtmlElement since that's not the only kind of documentElement we might encounter.
Diffstat (limited to 'Libraries')
-rw-r--r--Libraries/LibWeb/DOM/Document.cpp4
-rw-r--r--Libraries/LibWeb/DOM/Document.h2
-rw-r--r--Libraries/LibWeb/DOM/Document.idl1
-rw-r--r--Libraries/LibWeb/Tests/Document/documentElement.js8
4 files changed, 12 insertions, 3 deletions
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index 5f6a29fdd6..34ea160b00 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -127,9 +127,9 @@ void Document::fixup()
this->append_child(html);
}
-const HTML::HTMLHtmlElement* Document::document_element() const
+const Element* Document::document_element() const
{
- return first_child_of_type<HTML::HTMLHtmlElement>();
+ return first_child_of_type<Element>();
}
const HTML::HTMLHeadElement* Document::head() const
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 6997e1b493..5bdac924b7 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -85,7 +85,7 @@ public:
Node* inspected_node() { return m_inspected_node; }
const Node* inspected_node() const { return m_inspected_node; }
- const HTML::HTMLHtmlElement* document_element() const;
+ const Element* document_element() const;
const HTML::HTMLHeadElement* head() const;
const HTML::HTMLElement* body() const;
diff --git a/Libraries/LibWeb/DOM/Document.idl b/Libraries/LibWeb/DOM/Document.idl
index 9d1184115b..f2cbf8eafa 100644
--- a/Libraries/LibWeb/DOM/Document.idl
+++ b/Libraries/LibWeb/DOM/Document.idl
@@ -9,6 +9,7 @@ interface Document : Node {
readonly attribute DOMString compatMode;
readonly attribute DocumentType? doctype;
+ readonly attribute Element? documentElement;
readonly attribute HTMLElement? body;
}
diff --git a/Libraries/LibWeb/Tests/Document/documentElement.js b/Libraries/LibWeb/Tests/Document/documentElement.js
new file mode 100644
index 0000000000..a9b084e78e
--- /dev/null
+++ b/Libraries/LibWeb/Tests/Document/documentElement.js
@@ -0,0 +1,8 @@
+loadPage("file:///res/html/misc/blank.html");
+
+afterInitialPageLoad(() => {
+ test("Basic functionality", () => {
+ expect(document.documentElement).not.toBe(null);
+ expect(document.documentElement.nodeName).toBe("html");
+ });
+});