ladybird/Userland/Libraries/LibWeb/CSS/Screen.cpp
Timothy Flynn b75b7f0c0d LibJS+Everywhere: Propagate Cell::initialize errors from Heap::allocate
Callers that are already in a fallible context will now TRY to allocate
cells. Callers in infallible contexts get a FIXME.
2023-01-29 00:02:45 +00:00

52 lines
1.3 KiB
C++

/*
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibGfx/Rect.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/Bindings/ScreenPrototype.h>
#include <LibWeb/CSS/Screen.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Page/Page.h>
namespace Web::CSS {
JS::NonnullGCPtr<Screen> Screen::create(HTML::Window& window)
{
return window.heap().allocate<Screen>(window.realm(), window).release_allocated_value_but_fixme_should_propagate_errors();
}
Screen::Screen(HTML::Window& window)
: PlatformObject(window.realm())
, m_window(window)
{
}
JS::ThrowCompletionOr<void> Screen::initialize(JS::Realm& realm)
{
MUST_OR_THROW_OOM(Base::initialize(realm));
set_prototype(&Bindings::ensure_web_prototype<Bindings::ScreenPrototype>(realm, "Screen"));
return {};
}
void Screen::visit_edges(Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
visitor.visit(m_window.ptr());
}
Gfx::IntRect Screen::screen_rect() const
{
auto screen_rect_in_css_pixels = window().page()->web_exposed_screen_area();
return {
screen_rect_in_css_pixels.x().value(),
screen_rect_in_css_pixels.y().value(),
screen_rect_in_css_pixels.width().value(),
screen_rect_in_css_pixels.height().value()
};
}
}