diff --git a/Userland/Libraries/LibWeb/Animations/Animation.h b/Userland/Libraries/LibWeb/Animations/Animation.h index 11ab6ee575..b514f70b4b 100644 --- a/Userland/Libraries/LibWeb/Animations/Animation.h +++ b/Userland/Libraries/LibWeb/Animations/Animation.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, Matthew Olsson . + * Copyright (c) 2023-2024, Matthew Olsson . * * SPDX-License-Identifier: BSD-2-Clause */ @@ -67,6 +67,8 @@ public: void effect_timing_changed(Badge); + virtual bool is_css_animation() const { return false; } + protected: Animation(JS::Realm&); diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 2154202229..89e7a041e5 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -32,6 +32,7 @@ set(SOURCES CSS/CalculatedOr.cpp CSS/Clip.cpp CSS/CSS.cpp + CSS/CSSAnimation.cpp CSS/CSSConditionRule.cpp CSS/CSSGroupingRule.cpp CSS/CSSImportRule.cpp diff --git a/Userland/Libraries/LibWeb/CSS/CSSAnimation.cpp b/Userland/Libraries/LibWeb/CSS/CSSAnimation.cpp new file mode 100644 index 0000000000..cf8edeba96 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/CSSAnimation.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, Matthew Olsson . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include +#include +#include + +namespace Web::CSS { + +JS::NonnullGCPtr CSSAnimation::create(JS::Realm& realm) +{ + return realm.heap().allocate(realm, realm); +} + +CSSAnimation::CSSAnimation(JS::Realm& realm) + : Animations::Animation(realm) +{ +} + +void CSSAnimation::initialize(JS::Realm& realm) +{ + Base::initialize(realm); + set_prototype(&Bindings::ensure_web_prototype(realm, "CSSAnimation"_fly_string)); +} + +void CSSAnimation::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_owning_element); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/CSSAnimation.h b/Userland/Libraries/LibWeb/CSS/CSSAnimation.h new file mode 100644 index 0000000000..d6cab51dc3 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/CSSAnimation.h @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024, Matthew Olsson . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Web::CSS { + +// https://www.w3.org/TR/css-animations-2/#cssanimation +class CSSAnimation : public Animations::Animation { + WEB_PLATFORM_OBJECT(CSSAnimation, Animations::Animation); + +public: + static JS::NonnullGCPtr create(JS::Realm&); + + JS::GCPtr owning_element() const { return m_owning_element; } + void set_owning_element(JS::GCPtr value) { m_owning_element = value; } + + FlyString const& animation_name() const { return id(); } + +private: + explicit CSSAnimation(JS::Realm&); + + virtual void initialize(JS::Realm&) override; + virtual void visit_edges(Cell::Visitor&) override; + + virtual bool is_css_animation() const override { return true; } + + // https://www.w3.org/TR/css-animations-2/#owning-element-section + JS::GCPtr m_owning_element; +}; + +} diff --git a/Userland/Libraries/LibWeb/CSS/CSSAnimation.idl b/Userland/Libraries/LibWeb/CSS/CSSAnimation.idl new file mode 100644 index 0000000000..3e8f2b1808 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/CSSAnimation.idl @@ -0,0 +1,7 @@ +#import + +// https://www.w3.org/TR/css-animations-2/#cssanimation +[Exposed=Window] +interface CSSAnimation : Animation { + readonly attribute CSSOMString animationName; +}; diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index d69e6f4ca2..8b95b9f338 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -92,6 +92,7 @@ class AngleStyleValue; class BackgroundRepeatStyleValue; class BackgroundSizeStyleValue; class BorderRadiusStyleValue; +class CSSAnimation; class CSSConditionRule; class CSSFontFaceRule; class CSSGroupingRule; diff --git a/Userland/Libraries/LibWeb/idl_files.cmake b/Userland/Libraries/LibWeb/idl_files.cmake index ac2308145f..9499daae1d 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/CSSAnimation) libweb_js_bindings(CSS/CSSConditionRule) libweb_js_bindings(CSS/CSSFontFaceRule) libweb_js_bindings(CSS/CSSGroupingRule)