diff --git a/Userland/Libraries/LibWeb/CSS/Screen.cpp b/Userland/Libraries/LibWeb/CSS/Screen.cpp index b4458e7256..2a286f0451 100644 --- a/Userland/Libraries/LibWeb/CSS/Screen.cpp +++ b/Userland/Libraries/LibWeb/CSS/Screen.cpp @@ -11,9 +11,22 @@ namespace Web::CSS { -Screen::Screen(HTML::Window& window) - : m_window(JS::make_handle(window)) +JS::NonnullGCPtr Screen::create(HTML::Window& window) { + return *window.heap().allocate(window.realm(), window); +} + +Screen::Screen(HTML::Window& window) + : PlatformObject(window.realm()) + , m_window(window) +{ + set_prototype(&window.cached_web_prototype("Screen")); +} + +void Screen::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_window.ptr()); } Gfx::IntRect Screen::screen_rect() const diff --git a/Userland/Libraries/LibWeb/CSS/Screen.h b/Userland/Libraries/LibWeb/CSS/Screen.h index ce0e1abd9e..e88813e4b7 100644 --- a/Userland/Libraries/LibWeb/CSS/Screen.h +++ b/Userland/Libraries/LibWeb/CSS/Screen.h @@ -6,26 +6,20 @@ #pragma once -#include #include -#include +#include #include #include namespace Web::CSS { -class Screen final - : public RefCounted - , public Bindings::Wrappable { +class Screen final : public Bindings::PlatformObject { + WEB_PLATFORM_OBJECT(Screen, Bindings::PlatformObject); public: - using WrapperType = Bindings::ScreenWrapper; using AllowOwnPtr = TrueType; - static NonnullOwnPtr create(Badge, HTML::Window& window) - { - return adopt_own(*new Screen(window)); - } + static JS::NonnullGCPtr create(HTML::Window&); i32 width() const { return screen_rect().width(); } i32 height() const { return screen_rect().height(); } @@ -37,11 +31,15 @@ public: private: explicit Screen(HTML::Window&); + virtual void visit_edges(Cell::Visitor&) override; + HTML::Window const& window() const { return *m_window; } Gfx::IntRect screen_rect() const; - JS::Handle m_window; + JS::NonnullGCPtr m_window; }; } + +WRAPPER_HACK(Screen, Web::CSS) diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 65c5468e59..0d2cef56eb 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -477,7 +477,6 @@ class Path2DWrapper; class PerformanceTimingWrapper; class RangePrototype; class ResizeObserverWrapper; -class ScreenWrapper; class SelectionWrapper; class StorageWrapper; class SubtleCryptoWrapper; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index 6907e41210..942ac9be98 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -33,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -95,7 +95,6 @@ JS::NonnullGCPtr Window::create_with_document(DOM::Document& document) Window::Window(JS::Realm& realm) : DOM::EventTarget(realm) , m_crypto(Crypto::Crypto::create()) - , m_screen(CSS::Screen::create({}, *this)) { // FIXME: Should this be WindowPrototype? } @@ -104,7 +103,6 @@ Window::Window(DOM::Document& document) : DOM::EventTarget(document.shape().realm()) , m_associated_document(document) , m_crypto(Crypto::Crypto::create()) - , m_screen(CSS::Screen::create({}, *this)) { } @@ -114,6 +112,7 @@ void Window::visit_edges(JS::Cell::Visitor& visitor) visitor.visit(m_associated_document.ptr()); visitor.visit(m_current_event.ptr()); visitor.visit(m_performance.ptr()); + visitor.visit(m_screen.ptr()); visitor.visit(m_location_object); for (auto& it : m_prototypes) visitor.visit(it.value); @@ -140,6 +139,13 @@ HighResolutionTime::Performance& Window::performance() return *m_performance; } +CSS::Screen& Window::screen() +{ + if (!m_screen) + m_screen = heap().allocate(realm(), *this); + return *m_screen; +} + void Window::alert_impl(String const& message) { if (auto* page = this->page()) diff --git a/Userland/Libraries/LibWeb/HTML/Window.h b/Userland/Libraries/LibWeb/HTML/Window.h index 00a33f37a2..463eb28e51 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.h +++ b/Userland/Libraries/LibWeb/HTML/Window.h @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include @@ -79,7 +78,7 @@ public: Crypto::Crypto& crypto() { return *m_crypto; } - CSS::Screen& screen() { return *m_screen; } + CSS::Screen& screen(); DOM::Event* current_event() { return m_current_event.ptr(); } DOM::Event const* current_event() const { return m_current_event.ptr(); } @@ -149,7 +148,7 @@ private: JS::GCPtr m_performance; NonnullRefPtr m_crypto; - NonnullOwnPtr m_screen; + JS::GCPtr m_screen; AnimationFrameCallbackDriver m_animation_frame_callback_driver; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 5a69d6a356..8e9af7b273 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -17,7 +17,7 @@ libweb_js_wrapper(CSS/CSSSupportsRule NO_INSTANCE) libweb_js_wrapper(CSS/MediaList NO_INSTANCE) libweb_js_wrapper(CSS/MediaQueryList NO_INSTANCE) libweb_js_wrapper(CSS/MediaQueryListEvent NO_INSTANCE) -libweb_js_wrapper(CSS/Screen) +libweb_js_wrapper(CSS/Screen NO_INSTANCE) libweb_js_wrapper(CSS/StyleSheet NO_INSTANCE) libweb_js_wrapper(CSS/StyleSheetList NO_INSTANCE) libweb_js_wrapper(DOM/AbstractRange NO_INSTANCE)