Serenity Operating System
1/*
2 * Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
3 *
4 * SPDX-License-Identifier: BSD-2-Clause
5 */
6
7#include <LibGfx/Rect.h>
8#include <LibWeb/Bindings/Intrinsics.h>
9#include <LibWeb/Bindings/ScreenPrototype.h>
10#include <LibWeb/CSS/Screen.h>
11#include <LibWeb/DOM/Document.h>
12#include <LibWeb/Page/Page.h>
13
14namespace Web::CSS {
15
16WebIDL::ExceptionOr<JS::NonnullGCPtr<Screen>> Screen::create(HTML::Window& window)
17{
18 return MUST_OR_THROW_OOM(window.heap().allocate<Screen>(window.realm(), window));
19}
20
21Screen::Screen(HTML::Window& window)
22 : PlatformObject(window.realm())
23 , m_window(window)
24{
25}
26
27JS::ThrowCompletionOr<void> Screen::initialize(JS::Realm& realm)
28{
29 MUST_OR_THROW_OOM(Base::initialize(realm));
30 set_prototype(&Bindings::ensure_web_prototype<Bindings::ScreenPrototype>(realm, "Screen"));
31
32 return {};
33}
34
35void Screen::visit_edges(Cell::Visitor& visitor)
36{
37 Base::visit_edges(visitor);
38 visitor.visit(m_window.ptr());
39}
40
41Gfx::IntRect Screen::screen_rect() const
42{
43 auto screen_rect_in_css_pixels = window().page()->web_exposed_screen_area();
44 return {
45 screen_rect_in_css_pixels.x().value(),
46 screen_rect_in_css_pixels.y().value(),
47 screen_rect_in_css_pixels.width().value(),
48 screen_rect_in_css_pixels.height().value()
49 };
50}
51
52}