LibWeb: Stub out Window-Management proposal extensions to Screen API

As defined in https://w3c.github.io/window-management
This commit is contained in:
Shannon Booth 2024-04-05 18:15:43 +02:00 committed by Andrew Kaster
parent b79815c5a5
commit 97bf9e7953
3 changed files with 35 additions and 4 deletions

View file

@ -22,7 +22,7 @@ JS::NonnullGCPtr<Screen> 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<ScreenOrientation> 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<WebIDL::CallbackType> event_handler)
{
set_event_handler_attribute(HTML::EventNames::change, event_handler);
}
// https://w3c.github.io/window-management/#dom-screen-onchange
JS::GCPtr<WebIDL::CallbackType> Screen::onchange()
{
return event_handler_attribute(HTML::EventNames::change);
}
}

View file

@ -8,13 +8,14 @@
#include <LibGfx/Rect.h>
#include <LibWeb/Bindings/PlatformObject.h>
#include <LibWeb/DOM/EventTarget.h>
#include <LibWeb/Forward.h>
#include <LibWeb/HTML/Window.h>
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<ScreenOrientation> orientation();
bool is_extended() const;
void set_onchange(JS::GCPtr<WebIDL::CallbackType> event_handler);
JS::GCPtr<WebIDL::CallbackType> onchange();
private:
explicit Screen(HTML::Window&);

View file

@ -1,8 +1,10 @@
#import <CSS/ScreenOrientation.idl>
#import <DOM/EventHandler.idl>
#import <DOM/EventTarget.idl>
// 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;
};