1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:48:12 +00:00

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.
This commit is contained in:
Luke 2020-08-03 21:23:40 +01:00 committed by Andreas Kling
parent 0622b60fbd
commit 567845c480
2 changed files with 11 additions and 2 deletions

View file

@ -132,9 +132,17 @@ const Element* Document::document_element() const
return first_child_of_type<Element>();
}
const HTML::HTMLHeadElement* Document::head() const
const HTML::HTMLHtmlElement* Document::html_element() const
{
auto* html = document_element();
if (is<HTML::HTMLHtmlElement>(html))
return downcast<HTML::HTMLHtmlElement>(html);
return nullptr;
}
const HTML::HTMLHeadElement* Document::head() const
{
auto* html = html_element();
if (!html)
return nullptr;
return html->first_child_of_type<HTML::HTMLHeadElement>();
@ -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<HTML::HTMLBodyElement>();