From 40f7cab21ea542828f17a798c73d937bb31aac39 Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Mon, 18 Dec 2023 14:00:30 +0000 Subject: [PATCH] LibWeb: Implement Document::populate_with_html_head_and_body() --- Userland/Libraries/LibWeb/DOM/Document.cpp | 24 ++++++++++++++++++++++ Userland/Libraries/LibWeb/DOM/Document.h | 2 ++ 2 files changed, 26 insertions(+) diff --git a/Userland/Libraries/LibWeb/DOM/Document.cpp b/Userland/Libraries/LibWeb/DOM/Document.cpp index 7d6b85e201..ae3711f799 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.cpp +++ b/Userland/Libraries/LibWeb/DOM/Document.cpp @@ -352,6 +352,30 @@ void Document::initialize(JS::Realm& realm) m_list_of_available_images = heap().allocate(realm); } +// https://html.spec.whatwg.org/multipage/document-lifecycle.html#populate-with-html/head/body +WebIDL::ExceptionOr Document::populate_with_html_head_and_body() +{ + // 1. Let html be the result of creating an element given document, html, and the HTML namespace. + auto html = TRY(DOM::create_element(*this, HTML::TagNames::html, Namespace::HTML)); + + // 2. Let head be the result of creating an element given document, head, and the HTML namespace. + auto head = TRY(DOM::create_element(*this, HTML::TagNames::head, Namespace::HTML)); + + // 3. Let body be the result of creating an element given document, body, and the HTML namespace. + auto body = TRY(DOM::create_element(*this, HTML::TagNames::body, Namespace::HTML)); + + // 4. Append html to document. + TRY(append_child(html)); + + // 5. Append head to html. + TRY(html->append_child(head)); + + // 6. Append body to html. + TRY(html->append_child(body)); + + return {}; +} + void Document::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index 97126d384e..fb93147bcb 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -96,6 +96,8 @@ public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&); virtual ~Document() override; + WebIDL::ExceptionOr populate_with_html_head_and_body(); + JS::GCPtr get_selection() const; String cookie(Cookie::Source = Cookie::Source::NonHttp);