Document.cpp 905 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include <LibHTML/CSS/StyleResolver.h>
  2. #include <LibHTML/DOM/Document.h>
  3. #include <LibHTML/DOM/Element.h>
  4. #include <LibHTML/Layout/LayoutDocument.h>
  5. #include <stdio.h>
  6. Document::Document()
  7. : ParentNode(*this, NodeType::DOCUMENT_NODE)
  8. {
  9. }
  10. Document::~Document()
  11. {
  12. }
  13. StyleResolver& Document::style_resolver()
  14. {
  15. if (!m_style_resolver)
  16. m_style_resolver = make<StyleResolver>(*this);
  17. return *m_style_resolver;
  18. }
  19. void Document::normalize()
  20. {
  21. if (first_child() != nullptr && first_child()->is_element()) {
  22. const Element& el = static_cast<const Element&>(*first_child());
  23. if (el.tag_name() == "html")
  24. return;
  25. }
  26. NonnullRefPtr<Element> body = adopt(*new Element(*this, "body"));
  27. NonnullRefPtr<Element> html = adopt(*new Element(*this, "html"));
  28. html->append_child(body);
  29. this->donate_all_children_to(body);
  30. this->append_child(html);
  31. }