From 567845c4805bd24894bc1788824739e2cdc76b4e Mon Sep 17 00:00:00 2001 From: Luke Date: Mon, 3 Aug 2020 21:23:40 +0100 Subject: [PATCH] LibWeb: Make sure that head and body always get the HTML element Now that document element returns a generic DOM element, we need to make sure head and body get a html element. The spec just says to check if the document element is a html element, so let's do that. --- Libraries/LibWeb/DOM/Document.cpp | 12 ++++++++++-- Libraries/LibWeb/DOM/Document.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index 34ea160b00..7191b42a68 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -132,9 +132,17 @@ const Element* Document::document_element() const return first_child_of_type(); } -const HTML::HTMLHeadElement* Document::head() const +const HTML::HTMLHtmlElement* Document::html_element() const { auto* html = document_element(); + if (is(html)) + return downcast(html); + return nullptr; +} + +const HTML::HTMLHeadElement* Document::head() const +{ + auto* html = html_element(); if (!html) return nullptr; return html->first_child_of_type(); @@ -142,7 +150,7 @@ const HTML::HTMLHeadElement* Document::head() const const HTML::HTMLElement* Document::body() const { - auto* html = document_element(); + auto* html = html_element(); if (!html) return nullptr; return html->first_child_of_type(); diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 5bdac924b7..5e1737c692 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -86,6 +86,7 @@ public: const Node* inspected_node() const { return m_inspected_node; } const Element* document_element() const; + const HTML::HTMLHtmlElement* html_element() const; const HTML::HTMLHeadElement* head() const; const HTML::HTMLElement* body() const;