Browse Source

LibWeb: Add the Animatable IDL object

Matthew Olsson 1 year ago
parent
commit
daaaaec2d0

+ 29 - 0
Userland/Libraries/LibWeb/Animations/Animatable.cpp

@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <LibWeb/Animations/Animatable.h>
+#include <LibWeb/WebIDL/ExceptionOr.h>
+
+namespace Web::Animations {
+
+// https://www.w3.org/TR/web-animations-1/#dom-animatable-animate
+WebIDL::ExceptionOr<JS::NonnullGCPtr<Animation>> Animatable::animate(Optional<JS::Handle<JS::Object>> keyframes, Variant<Empty, double, KeyframeAnimationOptions> 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<JS::NonnullGCPtr<Animation>> Animatable::get_animations(Web::Animations::GetAnimationsOptions options)
+{
+    // FIXME: Implement this
+    (void)options;
+    return {};
+}
+
+}

+ 34 - 0
Userland/Libraries/LibWeb/Animations/Animatable.h

@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2024, Matthew Olsson <mattco@serenityos.org>.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/FlyString.h>
+#include <LibWeb/Animations/KeyframeEffect.h>
+
+namespace Web::Animations {
+
+// https://www.w3.org/TR/web-animations-1/#dictdef-keyframeanimationoptions
+struct KeyframeAnimationOptions : public KeyframeEffectOptions {
+    FlyString id { ""_fly_string };
+    JS::GCPtr<AnimationTimeline> 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<JS::NonnullGCPtr<Animation>> animate(Optional<JS::Handle<JS::Object>> keyframes, Variant<Empty, double, KeyframeAnimationOptions> options = {});
+    Vector<JS::NonnullGCPtr<Animation>> get_animations(GetAnimationsOptions options = {});
+};
+
+}

+ 19 - 0
Userland/Libraries/LibWeb/Animations/Animatable.idl

@@ -0,0 +1,19 @@
+#import <Animations/Animation.idl>
+#import <Animations/KeyframeEffect.idl>
+
+// 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<Animation> 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;
+};

+ 1 - 0
Userland/Libraries/LibWeb/CMakeLists.txt

@@ -2,6 +2,7 @@ include(libweb_generators)
 include(accelerated_graphics)
 include(accelerated_graphics)
 
 
 set(SOURCES
 set(SOURCES
+    Animations/Animatable.cpp
     Animations/Animation.cpp
     Animations/Animation.cpp
     Animations/AnimationEffect.cpp
     Animations/AnimationEffect.cpp
     Animations/AnimationPlaybackEvent.cpp
     Animations/AnimationPlaybackEvent.cpp

+ 1 - 0
Userland/Libraries/LibWeb/Forward.h

@@ -27,6 +27,7 @@ class RecordingPainter;
 }
 }
 
 
 namespace Web::Animations {
 namespace Web::Animations {
+class Animatable;
 class Animation;
 class Animation;
 class AnimationEffect;
 class AnimationEffect;
 class AnimationPlaybackEvent;
 class AnimationPlaybackEvent;