Truly independent web browser
LibWeb: Implement three CSS event interfaces in Rust
Andreas Kling0e2515b407a0
diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/animation_event.rs b/Libraries/LibWeb/Bindings/Rust/src/css/animation_event.rsnew file mode 100644index 00000000000..378d8ab1b9f--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/css/animation_event.rs@@ -0,0 +1,113 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! AnimationEvent, https://drafts.csswg.org/css-animations-2/#interface-animationevent++use core::ffi::c_void;+use core::ptr::NonNull;++use ak::Utf16String;+use libjs_rust::api::{Gc, Realm, Trace, Vm};++use super::css_rule::wrap_cpp_cell;+use crate::bindings::conversions::CppInterface;+use crate::bindings::cpp_cell::CppCell;+use crate::bindings::event_target::CppEvent;+use crate::bindings::interface::{Ref, Wrappable, allocate};+use crate::bindings::{CallContext, WebIdlResult};+use crate::dom::event::EventInit;++unsafe extern "C" {+ fn web_css_animation_of_wrapper(wrapper: *mut c_void) -> *mut c_void;+}++/// The Animation behind a wrapper of it, which an event holds to wrap it again for the world of each caller.+pub(crate) fn animation_of_wrapper(animation: CppInterface) -> CppCell {+ // SAFETY: The caller passes a wrapper of an Animation, whose cell is live.+ unsafe { CppCell::from_raw(web_css_animation_of_wrapper(animation.wrapper().as_ptr().cast())) }+}++/// The dictionary AnimationEventInit of CSS/AnimationEvent.idl.+pub(crate) struct AnimationEventInit {+ pub(crate) parent: EventInit,+ pub(crate) animation: Option<CppInterface>,+ pub(crate) animation_name: Utf16String,+ pub(crate) elapsed_time: f64,+ pub(crate) pseudo_element: Utf16String,+}++// https://drafts.csswg.org/css-animations-2/#interface-animationevent+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct AnimationEvent {+ event: CppEvent,+ #[gc(untraced)]+ animation_name: Utf16String,+ elapsed_time: f64,+ #[gc(untraced)]+ pseudo_element: Utf16String,+ animation: Option<CppCell>,+}++impl Wrappable for AnimationEvent {+ fn cpp_parent(&self) -> Option<NonNull<c_void>> {+ self.event.as_cpp_parent()+ }+}++impl AnimationEvent {+ pub(crate) fn create(+ vm: &Vm,+ realm: Gc<Realm>,+ event_name: &Utf16String,+ event_init: AnimationEventInit,+ ) -> Ref<AnimationEvent> {+ let event = CppEvent::create_for_owner(+ realm,+ event_name,+ event_init.parent.bubbles,+ event_init.parent.cancelable,+ event_init.parent.composed,+ );+ let object = allocate(vm, |_| AnimationEvent {+ event,+ animation_name: event_init.animation_name,+ elapsed_time: event_init.elapsed_time,+ pseudo_element: event_init.pseudo_element,+ animation: event_init.animation.map(animation_of_wrapper),+ });+ object.event.set_owner(object);+ object+ }++ pub(crate) fn construct(+ cx: &mut CallContext,+ r#type: Utf16String,+ animation_event_init_dict: AnimationEventInit,+ ) -> WebIdlResult<Ref<AnimationEvent>> {+ Ok(Self::create(cx.vm(), cx.realm(), &r#type, animation_event_init_dict))+ }++ pub(crate) fn event(&self) -> &CppEvent {+ &self.event+ }++ pub(crate) fn animation_name(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.animation_name.clone())+ }++ pub(crate) fn elapsed_time(&self, _: &mut CallContext) -> WebIdlResult<f64> {+ Ok(self.elapsed_time)+ }++ pub(crate) fn pseudo_element(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.pseudo_element.clone())+ }++ pub(crate) fn animation(&self, cx: &mut CallContext) -> WebIdlResult<Option<CppInterface>> {+ Ok(self.animation.as_ref().map(|animation| wrap_cpp_cell(cx, animation)))+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/exports.rs b/Libraries/LibWeb/Bindings/Rust/src/css/exports.rsindex 52e963ee3ea..5429feafe78 100644--- a/Libraries/LibWeb/Bindings/Rust/src/css/exports.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/css/exports.rs@@ -8,13 +8,15 @@//! Libraries/LibWeb/CSS/TypedOM.cpp.use core::ffi::c_void;+use core::ptr::NonNull;use std::sync::Arc;use ak::Utf16String;-use libjs_rust::api::{MarkedVec, Vm};+use libjs_rust::api::{Gc, MarkedVec, Vm};use libweb_rust::NativeMediaList;use libweb_rust::typed_om::{FfiNumericType, RetainedStyleValue};+use super::animation_event::{AnimationEvent, AnimationEventInit};use super::css_image_value::CSSImageValue;use super::css_keyword_value::CSSKeywordValue;use super::css_math_clamp::CSSMathClamp;@@ -30,10 +32,14 @@ use super::css_transform_value::CSSTransformValue;use super::css_unit_value::CSSUnitValue;use super::css_unparsed_value::CSSUnparsedValue;use super::media_list::MediaList;+use super::media_query_list_event::{MediaQueryListEvent, MediaQueryListEventInit};+use super::transition_event::{TransitionEvent, TransitionEventInit};use super::typed_om;use crate::bindings::Exception;+use crate::bindings::conversions::CppInterface;use crate::bindings::cpp_cell::CppCell;-use crate::bindings::interface::{Ref, allocate, cell_from_abi, cell_if_abi, cell_into_abi};+use crate::bindings::interface::{Ref, allocate, cell_from_abi, cell_if_abi, cell_into_abi, realm_arguments};+use crate::dom::event::EventInit;/// # Safety///@@ -424,3 +430,130 @@ pub unsafe extern "C" fn web_css_keyword_value_value(value: *mut c_void) -> usizlet value: Ref<CSSKeywordValue> = unsafe { cell_from_abi(value) };value.raw_value().into_raw()}++/// A new MediaQueryListEvent named `change`, as the Event that C++ dispatches, given a raw string that C++ hands over.+///+/// # Safety+///+/// `vm` must be the live VM, `realm` a live realm, and `media` a raw string that C++ hands over.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_media_query_list_event_create(+ vm: *mut c_void,+ realm: *mut c_void,+ media: usize,+ matches: bool,+) -> *mut c_void {+ // SAFETY: The caller passes the live VM and a live realm.+ let (vm, realm) = unsafe { realm_arguments(vm, realm) };+ // SAFETY: The caller hands over the string.+ let media = unsafe { Utf16String::from_raw_owned(media) };+ let event_init = MediaQueryListEventInit {+ parent: EventInit {+ bubbles: false,+ cancelable: false,+ composed: false,+ },+ matches,+ media,+ };+ MediaQueryListEvent::create(vm, realm, &Utf16String::from_ascii(b"change"), event_init)+ .event()+ .as_ptr()+}++/// The object of a wrapper that C++ passes, if it passes one.+///+/// # Safety+///+/// `wrapper` must be null or a live wrapper of an object of an interface that LibWeb implements in C++.+unsafe fn cpp_interface_from_abi(wrapper: *mut c_void) -> Option<CppInterface> {+ let wrapper = NonNull::new(wrapper.cast())?;+ // SAFETY: The caller passes a live wrapper.+ Some(unsafe { CppInterface::from_wrapper(Gc::from_non_null(wrapper)) })+}++/// A new AnimationEvent that bubbles, as the Event that C++ dispatches.+///+/// # Safety+///+/// `vm` must be the live VM, `realm` a live realm, `event_name`, `animation_name` and `pseudo_element` raw strings that+/// C++ hands over, and `animation` a live wrapper of a CSSAnimation.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_animation_event_create(+ vm: *mut c_void,+ realm: *mut c_void,+ event_name: usize,+ animation_name: usize,+ elapsed_time: f64,+ pseudo_element: usize,+ animation: *mut c_void,+) -> *mut c_void {+ // SAFETY: The caller passes the live VM and a live realm.+ let (vm, realm) = unsafe { realm_arguments(vm, realm) };+ // SAFETY: The caller hands over the strings and passes a live wrapper.+ let (event_name, animation_name, pseudo_element, animation) = unsafe {+ (+ Utf16String::from_raw_owned(event_name),+ Utf16String::from_raw_owned(animation_name),+ Utf16String::from_raw_owned(pseudo_element),+ cpp_interface_from_abi(animation),+ )+ };+ let event_init = AnimationEventInit {+ parent: bubbling_event_init(),+ animation,+ animation_name,+ elapsed_time,+ pseudo_element,+ };+ AnimationEvent::create(vm, realm, &event_name, event_init)+ .event()+ .as_ptr()+}++/// A new TransitionEvent that bubbles, as the Event that C++ dispatches.+///+/// # Safety+///+/// `vm` must be the live VM, `realm` a live realm, `event_name`, `property_name` and `pseudo_element` raw strings that+/// C++ hands over, and `animation` a live wrapper of a CSSTransition.+#[unsafe(no_mangle)]+pub unsafe extern "C" fn web_transition_event_create(+ vm: *mut c_void,+ realm: *mut c_void,+ event_name: usize,+ property_name: usize,+ elapsed_time: f64,+ pseudo_element: usize,+ animation: *mut c_void,+) -> *mut c_void {+ // SAFETY: The caller passes the live VM and a live realm.+ let (vm, realm) = unsafe { realm_arguments(vm, realm) };+ // SAFETY: The caller hands over the strings and passes a live wrapper.+ let (event_name, property_name, pseudo_element, animation) = unsafe {+ (+ Utf16String::from_raw_owned(event_name),+ Utf16String::from_raw_owned(property_name),+ Utf16String::from_raw_owned(pseudo_element),+ cpp_interface_from_abi(animation),+ )+ };+ let event_init = TransitionEventInit {+ parent: bubbling_event_init(),+ animation,+ elapsed_time,+ property_name,+ pseudo_element,+ };+ TransitionEvent::create(vm, realm, &event_name, event_init)+ .event()+ .as_ptr()+}++fn bubbling_event_init() -> EventInit {+ EventInit {+ bubbles: true,+ cancelable: false,+ composed: false,+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/media_query_list_event.rs b/Libraries/LibWeb/Bindings/Rust/src/css/media_query_list_event.rsnew file mode 100644index 00000000000..4308b44c708--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/css/media_query_list_event.rs@@ -0,0 +1,85 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! MediaQueryListEvent, https://drafts.csswg.org/cssom-view/#mediaquerylistevent++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::CppEvent;+use crate::bindings::interface::{Ref, Wrappable, allocate};+use crate::bindings::{CallContext, WebIdlResult};+use crate::dom::event::EventInit;++/// The dictionary MediaQueryListEventInit of CSS/MediaQueryListEvent.idl.+pub(crate) struct MediaQueryListEventInit {+ pub(crate) parent: EventInit,+ pub(crate) matches: bool,+ pub(crate) media: Utf16String,+}++// https://drafts.csswg.org/cssom-view/#mediaquerylistevent+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct MediaQueryListEvent {+ event: CppEvent,+ #[gc(untraced)]+ media: Utf16String,+ matches: bool,+}++impl Wrappable for MediaQueryListEvent {+ fn cpp_parent(&self) -> Option<NonNull<c_void>> {+ self.event.as_cpp_parent()+ }+}++impl MediaQueryListEvent {+ pub(crate) fn create(+ vm: &Vm,+ realm: Gc<Realm>,+ event_name: &Utf16String,+ event_init: MediaQueryListEventInit,+ ) -> Ref<MediaQueryListEvent> {+ let event = CppEvent::create_for_owner(+ realm,+ event_name,+ event_init.parent.bubbles,+ event_init.parent.cancelable,+ event_init.parent.composed,+ );+ let object = allocate(vm, |_| MediaQueryListEvent {+ event,+ media: event_init.media,+ matches: event_init.matches,+ });+ object.event.set_owner(object);+ object+ }++ pub(crate) fn construct(+ cx: &mut CallContext,+ r#type: Utf16String,+ event_init_dict: MediaQueryListEventInit,+ ) -> WebIdlResult<Ref<MediaQueryListEvent>> {+ Ok(Self::create(cx.vm(), cx.realm(), &r#type, event_init_dict))+ }++ pub(crate) fn event(&self) -> &CppEvent {+ &self.event+ }++ pub(crate) fn media(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.media.clone())+ }++ pub(crate) fn matches(&self, _: &mut CallContext) -> WebIdlResult<bool> {+ Ok(self.matches)+ }+}diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs b/Libraries/LibWeb/Bindings/Rust/src/css/mod.rsindex 6c17c424846..0ead0240d4e 100644--- a/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs+++ b/Libraries/LibWeb/Bindings/Rust/src/css/mod.rs@@ -6,6 +6,7 @@//! The CSS Object Model, https://drafts.csswg.org/cssom/+pub(crate) mod animation_event;pub(crate) mod css_image_value;pub(crate) mod css_keyword_value;pub(crate) mod css_math_clamp;@@ -34,4 +35,6 @@ pub(crate) mod css_unparsed_value;pub(crate) mod css_variable_reference_value;pub(crate) mod exports;pub(crate) mod media_list;+pub(crate) mod media_query_list_event;+pub(crate) mod transition_event;pub(crate) mod typed_om;diff --git a/Libraries/LibWeb/Bindings/Rust/src/css/transition_event.rs b/Libraries/LibWeb/Bindings/Rust/src/css/transition_event.rsnew file mode 100644index 00000000000..d073d6be0db--- /dev/null+++ b/Libraries/LibWeb/Bindings/Rust/src/css/transition_event.rs@@ -0,0 +1,104 @@+/*+ * Copyright (c) 2026-present, the Ladybird developers.+ *+ * SPDX-License-Identifier: BSD-2-Clause+ */++//! TransitionEvent, https://drafts.csswg.org/css-transitions-2/#interface-transitionevent-idl++use core::ffi::c_void;+use core::ptr::NonNull;++use ak::Utf16String;+use libjs_rust::api::{Gc, Realm, Trace, Vm};++use super::animation_event::animation_of_wrapper;+use super::css_rule::wrap_cpp_cell;+use crate::bindings::conversions::CppInterface;+use crate::bindings::cpp_cell::CppCell;+use crate::bindings::event_target::CppEvent;+use crate::bindings::interface::{Ref, Wrappable, allocate};+use crate::bindings::{CallContext, WebIdlResult};+use crate::dom::event::EventInit;++/// The dictionary TransitionEventInit of CSS/TransitionEvent.idl.+pub(crate) struct TransitionEventInit {+ pub(crate) parent: EventInit,+ pub(crate) animation: Option<CppInterface>,+ pub(crate) elapsed_time: f64,+ pub(crate) property_name: Utf16String,+ pub(crate) pseudo_element: Utf16String,+}++// https://drafts.csswg.org/css-transitions-2/#interface-transitionevent-idl+#[derive(Trace)]+#[gc(crate = libjs_rust)]+pub(crate) struct TransitionEvent {+ event: CppEvent,+ #[gc(untraced)]+ property_name: Utf16String,+ elapsed_time: f64,+ #[gc(untraced)]+ pseudo_element: Utf16String,+ animation: Option<CppCell>,+}++impl Wrappable for TransitionEvent {+ fn cpp_parent(&self) -> Option<NonNull<c_void>> {+ self.event.as_cpp_parent()+ }+}++impl TransitionEvent {+ pub(crate) fn create(+ vm: &Vm,+ realm: Gc<Realm>,+ event_name: &Utf16String,+ event_init: TransitionEventInit,+ ) -> Ref<TransitionEvent> {+ let event = CppEvent::create_for_owner(+ realm,+ event_name,+ event_init.parent.bubbles,+ event_init.parent.cancelable,+ event_init.parent.composed,+ );+ let object = allocate(vm, |_| TransitionEvent {+ event,+ property_name: event_init.property_name,+ elapsed_time: event_init.elapsed_time,+ pseudo_element: event_init.pseudo_element,+ animation: event_init.animation.map(animation_of_wrapper),+ });+ object.event.set_owner(object);+ object+ }++ pub(crate) fn construct(+ cx: &mut CallContext,+ r#type: Utf16String,+ transition_event_init_dict: TransitionEventInit,+ ) -> WebIdlResult<Ref<TransitionEvent>> {+ Ok(Self::create(cx.vm(), cx.realm(), &r#type, transition_event_init_dict))+ }++ pub(crate) fn event(&self) -> &CppEvent {+ &self.event+ }++ pub(crate) fn property_name(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.property_name.clone())+ }++ pub(crate) fn elapsed_time(&self, _: &mut CallContext) -> WebIdlResult<f64> {+ Ok(self.elapsed_time)+ }++ pub(crate) fn pseudo_element(&self, _: &mut CallContext) -> WebIdlResult<Utf16String> {+ Ok(self.pseudo_element.clone())+ }++ pub(crate) fn animation(&self, cx: &mut CallContext) -> WebIdlResult<Option<CppInterface>> {+ Ok(self.animation.as_ref().map(|animation| wrap_cpp_cell(cx, animation)))+ }+}diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txtindex ccc36a557e2..789edba3abe 100644--- a/Libraries/LibWeb/CMakeLists.txt+++ b/Libraries/LibWeb/CMakeLists.txt@@ -70,7 +70,6 @@ set(SOURCESCrypto/CryptoKey.cppCrypto/SubtleCrypto.cppCSS/Angle.cpp- CSS/AnimationEvent.cppCSS/ComputedStyleWorkingSet.cppCSS/ComputedValues.cppCSS/RustDeclarationBlock.cpp@@ -148,7 +147,6 @@ set(SOURCESCSS/LengthBox.cppCSS/MediaList.cppCSS/MediaQueryList.cpp- CSS/MediaQueryListEvent.cppCSS/Number.cppCSS/NumericType.cppCSS/Parser/ErrorReporter.cpp@@ -217,7 +215,6 @@ set(SOURCESCSS/Supports.cppCSS/SyntaxHighlighter/SyntaxHighlighter.cppCSS/Time.cpp- CSS/TransitionEvent.cppCSS/TypedOM.cppCSS/URL.cppCSS/UpdateStyle.cppdiff --git a/Libraries/LibWeb/CSS/AnimationEvent.cpp b/Libraries/LibWeb/CSS/AnimationEvent.cppdeleted file mode 100644index ff6b03fa1e3..00000000000--- a/Libraries/LibWeb/CSS/AnimationEvent.cpp+++ /dev/null@@ -1,55 +0,0 @@-/*- * Copyright (c) 2024, Matthew Olsson <[email protected]>.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibGC/Heap.h>-#include <LibWeb/CSS/AnimationEvent.h>-#include <LibWeb/CSS/CSSAnimation.h>--namespace Web::CSS {--GC_DEFINE_ALLOCATOR(AnimationEvent);--GC::Ref<AnimationEvent> AnimationEvent::create(Utf16FlyString const& type, Bindings::AnimationEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)-{- return GC::Heap::the().allocate<AnimationEvent>(type, event_init, time_stamp);-}--GC::Ref<AnimationEvent> AnimationEvent::create(Utf16FlyString const& type, Utf16String animation_name, double elapsed_time, FlyString pseudo_element, HighResolutionTime::DOMHighResTimeStamp time_stamp)-{- auto event = GC::Heap::the().allocate<AnimationEvent>(type, move(animation_name), elapsed_time, move(pseudo_element), time_stamp);- event->set_is_trusted(true);- return event;-}--WebIDL::ExceptionOr<GC::Ref<AnimationEvent>> AnimationEvent::create_for_constructor(Utf16FlyString const& type, Bindings::AnimationEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)-{- return create(type, event_init, time_stamp);-}--AnimationEvent::AnimationEvent(Utf16FlyString const& type, Bindings::AnimationEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)- : DOM::Event(FlyString { type.view().to_utf8_but_should_be_ported_to_utf16() }, event_init, time_stamp)- , m_animation_name(event_init.animation_name)- , m_elapsed_time(event_init.elapsed_time)- , m_pseudo_element(event_init.pseudo_element)- , m_animation(event_init.animation)-{-}--AnimationEvent::AnimationEvent(Utf16FlyString const& type, Utf16String animation_name, double elapsed_time, FlyString pseudo_element, HighResolutionTime::DOMHighResTimeStamp time_stamp)- : DOM::Event(FlyString { type.to_utf16_string().to_utf8() }, time_stamp)- , m_animation_name(move(animation_name))- , m_elapsed_time(elapsed_time)- , m_pseudo_element(Utf16String::from_utf8(pseudo_element))-{-}--void AnimationEvent::visit_edges(Cell::Visitor& visitor)-{- Base::visit_edges(visitor);- visitor.visit(m_animation);-}--}diff --git a/Libraries/LibWeb/CSS/AnimationEvent.h b/Libraries/LibWeb/CSS/AnimationEvent.hdeleted file mode 100644index bb5cc75dd5d..00000000000--- a/Libraries/LibWeb/CSS/AnimationEvent.h+++ /dev/null@@ -1,61 +0,0 @@-/*- * Copyright (c) 2024, Matthew Olsson <[email protected]>.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Utf16String.h>-#include <LibWeb/Bindings/AnimationEvent.h>-#include <LibWeb/DOM/Event.h>-#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>--namespace Web::HTML {--class Window;--}--namespace Web::CSS {--using AnimationEventInit = Bindings::AnimationEventInit;--// https://www.w3.org/TR/css-animations-1/#animationevent-class AnimationEvent : public DOM::Event {- WEB_WRAPPABLE(AnimationEvent, DOM::Event);- GC_DECLARE_ALLOCATOR(AnimationEvent);--public:- [[nodiscard]] static GC::Ref<AnimationEvent> create(Utf16FlyString const& type, Bindings::AnimationEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp);- [[nodiscard]] static GC::Ref<AnimationEvent> create(Utf16FlyString const& type, Utf16String animation_name, double elapsed_time, FlyString pseudo_element, HighResolutionTime::DOMHighResTimeStamp);- static WebIDL::ExceptionOr<GC::Ref<AnimationEvent>> create_for_constructor(Utf16FlyString const& type, Bindings::AnimationEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp);-- virtual ~AnimationEvent() override = default;-- Utf16String const& animation_name() const { return m_animation_name; }- double elapsed_time() const { return m_elapsed_time; }- Utf16String const& pseudo_element() const { return m_pseudo_element; }- GC::Ptr<CSSAnimation> animation() const { return m_animation; }- static constexpr size_t animation_offset() { return offsetof(AnimationEvent, m_animation); }-- virtual void visit_edges(Cell::Visitor&) override;--private:- AnimationEvent(Utf16FlyString const& type, Bindings::AnimationEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp);- AnimationEvent(Utf16FlyString const& type, Utf16String animation_name, double elapsed_time, FlyString pseudo_element, HighResolutionTime::DOMHighResTimeStamp);-- // https://www.w3.org/TR/css-animations-1/#dom-animationevent-animationname- Utf16String m_animation_name {};-- // https://www.w3.org/TR/css-animations-1/#dom-animationevent-elapsedtime- double m_elapsed_time { 0.0 };-- // https://www.w3.org/TR/css-animations-1/#dom-animationevent-pseudoelement- Utf16String m_pseudo_element {};-- // https://drafts.csswg.org/css-animations-2/#dom-animationevent-animation- GC::Ptr<CSSAnimation> m_animation;-};--}diff --git a/Libraries/LibWeb/CSS/AnimationEvent.idl b/Libraries/LibWeb/CSS/AnimationEvent.idlindex ba163cf7a94..4dcfd07ec62 100644--- a/Libraries/LibWeb/CSS/AnimationEvent.idl+++ b/Libraries/LibWeb/CSS/AnimationEvent.idl@@ -1,12 +1,12 @@// https://drafts.csswg.org/css-animations-1/#animationevent// https://drafts.csswg.org/css-animations-2/#interface-animationevent-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface AnimationEvent : Event {- constructor([FlyString] CSSOMString type, optional AnimationEventInit animationEventInitDict = {});+ constructor(CSSOMString type, optional AnimationEventInit animationEventInitDict = {});readonly attribute CSSOMString animationName;readonly attribute double elapsedTime;readonly attribute CSSOMString pseudoElement;- [DirectGetter] readonly attribute CSSAnimation? animation;+ readonly attribute CSSAnimation? animation;};// https://drafts.csswg.org/css-animations-1/#dictdef-animationeventinitdiff --git a/Libraries/LibWeb/CSS/CSSAnimation.cpp b/Libraries/LibWeb/CSS/CSSAnimation.cppindex 09d4e2ae531..467ac74f59e 100644--- a/Libraries/LibWeb/CSS/CSSAnimation.cpp+++ b/Libraries/LibWeb/CSS/CSSAnimation.cpp@@ -5,20 +5,48 @@*/#include <LibGC/Heap.h>+#include <LibJS/HostClassBuilder.h>#include <LibWeb/Animations/DocumentTimeline.h>#include <LibWeb/Animations/KeyframeEffect.h>#include <LibWeb/Animations/NamedTimelines.h>#include <LibWeb/Animations/ScrollTimeline.h>#include <LibWeb/Animations/ViewTimeline.h>+#include <LibWeb/Bindings/WrapperWorld.h>#include <LibWeb/CSS/CSSAnimation.h>#include <LibWeb/CSS/PropertyID.h>#include <LibWeb/CSS/PseudoElement.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/Element.h>+#include <LibWeb/DOM/Event.h>+#include <LibWeb/HTML/Scripting/Environments.h>#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>namespace Web::CSS {+extern "C" {++// Declared in Bindings/Rust/src/css/animation_event.rs.+void* web_css_animation_of_wrapper(void* wrapper);++// Defined in Bindings/Rust/src/css/exports.rs.+void* web_animation_event_create(JSVM*, void* realm, FlatPtr event_name, FlatPtr name, double elapsed_time, FlatPtr pseudo_element, void* animation);+}++void* web_css_animation_of_wrapper(void* wrapper)+{+ auto* animation = Bindings::impl_from<Animations::Animation>(static_cast<JS::Object*>(wrapper));+ VERIFY(animation);+ return static_cast<GC::Cell*>(animation);+}++GC::Ref<DOM::Event> CSSAnimation::create_event(DOM::Document const& document, Utf16FlyString const& type, double elapsed_time, Utf16String pseudo_element)+{+ auto& realm = HTML::relevant_realm(document);+ auto wrapper = Bindings::wrap(Bindings::host_defined_wrapper_world(realm), realm, GC::Ref<CSSAnimation> { *this });+ auto* event = web_animation_event_create(JS::HostABI::vm_to_abi(realm.vm()), &realm, type.to_utf16_string().into_raw(), animation_name().to_utf16_string().into_raw(), elapsed_time, move(pseudo_element).into_raw(), JS::HostABI::object_to_abi(wrapper.ptr()));+ return GC::Ref { *static_cast<DOM::Event*>(static_cast<GC::Cell*>(event)) };+}+GC_DEFINE_ALLOCATOR(CSSAnimation);GC::Ref<CSSAnimation> CSSAnimation::create(HTML::EnvironmentSettingsObject& environment)diff --git a/Libraries/LibWeb/CSS/CSSAnimation.h b/Libraries/LibWeb/CSS/CSSAnimation.hindex b7672585a2c..c1be707adce 100644--- a/Libraries/LibWeb/CSS/CSSAnimation.h+++ b/Libraries/LibWeb/CSS/CSSAnimation.h@@ -22,6 +22,9 @@ class CSSAnimation : public Animations::Animation {public:static GC::Ref<CSSAnimation> create(HTML::EnvironmentSettingsObject&);+ // A new AnimationEvent for this animation that bubbles, which is implemented in Rust.+ GC::Ref<DOM::Event> create_event(DOM::Document const&, Utf16FlyString const& type, double elapsed_time, Utf16String pseudo_element);+Utf16FlyString const& animation_name() const { return m_animation_name; }void set_animation_name(Utf16FlyString const& animation_name) { m_animation_name = animation_name; }diff --git a/Libraries/LibWeb/CSS/CSSTransition.cpp b/Libraries/LibWeb/CSS/CSSTransition.cppindex c844bfb1cac..2dee5222f5f 100644--- a/Libraries/LibWeb/CSS/CSSTransition.cpp+++ b/Libraries/LibWeb/CSS/CSSTransition.cpp@@ -6,13 +6,17 @@*/#include <LibGC/Heap.h>+#include <LibJS/HostClassBuilder.h>#include <LibWeb/Animations/DocumentTimeline.h>+#include <LibWeb/Bindings/WrapperWorld.h>#include <LibWeb/CSS/CSSStyleDeclaration.h>#include <LibWeb/CSS/CSSTransition.h>#include <LibWeb/CSS/PropertyID.h>#include <LibWeb/CSS/StyleComputer.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/Element.h>+#include <LibWeb/DOM/Event.h>+#include <LibWeb/HTML/Scripting/Environments.h>#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>#include <LibWeb/Layout/NodeArena.h>#include <LibWeb/StyleEngineRustFFI.h>@@ -20,6 +24,20 @@namespace Web::CSS {+extern "C" {++// Defined in Bindings/Rust/src/css/exports.rs.+void* web_transition_event_create(JSVM*, void* realm, FlatPtr event_name, FlatPtr name, double elapsed_time, FlatPtr pseudo_element, void* animation);+}++GC::Ref<DOM::Event> CSSTransition::create_event(DOM::Document const& document, Utf16FlyString const& type, double elapsed_time, Utf16String pseudo_element)+{+ auto& realm = HTML::relevant_realm(document);+ auto wrapper = Bindings::wrap(Bindings::host_defined_wrapper_world(realm), realm, GC::Ref<CSSTransition> { *this });+ auto* event = web_transition_event_create(JS::HostABI::vm_to_abi(realm.vm()), &realm, type.to_utf16_string().into_raw(), transition_property().to_utf16_string().into_raw(), elapsed_time, move(pseudo_element).into_raw(), JS::HostABI::object_to_abi(wrapper.ptr()));+ return GC::Ref { *static_cast<DOM::Event*>(static_cast<GC::Cell*>(event)) };+}+GC_DEFINE_ALLOCATOR(CSSTransition);GC::Ref<CSSTransition> CSSTransition::start_a_provisional_transition(diff --git a/Libraries/LibWeb/CSS/CSSTransition.h b/Libraries/LibWeb/CSS/CSSTransition.hindex b8049aeb2ea..ffb717cf18c 100644--- a/Libraries/LibWeb/CSS/CSSTransition.h+++ b/Libraries/LibWeb/CSS/CSSTransition.h@@ -19,6 +19,9 @@ class CSSTransition : public Animations::Animation {GC_DECLARE_ALLOCATOR(CSSTransition);public:+ // A new TransitionEvent for this transition that bubbles, which is implemented in Rust.+ GC::Ref<DOM::Event> create_event(DOM::Document const&, Utf16FlyString const& type, double elapsed_time, Utf16String pseudo_element);+// A transition is started provisionally, and associated with its target only once committed.static GC::Ref<CSSTransition> start_a_provisional_transition(DOM::AbstractElement,diff --git a/Libraries/LibWeb/CSS/DevToolsAppliedStyleRules.cpp b/Libraries/LibWeb/CSS/DevToolsAppliedStyleRules.cppindex 8328f1cfafc..465e64e035a 100644--- a/Libraries/LibWeb/CSS/DevToolsAppliedStyleRules.cpp+++ b/Libraries/LibWeb/CSS/DevToolsAppliedStyleRules.cpp@@ -29,7 +29,6 @@#include <LibWeb/Animations/ScrollTimeline.h>#include <LibWeb/Animations/ViewTimeline.h>#include <LibWeb/Bindings/PrincipalHostDefined.h>-#include <LibWeb/CSS/AnimationEvent.h>#include <LibWeb/CSS/CSSAnimation.h>#include <LibWeb/CSS/CSSImportRule.h>#include <LibWeb/CSS/CSSLayerBlockRule.h>diff --git a/Libraries/LibWeb/CSS/MediaQueryList.cpp b/Libraries/LibWeb/CSS/MediaQueryList.cppindex 11c91bcc610..f6a25c2d442 100644--- a/Libraries/LibWeb/CSS/MediaQueryList.cpp+++ b/Libraries/LibWeb/CSS/MediaQueryList.cpp@@ -6,6 +6,8 @@*/#include <LibGC/Heap.h>+#include <LibJS/HostClassBuilder.h>+#include <LibJS/Runtime/VM.h>#include <LibWeb/CSS/MediaQueryList.h>#include <LibWeb/DOM/Document.h>#include <LibWeb/DOM/EventDispatcher.h>@@ -17,6 +19,12 @@namespace Web::CSS {+extern "C" {++// Defined in Bindings/Rust/src/css/exports.rs.+void* web_media_query_list_event_create(JSVM*, void* realm, FlatPtr media, bool matches);+}+GC_DEFINE_ALLOCATOR(MediaQueryList);GC::Ref<MediaQueryList> MediaQueryList::create(DOM::Document& document, RustMediaList media)@@ -68,6 +76,12 @@ bool MediaQueryList::matches() constreturn now_matches;}+GC::Ref<DOM::Event> MediaQueryList::create_change_event(bool matches) const+{+ auto* event = web_media_query_list_event_create(JS::HostABI::vm_to_abi(JS::VM::the()), &HTML::relevant_realm(*m_document), media().into_raw(), matches);+ return GC::Ref { *static_cast<DOM::Event*>(static_cast<GC::Cell*>(event)) };+}+bool MediaQueryList::evaluate(){return m_media.evaluate(m_document);diff --git a/Libraries/LibWeb/CSS/MediaQueryList.h b/Libraries/LibWeb/CSS/MediaQueryList.hindex 3029b685c09..47f9df7c312 100644--- a/Libraries/LibWeb/CSS/MediaQueryList.h+++ b/Libraries/LibWeb/CSS/MediaQueryList.h@@ -27,6 +27,9 @@ public:bool matches() const;bool evaluate();+ // A new MediaQueryListEvent named `change` for this list, which is implemented in Rust.+ GC::Ref<DOM::Event> create_change_event(bool matches) const;+void add_listener(GC::Ptr<DOM::IDLEventListener>);void remove_listener(GC::Ptr<DOM::IDLEventListener>);diff --git a/Libraries/LibWeb/CSS/MediaQueryListEvent.cpp b/Libraries/LibWeb/CSS/MediaQueryListEvent.cppdeleted file mode 100644index f9009d3f597..00000000000--- a/Libraries/LibWeb/CSS/MediaQueryListEvent.cpp+++ /dev/null@@ -1,49 +0,0 @@-/*- * Copyright (c) 2022, Andreas Kling <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include <LibGC/Heap.h>-#include <LibWeb/CSS/MediaQueryListEvent.h>--namespace Web::CSS {--GC_DEFINE_ALLOCATOR(MediaQueryListEvent);--GC::Ref<MediaQueryListEvent> MediaQueryListEvent::create(Utf16FlyString const& event_name, Bindings::MediaQueryListEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)-{- return GC::Heap::the().allocate<MediaQueryListEvent>(event_name, event_init, time_stamp);-}--GC::Ref<MediaQueryListEvent> MediaQueryListEvent::create(- Utf16FlyString const& event_name, Utf16String media, bool matches,- HighResolutionTime::DOMHighResTimeStamp time_stamp)-{- auto event = GC::Heap::the().allocate<MediaQueryListEvent>(event_name, move(media), matches, time_stamp);- event->set_is_trusted(true);- return event;-}--GC::Ref<MediaQueryListEvent> MediaQueryListEvent::create_for_constructor(Utf16FlyString const& event_name, Bindings::MediaQueryListEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)-{- return create(event_name, event_init, time_stamp);-}--MediaQueryListEvent::MediaQueryListEvent(Utf16FlyString const& event_name, Bindings::MediaQueryListEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)- : DOM::Event(FlyString { event_name.to_utf16_string().to_utf8() }, event_init, time_stamp)- , m_media(event_init.media)- , m_matches(event_init.matches)-{-}--MediaQueryListEvent::MediaQueryListEvent(Utf16FlyString const& event_name, Utf16String media, bool matches, HighResolutionTime::DOMHighResTimeStamp time_stamp)- : DOM::Event(FlyString { event_name.to_utf16_string().to_utf8() }, time_stamp)- , m_media(move(media))- , m_matches(matches)-{-}--MediaQueryListEvent::~MediaQueryListEvent() = default;--}diff --git a/Libraries/LibWeb/CSS/MediaQueryListEvent.h b/Libraries/LibWeb/CSS/MediaQueryListEvent.hdeleted file mode 100644index 77b8e336fd2..00000000000--- a/Libraries/LibWeb/CSS/MediaQueryListEvent.h+++ /dev/null@@ -1,46 +0,0 @@-/*- * Copyright (c) 2021, Sam Atkins <[email protected]>- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Utf16FlyString.h>-#include <LibWeb/Bindings/MediaQueryListEvent.h>-#include <LibWeb/DOM/Event.h>-#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>--namespace Web::HTML {--class Window;--}--namespace Web::CSS {--using MediaQueryListEventInit = Bindings::MediaQueryListEventInit;--class MediaQueryListEvent final : public DOM::Event {- WEB_WRAPPABLE(MediaQueryListEvent, DOM::Event);- GC_DECLARE_ALLOCATOR(MediaQueryListEvent);--public:- [[nodiscard]] static GC::Ref<MediaQueryListEvent> create(Utf16FlyString const& event_name, Bindings::MediaQueryListEventInit const&, HighResolutionTime::DOMHighResTimeStamp);- [[nodiscard]] static GC::Ref<MediaQueryListEvent> create(Utf16FlyString const& event_name, Utf16String media, bool matches, HighResolutionTime::DOMHighResTimeStamp);- [[nodiscard]] static GC::Ref<MediaQueryListEvent> create_for_constructor(Utf16FlyString const& event_name, Bindings::MediaQueryListEventInit const&, HighResolutionTime::DOMHighResTimeStamp);-- virtual ~MediaQueryListEvent() override;-- Utf16String const& media() const { return m_media; }- bool matches() const { return m_matches; }--private:- MediaQueryListEvent(Utf16FlyString const& event_name, Bindings::MediaQueryListEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp);- MediaQueryListEvent(Utf16FlyString const& event_name, Utf16String media, bool matches, HighResolutionTime::DOMHighResTimeStamp);-- Utf16String m_media;- bool m_matches;-};--}diff --git a/Libraries/LibWeb/CSS/MediaQueryListEvent.idl b/Libraries/LibWeb/CSS/MediaQueryListEvent.idlindex 8db05fce2ba..b647ae48b20 100644--- a/Libraries/LibWeb/CSS/MediaQueryListEvent.idl+++ b/Libraries/LibWeb/CSS/MediaQueryListEvent.idl@@ -1,7 +1,7 @@// https://w3c.github.io/csswg-drafts/cssom-view-1/#mediaquerylistevent-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface MediaQueryListEvent : Event {- constructor([FlyString] CSSOMString type, optional MediaQueryListEventInit eventInitDict = {});+ constructor(CSSOMString type, optional MediaQueryListEventInit eventInitDict = {});readonly attribute CSSOMString media;readonly attribute boolean matches;diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cppindex cc3dd684eaf..c50cccd2c1a 100644--- a/Libraries/LibWeb/CSS/StyleComputer.cpp+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp@@ -32,7 +32,6 @@#include <LibWeb/Animations/ScrollTimeline.h>#include <LibWeb/Animations/ViewTimeline.h>#include <LibWeb/Bindings/PrincipalHostDefined.h>-#include <LibWeb/CSS/AnimationEvent.h>#include <LibWeb/CSS/CSSAnimation.h>#include <LibWeb/CSS/CSSImportRule.h>#include <LibWeb/CSS/CSSLayerBlockRule.h>diff --git a/Libraries/LibWeb/CSS/TransitionEvent.cpp b/Libraries/LibWeb/CSS/TransitionEvent.cppdeleted file mode 100644index f834e8c7987..00000000000--- a/Libraries/LibWeb/CSS/TransitionEvent.cpp+++ /dev/null@@ -1,59 +0,0 @@-/*- * Copyright (c) 2024, Lucas Chollet <[email protected]>.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#include "TransitionEvent.h"-#include <LibGC/Heap.h>-#include <LibWeb/CSS/CSSTransition.h>--namespace Web::CSS {--GC_DEFINE_ALLOCATOR(TransitionEvent);--GC::Ref<TransitionEvent> TransitionEvent::create(Utf16FlyString const& type, Bindings::TransitionEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)-{- return GC::Heap::the().allocate<TransitionEvent>(type, event_init, time_stamp);-}--GC::Ref<TransitionEvent> TransitionEvent::create(Utf16FlyString const& type, String property_name, double elapsed_time, String pseudo_element, HighResolutionTime::DOMHighResTimeStamp time_stamp, GC::Ptr<CSSTransition> animation)-{- auto event = GC::Heap::the().allocate<TransitionEvent>(type, move(property_name), elapsed_time, move(pseudo_element), time_stamp, animation);- event->set_bubbles(true);- event->set_is_trusted(true);- return event;-}--GC::Ref<TransitionEvent> TransitionEvent::create_for_constructor(Utf16FlyString const& type, Bindings::TransitionEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)-{- return create(type, event_init, time_stamp);-}--TransitionEvent::TransitionEvent(Utf16FlyString const& type, Bindings::TransitionEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp time_stamp)- : DOM::Event(FlyString { type.to_utf16_string().to_utf8() }, event_init, time_stamp)- , m_property_name(event_init.property_name)- , m_elapsed_time(event_init.elapsed_time)- , m_pseudo_element(event_init.pseudo_element)- , m_animation(event_init.animation)-{-}--TransitionEvent::TransitionEvent(Utf16FlyString const& type, String property_name, double elapsed_time, String pseudo_element, HighResolutionTime::DOMHighResTimeStamp time_stamp, GC::Ptr<CSSTransition> animation)- : DOM::Event(FlyString { type.to_utf16_string().to_utf8() }, time_stamp)- , m_property_name(Utf16String::from_utf8(property_name))- , m_elapsed_time(elapsed_time)- , m_pseudo_element(Utf16String::from_utf8(pseudo_element))- , m_animation(animation)-{-}--TransitionEvent::~TransitionEvent() = default;--void TransitionEvent::visit_edges(Visitor& visitor)-{- Base::visit_edges(visitor);- visitor.visit(m_animation);-}--}diff --git a/Libraries/LibWeb/CSS/TransitionEvent.h b/Libraries/LibWeb/CSS/TransitionEvent.hdeleted file mode 100644index ca8a74dc9ed..00000000000--- a/Libraries/LibWeb/CSS/TransitionEvent.h+++ /dev/null@@ -1,53 +0,0 @@-/*- * Copyright (c) 2024, Lucas Chollet <[email protected]>.- *- * SPDX-License-Identifier: BSD-2-Clause- */--#pragma once--#include <AK/Utf16String.h>-#include <LibWeb/Bindings/TransitionEvent.h>-#include <LibWeb/DOM/Event.h>-#include <LibWebCommon/HighResolutionTime/DOMHighResTimeStamp.h>--namespace Web::HTML {--class Window;--}--namespace Web::CSS {--using TransitionEventInit = Bindings::TransitionEventInit;--class TransitionEvent final : public DOM::Event {- WEB_WRAPPABLE(TransitionEvent, DOM::Event);- GC_DECLARE_ALLOCATOR(TransitionEvent);--public:- [[nodiscard]] static GC::Ref<TransitionEvent> create(Utf16FlyString const& event_name, Bindings::TransitionEventInit const&, HighResolutionTime::DOMHighResTimeStamp);- [[nodiscard]] static GC::Ref<TransitionEvent> create(Utf16FlyString const& event_name, String property_name, double elapsed_time, String pseudo_element, HighResolutionTime::DOMHighResTimeStamp, GC::Ptr<CSSTransition> animation = nullptr);- [[nodiscard]] static GC::Ref<TransitionEvent> create_for_constructor(Utf16FlyString const& event_name, Bindings::TransitionEventInit const&, HighResolutionTime::DOMHighResTimeStamp);-- virtual ~TransitionEvent() override;-- Utf16String const& property_name() const { return m_property_name; }- double elapsed_time() const { return m_elapsed_time; }- Utf16String const& pseudo_element() const { return m_pseudo_element; }- GC::Ptr<CSSTransition> animation() const { return m_animation; }- static constexpr size_t animation_offset() { return offsetof(TransitionEvent, m_animation); }-- virtual void visit_edges(Cell::Visitor&) override;--private:- TransitionEvent(Utf16FlyString const& event_name, Bindings::TransitionEventInit const& event_init, HighResolutionTime::DOMHighResTimeStamp);- TransitionEvent(Utf16FlyString const& event_name, String property_name, double elapsed_time, String pseudo_element, HighResolutionTime::DOMHighResTimeStamp, GC::Ptr<CSSTransition> animation);-- Utf16String m_property_name {};- double m_elapsed_time {};- Utf16String m_pseudo_element {};- GC::Ptr<CSSTransition> m_animation;-};--}diff --git a/Libraries/LibWeb/CSS/TransitionEvent.idl b/Libraries/LibWeb/CSS/TransitionEvent.idlindex 36a20de5dc9..f8899d61739 100644--- a/Libraries/LibWeb/CSS/TransitionEvent.idl+++ b/Libraries/LibWeb/CSS/TransitionEvent.idl@@ -1,11 +1,11 @@// https://drafts.csswg.org/css-transitions-2/#interface-transitionevent-idl-[Exposed=Window]+[Exposed=Window, ImplementedIn=Rust]interface TransitionEvent : Event {- constructor([FlyString] CSSOMString type, optional TransitionEventInit transitionEventInitDict = {});+ constructor(CSSOMString type, optional TransitionEventInit transitionEventInitDict = {});readonly attribute CSSOMString propertyName;readonly attribute double elapsedTime;readonly attribute CSSOMString pseudoElement;- [DirectGetter] readonly attribute CSSTransition? animation;+ readonly attribute CSSTransition? animation;};// https://drafts.csswg.org/css-transitions-2/#interface-transitionevent-idldiff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cppindex 129214de22e..ce40939fec3 100644--- a/Libraries/LibWeb/DOM/Document.cpp+++ b/Libraries/LibWeb/DOM/Document.cpp@@ -52,7 +52,6 @@#include <LibWeb/Bindings/Wrappable.h>#include <LibWeb/Bindings/WrapperWorld.h>#include <LibWeb/CSS/Angle.h>-#include <LibWeb/CSS/AnimationEvent.h>#include <LibWeb/CSS/CSSAnimation.h>#include <LibWeb/CSS/CSSTransition.h>#include <LibWeb/CSS/ComputedStyleWorkingSet.h>@@ -69,7 +68,6 @@#include <LibWeb/CSS/Invalidation/PseudoClassInvalidator.h>#include <LibWeb/CSS/Length.h>#include <LibWeb/CSS/MediaQueryList.h>-#include <LibWeb/CSS/MediaQueryListEvent.h>#include <LibWeb/CSS/Parser/Parser.h>#include <LibWeb/CSS/PropertyID.h>#include <LibWeb/CSS/PropertyNameAndID.h>@@ -88,7 +86,6 @@#include <LibWeb/CSS/StyleValues/OpacityValueStyleValue.h>#include <LibWeb/CSS/StyleValues/StyleValueList.h>#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>-#include <LibWeb/CSS/TransitionEvent.h>#include <LibWeb/CSS/VisualViewport.h>#include <LibWeb/ComputedValuesRustFFI.h>#include <LibWeb/ContentSecurityPolicy/Directives/HTMLIntegration.h>@@ -4693,17 +4690,18 @@ void Document::dispatch_events_for_transition(GC::Ref<CSS::CSSTransition> transiauto timeline = transition->timeline();+ auto owning_element = transition->owning_element().value();+ auto& global = HTML::relevant_global_object(owning_element.element().document());+ auto pseudo_element = owning_element.pseudo_element().map([](auto it) {+ return Utf16String::formatted("::{}", CSS::pseudo_element_name(it));+ })+ .value_or({});+ auto event = transition->create_event(owning_element.element().document(), type, elapsed_time_output, move(pseudo_element));+ event->set_time_stamp(HighResolutionTime::current_high_resolution_time(global));+ event->set_is_trusted(true);+append_pending_animation_event({- .event = CSS::TransitionEvent::create(- type,- String { transition->transition_property().view().to_utf8_but_should_be_ported_to_utf16() },- elapsed_time_output,- transition->owning_element()->pseudo_element().map([](auto it) {- return MUST(String::formatted("::{}", CSS::pseudo_element_name(it)));- })- .value_or({}),- HighResolutionTime::current_high_resolution_time(HTML::relevant_global_object(transition->owning_element()->element().document())),- transition),+ .event = event,.animation = transition,.target = transition->owning_element()->element(),.scheduled_event_time = timeline && timeline->can_convert_a_timeline_time_to_an_origin_relative_time()@@ -4804,22 +4802,13 @@ void Document::dispatch_events_for_animation_if_necessary(GC::Ref<Animations::Anauto timeline = animation->timeline();- Bindings::AnimationEventInit event_init {};- event_init.bubbles = true;- event_init.animation_name = css_animation.animation_name().to_utf16_string();- event_init.elapsed_time = elapsed_time_output;- if (auto pseudo_element = owning_element->pseudo_element().map([](auto it) {- return Utf16String::formatted("::{}", CSS::pseudo_element_name(it));- });- pseudo_element.has_value()) {- event_init.pseudo_element = pseudo_element.release_value();- }- event_init.animation = css_animation;-- auto event = CSS::AnimationEvent::create(- name,- event_init,- HighResolutionTime::current_high_resolution_time(HTML::relevant_global_object(owning_element->element())));+ auto pseudo_element = owning_element->pseudo_element().map([](auto it) {+ return Utf16String::formatted("::{}", CSS::pseudo_element_name(it));+ })+ .value_or({});+ auto& global = HTML::relevant_global_object(owning_element->element());+ auto event = css_animation.create_event(owning_element->element().document(), name, elapsed_time_output, move(pseudo_element));+ event->set_time_stamp(HighResolutionTime::current_high_resolution_time(global));event->set_is_trusted(true);append_pending_animation_event({@@ -5846,11 +5835,8 @@ void Document::evaluate_media_queries_and_report_changes()auto did_change_internally = media_query_list->has_changed_state();media_query_list->set_has_changed_state(false);if (did_change_internally == true || did_match != now_matches) {- auto event = CSS::MediaQueryListEvent::create(- HTML::EventNames::change,- media_query_list->media(),- now_matches,- HighResolutionTime::current_high_resolution_time(relevant_global_object(*this)));+ auto event = media_query_list->create_change_event(now_matches);+ event->set_time_stamp(HighResolutionTime::current_high_resolution_time(relevant_global_object(*this)));event->set_is_trusted(true);media_query_list->dispatch_event(*event);}diff --git a/Libraries/LibWeb/Forward.h b/Libraries/LibWeb/Forward.hindex 9bf0f3f7b2a..b17f46b2673 100644--- a/Libraries/LibWeb/Forward.h+++ b/Libraries/LibWeb/Forward.h@@ -327,7 +327,6 @@ class LengthPercentageOrAuto;class LengthStyleValue;class MediaList;class MediaQueryList;-class MediaQueryListEvent;class Number;class NumberStyleValue;class NumericType;diff --git a/Tests/LibWeb/Text/expected/css/AnimationEvent-animation-attribute.txt b/Tests/LibWeb/Text/expected/css/AnimationEvent-animation-attribute.txtnew file mode 100644index 00000000000..af3910b5f3a--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/AnimationEvent-animation-attribute.txt@@ -0,0 +1,5 @@+AnimationEvent default: null+AnimationEvent init: true+TransitionEvent default: null+TransitionEvent init: true+AnimationEvent with a CSSTransition: TypeErrordiff --git a/Tests/LibWeb/Text/input/css/AnimationEvent-animation-attribute.html b/Tests/LibWeb/Text/input/css/AnimationEvent-animation-attribute.htmlnew file mode 100644index 00000000000..6990fdc623a--- /dev/null+++ b/Tests/LibWeb/Text/input/css/AnimationEvent-animation-attribute.html@@ -0,0 +1,35 @@+<!DOCTYPE html>+<style>+ @keyframes move {+ from { margin-left: 0; }+ to { margin-left: 10px; }+ }+ #animated {+ animation: move 100s;+ }+ #transitioned {+ transition: margin-left 100s;+ }+</style>+<div id="animated"></div>+<div id="transitioned"></div>+<script src="../include.js"></script>+<script>+ test(() => {+ const cssAnimation = animated.getAnimations()[0];+ println(`AnimationEvent default: ${new AnimationEvent("a").animation}`);+ println(`AnimationEvent init: ${new AnimationEvent("a", { animation: cssAnimation }).animation === cssAnimation}`);++ getComputedStyle(transitioned).marginLeft;+ transitioned.style.marginLeft = "10px";+ const cssTransition = transitioned.getAnimations()[0];+ println(`TransitionEvent default: ${new TransitionEvent("t").animation}`);+ println(`TransitionEvent init: ${new TransitionEvent("t", { animation: cssTransition }).animation === cssTransition}`);++ try {+ new AnimationEvent("a", { animation: cssTransition });+ } catch (error) {+ println(`AnimationEvent with a CSSTransition: ${error.name}`);+ }+ });+</script>