mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:27:35 +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:
parent
0622b60fbd
commit
567845c480
2 changed files with 11 additions and 2 deletions
|
@ -132,9 +132,17 @@ const Element* Document::document_element() const
|
||||||
return first_child_of_type<Element>();
|
return first_child_of_type<Element>();
|
||||||
}
|
}
|
||||||
|
|
||||||
const HTML::HTMLHeadElement* Document::head() const
|
const HTML::HTMLHtmlElement* Document::html_element() const
|
||||||
{
|
{
|
||||||
auto* html = document_element();
|
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)
|
if (!html)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return html->first_child_of_type<HTML::HTMLHeadElement>();
|
return html->first_child_of_type<HTML::HTMLHeadElement>();
|
||||||
|
@ -142,7 +150,7 @@ const HTML::HTMLHeadElement* Document::head() const
|
||||||
|
|
||||||
const HTML::HTMLElement* Document::body() const
|
const HTML::HTMLElement* Document::body() const
|
||||||
{
|
{
|
||||||
auto* html = document_element();
|
auto* html = html_element();
|
||||||
if (!html)
|
if (!html)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return html->first_child_of_type<HTML::HTMLBodyElement>();
|
return html->first_child_of_type<HTML::HTMLBodyElement>();
|
||||||
|
|
|
@ -86,6 +86,7 @@ public:
|
||||||
const Node* inspected_node() const { return m_inspected_node; }
|
const Node* inspected_node() const { return m_inspected_node; }
|
||||||
|
|
||||||
const Element* document_element() const;
|
const Element* document_element() const;
|
||||||
|
const HTML::HTMLHtmlElement* html_element() const;
|
||||||
const HTML::HTMLHeadElement* head() const;
|
const HTML::HTMLHeadElement* head() const;
|
||||||
const HTML::HTMLElement* body() const;
|
const HTML::HTMLElement* body() const;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue