2021-04-03 19:14:39 -03:00
|
|
|
/*
|
2022-12-14 14:40:33 -03:00
|
|
|
* Copyright (c) 2021-2022, Linus Groh <linusg@serenityos.org>
|
2021-04-03 19:14:39 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-04-03 19:14:39 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <LibGfx/Rect.h>
|
2022-09-24 19:34:04 -03:00
|
|
|
#include <LibWeb/Bindings/Intrinsics.h>
|
|
|
|
|
#include <LibWeb/Bindings/ScreenPrototype.h>
|
2021-04-03 19:14:39 -03:00
|
|
|
#include <LibWeb/CSS/Screen.h>
|
2024-04-02 17:44:05 -03:00
|
|
|
#include <LibWeb/CSS/ScreenOrientation.h>
|
2021-04-03 19:14:39 -03:00
|
|
|
#include <LibWeb/DOM/Document.h>
|
|
|
|
|
#include <LibWeb/Page/Page.h>
|
|
|
|
|
|
|
|
|
|
namespace Web::CSS {
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC_DEFINE_ALLOCATOR(Screen);
|
2023-11-19 15:47:52 -03:00
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<Screen> Screen::create(HTML::Window& window)
|
2022-08-31 13:52:54 -03:00
|
|
|
{
|
2024-11-13 13:50:17 -03:00
|
|
|
return window.realm().create<Screen>(window);
|
2022-08-31 13:52:54 -03:00
|
|
|
}
|
|
|
|
|
|
2022-03-07 19:08:26 -03:00
|
|
|
Screen::Screen(HTML::Window& window)
|
2024-04-05 13:15:43 -03:00
|
|
|
: DOM::EventTarget(window.realm())
|
2022-08-31 13:52:54 -03:00
|
|
|
, m_window(window)
|
|
|
|
|
{
|
2023-01-10 08:28:20 -03:00
|
|
|
}
|
|
|
|
|
|
2023-08-07 03:41:28 -03:00
|
|
|
void Screen::initialize(JS::Realm& realm)
|
2023-01-10 08:28:20 -03:00
|
|
|
{
|
2024-03-16 09:13:08 -03:00
|
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(Screen);
|
2025-04-20 11:22:57 -03:00
|
|
|
Base::initialize(realm);
|
2022-08-31 13:52:54 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Screen::visit_edges(Cell::Visitor& visitor)
|
2021-04-03 19:14:39 -03:00
|
|
|
{
|
2022-08-31 13:52:54 -03:00
|
|
|
Base::visit_edges(visitor);
|
2023-11-19 00:18:00 -03:00
|
|
|
visitor.visit(m_window);
|
2024-04-02 17:44:05 -03:00
|
|
|
visitor.visit(m_orientation);
|
2021-04-03 19:14:39 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Gfx::IntRect Screen::screen_rect() const
|
|
|
|
|
{
|
2023-12-15 16:33:16 -03:00
|
|
|
auto screen_rect_in_css_pixels = window().page().web_exposed_screen_area();
|
2022-11-25 14:07:19 -03:00
|
|
|
return {
|
2023-06-12 15:37:35 -03:00
|
|
|
screen_rect_in_css_pixels.x().to_int(),
|
|
|
|
|
screen_rect_in_css_pixels.y().to_int(),
|
|
|
|
|
screen_rect_in_css_pixels.width().to_int(),
|
|
|
|
|
screen_rect_in_css_pixels.height().to_int()
|
2022-11-25 14:07:19 -03:00
|
|
|
};
|
2021-04-03 19:14:39 -03:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ref<ScreenOrientation> Screen::orientation()
|
2024-04-02 17:44:05 -03:00
|
|
|
{
|
|
|
|
|
if (!m_orientation)
|
|
|
|
|
m_orientation = ScreenOrientation::create(realm());
|
|
|
|
|
return *m_orientation;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-05 13:15:43 -03:00
|
|
|
// https://w3c.github.io/window-management/#dom-screen-isextended
|
|
|
|
|
bool Screen::is_extended() const
|
|
|
|
|
{
|
|
|
|
|
dbgln("FIXME: Unimplemented Screen::is_extended");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://w3c.github.io/window-management/#dom-screen-onchange
|
2024-11-14 12:01:23 -03:00
|
|
|
void Screen::set_onchange(GC::Ptr<WebIDL::CallbackType> event_handler)
|
2024-04-05 13:15:43 -03:00
|
|
|
{
|
|
|
|
|
set_event_handler_attribute(HTML::EventNames::change, event_handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// https://w3c.github.io/window-management/#dom-screen-onchange
|
2024-11-14 12:01:23 -03:00
|
|
|
GC::Ptr<WebIDL::CallbackType> Screen::onchange()
|
2024-04-05 13:15:43 -03:00
|
|
|
{
|
|
|
|
|
return event_handler_attribute(HTML::EventNames::change);
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-03 19:14:39 -03:00
|
|
|
}
|