mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-21 09:49:21 +00:00
LibWeb: Add stubs for the Screen Orientation API
As defined in: https://w3c.github.io/screen-orientation
This commit is contained in:
parent
7fb09bf95b
commit
ccebc7a905
Notes:
sideshowbarker
2024-07-17 08:27:05 +09:00
Author: https://github.com/shannonbooth
Commit: ccebc7a905
Pull-request: https://github.com/SerenityOS/serenity/pull/23809
Reviewed-by: https://github.com/AtkinsSJ ✅
9 changed files with 156 additions and 0 deletions
|
@ -85,6 +85,7 @@ set(SOURCES
|
|||
CSS/Resolution.cpp
|
||||
CSS/ResolvedCSSStyleDeclaration.cpp
|
||||
CSS/Screen.cpp
|
||||
CSS/ScreenOrientation.cpp
|
||||
CSS/Selector.cpp
|
||||
CSS/SelectorEngine.cpp
|
||||
CSS/Serialize.cpp
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#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>
|
||||
|
||||
|
@ -36,6 +37,7 @@ 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
|
||||
|
@ -49,4 +51,11 @@ Gfx::IntRect Screen::screen_rect() const
|
|||
};
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<ScreenOrientation> Screen::orientation()
|
||||
{
|
||||
if (!m_orientation)
|
||||
m_orientation = ScreenOrientation::create(realm());
|
||||
return *m_orientation;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ public:
|
|||
i32 avail_height() const { return screen_rect().height(); }
|
||||
u32 color_depth() const { return 24; }
|
||||
u32 pixel_depth() const { return 24; }
|
||||
JS::NonnullGCPtr<ScreenOrientation> orientation();
|
||||
|
||||
private:
|
||||
explicit Screen(HTML::Window&);
|
||||
|
@ -38,6 +39,7 @@ private:
|
|||
Gfx::IntRect screen_rect() const;
|
||||
|
||||
JS::NonnullGCPtr<HTML::Window> m_window;
|
||||
JS::GCPtr<ScreenOrientation> m_orientation;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
#import <CSS/ScreenOrientation.idl>
|
||||
|
||||
// https://w3c.github.io/csswg-drafts/cssom-view-1/#screen
|
||||
[Exposed=Window]
|
||||
interface Screen {
|
||||
|
@ -7,4 +9,7 @@ interface Screen {
|
|||
readonly attribute long height;
|
||||
readonly attribute unsigned long colorDepth;
|
||||
readonly attribute unsigned long pixelDepth;
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#extensions-to-the-screen-interface
|
||||
[SameObject] readonly attribute ScreenOrientation orientation;
|
||||
};
|
||||
|
|
69
Userland/Libraries/LibWeb/CSS/ScreenOrientation.cpp
Normal file
69
Userland/Libraries/LibWeb/CSS/ScreenOrientation.cpp
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/ScreenOrientation.h>
|
||||
#include <LibWeb/HTML/EventNames.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
JS_DEFINE_ALLOCATOR(ScreenOrientation);
|
||||
|
||||
ScreenOrientation::ScreenOrientation(JS::Realm& realm)
|
||||
: DOM::EventTarget(realm)
|
||||
{
|
||||
}
|
||||
|
||||
void ScreenOrientation::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(ScreenOrientation);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<ScreenOrientation> ScreenOrientation::create(JS::Realm& realm)
|
||||
{
|
||||
return realm.heap().allocate<ScreenOrientation>(realm, realm);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#lock-method
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> ScreenOrientation::lock(Bindings::OrientationLockType)
|
||||
{
|
||||
return WebIDL::NotSupportedError::create(realm(), "FIXME: ScreenOrientation::lock() is not implemented"_fly_string);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#unlock-method
|
||||
void ScreenOrientation::unlock()
|
||||
{
|
||||
dbgln("FIXME: Stubbed ScreenOrientation::unlock()");
|
||||
}
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#type-attribute
|
||||
Bindings::OrientationType ScreenOrientation::type() const
|
||||
{
|
||||
dbgln("FIXME: Stubbed ScreenOrientation::type()");
|
||||
return Bindings::OrientationType::LandscapePrimary;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#angle-attribute
|
||||
WebIDL::UnsignedShort ScreenOrientation::angle() const
|
||||
{
|
||||
dbgln("FIXME: Stubbed ScreenOrientation::angle()");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#onchange-event-handler-attribute
|
||||
void ScreenOrientation::set_onchange(JS::GCPtr<WebIDL::CallbackType> event_handler)
|
||||
{
|
||||
set_event_handler_attribute(HTML::EventNames::change, event_handler);
|
||||
}
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#onchange-event-handler-attribute
|
||||
JS::GCPtr<WebIDL::CallbackType> ScreenOrientation::onchange()
|
||||
{
|
||||
return event_handler_attribute(HTML::EventNames::change);
|
||||
}
|
||||
|
||||
}
|
37
Userland/Libraries/LibWeb/CSS/ScreenOrientation.h
Normal file
37
Userland/Libraries/LibWeb/CSS/ScreenOrientation.h
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/Bindings/ScreenOrientationPrototype.h>
|
||||
#include <LibWeb/DOM/EventTarget.h>
|
||||
#include <LibWeb/WebIDL/Types.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class ScreenOrientation final : public DOM::EventTarget {
|
||||
WEB_PLATFORM_OBJECT(ScreenOrientation, DOM::EventTarget);
|
||||
JS_DECLARE_ALLOCATOR(ScreenOrientation);
|
||||
|
||||
public:
|
||||
[[nodiscard]] static JS::NonnullGCPtr<ScreenOrientation> create(JS::Realm&);
|
||||
|
||||
WebIDL::ExceptionOr<JS::NonnullGCPtr<JS::Promise>> lock(Bindings::OrientationLockType);
|
||||
void unlock();
|
||||
Bindings::OrientationType type() const;
|
||||
WebIDL::UnsignedShort angle() const;
|
||||
|
||||
void set_onchange(JS::GCPtr<WebIDL::CallbackType>);
|
||||
JS::GCPtr<WebIDL::CallbackType> onchange();
|
||||
|
||||
private:
|
||||
explicit ScreenOrientation(JS::Realm&);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
};
|
||||
|
||||
}
|
31
Userland/Libraries/LibWeb/CSS/ScreenOrientation.idl
Normal file
31
Userland/Libraries/LibWeb/CSS/ScreenOrientation.idl
Normal file
|
@ -0,0 +1,31 @@
|
|||
#import <DOM/EventHandler.idl>
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#orientationtype-enum
|
||||
enum OrientationType {
|
||||
"portrait-primary",
|
||||
"portrait-secondary",
|
||||
"landscape-primary",
|
||||
"landscape-secondary"
|
||||
};
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#orientationlocktype-enum
|
||||
enum OrientationLockType {
|
||||
"any",
|
||||
"natural",
|
||||
"landscape",
|
||||
"portrait",
|
||||
"portrait-primary",
|
||||
"portrait-secondary",
|
||||
"landscape-primary",
|
||||
"landscape-secondary"
|
||||
};
|
||||
|
||||
// https://w3c.github.io/screen-orientation/#screenorientation-interface
|
||||
[Exposed=Window]
|
||||
interface ScreenOrientation : EventTarget {
|
||||
Promise<undefined> lock(OrientationLockType orientation);
|
||||
undefined unlock();
|
||||
readonly attribute OrientationType type;
|
||||
readonly attribute unsigned short angle;
|
||||
attribute EventHandler onchange;
|
||||
};
|
|
@ -172,6 +172,7 @@ class ResolutionOrCalculated;
|
|||
class ResolutionStyleValue;
|
||||
class RevertStyleValue;
|
||||
class Screen;
|
||||
class ScreenOrientation;
|
||||
class Selector;
|
||||
class ShadowStyleValue;
|
||||
class ShorthandStyleValue;
|
||||
|
|
|
@ -33,6 +33,7 @@ libweb_js_bindings(CSS/MediaList)
|
|||
libweb_js_bindings(CSS/MediaQueryList)
|
||||
libweb_js_bindings(CSS/MediaQueryListEvent)
|
||||
libweb_js_bindings(CSS/Screen)
|
||||
libweb_js_bindings(CSS/ScreenOrientation)
|
||||
libweb_js_bindings(CSS/StyleSheet)
|
||||
libweb_js_bindings(CSS/StyleSheetList)
|
||||
libweb_js_bindings(CSS/VisualViewport)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue