From e756b5450da8a788d5b625f0b0293f137e137b68 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 4 Aug 2022 21:19:30 +0200 Subject: [PATCH] LibWeb: Add a way to construct HTML::Window without a DOM::Document This will be used to implement the rather intricate construction order in the HTML spec. --- Userland/Libraries/LibWeb/HTML/Window.cpp | 18 ++++++++++++++++++ Userland/Libraries/LibWeb/HTML/Window.h | 3 +++ 2 files changed, 21 insertions(+) diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 9be67eb7e8..ab07a46022 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -56,11 +56,24 @@ private: u32 m_handle { 0 }; }; +NonnullRefPtr Window::create() +{ + return adopt_ref(*new Window); +} + NonnullRefPtr Window::create_with_document(DOM::Document& document) { return adopt_ref(*new Window(document)); } +Window::Window() + : DOM::EventTarget() + , m_performance(make(*this)) + , m_crypto(Crypto::Crypto::create()) + , m_screen(CSS::Screen::create({}, *this)) +{ +} + Window::Window(DOM::Document& document) : DOM::EventTarget() , m_associated_document(document) @@ -670,4 +683,9 @@ void Window::cancel_idle_callback(u32 handle) }); } +void Window::set_associated_document(DOM::Document& document) +{ + m_associated_document = document; +} + } diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 41766c024e..dcb711f506 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -34,6 +34,7 @@ class Window final , public HTML::GlobalEventHandlers , public HTML::WindowEventHandlers { public: + static NonnullRefPtr create(); static NonnullRefPtr create_with_document(DOM::Document&); ~Window(); @@ -51,6 +52,7 @@ public: // https://html.spec.whatwg.org/multipage/window-object.html#concept-document-window DOM::Document const& associated_document() const { return *m_associated_document; } DOM::Document& associated_document() { return *m_associated_document; } + void set_associated_document(DOM::Document&); // https://html.spec.whatwg.org/multipage/window-object.html#window-bc HTML::BrowsingContext const* browsing_context() const { return m_associated_document->browsing_context(); } @@ -127,6 +129,7 @@ public: AnimationFrameCallbackDriver& animation_frame_callback_driver() { return m_animation_frame_callback_driver; } private: + Window(); explicit Window(DOM::Document&); // ^HTML::GlobalEventHandlers