diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 89e7a041e5..550a96e146 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -29,6 +29,7 @@ set(SOURCES Crypto/CryptoKey.cpp Crypto/SubtleCrypto.cpp CSS/Angle.cpp + CSS/AnimationEvent.cpp CSS/CalculatedOr.cpp CSS/Clip.cpp CSS/CSS.cpp diff --git a/Userland/Libraries/LibWeb/CSS/AnimationEvent.cpp b/Userland/Libraries/LibWeb/CSS/AnimationEvent.cpp new file mode 100644 index 0000000000..6ed52600d5 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/AnimationEvent.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, Matthew Olsson . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::CSS { + +JS::NonnullGCPtr AnimationEvent::create(JS::Realm& realm, FlyString const& type, AnimationEventInit const& event_init) +{ + return realm.heap().allocate(realm, realm, type, event_init); +} + +WebIDL::ExceptionOr> AnimationEvent::construct_impl(JS::Realm& realm, FlyString const& type, AnimationEventInit const& event_init) +{ + return create(realm, type, event_init); +} + +AnimationEvent::AnimationEvent(JS::Realm& realm, FlyString const& type, AnimationEventInit const& event_init) + : DOM::Event(realm, type, event_init) + , m_animation_name(event_init.animation_name) + , m_elapsed_time(event_init.elapsed_time) + , m_pseudo_element(event_init.pseudo_element) +{ +} + +void AnimationEvent::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "AnimationEvent"_fly_string)); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/AnimationEvent.h b/Userland/Libraries/LibWeb/CSS/AnimationEvent.h new file mode 100644 index 0000000000..d3986f2cf5 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/AnimationEvent.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024, Matthew Olsson . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::CSS { + +// https://www.w3.org/TR/css-animations-1/#dictdef-animationeventinit +struct AnimationEventInit : public DOM::EventInit { + FlyString animation_name { ""_fly_string }; + double elapsed_time { 0.0 }; + FlyString pseudo_element { ""_fly_string }; +}; + +// https://www.w3.org/TR/css-animations-1/#animationevent +class AnimationEvent : public DOM::Event { + WEB_PLATFORM_OBJECT(AnimationEvent, DOM::Event); + +public: + [[nodiscard]] static JS::NonnullGCPtr create(JS::Realm&, FlyString const& type, AnimationEventInit const& event_init = {}); + static WebIDL::ExceptionOr> construct_impl(JS::Realm&, FlyString const& type, AnimationEventInit const& event_init); + + virtual ~AnimationEvent() override = default; + + FlyString const& animation_name() const { return m_animation_name; } + double elapsed_time() const { return m_elapsed_time; } + FlyString const& pseudo_element() const { return m_pseudo_element; } + +private: + AnimationEvent(JS::Realm&, FlyString const& type, AnimationEventInit const& event_init); + + virtual void initialize(JS::Realm&) override; + + // https://www.w3.org/TR/css-animations-1/#dom-animationevent-animationname + FlyString 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 + FlyString m_pseudo_element {}; +}; + +} diff --git a/Userland/Libraries/LibWeb/CSS/AnimationEvent.idl b/Userland/Libraries/LibWeb/CSS/AnimationEvent.idl new file mode 100644 index 0000000000..d14452af39 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/AnimationEvent.idl @@ -0,0 +1,17 @@ +#import + +// https://www.w3.org/TR/css-animations-1/#animationevent +[Exposed=Window] +interface AnimationEvent : Event { + constructor(CSSOMString type, optional AnimationEventInit animationEventInitDict = {}); + readonly attribute CSSOMString animationName; + readonly attribute double elapsedTime; + readonly attribute CSSOMString pseudoElement; +}; + +// https://www.w3.org/TR/css-animations-1/#dictdef-animationeventinit +dictionary AnimationEventInit : EventInit { + CSSOMString animationName = ""; + double elapsedTime = 0.0; + CSSOMString pseudoElement = ""; +}; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index 9499daae1d..7039a11b54 100644 --- a/Userland/Libraries/LibWeb/idl_files.cmake +++ b/Userland/Libraries/LibWeb/idl_files.cmake @@ -11,6 +11,7 @@ libweb_js_bindings(Clipboard/Clipboard) libweb_js_bindings(Crypto/Crypto) libweb_js_bindings(Crypto/CryptoKey) libweb_js_bindings(Crypto/SubtleCrypto) +libweb_js_bindings(CSS/AnimationEvent) libweb_js_bindings(CSS/CSSAnimation) libweb_js_bindings(CSS/CSSConditionRule) libweb_js_bindings(CSS/CSSFontFaceRule)