2019-06-29 21:42:07 +02:00
|
|
|
#include <LibHTML/CSS/StyleResolver.h>
|
2019-06-15 23:41:15 +02:00
|
|
|
#include <LibHTML/DOM/Document.h>
|
|
|
|
#include <LibHTML/DOM/Element.h>
|
2019-09-29 16:24:57 +02:00
|
|
|
#include <LibHTML/DOM/HTMLHeadElement.h>
|
|
|
|
#include <LibHTML/DOM/HTMLHtmlElement.h>
|
|
|
|
#include <LibHTML/DOM/HTMLTitleElement.h>
|
2019-06-15 23:41:15 +02:00
|
|
|
#include <LibHTML/Layout/LayoutDocument.h>
|
2019-06-15 22:49:44 +02:00
|
|
|
#include <stdio.h>
|
2019-06-15 18:55:47 +02:00
|
|
|
|
|
|
|
Document::Document()
|
2019-09-29 11:43:07 +02:00
|
|
|
: ParentNode(*this, NodeType::DOCUMENT_NODE)
|
2019-06-15 18:55:47 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Document::~Document()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-06-29 21:42:07 +02:00
|
|
|
StyleResolver& Document::style_resolver()
|
2019-06-15 22:49:44 +02:00
|
|
|
{
|
2019-06-29 21:42:07 +02:00
|
|
|
if (!m_style_resolver)
|
|
|
|
m_style_resolver = make<StyleResolver>(*this);
|
|
|
|
return *m_style_resolver;
|
2019-06-15 22:49:44 +02:00
|
|
|
}
|
2019-09-25 12:26:26 +03:00
|
|
|
|
|
|
|
void Document::normalize()
|
|
|
|
{
|
|
|
|
if (first_child() != nullptr && first_child()->is_element()) {
|
|
|
|
const Element& el = static_cast<const Element&>(*first_child());
|
|
|
|
if (el.tag_name() == "html")
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-29 11:43:07 +02:00
|
|
|
NonnullRefPtr<Element> body = adopt(*new Element(*this, "body"));
|
|
|
|
NonnullRefPtr<Element> html = adopt(*new Element(*this, "html"));
|
2019-09-25 12:26:26 +03:00
|
|
|
html->append_child(body);
|
|
|
|
this->donate_all_children_to(body);
|
|
|
|
this->append_child(html);
|
|
|
|
}
|
2019-09-29 16:24:57 +02:00
|
|
|
|
|
|
|
const HTMLHtmlElement* Document::document_element() const
|
|
|
|
{
|
|
|
|
return static_cast<const HTMLHtmlElement*>(first_child_with_tag_name("html"));
|
|
|
|
}
|
|
|
|
|
|
|
|
const HTMLHeadElement* Document::head() const
|
|
|
|
{
|
|
|
|
auto* html = document_element();
|
|
|
|
if (!html)
|
|
|
|
return nullptr;
|
|
|
|
return static_cast<const HTMLHeadElement*>(html->first_child_with_tag_name("head"));
|
|
|
|
}
|
|
|
|
|
|
|
|
String Document::title() const
|
|
|
|
{
|
|
|
|
auto* head_element = head();
|
|
|
|
if (!head_element)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
auto* title_element = static_cast<const HTMLTitleElement*>(head_element->first_child_with_tag_name("title"));
|
|
|
|
if (!title_element)
|
|
|
|
return {};
|
|
|
|
|
|
|
|
return title_element->text_content();
|
|
|
|
}
|