diff --git a/Userland/Libraries/LibWeb/Animations/Animatable.cpp b/Userland/Libraries/LibWeb/Animations/Animatable.cpp new file mode 100644 index 0000000000..800d8ad8f9 --- /dev/null +++ b/Userland/Libraries/LibWeb/Animations/Animatable.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2024, Matthew Olsson . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +namespace Web::Animations { + +// https://www.w3.org/TR/web-animations-1/#dom-animatable-animate +WebIDL::ExceptionOr> Animatable::animate(Optional> keyframes, Variant options) +{ + // FIXME: Implement this + (void)keyframes; + (void)options; + return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, "Element.animate is not implemented"sv }; +} + +// https://www.w3.org/TR/web-animations-1/#dom-animatable-getanimations +Vector> Animatable::get_animations(Web::Animations::GetAnimationsOptions options) +{ + // FIXME: Implement this + (void)options; + return {}; +} + +} diff --git a/Userland/Libraries/LibWeb/Animations/Animatable.h b/Userland/Libraries/LibWeb/Animations/Animatable.h new file mode 100644 index 0000000000..805b9918fd --- /dev/null +++ b/Userland/Libraries/LibWeb/Animations/Animatable.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2024, Matthew Olsson . + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::Animations { + +// https://www.w3.org/TR/web-animations-1/#dictdef-keyframeanimationoptions +struct KeyframeAnimationOptions : public KeyframeEffectOptions { + FlyString id { ""_fly_string }; + JS::GCPtr timeline; +}; + +// https://www.w3.org/TR/web-animations-1/#dictdef-getanimationsoptions +struct GetAnimationsOptions { + bool subtree { false }; +}; + +// https://www.w3.org/TR/web-animations-1/#animatable +class Animatable { +public: + virtual ~Animatable() = default; + + WebIDL::ExceptionOr> animate(Optional> keyframes, Variant options = {}); + Vector> get_animations(GetAnimationsOptions options = {}); +}; + +} diff --git a/Userland/Libraries/LibWeb/Animations/Animatable.idl b/Userland/Libraries/LibWeb/Animations/Animatable.idl new file mode 100644 index 0000000000..249e7e8b63 --- /dev/null +++ b/Userland/Libraries/LibWeb/Animations/Animatable.idl @@ -0,0 +1,19 @@ +#import +#import + +// https://www.w3.org/TR/web-animations-1/#the-animatable-interface-mixin +interface mixin Animatable { + Animation animate(object? keyframes, optional (unrestricted double or KeyframeAnimationOptions) options = {}); + sequence getAnimations(optional GetAnimationsOptions options = {}); +}; + +// https://www.w3.org/TR/web-animations-1/#dictdef-keyframeanimationoptions +dictionary KeyframeAnimationOptions : KeyframeEffectOptions { + DOMString id = ""; + AnimationTimeline? timeline; +}; + +// https://www.w3.org/TR/web-animations-1/#dictdef-getanimationsoptions +dictionary GetAnimationsOptions { + boolean subtree = false; +}; diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index fc47079532..2154202229 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -2,6 +2,7 @@ include(libweb_generators) include(accelerated_graphics) set(SOURCES + Animations/Animatable.cpp Animations/Animation.cpp Animations/AnimationEffect.cpp Animations/AnimationPlaybackEvent.cpp diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 7bd1e2a67c..d69e6f4ca2 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -27,6 +27,7 @@ class RecordingPainter; } namespace Web::Animations { +class Animatable; class Animation; class AnimationEffect; class AnimationPlaybackEvent;