mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-25 14:05:15 +00:00
Before this change, we were going through the chain of base classes for each IDL interface object and having them set the prototype to their prototype. Instead of doing that, reorder things so that we set the right prototype immediately in Foo::initialize(), and then don't bother in all the base class overrides. This knocks off a ~1% profile item on Speedometer 3.
80 lines
1.9 KiB
C++
80 lines
1.9 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/CSS/ScreenOrientation.h>
|
|
#include <LibWeb/DOM/Document.h>
|
|
#include <LibWeb/Page/Page.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
GC_DEFINE_ALLOCATOR(Screen);
|
|
|
|
GC::Ref<Screen> Screen::create(HTML::Window& window)
|
|
{
|
|
return window.realm().create<Screen>(window);
|
|
}
|
|
|
|
Screen::Screen(HTML::Window& window)
|
|
: DOM::EventTarget(window.realm())
|
|
, m_window(window)
|
|
{
|
|
}
|
|
|
|
void Screen::initialize(JS::Realm& realm)
|
|
{
|
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(Screen);
|
|
Base::initialize(realm);
|
|
}
|
|
|
|
void Screen::visit_edges(Cell::Visitor& visitor)
|
|
{
|
|
Base::visit_edges(visitor);
|
|
visitor.visit(m_window);
|
|
visitor.visit(m_orientation);
|
|
}
|
|
|
|
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().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()
|
|
};
|
|
}
|
|
|
|
GC::Ref<ScreenOrientation> Screen::orientation()
|
|
{
|
|
if (!m_orientation)
|
|
m_orientation = ScreenOrientation::create(realm());
|
|
return *m_orientation;
|
|
}
|
|
|
|
// 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
|
|
void Screen::set_onchange(GC::Ptr<WebIDL::CallbackType> event_handler)
|
|
{
|
|
set_event_handler_attribute(HTML::EventNames::change, event_handler);
|
|
}
|
|
|
|
// https://w3c.github.io/window-management/#dom-screen-onchange
|
|
GC::Ptr<WebIDL::CallbackType> Screen::onchange()
|
|
{
|
|
return event_handler_attribute(HTML::EventNames::change);
|
|
}
|
|
|
|
}
|