Changeset 286555 in webkit


Ignore:
Timestamp:
Dec 6, 2021 11:30:57 AM (8 months ago)
Author:
graouts@webkit.org
Message:

[Web Animations] Add a way to run scripted animations
https://bugs.webkit.org/show_bug.cgi?id=233869
rdar://85983542

Reviewed by Dean Jackson.

Source/WebCore:

Tests: webanimations/custom-effect/custom-effect.html

webanimations/custom-effect/document-timeline-animate.html

This patch adds two new Web-exposed features to allow authors to write callback-based animations
leveraging the full power of the Web Animations model.

First, we add a new AnimationEffect subclass which wraps a callback to be executed on every tick
of the associated animation's timeline: CustomEffect. It can be constructed by providing a JS function
as its first parameter, and either a number or a dictionary to provide timing properties for the effect.
This is similar to how KeyframeEffect will accept a keyframes object and then timing data. The callback
is provided the effect progress as its sole parameter. Web authors can use this new interface as follows:

const animation = new Animation;
animation.effect = new CustomEffect(progress => { … }, 1000);
animation.play();

Second, to make starting callback-based animations more straightforward and in a very similar fashion
to how keyframe animations can be initiated on an element using Element.animate(), we introduce a new
animate() method on DocumentTimeline, allowing the previous exmaple to be written as:

const animation = document.timeline.animate(progress => { … }, 1000);

This simple approach allows Web authors to move past the simple use of requestAnimationFrame() and harness
the Web Animations timing model which will let them pause and resume animations, seek them, control their
playback rate, apply easing, respond to the "finished" promise, etc.

The code itself is very simple, CustomEffect is simply an AnimationEffect subclass that indicates that it's
always interested in scheduling updates while active using the ticksContinouslyWhileActive() method. This
means that all the scheduling logic contained in WebAnimation and AnimationEffect applies, allowing callbacks
to not be fired when the animation is paused or when the page is suspended, or fired sparingly when a steps()
timing function is specified.

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • Headers.cmake:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • animation/AnimationEffect.h:

(WebCore::AnimationEffect::isCustomEffect const):

  • animation/CustomAnimationOptions.h: Added.
  • animation/CustomAnimationOptions.idl: Added.
  • animation/CustomEffect.cpp: Added.

(WebCore::CustomEffect::create):
(WebCore::CustomEffect::CustomEffect):
(WebCore::CustomEffect::animationDidTick):

  • animation/CustomEffect.h: Added.

(WebCore::CustomEffect::~CustomEffect):

  • animation/CustomEffect.idl: Added.
  • animation/CustomEffectCallback.h: Added.
  • animation/CustomEffectCallback.idl: Added.
  • animation/DocumentTimeline.cpp:

(WebCore::DocumentTimeline::animate):

  • animation/DocumentTimeline.h:
  • animation/DocumentTimeline.idl:
  • bindings/js/WebCoreBuiltinNames.h:

Source/WTF:

Add a new experimental feature for the CustomEffect interface.

  • Scripts/Preferences/WebPreferencesExperimental.yaml:

LayoutTests:

Add tests for the new CustomEffect interface and the document.timeline.animate() method.
These are written using WPT libraries such that they may be upstreamed to the WPT repository
in the future if and when the CustomEffect interface is standardized.

  • platform/win/TestExpectations:
  • webanimations/custom-effect/custom-effect-expected.txt: Added.
  • webanimations/custom-effect/custom-effect.html: Added.
  • webanimations/custom-effect/document-timeline-animate-expected.txt: Added.
  • webanimations/custom-effect/document-timeline-animate.html: Added.
