1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-24 22:07:34 +00:00

LibWeb: Make CSS::Screen GC-allocated

This commit is contained in:
Andreas Kling 2022-08-31 18:52:54 +02:00
parent d5e831988e
commit 8c90e08e0b
6 changed files with 36 additions and 21 deletions

View file

@ -11,9 +11,22 @@
namespace Web::CSS { namespace Web::CSS {
Screen::Screen(HTML::Window& window) JS::NonnullGCPtr<Screen> Screen::create(HTML::Window& window)
: m_window(JS::make_handle(window))
{ {
return *window.heap().allocate<Screen>(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 Gfx::IntRect Screen::screen_rect() const

View file

@ -6,26 +6,20 @@
#pragma once #pragma once
#include <AK/RefCountForwarder.h>
#include <LibGfx/Rect.h> #include <LibGfx/Rect.h>
#include <LibWeb/Bindings/Wrappable.h> #include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/Forward.h> #include <LibWeb/Forward.h>
#include <LibWeb/HTML/Window.h> #include <LibWeb/HTML/Window.h>
namespace Web::CSS { namespace Web::CSS {
class Screen final class Screen final : public Bindings::PlatformObject {
: public RefCounted<Screen> WEB_PLATFORM_OBJECT(Screen, Bindings::PlatformObject);
, public Bindings::Wrappable {
public: public:
using WrapperType = Bindings::ScreenWrapper;
using AllowOwnPtr = TrueType; using AllowOwnPtr = TrueType;
static NonnullOwnPtr<Screen> create(Badge<HTML::Window>, HTML::Window& window) static JS::NonnullGCPtr<Screen> create(HTML::Window&);
{
return adopt_own(*new Screen(window));
}
i32 width() const { return screen_rect().width(); } i32 width() const { return screen_rect().width(); }
i32 height() const { return screen_rect().height(); } i32 height() const { return screen_rect().height(); }
@ -37,11 +31,15 @@ public:
private: private:
explicit Screen(HTML::Window&); explicit Screen(HTML::Window&);
virtual void visit_edges(Cell::Visitor&) override;
HTML::Window const& window() const { return *m_window; } HTML::Window const& window() const { return *m_window; }
Gfx::IntRect screen_rect() const; Gfx::IntRect screen_rect() const;
JS::Handle<HTML::Window> m_window; JS::NonnullGCPtr<HTML::Window> m_window;
}; };
} }
WRAPPER_HACK(Screen, Web::CSS)

View file

@ -477,7 +477,6 @@ class Path2DWrapper;
class PerformanceTimingWrapper; class PerformanceTimingWrapper;
class RangePrototype; class RangePrototype;
class ResizeObserverWrapper; class ResizeObserverWrapper;
class ScreenWrapper;
class SelectionWrapper; class SelectionWrapper;
class StorageWrapper; class StorageWrapper;
class SubtleCryptoWrapper; class SubtleCryptoWrapper;

View file

@ -25,7 +25,6 @@
#include <LibWeb/Bindings/LocationObject.h> #include <LibWeb/Bindings/LocationObject.h>
#include <LibWeb/Bindings/NavigatorObject.h> #include <LibWeb/Bindings/NavigatorObject.h>
#include <LibWeb/Bindings/Replaceable.h> #include <LibWeb/Bindings/Replaceable.h>
#include <LibWeb/Bindings/ScreenWrapper.h>
#include <LibWeb/Bindings/SelectionWrapper.h> #include <LibWeb/Bindings/SelectionWrapper.h>
#include <LibWeb/Bindings/StorageWrapper.h> #include <LibWeb/Bindings/StorageWrapper.h>
#include <LibWeb/Bindings/WindowObjectHelper.h> #include <LibWeb/Bindings/WindowObjectHelper.h>
@ -33,6 +32,7 @@
#include <LibWeb/CSS/MediaQueryList.h> #include <LibWeb/CSS/MediaQueryList.h>
#include <LibWeb/CSS/Parser/Parser.h> #include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h> #include <LibWeb/CSS/ResolvedCSSStyleDeclaration.h>
#include <LibWeb/CSS/Screen.h>
#include <LibWeb/Crypto/Crypto.h> #include <LibWeb/Crypto/Crypto.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Event.h> #include <LibWeb/DOM/Event.h>
@ -95,7 +95,6 @@ JS::NonnullGCPtr<Window> Window::create_with_document(DOM::Document& document)
Window::Window(JS::Realm& realm) Window::Window(JS::Realm& realm)
: DOM::EventTarget(realm) : DOM::EventTarget(realm)
, m_crypto(Crypto::Crypto::create()) , m_crypto(Crypto::Crypto::create())
, m_screen(CSS::Screen::create({}, *this))
{ {
// FIXME: Should this be WindowPrototype? // FIXME: Should this be WindowPrototype?
} }
@ -104,7 +103,6 @@ Window::Window(DOM::Document& document)
: DOM::EventTarget(document.shape().realm()) : DOM::EventTarget(document.shape().realm())
, m_associated_document(document) , m_associated_document(document)
, m_crypto(Crypto::Crypto::create()) , 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_associated_document.ptr());
visitor.visit(m_current_event.ptr()); visitor.visit(m_current_event.ptr());
visitor.visit(m_performance.ptr()); visitor.visit(m_performance.ptr());
visitor.visit(m_screen.ptr());
visitor.visit(m_location_object); visitor.visit(m_location_object);
for (auto& it : m_prototypes) for (auto& it : m_prototypes)
visitor.visit(it.value); visitor.visit(it.value);
@ -140,6 +139,13 @@ HighResolutionTime::Performance& Window::performance()
return *m_performance; return *m_performance;
} }
CSS::Screen& Window::screen()
{
if (!m_screen)
m_screen = heap().allocate<CSS::Screen>(realm(), *this);
return *m_screen;
}
void Window::alert_impl(String const& message) void Window::alert_impl(String const& message)
{ {
if (auto* page = this->page()) if (auto* page = this->page())

View file

@ -12,7 +12,6 @@
#include <AK/URL.h> #include <AK/URL.h>
#include <LibJS/Heap/Heap.h> #include <LibJS/Heap/Heap.h>
#include <LibWeb/Bindings/CrossOriginAbstractOperations.h> #include <LibWeb/Bindings/CrossOriginAbstractOperations.h>
#include <LibWeb/CSS/Screen.h>
#include <LibWeb/DOM/EventTarget.h> #include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/Forward.h> #include <LibWeb/Forward.h>
#include <LibWeb/HTML/AnimationFrameCallbackDriver.h> #include <LibWeb/HTML/AnimationFrameCallbackDriver.h>
@ -79,7 +78,7 @@ public:
Crypto::Crypto& crypto() { return *m_crypto; } 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* current_event() { return m_current_event.ptr(); }
DOM::Event const* current_event() const { return m_current_event.ptr(); } DOM::Event const* current_event() const { return m_current_event.ptr(); }
@ -149,7 +148,7 @@ private:
JS::GCPtr<HighResolutionTime::Performance> m_performance; JS::GCPtr<HighResolutionTime::Performance> m_performance;
NonnullRefPtr<Crypto::Crypto> m_crypto; NonnullRefPtr<Crypto::Crypto> m_crypto;
NonnullOwnPtr<CSS::Screen> m_screen; JS::GCPtr<CSS::Screen> m_screen;
AnimationFrameCallbackDriver m_animation_frame_callback_driver; AnimationFrameCallbackDriver m_animation_frame_callback_driver;

View file

@ -17,7 +17,7 @@ libweb_js_wrapper(CSS/CSSSupportsRule NO_INSTANCE)
libweb_js_wrapper(CSS/MediaList NO_INSTANCE) libweb_js_wrapper(CSS/MediaList NO_INSTANCE)
libweb_js_wrapper(CSS/MediaQueryList NO_INSTANCE) libweb_js_wrapper(CSS/MediaQueryList NO_INSTANCE)
libweb_js_wrapper(CSS/MediaQueryListEvent 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/StyleSheet NO_INSTANCE)
libweb_js_wrapper(CSS/StyleSheetList NO_INSTANCE) libweb_js_wrapper(CSS/StyleSheetList NO_INSTANCE)
libweb_js_wrapper(DOM/AbstractRange NO_INSTANCE) libweb_js_wrapper(DOM/AbstractRange NO_INSTANCE)