From 97bf9e7953edafd999ff294858c15b8de119aba2 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Fri, 5 Apr 2024 18:15:43 +0200 Subject: [PATCH] LibWeb: Stub out Window-Management proposal extensions to Screen API As defined in https://w3c.github.io/window-management --- Userland/Libraries/LibWeb/CSS/Screen.cpp | 21 ++++++++++++++++++++- Userland/Libraries/LibWeb/CSS/Screen.h | 10 ++++++++-- Userland/Libraries/LibWeb/CSS/Screen.idl | 8 +++++++- 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/Screen.cpp b/Userland/Libraries/LibWeb/CSS/Screen.cpp index 9fcf70e8000..e6dc367eff8 100644 --- a/Userland/Libraries/LibWeb/CSS/Screen.cpp +++ b/Userland/Libraries/LibWeb/CSS/Screen.cpp @@ -22,7 +22,7 @@ JS::NonnullGCPtr Screen::create(HTML::Window& window) } Screen::Screen(HTML::Window& window) - : PlatformObject(window.realm()) + : DOM::EventTarget(window.realm()) , m_window(window) { } @@ -58,4 +58,23 @@ JS::NonnullGCPtr Screen::orientation() 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(JS::GCPtr event_handler) +{ + set_event_handler_attribute(HTML::EventNames::change, event_handler); +} + +// https://w3c.github.io/window-management/#dom-screen-onchange +JS::GCPtr Screen::onchange() +{ + return event_handler_attribute(HTML::EventNames::change); +} + } diff --git a/Userland/Libraries/LibWeb/CSS/Screen.h b/Userland/Libraries/LibWeb/CSS/Screen.h index ae84012a5c0..67dd0fb0d49 100644 --- a/Userland/Libraries/LibWeb/CSS/Screen.h +++ b/Userland/Libraries/LibWeb/CSS/Screen.h @@ -8,13 +8,14 @@ #include #include +#include #include #include namespace Web::CSS { -class Screen final : public Bindings::PlatformObject { - WEB_PLATFORM_OBJECT(Screen, Bindings::PlatformObject); +class Screen final : public DOM::EventTarget { + WEB_PLATFORM_OBJECT(Screen, DOM::EventTarget); JS_DECLARE_ALLOCATOR(Screen); public: @@ -28,6 +29,11 @@ public: u32 pixel_depth() const { return 24; } JS::NonnullGCPtr orientation(); + bool is_extended() const; + + void set_onchange(JS::GCPtr event_handler); + JS::GCPtr onchange(); + private: explicit Screen(HTML::Window&); diff --git a/Userland/Libraries/LibWeb/CSS/Screen.idl b/Userland/Libraries/LibWeb/CSS/Screen.idl index 1266a071b6c..06d30808056 100644 --- a/Userland/Libraries/LibWeb/CSS/Screen.idl +++ b/Userland/Libraries/LibWeb/CSS/Screen.idl @@ -1,8 +1,10 @@ #import +#import +#import // https://w3c.github.io/csswg-drafts/cssom-view-1/#screen [Exposed=Window] -interface Screen { +interface Screen : EventTarget { readonly attribute long availWidth; readonly attribute long availHeight; readonly attribute long width; @@ -12,4 +14,8 @@ interface Screen { // https://w3c.github.io/screen-orientation/#extensions-to-the-screen-interface [SameObject] readonly attribute ScreenOrientation orientation; + + // https://w3c.github.io/window-management/#api-extensions-to-screen + [SecureContext] readonly attribute boolean isExtended; + [SecureContext] attribute EventHandler onchange; };