Skip to content

Truly independent web browser

LibWeb: Implement Screen and ScreenOrientation in Rust

Andreas Klinge535736c6e05
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/css/exports.rs
index 50740481416..73805235c54 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/exports.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/exports.rs
@@ -58,6 +58,7 @@ use super::css_unit_value::CSSUnitValue;
use super::css_unparsed_value::CSSUnparsedValue;
use super::media_list::MediaList;
use super::media_query_list::MediaQueryList;
+use super::screen::Screen;
use super::style_sheet_list::StyleSheetList;
use super::transition_event::{TransitionEvent, TransitionEventInit};
use super::typed_om;
@@ -496,6 +497,21 @@ pub unsafe extern "C" fn web_media_query_list_evaluate_and_report_change(vm: *mu
list.evaluate_and_report_change(vm);
}
+/// A new Screen of the window.
+///
+/// # Safety
+///
+/// `vm` must be the live VM, `realm` a live realm, and `window` the live Window of the realm.
+#[unsafe(no_mangle)]
+pub unsafe extern "C" fn web_screen_create(vm: *mut c_void, realm: *mut c_void, window: *mut c_void) -> *mut c_void {
+ // SAFETY: The caller passes the live VM, a live realm and a live Window.
+ let (vm, realm, window) = unsafe {
+ let (vm, realm) = realm_arguments(vm, realm);
+ (vm, realm, CppCell::from_raw(window))
+ };
+ cell_into_abi(Screen::create(vm, realm, window))
+}
+
/// The object of a wrapper that C++ passes, if it passes one.
///
/// # Safety
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
index 6995bf214f9..e12c06307c0 100644
--- a/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs
@@ -67,6 +67,8 @@ pub(crate) mod exports;
pub(crate) mod media_list;
pub(crate) mod media_query_list;
pub(crate) mod media_query_list_event;
+pub(crate) mod screen;
+pub(crate) mod screen_orientation;
pub(crate) mod style_sheet;
pub(crate) mod style_sheet_list;
pub(crate) mod transition_event;
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/screen.rs b/Libraries/LibWeb/Bindings/Rust/src/css/screen.rs
new file mode 100644
index 00000000000..0e5a76fe58e
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/screen.rs
@@ -0,0 +1,140 @@
+/*
+ * Copyright (c) 2021-2022, Linus Groh <[email protected]>
+ * Copyright (c) 2025, Sam Atkins <[email protected]>
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! Screen, https://drafts.csswg.org/cssom-view-1/#screen
+
+use core::ffi::c_void;
+use core::ptr::NonNull;
+
+use libjs_rust::api::{Gc, GcRefCell, Realm, Trace, Vm};
+
+use crate::bindings::cpp_cell::CppCell;
+use crate::bindings::event_target::{CppEventTarget, GetTheParent};
+use crate::bindings::interface::{Ref, Wrappable, allocate};
+use crate::bindings::{CallContext, WebIdlResult};
+use crate::css::screen_orientation::ScreenOrientation;
+
+unsafe extern "C" {
+ fn web_css_screen_area(window: *mut c_void, available: bool, width: *mut i32, height: *mut i32);
+ fn web_css_screen_is_extended(window: *mut c_void) -> bool;
+}
+
+/// Which area of the screen an attribute reports.
+#[derive(Clone, Copy)]
+enum ScreenArea {
+ /// https://drafts.csswg.org/cssom-view-1/#web-exposed-screen-area
+ WebExposed,
+ /// https://drafts.csswg.org/cssom-view-1/#web-exposed-available-screen-area
+ WebExposedAvailable,
+}
+
+// The colorDepth and pixelDepth attributes should return the number of bits allocated to colors for a pixel in the
+// output device, excluding the alpha channel.
+const COLOR_DEPTH: u32 = 24;
+
+// https://drafts.csswg.org/cssom-view-1/#screen
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct Screen {
+ event_target: CppEventTarget,
+ realm: Gc<Realm>,
+ window: CppCell,
+ orientation: GcRefCell<Option<Ref<ScreenOrientation>>>,
+}
+
+impl Wrappable for Screen {
+ fn relevant_realm(&self) -> Option<Gc<Realm>> {
+ Some(self.realm)
+ }
+
+ fn cpp_parent(&self) -> Option<NonNull<c_void>> {
+ self.event_target.as_cpp_parent()
+ }
+}
+
+impl GetTheParent for Screen {
+ fn get_the_parent(&self) -> Option<CppEventTarget> {
+ None
+ }
+}
+
+impl Screen {
+ pub(crate) fn create(vm: &Vm, realm: Gc<Realm>, window: CppCell) -> Ref<Self> {
+ let object = allocate(vm, |_| Screen {
+ event_target: CppEventTarget::new(),
+ realm,
+ window,
+ orientation: GcRefCell::new(None),
+ });
+ object.event_target.set_owner(object);
+ object
+ }
+
+ fn area(&self, area: ScreenArea) -> (i32, i32) {
+ let (mut width, mut height) = (0, 0);
+ // SAFETY: The window is live, and the sizes are lent for the call.
+ unsafe {
+ web_css_screen_area(
+ self.window.as_ptr(),
+ matches!(area, ScreenArea::WebExposedAvailable),
+ &raw mut width,
+ &raw mut height,
+ );
+ }
+ (width, height)
+ }
+
+ // https://drafts.csswg.org/cssom-view-1/#dom-screen-availwidth
+ pub(crate) fn avail_width(&self, _: &mut CallContext) -> WebIdlResult<i32> {
+ // The availWidth attribute must return the width of the Web-exposed available screen area.
+ Ok(self.area(ScreenArea::WebExposedAvailable).0)
+ }
+
+ // https://drafts.csswg.org/cssom-view-1/#dom-screen-availheight
+ pub(crate) fn avail_height(&self, _: &mut CallContext) -> WebIdlResult<i32> {
+ // The availHeight attribute must return the height of the Web-exposed available screen area.
+ Ok(self.area(ScreenArea::WebExposedAvailable).1)
+ }
+
+ // https://drafts.csswg.org/cssom-view-1/#dom-screen-width
+ pub(crate) fn width(&self, _: &mut CallContext) -> WebIdlResult<i32> {
+ // The width attribute must return the width of the Web-exposed screen area.
+ Ok(self.area(ScreenArea::WebExposed).0)
+ }
+
+ // https://drafts.csswg.org/cssom-view-1/#dom-screen-height
+ pub(crate) fn height(&self, _: &mut CallContext) -> WebIdlResult<i32> {
+ // The height attribute must return the height of the Web-exposed screen area.
+ Ok(self.area(ScreenArea::WebExposed).1)
+ }
+
+ // https://drafts.csswg.org/cssom-view-1/#dom-screen-colordepth
+ pub(crate) fn color_depth(&self, _: &mut CallContext) -> WebIdlResult<u32> {
+ Ok(COLOR_DEPTH)
+ }
+
+ // https://drafts.csswg.org/cssom-view-1/#dom-screen-pixeldepth
+ pub(crate) fn pixel_depth(&self, _: &mut CallContext) -> WebIdlResult<u32> {
+ Ok(COLOR_DEPTH)
+ }
+
+ pub(crate) fn orientation(&self, cx: &mut CallContext) -> WebIdlResult<Ref<ScreenOrientation>> {
+ if let Some(orientation) = *self.orientation.borrow() {
+ return Ok(orientation);
+ }
+ let orientation = ScreenOrientation::create(cx.vm(), self.realm);
+ *self.orientation.borrow_mut(cx.vm()) = Some(orientation);
+ Ok(orientation)
+ }
+
+ // https://w3c.github.io/window-management/#dom-screen-isextended
+ pub(crate) fn is_extended(&self, _: &mut CallContext) -> WebIdlResult<bool> {
+ // SAFETY: The window is live.
+ Ok(unsafe { web_css_screen_is_extended(self.window.as_ptr()) })
+ }
+}
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/screen_orientation.rs b/Libraries/LibWeb/Bindings/Rust/src/css/screen_orientation.rs
new file mode 100644
index 00000000000..92df89ef3fe
--- /dev/null
+++ b/Libraries/LibWeb/Bindings/Rust/src/css/screen_orientation.rs
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2024, Shannon Booth <[email protected]>
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+//! ScreenOrientation, https://w3c.github.io/screen-orientation/#screenorientation-interface
+
+use core::ffi::c_void;
+use core::ptr::NonNull;
+
+use ak::Utf16String;
+use libjs_rust::api::{Gc, Realm, Trace, Vm};
+
+use crate::bindings::event_target::{CppEventTarget, GetTheParent};
+use crate::bindings::interface::{Ref, Wrappable, allocate};
+use crate::bindings::promise::WebIdlPromise;
+use crate::bindings::{CallContext, Exception, WebIdlResult};
+
+/// The enumeration OrientationType of CSS/ScreenOrientation.idl.
+#[derive(Clone, Copy, Eq, PartialEq)]
+#[expect(dead_code, reason = "the type attribute is a stub that reports one orientation")]
+pub(crate) enum OrientationType {
+ PortraitPrimary,
+ PortraitSecondary,
+ LandscapePrimary,
+ LandscapeSecondary,
+}
+
+/// The enumeration OrientationLockType of CSS/ScreenOrientation.idl.
+#[derive(Clone, Copy, Eq, PartialEq)]
+pub(crate) enum OrientationLockType {
+ Any,
+ Natural,
+ Landscape,
+ Portrait,
+ PortraitPrimary,
+ PortraitSecondary,
+ LandscapePrimary,
+ LandscapeSecondary,
+}
+
+// https://w3c.github.io/screen-orientation/#screenorientation-interface
+#[derive(Trace)]
+#[gc(crate = libjs_rust)]
+pub(crate) struct ScreenOrientation {
+ event_target: CppEventTarget,
+ realm: Gc<Realm>,
+}
+
+impl Wrappable for ScreenOrientation {
+ fn relevant_realm(&self) -> Option<Gc<Realm>> {
+ Some(self.realm)
+ }
+
+ fn cpp_parent(&self) -> Option<NonNull<c_void>> {
+ self.event_target.as_cpp_parent()
+ }
+}
+
+impl GetTheParent for ScreenOrientation {
+ fn get_the_parent(&self) -> Option<CppEventTarget> {
+ None
+ }
+}
+
+impl ScreenOrientation {
+ pub(crate) fn create(vm: &Vm, realm: Gc<Realm>) -> Ref<Self> {
+ let object = allocate(vm, |_| ScreenOrientation {
+ event_target: CppEventTarget::new(),
+ realm,
+ });
+ object.event_target.set_owner(object);
+ object
+ }
+
+ // https://w3c.github.io/screen-orientation/#lock-method
+ pub(crate) fn lock(&self, _: &mut CallContext, _: OrientationLockType) -> WebIdlResult<WebIdlPromise> {
+ Err(Exception::Dom(
+ "NotSupportedError",
+ Utf16String::from_utf8("FIXME: ScreenOrientation::lock() is not implemented"),
+ ))
+ }
+
+ // https://w3c.github.io/screen-orientation/#unlock-method
+ pub(crate) fn unlock(&self, _: &mut CallContext) -> WebIdlResult<()> {
+ // FIXME: Implement this.
+ Ok(())
+ }
+
+ // https://w3c.github.io/screen-orientation/#type-attribute
+ pub(crate) fn r#type(&self, _: &mut CallContext) -> WebIdlResult<OrientationType> {
+ // FIXME: Implement this.
+ Ok(OrientationType::LandscapePrimary)
+ }
+
+ // https://w3c.github.io/screen-orientation/#angle-attribute
+ pub(crate) fn angle(&self, _: &mut CallContext) -> WebIdlResult<u16> {
+ // FIXME: Implement this.
+ Ok(0)
+ }
+}
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 06c69840e49..d836a0a89d7 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -144,7 +144,6 @@ set(SOURCES
CSS/Resolution.cpp
CSS/ResolvedTransform.cpp
CSS/Screen.cpp
- CSS/ScreenOrientation.cpp
CSS/ScrollStateContainerQuery.cpp
CSS/Selector.cpp
CSS/SelectorMatching.cpp
diff --git a/Libraries/LibWeb/CSS/Screen.cpp b/Libraries/LibWeb/CSS/Screen.cpp
index 38fb33dd7fd..02dab0b2706 100644
--- a/Libraries/LibWeb/CSS/Screen.cpp
+++ b/Libraries/LibWeb/CSS/Screen.cpp
@@ -5,108 +5,58 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
-#include <LibGC/Heap.h>
#include <LibGfx/Rect.h>
+#include <LibJS/HostClassBuilder.h>
+#include <LibJS/Runtime/VM.h>
#include <LibWeb/CSS/Screen.h>
-#include <LibWeb/CSS/ScreenOrientation.h>
#include <LibWeb/DOM/Document.h>
+#include <LibWeb/HTML/Scripting/Environments.h>
+#include <LibWeb/HTML/Window.h>
#include <LibWeb/Page/Page.h>
namespace Web::CSS {
-GC_DEFINE_ALLOCATOR(Screen);
+extern "C" {
-GC::Ref<Screen> Screen::create(HTML::Window& window)
-{
- return GC::Heap::the().allocate<Screen>(window);
-}
-
-Screen::Screen(HTML::Window& window)
- : DOM::EventTarget()
- , m_window(window)
-{
-}
-
-void Screen::visit_edges(Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_window);
- visitor.visit(m_orientation);
-}
+// Defined in Bindings/Rust/src/css/exports.rs.
+void* web_screen_create(JSVM*, void* realm, void* window);
-// https://drafts.csswg.org/cssom-view-1/#dom-screen-width
-i32 Screen::width() const
-{
- // The width attribute must return the width of the Web-exposed screen area.
- return window().page().web_exposed_screen_area().width().to_int();
+// Declared in Bindings/Rust/src/css/screen.rs.
+void web_css_screen_area(void* window, bool available, i32* width, i32* height);
+bool web_css_screen_is_extended(void* window);
}
-// https://drafts.csswg.org/cssom-view-1/#dom-screen-height
-i32 Screen::height() const
+static HTML::Window& window_from_abi(void* window)
{
- // The height attribute must return the height of the Web-exposed screen area.
- return window().page().web_exposed_screen_area().height().to_int();
+ return *static_cast<HTML::Window*>(static_cast<GC::Cell*>(window));
}
-// https://drafts.csswg.org/cssom-view-1/#dom-screen-availwidth
-i32 Screen::avail_width() const
+void web_css_screen_area(void* window, bool available, i32* width, i32* height)
{
- // The availWidth attribute must return the width of the Web-exposed available screen area.
- return window().page().web_exposed_available_screen_area().width().to_int();
-}
-
-// https://drafts.csswg.org/cssom-view-1/#dom-screen-availheight
-i32 Screen::avail_height() const
-{
- // The availHeight attribute must return the height of the Web-exposed available screen area.
- return window().page().web_exposed_available_screen_area().height().to_int();
-}
-
-// https://drafts.csswg.org/cssom-view-1/#dom-screen-colordepth
-u32 Screen::color_depth() const
-{
- // The colorDepth and pixelDepth attributes should return the number of bits allocated to colors for a pixel in
- // the output device, excluding the alpha channel.
- return 24;
-}
-
-// https://drafts.csswg.org/cssom-view-1/#dom-screen-pixeldepth
-u32 Screen::pixel_depth() const
-{
- // The colorDepth and pixelDepth attributes should return the number of bits allocated to colors for a pixel in
- // the output device, excluding the alpha channel.
- return 24;
-}
-
-GC::Ref<ScreenOrientation> Screen::orientation()
-{
- if (!m_orientation)
- m_orientation = ScreenOrientation::create(window());
- return *m_orientation;
+ auto& page = window_from_abi(window).page();
+ auto area = available ? page.web_exposed_available_screen_area() : page.web_exposed_screen_area();
+ *width = area.width().to_int();
+ *height = area.height().to_int();
}
// https://w3c.github.io/window-management/#dom-screen-isextended
-bool Screen::is_extended() const
+bool web_css_screen_is_extended(void* window_pointer)
{
+ auto& window = window_from_abi(window_pointer);
+
// 1. If this's relevant global object's associated Document is not allowed to use
// the policy-controlled feature named "window-management", return false.
- if (!window().associated_document().is_allowed_to_use_feature(DOM::PolicyControlledFeature::WindowManagement))
+ if (!window.associated_document().is_allowed_to_use_feature(DOM::PolicyControlledFeature::WindowManagement))
return false;
// 2. Return true if the device has more than one screen, and false otherwise.
- return window().page().client().screen_count() > 1;
-}
-
-// 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);
+ return window.page().client().screen_count() > 1;
}
-// https://w3c.github.io/window-management/#dom-screen-onchange
-GC::Ptr<WebIDL::CallbackType> Screen::onchange()
+GC::Ref<Screen> Screen::create(HTML::Window& window)
{
- return event_handler_attribute(HTML::EventNames::change);
+ auto* screen = web_screen_create(JS::HostABI::vm_to_abi(JS::VM::the()), &HTML::relevant_realm(window), static_cast<GC::Cell*>(&window));
+ return GC::Ref { *static_cast<Screen*>(screen) };
}
}
diff --git a/Libraries/LibWeb/CSS/Screen.h b/Libraries/LibWeb/CSS/Screen.h
index f94bbf0e41e..a96ef9ba020 100644
--- a/Libraries/LibWeb/CSS/Screen.h
+++ b/Libraries/LibWeb/CSS/Screen.h
@@ -7,41 +7,19 @@
#pragma once
-#include <LibWeb/DOM/EventTarget.h>
+#include <LibGC/Ptr.h>
+#include <LibWeb/Bindings/RustInterface.h>
+#include <LibWeb/Bindings/Screen.h>
#include <LibWeb/Forward.h>
-#include <LibWeb/HTML/Window.h>
namespace Web::CSS {
-class Screen final : public DOM::EventTarget {
- WEB_WRAPPABLE(Screen, DOM::EventTarget);
- GC_DECLARE_ALLOCATOR(Screen);
+// https://drafts.csswg.org/cssom-view-1/#screen
+class Screen final : public Bindings::RustInterfaceCell {
+ WEB_RUST_INTERFACE(Screen, screen)
public:
[[nodiscard]] static GC::Ref<Screen> create(HTML::Window&);
-
- i32 width() const;
- i32 height() const;
- i32 avail_width() const;
- i32 avail_height() const;
- u32 color_depth() const;
- u32 pixel_depth() const;
- GC::Ref<ScreenOrientation> orientation();
-
- bool is_extended() const;
-
- void set_onchange(GC::Ptr<WebIDL::CallbackType> event_handler);
- GC::Ptr<WebIDL::CallbackType> onchange();
-
-private:
- explicit Screen(HTML::Window&);
- virtual void visit_edges(Cell::Visitor&) override;
-
- HTML::Window const& window() const { return *m_window; }
- HTML::Window& window() { return *m_window; }
-
- GC::Ref<HTML::Window> m_window;
- GC::Ptr<ScreenOrientation> m_orientation;
};
}
diff --git a/Libraries/LibWeb/CSS/Screen.idl b/Libraries/LibWeb/CSS/Screen.idl
index 1c1e0e95a62..5def7647f87 100644
--- a/Libraries/LibWeb/CSS/Screen.idl
+++ b/Libraries/LibWeb/CSS/Screen.idl
@@ -1,5 +1,5 @@
// https://w3c.github.io/csswg-drafts/cssom-view-1/#screen
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface Screen {
readonly attribute long availWidth;
readonly attribute long availHeight;
diff --git a/Libraries/LibWeb/CSS/ScreenOrientation.cpp b/Libraries/LibWeb/CSS/ScreenOrientation.cpp
deleted file mode 100644
index bf131050a6b..00000000000
--- a/Libraries/LibWeb/CSS/ScreenOrientation.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright (c) 2024, Shannon Booth <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <LibGC/Heap.h>
-#include <LibWeb/CSS/ScreenOrientation.h>
-#include <LibWeb/HTML/EventNames.h>
-#include <LibWeb/HTML/Window.h>
-#include <LibWeb/WebIDL/Promise.h>
-
-namespace Web::CSS {
-
-GC_DEFINE_ALLOCATOR(ScreenOrientation);
-
-ScreenOrientation::ScreenOrientation(HTML::Window& window)
- : DOM::EventTarget()
- , m_window(window)
-{
-}
-
-GC::Ref<ScreenOrientation> ScreenOrientation::create(HTML::Window& window)
-{
- return GC::Heap::the().allocate<ScreenOrientation>(window);
-}
-
-void ScreenOrientation::visit_edges(Cell::Visitor& visitor)
-{
- Base::visit_edges(visitor);
- visitor.visit(m_window);
-}
-
-// https://w3c.github.io/screen-orientation/#lock-method
-WebIDL::ExceptionOr<GC::Ref<WebIDL::Promise>> ScreenOrientation::lock(OrientationLockType)
-{
- TRY(lock());
- auto promise = WebIDL::create_promise_for(m_window);
- WebIDL::resolve_promise(promise);
- return promise;
-}
-
-// https://w3c.github.io/screen-orientation/#lock-method
-WebIDL::ExceptionOr<void> ScreenOrientation::lock()
-{
- return WebIDL::NotSupportedError::create("FIXME: ScreenOrientation::lock() is not implemented"_utf16);
-}
-
-// https://w3c.github.io/screen-orientation/#unlock-method
-void ScreenOrientation::unlock()
-{
- dbgln("FIXME: Stubbed ScreenOrientation::unlock()");
-}
-
-// https://w3c.github.io/screen-orientation/#type-attribute
-OrientationType ScreenOrientation::type() const
-{
- dbgln("FIXME: Stubbed ScreenOrientation::type()");
- return 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(GC::Ptr<WebIDL::CallbackType> event_handler)
-{
- set_event_handler_attribute(HTML::EventNames::change, event_handler);
-}
-
-// https://w3c.github.io/screen-orientation/#onchange-event-handler-attribute
-GC::Ptr<WebIDL::CallbackType> ScreenOrientation::onchange()
-{
- return event_handler_attribute(HTML::EventNames::change);
-}
-
-}
diff --git a/Libraries/LibWeb/CSS/ScreenOrientation.h b/Libraries/LibWeb/CSS/ScreenOrientation.h
deleted file mode 100644
index a84dad8616b..00000000000
--- a/Libraries/LibWeb/CSS/ScreenOrientation.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Copyright (c) 2024, Shannon Booth <[email protected]>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <LibWeb/Bindings/ScreenOrientation.h>
-#include <LibWeb/DOM/EventTarget.h>
-#include <LibWeb/WebIDL/ExceptionOr.h>
-#include <LibWeb/WebIDL/Promise.h>
-#include <LibWebCommon/WebIDL/Types.h>
-
-namespace Web::CSS {
-
-using OrientationLockType = Bindings::OrientationLockType;
-using OrientationType = Bindings::OrientationType;
-
-class ScreenOrientation final : public DOM::EventTarget {
- WEB_WRAPPABLE(ScreenOrientation, DOM::EventTarget);
- GC_DECLARE_ALLOCATOR(ScreenOrientation);
-
-public:
- [[nodiscard]] static GC::Ref<ScreenOrientation> create(HTML::Window&);
-
- WebIDL::ExceptionOr<GC::Ref<WebIDL::Promise>> lock(OrientationLockType);
- WebIDL::ExceptionOr<void> lock();
- void unlock();
- OrientationType type() const;
- WebIDL::UnsignedShort angle() const;
-
- void set_onchange(GC::Ptr<WebIDL::CallbackType>);
- GC::Ptr<WebIDL::CallbackType> onchange();
-
-private:
- explicit ScreenOrientation(HTML::Window&);
- virtual void visit_edges(Cell::Visitor&) override;
-
- GC::Ref<HTML::Window> m_window;
-};
-
-}
diff --git a/Libraries/LibWeb/CSS/ScreenOrientation.idl b/Libraries/LibWeb/CSS/ScreenOrientation.idl
index 529685c05f5..c2d67afbccc 100644
--- a/Libraries/LibWeb/CSS/ScreenOrientation.idl
+++ b/Libraries/LibWeb/CSS/ScreenOrientation.idl
@@ -19,7 +19,7 @@ enum OrientationLockType {
};
// https://w3c.github.io/screen-orientation/#screenorientation-interface
-[Exposed=Window]
+[Exposed=Window, ImplementedIn=Rust]
interface ScreenOrientation : EventTarget {
Promise<undefined> lock(OrientationLockType orientation);
undefined unlock();
diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.h
index 5707a791da4..c049f3bf6a3 100644
--- a/Libraries/LibWeb/Forward.h
+++ b/Libraries/LibWeb/Forward.h
@@ -323,7 +323,6 @@ class RatioStyleValue;
class Resolution;
class ResolutionStyleValue;
class Screen;
-class ScreenOrientation;
class Selector;
class ShadowStyleValue;
class ShorthandStyleValue;