Location:
trunk
Files:
6 added
17 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r286553 r286555  
     12021-12-06  Antoine Quint  <graouts@webkit.org>
     2
     3        [Web Animations] Add a way to run scripted animations
     4        https://bugs.webkit.org/show_bug.cgi?id=233869
     5        rdar://85983542
     6
     7        Reviewed by Dean Jackson.
     8
     9        Add tests for the new CustomEffect interface and the document.timeline.animate() method.
     10        These are written using WPT libraries such that they may be upstreamed to the WPT repository
     11        in the future if and when the CustomEffect interface is standardized.
     12
     13        * platform/win/TestExpectations:
     14        * webanimations/custom-effect/custom-effect-expected.txt: Added.
     15        * webanimations/custom-effect/custom-effect.html: Added.
     16        * webanimations/custom-effect/document-timeline-animate-expected.txt: Added.
     17        * webanimations/custom-effect/document-timeline-animate.html: Added.
     18
    1192021-12-06  Rob Buis  <rbuis@igalia.com>
    220
  • trunk/LayoutTests/platform/win/TestExpectations

    r286406 r286555  
    47614761
    47624762webkit.org/b/232703 webanimations/no-style-updates-for-animated-sibling-elements-accelerated.html [ Failure ]
     4763
     4764webkit.org/b/233887 webanimations/custom-effect [ Failure ]
  • trunk/Source/WTF/ChangeLog

    r286554 r286555  
     12021-12-06  Antoine Quint  <graouts@webkit.org>
     2
     3        [Web Animations] Add a way to run scripted animations
     4        https://bugs.webkit.org/show_bug.cgi?id=233869
     5        rdar://85983542
     6
     7        Reviewed by Dean Jackson.
     8
     9        Add a new experimental feature for the CustomEffect interface.
     10
     11        * Scripts/Preferences/WebPreferencesExperimental.yaml:
     12
    1132021-12-06  Jon Lee  <jonlee@apple.com>
    214
  • trunk/Source/WTF/Scripts/Preferences/WebPreferencesExperimental.yaml

    r286554 r286555  
    14721472      default: false
    14731473
     1474WebAnimationsCustomEffectsEnabled:
     1475  type: bool
     1476  humanReadableName: "Web Animations custom effects"
     1477  humanReadableDescription: "Support for the CustomEffect interface"
     1478  defaultValue:
     1479    WebKitLegacy:
     1480      default: false
     1481    WebKit:
     1482      "ENABLE(EXPERIMENTAL_FEATURES)" : true
     1483      default: false
     1484    WebCore:
     1485      default: false
     1486
    14741487# FIXME: This is enabled when ENABLE(EXPERIMENTAL_FEATURES) is true in WebKit2. Perhaps we should consider using that for WebKitLegacy as well.
    14751488WebAnimationsMutableTimelinesEnabled:
  • trunk/Source/WebCore/CMakeLists.txt

    r286464 r286555  
    680680    animation/AnimationEffect.idl
    681681    animation/AnimationFrameProvider.idl
    682     animation/EffectTiming.idl
    683682    animation/AnimationPlaybackEvent.idl
    684683    animation/AnimationPlaybackEventInit.idl
     
    689688    animation/CompositeOperationOrAuto.idl
    690689    animation/ComputedEffectTiming.idl
     690    animation/CustomAnimationOptions.idl
     691    animation/CustomEffect.idl
     692    animation/CustomEffectCallback.idl
    691693    animation/Document+WebAnimations.idl
    692694    animation/DocumentOrShadowRoot+WebAnimations.idl
    693695    animation/DocumentTimeline.idl
    694696    animation/DocumentTimelineOptions.idl
     697    animation/EffectTiming.idl
    695698    animation/FillMode.idl
    696699    animation/GetAnimationsOptions.idl
  • trunk/Source/WebCore/ChangeLog

    r286553 r286555  
     12021-12-06  Antoine Quint  <graouts@webkit.org>
     2
     3        [Web Animations] Add a way to run scripted animations
     4        https://bugs.webkit.org/show_bug.cgi?id=233869
     5        rdar://85983542
     6
     7        Reviewed by Dean Jackson.
     8
     9        Tests: webanimations/custom-effect/custom-effect.html
     10               webanimations/custom-effect/document-timeline-animate.html
     11
     12        This patch adds two new Web-exposed features to allow authors to write callback-based animations
     13        leveraging the full power of the Web Animations model.
     14
     15        First, we add a new AnimationEffect subclass which wraps a callback to be executed on every tick
     16        of the associated animation's timeline: CustomEffect. It can be constructed by providing a JS function
     17        as its first parameter, and either a number or a dictionary to provide timing properties for the effect.
     18        This is similar to how KeyframeEffect will accept a keyframes object and then timing data. The callback
     19        is provided the effect progress as its sole parameter. Web authors can use this new interface as follows:
     20
     21            const animation = new Animation;
     22            animation.effect = new CustomEffect(progress => { … }, 1000);
     23            animation.play();
     24
     25        Second, to make starting callback-based animations more straightforward and in a very similar fashion
     26        to how keyframe animations can be initiated on an element using Element.animate(), we introduce a new
     27        animate() method on DocumentTimeline, allowing the previous exmaple to be written as:
     28
     29            const animation = document.timeline.animate(progress => { … }, 1000);
     30
     31        This simple approach allows Web authors to move past the simple use of requestAnimationFrame() and harness
     32        the Web Animations timing model which will let them pause and resume animations, seek them, control their
     33        playback rate, apply easing, respond to the "finished" promise, etc.
     34
     35        The code itself is very simple, CustomEffect is simply an AnimationEffect subclass that indicates that it's
     36        always interested in scheduling updates while active using the ticksContinouslyWhileActive() method. This
     37        means that all the scheduling logic contained in WebAnimation and AnimationEffect applies, allowing callbacks
     38        to not be fired when the animation is paused or when the page is suspended, or fired sparingly when a steps()
     39        timing function is specified.
     40
     41        * CMakeLists.txt:
     42        * DerivedSources-input.xcfilelist:
     43        * DerivedSources-output.xcfilelist:
     44        * DerivedSources.make:
     45        * Headers.cmake:
     46        * Sources.txt:
     47        * WebCore.xcodeproj/project.pbxproj:
     48        * animation/AnimationEffect.h:
     49        (WebCore::AnimationEffect::isCustomEffect const):
     50        * animation/CustomAnimationOptions.h: Added.
     51        * animation/CustomAnimationOptions.idl: Added.
     52        * animation/CustomEffect.cpp: Added.
     53        (WebCore::CustomEffect::create):
     54        (WebCore::CustomEffect::CustomEffect):
     55        (WebCore::CustomEffect::animationDidTick):
     56        * animation/CustomEffect.h: Added.
     57        (WebCore::CustomEffect::~CustomEffect):
     58        * animation/CustomEffect.idl: Added.
     59        * animation/CustomEffectCallback.h: Added.
     60        * animation/CustomEffectCallback.idl: Added.
     61        * animation/DocumentTimeline.cpp:
     62        (WebCore::DocumentTimeline::animate):
     63        * animation/DocumentTimeline.h:
     64        * animation/DocumentTimeline.idl:
     65        * bindings/js/WebCoreBuiltinNames.h:
     66
    1672021-12-06  Rob Buis  <rbuis@igalia.com>
    268
  • trunk/Source/WebCore/DerivedSources-input.xcfilelist

    r286464 r286555  
    815815$(PROJECT_DIR)/animation/CompositeOperationOrAuto.idl
    816816$(PROJECT_DIR)/animation/ComputedEffectTiming.idl
     817$(PROJECT_DIR)/animation/CustomAnimationOptions.idl
     818$(PROJECT_DIR)/animation/CustomEffect.idl
     819$(PROJECT_DIR)/animation/CustomEffectCallback.idl
    817820$(PROJECT_DIR)/animation/Document+WebAnimations.idl
    818821$(PROJECT_DIR)/animation/DocumentOrShadowRoot+WebAnimations.idl
  • trunk/Source/WebCore/DerivedSources-output.xcfilelist

    r286419 r286555  
    531531$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCryptoRsaKeyAlgorithm.cpp
    532532$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCryptoRsaKeyAlgorithm.h
     533$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCustomAnimationOptions.cpp
     534$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCustomAnimationOptions.h
     535$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCustomEffect.cpp
     536$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCustomEffect.h
     537$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCustomEffectCallback.cpp
     538$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCustomEffectCallback.h
    533539$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCustomElementRegistry.cpp
    534540$(BUILT_PRODUCTS_DIR)/DerivedSources/WebCore/JSCustomElementRegistry.h
  • trunk/Source/WebCore/DerivedSources.make

    r286464 r286555  
    704704    $(WebCore)/animation/CompositeOperationOrAuto.idl \
    705705    $(WebCore)/animation/ComputedEffectTiming.idl \
     706    $(WebCore)/animation/CustomAnimationOptions.idl \
     707    $(WebCore)/animation/CustomEffect.idl \
     708    $(WebCore)/animation/CustomEffectCallback.idl \
    706709    $(WebCore)/animation/Document+WebAnimations.idl \
    707710    $(WebCore)/animation/DocumentOrShadowRoot+WebAnimations.idl \
  • trunk/Source/WebCore/Headers.cmake

    r286538 r286555  
    385385
    386386    animation/CSSPropertyBlendingClient.h
     387    animation/CustomAnimationOptions.h
    387388    animation/CompositeOperation.h
    388389    animation/DocumentTimelinesController.h
  • trunk/Source/WebCore/Sources.txt

    r286464 r286555  
    470470animation/CSSPropertyAnimation.cpp
    471471animation/CSSTransition.cpp
     472animation/CustomEffect.cpp
    472473animation/DeclarativeAnimation.cpp
    473474animation/DocumentTimeline.cpp
     
    30063007JSCryptoRsaHashedKeyAlgorithm.cpp
    30073008JSCryptoRsaKeyAlgorithm.cpp
     3009JSCustomAnimationOptions.cpp
     3010JSCustomEffect.cpp
     3011JSCustomEffectCallback.cpp
    30083012JSCustomElementRegistry.cpp
    30093013JSCustomEvent.cpp
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r286538 r286555  
    22802280                71729F7B20F3BA4900801CE6 /* DocumentTimelineOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 71729F7A20F3BA3A00801CE6 /* DocumentTimelineOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
    22812281                71729F7E20F3BB4700801CE6 /* JSDocumentTimelineOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 71729F7C20F3BAB900801CE6 /* JSDocumentTimelineOptions.h */; };
     2282                7173694A275E0B5E003ADA9B /* CustomEffect.h in Headers */ = {isa = PBXBuildFile; fileRef = 71A74B082759293600DE80BA /* CustomEffect.h */; };
     2283                7173694B275E0B6A003ADA9B /* CustomEffectCallback.h in Headers */ = {isa = PBXBuildFile; fileRef = 71A74B0A27592B3500DE80BA /* CustomEffectCallback.h */; };
     2284                7173694C275E0BAB003ADA9B /* CustomAnimationOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 71736947275E0B4B003ADA9B /* CustomAnimationOptions.h */; };
    22822285                7177AD57274295D1002F103B /* HTMLModelElementCamera.h in Headers */ = {isa = PBXBuildFile; fileRef = 7177AD5627429590002F103B /* HTMLModelElementCamera.h */; settings = {ATTRIBUTES = (Private, ); }; };
    22832286                7181A16C244F0F40007D8A24 /* DocumentTimelinesController.h in Headers */ = {isa = PBXBuildFile; fileRef = 7181A169244F0F2C007D8A24 /* DocumentTimelinesController.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    1107711080                71729F7C20F3BAB900801CE6 /* JSDocumentTimelineOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDocumentTimelineOptions.h; sourceTree = "<group>"; };
    1107811081                71729F7D20F3BABA00801CE6 /* JSDocumentTimelineOptions.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDocumentTimelineOptions.cpp; sourceTree = "<group>"; };
     11082                71736947275E0B4B003ADA9B /* CustomAnimationOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomAnimationOptions.h; sourceTree = "<group>"; };
     11083                71736949275E0B4C003ADA9B /* CustomAnimationOptions.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CustomAnimationOptions.idl; sourceTree = "<group>"; };
    1107911084                7173DEBD2614DF040097DF32 /* Styleable.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Styleable.cpp; sourceTree = "<group>"; };
    1108011085                7177AD542742952F002F103B /* HTMLModelElementCamera.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = HTMLModelElementCamera.idl; sourceTree = "<group>"; };
     
    1111311118                71A58193236F466400D81A24 /* KeyframeEffectStack.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KeyframeEffectStack.h; sourceTree = "<group>"; };
    1111411119                71A58195236F466500D81A24 /* KeyframeEffectStack.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = KeyframeEffectStack.cpp; sourceTree = "<group>"; };
     11120                71A74B052759293600DE80BA /* CustomEffect.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CustomEffect.idl; sourceTree = "<group>"; };
     11121                71A74B072759293600DE80BA /* CustomEffect.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomEffect.cpp; sourceTree = "<group>"; };
     11122                71A74B082759293600DE80BA /* CustomEffect.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomEffect.h; sourceTree = "<group>"; };
     11123                71A74B0927592A5300DE80BA /* CustomEffectCallback.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CustomEffectCallback.idl; sourceTree = "<group>"; };
     11124                71A74B0A27592B3500DE80BA /* CustomEffectCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomEffectCallback.h; sourceTree = "<group>"; };
    1111511125                71AEE4EB21B5A49C00DDB036 /* TouchAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TouchAction.h; sourceTree = "<group>"; };
    1111611126                71B0460A1DD3C2EE00EE19CF /* status-support.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = "status-support.js"; sourceTree = "<group>"; };
     
    2425824268                                7123C186204739BA00789392 /* CSSTransition.h */,
    2425924269                                7123C185204739B900789392 /* CSSTransition.idl */,
     24270                                71736947275E0B4B003ADA9B /* CustomAnimationOptions.h */,
     24271                                71736949275E0B4C003ADA9B /* CustomAnimationOptions.idl */,
     24272                                71A74B072759293600DE80BA /* CustomEffect.cpp */,
     24273                                71A74B082759293600DE80BA /* CustomEffect.h */,
     24274                                71A74B052759293600DE80BA /* CustomEffect.idl */,
     24275                                71A74B0A27592B3500DE80BA /* CustomEffectCallback.h */,
     24276                                71A74B0927592A5300DE80BA /* CustomEffectCallback.idl */,
    2426024277                                715AD71F2050512400D592DC /* DeclarativeAnimation.cpp */,
    2426124278                                715AD71D2050512400D592DC /* DeclarativeAnimation.h */,
     
    3380933826                                BC2272A20E82E87C00E7F975 /* CursorData.h in Headers */,
    3381033827                                BC2272AD0E82E8F300E7F975 /* CursorList.h in Headers */,
     33828                                7173694C275E0BAB003ADA9B /* CustomAnimationOptions.h in Headers */,
     33829                                7173694A275E0B5E003ADA9B /* CustomEffect.h in Headers */,
     33830                                7173694B275E0B6A003ADA9B /* CustomEffectCallback.h in Headers */,
    3381133831                                93D437A01D57B19A00AB85EA /* CustomElementReactionQueue.h in Headers */,
    3381233832                                9BD4E91B1C462CFC005065BC /* CustomElementRegistry.h in Headers */,
  • trunk/Source/WebCore/animation/AnimationEffect.h

    r286544 r286555  
    5252    virtual ~AnimationEffect();
    5353
     54    virtual bool isCustomEffect() const { return false; }
    5455    virtual bool isKeyframeEffect() const { return false; }
    5556
  • trunk/Source/WebCore/animation/CustomAnimationOptions.h

    r286554 r286555  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 [
    27     Exposed=Window
    28 ] interface DocumentTimeline : AnimationTimeline {
    29     [CallWith=Document] constructor(optional DocumentTimelineOptions options);
     26#pragma once
     27
     28#include "EffectTiming.h"
     29
     30namespace WebCore {
     31
     32struct CustomAnimationOptions : EffectTiming {
     33    String id;
    3034};
     35
     36} // namespace WebCore
     37
  • trunk/Source/WebCore/animation/CustomAnimationOptions.idl

    r286554 r286555  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 [
    27     Exposed=Window
    28 ] interface DocumentTimeline : AnimationTimeline {
    29     [CallWith=Document] constructor(optional DocumentTimelineOptions options);
     26dictionary CustomAnimationOptions : EffectTiming {
     27    DOMString id = "";
    3028};
     29
  • trunk/Source/WebCore/animation/CustomEffect.h

    r286554 r286555  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 [
    27     Exposed=Window
    28 ] interface DocumentTimeline : AnimationTimeline {
    29     [CallWith=Document] constructor(optional DocumentTimelineOptions options);
     26#pragma once
     27
     28#include "AnimationEffect.h"
     29#include "CustomEffectCallback.h"
     30#include "EffectTiming.h"
     31#include <wtf/Ref.h>
     32
     33namespace WebCore {
     34
     35class CustomEffect : public AnimationEffect {
     36public:
     37    static ExceptionOr<Ref<CustomEffect>> create(Ref<CustomEffectCallback>&&, std::optional<std::variant<double, EffectTiming>>&&);
     38    ~CustomEffect() { }
     39
     40private:
     41    CustomEffect(Ref<CustomEffectCallback>&&);
     42
     43    // AnimationEffect
     44    bool isCustomEffect() const final { return true; }
     45    void animationDidTick() final;
     46    bool ticksContinouslyWhileActive() const final { return true; }
     47
     48    Ref<CustomEffectCallback> m_callback;
    3049};
     50
     51} // namespace WebCore
     52
     53SPECIALIZE_TYPE_TRAITS_ANIMATION_EFFECT(CustomEffect, isCustomEffect());
  • trunk/Source/WebCore/animation/CustomEffect.idl

    r286554 r286555  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2525
    2626[
    27     Exposed=Window
    28 ] interface DocumentTimeline : AnimationTimeline {
    29     [CallWith=Document] constructor(optional DocumentTimelineOptions options);
     27    EnabledBySetting=WebAnimationsCustomEffectsEnabled,
     28    Exposed=Window,
     29    JSGenerateToNativeObject,
     30] interface CustomEffect : AnimationEffect {
     31    constructor(CustomEffectCallback callback, optional (unrestricted double or EffectTiming) options);
    3032};
  • trunk/Source/WebCore/animation/CustomEffectCallback.h

    r286554 r286555  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 [
    27     Exposed=Window
    28 ] interface DocumentTimeline : AnimationTimeline {
    29     [CallWith=Document] constructor(optional DocumentTimelineOptions options);
     26#pragma once
     27
     28#include "ActiveDOMCallback.h"
     29#include "CallbackResult.h"
     30#include <wtf/RefCounted.h>
     31#include <wtf/Seconds.h>
     32
     33namespace WebCore {
     34
     35class CustomEffectCallback : public RefCounted<CustomEffectCallback>, public ActiveDOMCallback {
     36public:
     37    using ActiveDOMCallback::ActiveDOMCallback;
     38
     39    virtual CallbackResult<void> handleEvent(double progress) = 0;
    3040};
     41
     42} // namespace WebCore
  • trunk/Source/WebCore/animation/CustomEffectCallback.idl

    r286554 r286555  
    11/*
    2  * Copyright (C) 2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 [
    27     Exposed=Window
    28 ] interface DocumentTimeline : AnimationTimeline {
    29     [CallWith=Document] constructor(optional DocumentTimelineOptions options);
    30 };
     26callback CustomEffectCallback = undefined (double progress);
  • trunk/Source/WebCore/animation/DocumentTimeline.cpp

    r285397 r286555  
    2929#include "AnimationEventBase.h"
    3030#include "CSSTransition.h"
     31#include "CustomAnimationOptions.h"
     32#include "CustomEffect.h"
     33#include "CustomEffectCallback.h"
    3134#include "DeclarativeAnimation.h"
    3235#include "Document.h"
     
    495498}
    496499
     500ExceptionOr<Ref<WebAnimation>> DocumentTimeline::animate(Ref<CustomEffectCallback>&& callback, std::optional<std::variant<double, CustomAnimationOptions>>&& options)
     501{
     502    ASSERT(m_document);
     503
     504    String id = "";
     505    std::optional<std::variant<double, EffectTiming>> customEffectOptions;
     506
     507    if (options) {
     508        std::variant<double, EffectTiming> customEffectOptionsVariant;
     509        if (std::holds_alternative<double>(*options))
     510            customEffectOptionsVariant = std::get<double>(*options);
     511        else {
     512            auto customEffectOptions = std::get<CustomAnimationOptions>(*options);
     513            id = customEffectOptions.id;
     514            customEffectOptionsVariant = WTFMove(customEffectOptions);
     515        }
     516        customEffectOptions = customEffectOptionsVariant;
     517    }
     518
     519    auto customEffectResult = CustomEffect::create(WTFMove(callback), WTFMove(customEffectOptions));
     520    if (customEffectResult.hasException())
     521        return customEffectResult.releaseException();
     522
     523    auto animation = WebAnimation::create(*document(), &customEffectResult.returnValue().get());
     524    animation->setId(id);
     525
     526    auto animationPlayResult = animation->play();
     527    if (animationPlayResult.hasException())
     528        return animationPlayResult.releaseException();
     529
     530    return animation;
     531}
     532
    497533} // namespace WebCore
  • trunk/Source/WebCore/animation/DocumentTimeline.h

    r284202 r286555  
    3535
    3636class AnimationEventBase;
     37class CustomEffectCallback;
    3738class DocumentTimelinesController;
    3839class RenderBoxModelObject;
    3940class RenderElement;
     41
     42struct CustomAnimationOptions;
    4043
    4144class DocumentTimeline final : public AnimationTimeline
     
    5154
    5255    std::optional<Seconds> currentTime() override;
     56    ExceptionOr<Ref<WebAnimation>> animate(Ref<CustomEffectCallback>&&, std::optional<std::variant<double, CustomAnimationOptions>>&&);
    5357
    5458    void animationTimingDidChange(WebAnimation&) override;
  • trunk/Source/WebCore/animation/DocumentTimeline.idl

    r267813 r286555  
    2828] interface DocumentTimeline : AnimationTimeline {
    2929    [CallWith=Document] constructor(optional DocumentTimelineOptions options);
     30    [EnabledBySetting=WebAnimationsCustomEffectsEnabled] WebAnimation animate(CustomEffectCallback callback, optional (unrestricted double or CustomAnimationOptions) options);
    3031};
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r286419 r286555  
    107107    macro(CSSVariableReferenceValue) \
    108108    macro(CustomElementRegistry) \
     109    macro(CustomEffect) \
    109110    macro(Database) \
    110111    macro(DataTransferItem) \
Note: See TracChangeset for help on using the changeset viewer.