LibWeb/HTML: Port Window.screen to IDL

This commit is contained in:
Linus Groh 2023-03-06 19:51:16 +00:00
parent 2beb99b76e
commit 0c691087ca
3 changed files with 12 additions and 24 deletions

View file

@ -118,13 +118,6 @@ void Window::visit_edges(JS::Cell::Visitor& visitor)
Window::~Window() = default;
CSS::Screen& Window::screen()
{
if (!m_screen)
m_screen = heap().allocate<CSS::Screen>(realm(), *this).release_allocated_value_but_fixme_should_propagate_errors();
return *m_screen;
}
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#normalizing-the-feature-name
static StringView normalize_feature_name(StringView name)
{
@ -1037,7 +1030,6 @@ WebIDL::ExceptionOr<void> Window::initialize_web_interfaces(Badge<WindowEnvironm
MUST_OR_THROW_OOM(Bindings::WindowGlobalMixin::initialize(realm, *this));
// FIXME: These should be native accessors, not properties
define_native_accessor(realm, "screen", screen_getter, screen_setter, JS::Attribute::Enumerable | JS::Attribute::Configurable);
define_native_accessor(realm, "innerWidth", inner_width_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "innerHeight", inner_height_getter, {}, JS::Attribute::Enumerable);
define_native_accessor(realm, "devicePixelRatio", device_pixel_ratio_getter, {}, JS::Attribute::Enumerable | JS::Attribute::Configurable);
@ -1334,6 +1326,15 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::MediaQueryList>> Window::match_media(S
return media_query_list;
}
// https://w3c.github.io/csswg-drafts/cssom-view/#dom-window-screen
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::Screen>> Window::screen()
{
// The screen attribute must return the Screen object associated with the Window object.
if (!m_screen)
m_screen = MUST_OR_THROW_OOM(heap().allocate<CSS::Screen>(realm(), *this));
return JS::NonnullGCPtr { *m_screen };
}
// https://w3c.github.io/hr-time/#dom-windoworworkerglobalscope-performance
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> Window::performance()
{
@ -1523,17 +1524,6 @@ size_t Window::document_tree_child_browsing_context_count() const
return this_browsing_context->document_tree_child_browsing_context_count();
}
JS_DEFINE_NATIVE_FUNCTION(Window::screen_getter)
{
auto* impl = TRY(impl_from(vm));
return &impl->screen();
}
JS_DEFINE_NATIVE_FUNCTION(Window::screen_setter)
{
REPLACEABLE_PROPERTY_SETTER(Window, screen);
}
JS_DEFINE_NATIVE_FUNCTION(Window::location_setter)
{
auto* impl = TRY(impl_from(vm));

View file

@ -96,8 +96,6 @@ public:
void deallocate_timer_id(Badge<Timer>, i32);
CSS::Screen& screen();
DOM::Event* current_event() { return m_current_event.ptr(); }
DOM::Event const* current_event() const { return m_current_event.ptr(); }
void set_current_event(DOM::Event* event);
@ -165,6 +163,7 @@ public:
Variant<JS::Handle<DOM::Event>, JS::Value> event() const;
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::MediaQueryList>> match_media(String const& query);
WebIDL::ExceptionOr<JS::NonnullGCPtr<CSS::Screen>> screen();
WebIDL::ExceptionOr<JS::NonnullGCPtr<HighResolutionTime::Performance>> performance();
@ -232,9 +231,6 @@ public:
private:
JS_DECLARE_NATIVE_FUNCTION(location_setter);
JS_DECLARE_NATIVE_FUNCTION(screen_getter);
JS_DECLARE_NATIVE_FUNCTION(screen_setter);
JS_DECLARE_NATIVE_FUNCTION(inner_width_getter);
JS_DECLARE_NATIVE_FUNCTION(inner_height_getter);

View file

@ -1,5 +1,6 @@
#import <Crypto/Crypto.idl>
#import <CSS/MediaQueryList.idl>
#import <CSS/Screen.idl>
#import <DOM/Document.idl>
#import <DOM/EventHandler.idl>
#import <DOM/EventTarget.idl>
@ -45,6 +46,7 @@ interface Window : EventTarget {
// https://w3c.github.io/csswg-drafts/cssom-view/#extensions-to-the-window-interface
[NewObject] MediaQueryList matchMedia(CSSOMString query);
[SameObject, Replaceable] readonly attribute Screen screen;
// FIXME: Everything from here on should be shared through WindowOrWorkerGlobalScope
// https://w3c.github.io/hr-time/#the-performance-attribute