1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:37:35 +00:00

LibWeb: Make CSS::Screen forward its ref count to DOM::Window

This commit is contained in:
Andreas Kling 2021-12-09 15:47:48 +01:00
parent 7fc770cfac
commit c268d0fa13
4 changed files with 12 additions and 10 deletions

View file

@ -7,19 +7,18 @@
#include <LibGfx/Rect.h>
#include <LibWeb/CSS/Screen.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Page/Page.h>
namespace Web::CSS {
Screen::Screen(DOM::Window& window)
: m_window(window)
: RefCountForwarder(window)
{
}
Gfx::IntRect Screen::screen_rect() const
{
return m_window.page()->screen_rect();
return window().page()->screen_rect();
}
}

View file

@ -6,22 +6,25 @@
#pragma once
#include <AK/RefCountForwarder.h>
#include <LibGfx/Rect.h>
#include <LibWeb/Bindings/Wrappable.h>
#include <LibWeb/DOM/Window.h>
#include <LibWeb/Forward.h>
namespace Web::CSS {
class Screen final
: public RefCounted<Screen>
: public RefCountForwarder<DOM::Window>
, public Bindings::Wrappable {
public:
using WrapperType = Bindings::ScreenWrapper;
using AllowOwnPtr = TrueType;
static NonnullRefPtr<Screen> create(DOM::Window& window)
static NonnullOwnPtr<Screen> create(Badge<DOM::Window>, DOM::Window& window)
{
return adopt_ref(*new Screen(window));
return adopt_own(*new Screen(window));
}
i32 width() const { return screen_rect().width(); }
@ -34,9 +37,9 @@ public:
private:
explicit Screen(DOM::Window&);
Gfx::IntRect screen_rect() const;
DOM::Window const& window() const { return ref_count_target(); }
DOM::Window& m_window;
Gfx::IntRect screen_rect() const;
};
}

View file

@ -111,7 +111,7 @@ Window::Window(Document& document)
, m_associated_document(document)
, m_performance(make<HighResolutionTime::Performance>(*this))
, m_crypto(Crypto::Crypto::create())
, m_screen(CSS::Screen::create(*this))
, m_screen(CSS::Screen::create({}, *this))
{
}

View file

@ -114,7 +114,7 @@ private:
NonnullOwnPtr<HighResolutionTime::Performance> m_performance;
NonnullRefPtr<Crypto::Crypto> m_crypto;
NonnullRefPtr<CSS::Screen> m_screen;
NonnullOwnPtr<CSS::Screen> m_screen;
RefPtr<Event> m_current_event;
HashMap<i32, NonnullRefPtr<RequestAnimationFrameCallback>> m_request_animation_frame_callbacks;