[Web Animations] Support the copy constructors for KeyframeEffectReadOnly and Keyfram...
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Feb 2018 01:28:27 +0000 (01:28 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Feb 2018 01:28:27 +0000 (01:28 +0000)
https://bugs.webkit.org/show_bug.cgi?id=182712

Patch by Antoine Quint <graouts@apple.com> on 2018-02-12
Reviewed by Dean Jackson.

LayoutTests/imported/w3c:

Update test expectations for tests relevant to the copy constructors.

* web-platform-tests/web-animations/interfaces/KeyframeEffect/copy-constructor-expected.txt:
* web-platform-tests/web-animations/interfaces/KeyframeEffect/idlharness-expected.txt:

Source/WebCore:

We now support the variants for the KeyframeEffectReadOnly and KeyframeEffect constructors where
another KeyframeEffectReadOnly is provided as a source. All timing, keyframe and target properties
of that source are copied on the newly-constructed KeyframeEffect.

To support copying properties, we add new copyPropertiesFromSource() methods to
AnimationEffectTimingReadOnly and KeyframeEffectReadOnly to encapsulate copying various
member variables in the relevant classes. Copying properties of the backing KeyframeList
is performed in KeyframeEffectReadOnly::copyPropertiesFromSource() via public KeyframeList
methods.

* animation/AnimationEffectTimingReadOnly.cpp:
(WebCore::AnimationEffectTimingReadOnly::copyPropertiesFromSource):
* animation/AnimationEffectTimingReadOnly.h:
* animation/KeyframeEffect.cpp:
(WebCore::KeyframeEffect::create):
* animation/KeyframeEffect.h:
* animation/KeyframeEffect.idl:
* animation/KeyframeEffectOptions.idl:
* animation/KeyframeEffectReadOnly.cpp:
(WebCore::KeyframeEffectReadOnly::create):
(WebCore::KeyframeEffectReadOnly::copyPropertiesFromSource):
* animation/KeyframeEffectReadOnly.h:
* animation/KeyframeEffectReadOnly.idl:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228412 268f45cc-cd09-0410-ab3c-d52691b4dbfc

13 files changed:
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/KeyframeEffect/copy-constructor-expected.txt
LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/KeyframeEffect/idlharness-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/animation/AnimationEffectTimingReadOnly.cpp
Source/WebCore/animation/AnimationEffectTimingReadOnly.h
Source/WebCore/animation/KeyframeEffect.cpp
Source/WebCore/animation/KeyframeEffect.h
Source/WebCore/animation/KeyframeEffect.idl
Source/WebCore/animation/KeyframeEffectOptions.idl
Source/WebCore/animation/KeyframeEffectReadOnly.cpp
Source/WebCore/animation/KeyframeEffectReadOnly.h
Source/WebCore/animation/KeyframeEffectReadOnly.idl

index 65a4730..4e43ef8 100644 (file)
@@ -1,3 +1,15 @@
+2018-02-12  Antoine Quint  <graouts@apple.com>
+
+        [Web Animations] Support the copy constructors for KeyframeEffectReadOnly and KeyframeEffect
+        https://bugs.webkit.org/show_bug.cgi?id=182712
+
+        Reviewed by Dean Jackson.
+
+        Update test expectations for tests relevant to the copy constructors.
+
+        * web-platform-tests/web-animations/interfaces/KeyframeEffect/copy-constructor-expected.txt:
+        * web-platform-tests/web-animations/interfaces/KeyframeEffect/idlharness-expected.txt:
+
 2018-02-08  Antoine Quint  <graouts@apple.com>
 
         [Web Animations] Refactor AnimationEffect and KeyframeEffect into AnimationEffectReadOnly, KeyframeEffectReadOnly and KeyframeEffect
index 108514c..cf0f182 100644 (file)
@@ -1,7 +1,7 @@
 
-FAIL Copied KeyframeEffectReadOnly has the same target Not enough arguments
-FAIL Copied KeyframeEffectReadOnly has the same keyframes Not enough arguments
-FAIL Copied KeyframeEffectReadOnly has the same KeyframeEffectOptions Not enough arguments
-FAIL Copied KeyframeEffectReadOnly has the same timing content Not enough arguments
-FAIL KeyframeEffect constructed from a KeyframeEffectReadOnly is mutable Not enough arguments
+PASS Copied KeyframeEffectReadOnly has the same target 
+PASS Copied KeyframeEffectReadOnly has the same keyframes 
+PASS Copied KeyframeEffectReadOnly has the same KeyframeEffectOptions 
+PASS Copied KeyframeEffectReadOnly has the same timing content 
+PASS KeyframeEffect constructed from a KeyframeEffectReadOnly is mutable 
 
index b242ab2..746b3f6 100644 (file)
@@ -7,7 +7,7 @@ PASS AnimationEffectReadOnly interface: existence and properties of interface pr
 PASS AnimationEffectReadOnly interface: attribute timing 
 PASS AnimationEffectReadOnly interface: operation getComputedTiming() 
 PASS KeyframeEffectReadOnly interface: existence and properties of interface object 
-FAIL KeyframeEffectReadOnly interface object length assert_equals: wrong value for KeyframeEffectReadOnly.length expected 1 but got 2
+PASS KeyframeEffectReadOnly interface object length 
 PASS KeyframeEffectReadOnly interface object name 
 PASS KeyframeEffectReadOnly interface: existence and properties of interface prototype object 
 PASS KeyframeEffectReadOnly interface: existence and properties of interface prototype object's "constructor" property 
@@ -24,7 +24,7 @@ PASS KeyframeEffectReadOnly interface: new KeyframeEffectReadOnly(null, null) mu
 PASS AnimationEffectReadOnly interface: new KeyframeEffectReadOnly(null, null) must inherit property "timing" with the proper type 
 PASS AnimationEffectReadOnly interface: new KeyframeEffectReadOnly(null, null) must inherit property "getComputedTiming()" with the proper type 
 PASS KeyframeEffect interface: existence and properties of interface object 
-FAIL KeyframeEffect interface object length assert_equals: wrong value for KeyframeEffect.length expected 1 but got 2
+PASS KeyframeEffect interface object length 
 PASS KeyframeEffect interface object name 
 PASS KeyframeEffect interface: existence and properties of interface prototype object 
 PASS KeyframeEffect interface: existence and properties of interface prototype object's "constructor" property 
index f8a3253..4299c90 100644 (file)
@@ -1,3 +1,34 @@
+2018-02-12  Antoine Quint  <graouts@apple.com>
+
+        [Web Animations] Support the copy constructors for KeyframeEffectReadOnly and KeyframeEffect
+        https://bugs.webkit.org/show_bug.cgi?id=182712
+
+        Reviewed by Dean Jackson.
+
+        We now support the variants for the KeyframeEffectReadOnly and KeyframeEffect constructors where
+        another KeyframeEffectReadOnly is provided as a source. All timing, keyframe and target properties
+        of that source are copied on the newly-constructed KeyframeEffect.
+
+        To support copying properties, we add new copyPropertiesFromSource() methods to
+        AnimationEffectTimingReadOnly and KeyframeEffectReadOnly to encapsulate copying various
+        member variables in the relevant classes. Copying properties of the backing KeyframeList
+        is performed in KeyframeEffectReadOnly::copyPropertiesFromSource() via public KeyframeList
+        methods.
+
+        * animation/AnimationEffectTimingReadOnly.cpp:
+        (WebCore::AnimationEffectTimingReadOnly::copyPropertiesFromSource):
+        * animation/AnimationEffectTimingReadOnly.h:
+        * animation/KeyframeEffect.cpp:
+        (WebCore::KeyframeEffect::create):
+        * animation/KeyframeEffect.h:
+        * animation/KeyframeEffect.idl:
+        * animation/KeyframeEffectOptions.idl:
+        * animation/KeyframeEffectReadOnly.cpp:
+        (WebCore::KeyframeEffectReadOnly::create):
+        (WebCore::KeyframeEffectReadOnly::copyPropertiesFromSource):
+        * animation/KeyframeEffectReadOnly.h:
+        * animation/KeyframeEffectReadOnly.idl:
+
 2018-02-12  Zalan Bujtas  <zalan@apple.com>
 
         [RenderTreeBuilder] Introduce RenderTreebuilder::takeChild
index 84f24c7..9f2dbc3 100644 (file)
@@ -80,6 +80,18 @@ ExceptionOr<void> AnimationEffectTimingReadOnly::setProperties(std::optional<Var
     return { };
 }
 
+void AnimationEffectTimingReadOnly::copyPropertiesFromSource(AnimationEffectTimingReadOnly* source)
+{
+    m_fill = source->m_fill;
+    m_delay = source->m_delay;
+    m_endDelay = source->m_endDelay;
+    m_direction = source->m_direction;
+    m_iterations = source->m_iterations;
+    m_timingFunction = source->m_timingFunction;
+    m_iterationStart = source->m_iterationStart;
+    m_iterationDuration = source->m_iterationDuration;
+}
+
 ExceptionOr<void> AnimationEffectTimingReadOnly::setIterationStart(double iterationStart)
 {
     // https://drafts.csswg.org/web-animations-1/#dom-animationeffecttiming-iterationstart
index 9d87b45..9ceded3 100644 (file)
@@ -48,6 +48,7 @@ public:
     bool isAnimationEffectTiming() const { return m_classType == AnimationEffectTimingClass; }
 
     ExceptionOr<void> setProperties(std::optional<Variant<double, KeyframeEffectOptions>>&&);
+    void copyPropertiesFromSource(AnimationEffectTimingReadOnly*);
 
     double bindingsDelay() const { return secondsToWebAnimationsAPITime(m_delay); }
     void setBindingsDelay(double delay) { m_delay = Seconds::fromMilliseconds(delay); }
index 6d09670..894a428 100644 (file)
@@ -44,6 +44,13 @@ ExceptionOr<Ref<KeyframeEffect>> KeyframeEffect::create(ExecState& state, Elemen
     return WTFMove(keyframeEffect);
 }
 
+ExceptionOr<Ref<KeyframeEffect>> KeyframeEffect::create(JSC::ExecState&, Ref<KeyframeEffectReadOnly>&& source)
+{
+    auto keyframeEffect = adoptRef(*new KeyframeEffect(AnimationEffectTiming::create(), nullptr));
+    keyframeEffect->copyPropertiesFromSource(WTFMove(source));
+    return WTFMove(keyframeEffect);
+}
+
 KeyframeEffect::KeyframeEffect(Ref<AnimationEffectTimingReadOnly>&& timing, Element* target)
     : KeyframeEffectReadOnly(KeyframeEffectClass, WTFMove(timing), target)
 {
index 32c6761..fe9ea29 100644 (file)
@@ -38,6 +38,7 @@ class Element;
 class KeyframeEffect final : public KeyframeEffectReadOnly {
 public:
     static ExceptionOr<Ref<KeyframeEffect>> create(JSC::ExecState&, Element*, JSC::Strong<JSC::JSObject>&&, std::optional<Variant<double, KeyframeEffectOptions>>&&);
+    static ExceptionOr<Ref<KeyframeEffect>> create(JSC::ExecState&, Ref<KeyframeEffectReadOnly>&&);
     ~KeyframeEffect() { }
 
     void setIterationComposite(IterationCompositeOperation iterationCompositeOperation) { m_iterationCompositeOperation = iterationCompositeOperation; }
index 393dc1b..3f90dd5 100644 (file)
@@ -28,7 +28,8 @@
     Exposed=Window,
     ConstructorMayThrowException,
     ConstructorCallWith=ScriptState,
-    Constructor(Element? target, object? keyframes, optional (unrestricted double or KeyframeEffectOptions) options)
+    Constructor(Element? target, object? keyframes, optional (unrestricted double or KeyframeEffectOptions) options),
+    Constructor(KeyframeEffectReadOnly source)
 ] interface KeyframeEffect : KeyframeEffectReadOnly {
     inherit attribute IterationCompositeOperation iterationComposite;
     inherit attribute CompositeOperation composite;
index d14ae90..edb6bdb 100644 (file)
@@ -1,3 +1,27 @@
+/*
+ * Copyright (C) 2018 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
 
 dictionary KeyframeEffectOptions : AnimationEffectTimingProperties {
     IterationCompositeOperation iterationComposite = "replace";
index 1f73737..13d25e3 100644 (file)
@@ -399,6 +399,13 @@ ExceptionOr<Ref<KeyframeEffectReadOnly>> KeyframeEffectReadOnly::create(ExecStat
     return WTFMove(keyframeEffect);
 }
 
+ExceptionOr<Ref<KeyframeEffectReadOnly>> KeyframeEffectReadOnly::create(JSC::ExecState&, Ref<KeyframeEffectReadOnly>&& source)
+{
+    auto keyframeEffect = adoptRef(*new KeyframeEffectReadOnly(KeyframeEffectReadOnlyClass, AnimationEffectTimingReadOnly::create(), nullptr));
+    keyframeEffect->copyPropertiesFromSource(WTFMove(source));
+    return WTFMove(keyframeEffect);
+}
+
 KeyframeEffectReadOnly::KeyframeEffectReadOnly(ClassType classType, Ref<AnimationEffectTimingReadOnly>&& timing, Element* target)
     : AnimationEffectReadOnly(classType, WTFMove(timing))
     , m_target(target)
@@ -406,6 +413,27 @@ KeyframeEffectReadOnly::KeyframeEffectReadOnly(ClassType classType, Ref<Animatio
 {
 }
 
+void KeyframeEffectReadOnly::copyPropertiesFromSource(Ref<KeyframeEffectReadOnly>&& source)
+{
+    m_target = source->m_target;
+    m_offsets = source->m_offsets;
+    m_timingFunctions = source->m_timingFunctions;
+    m_compositeOperation = source->m_compositeOperation;
+    m_compositeOperations = source->m_compositeOperations;
+    m_iterationCompositeOperation = source->m_iterationCompositeOperation;
+
+    timing()->copyPropertiesFromSource(source->timing());
+
+    KeyframeList keyframeList("keyframe-effect-" + createCanonicalUUIDString());
+    for (auto& keyframe : source->m_keyframes.keyframes()) {
+        KeyframeValue keyframeValue(keyframe.key(), RenderStyle::clonePtr(*keyframe.style()));
+        for (auto propertyId : keyframe.properties())
+            keyframeValue.addProperty(propertyId);
+        keyframeList.insert(WTFMove(keyframeValue));
+    }
+    m_keyframes = WTFMove(keyframeList);
+}
+
 Vector<Strong<JSObject>> KeyframeEffectReadOnly::getKeyframes(ExecState& state)
 {
     // https://drafts.csswg.org/web-animations-1/#dom-keyframeeffectreadonly-getkeyframes
index 976b263..f51cfcc 100644 (file)
@@ -44,6 +44,7 @@ class KeyframeEffectReadOnly : public AnimationEffectReadOnly
     , public CSSPropertyBlendingClient {
 public:
     static ExceptionOr<Ref<KeyframeEffectReadOnly>> create(JSC::ExecState&, Element*, JSC::Strong<JSC::JSObject>&&, std::optional<Variant<double, KeyframeEffectOptions>>&&);
+    static ExceptionOr<Ref<KeyframeEffectReadOnly>> create(JSC::ExecState&, Ref<KeyframeEffectReadOnly>&&);
     ~KeyframeEffectReadOnly() { }
 
     struct BasePropertyIndexedKeyframe {
@@ -98,7 +99,9 @@ public:
 #endif
 
 protected:
+    void copyPropertiesFromSource(Ref<KeyframeEffectReadOnly>&&);
     ExceptionOr<void> processKeyframes(JSC::ExecState&, JSC::Strong<JSC::JSObject>&&);
+
     IterationCompositeOperation m_iterationCompositeOperation { IterationCompositeOperation::Replace };
     CompositeOperation m_compositeOperation { CompositeOperation::Replace };
 
index 668da4c..8e7ae9c 100644 (file)
 [
     EnabledAtRuntime=WebAnimations,
     Exposed=Window,
+    JSGenerateToNativeObject,
     ConstructorMayThrowException,
     ConstructorCallWith=ScriptState,
-    Constructor(Element? target, object? keyframes, optional (unrestricted double or KeyframeEffectOptions) options)
+    Constructor(Element? target, object? keyframes, optional (unrestricted double or KeyframeEffectOptions) options),
+    Constructor(KeyframeEffectReadOnly source)
 ] interface KeyframeEffectReadOnly : AnimationEffectReadOnly {
     readonly attribute Element? target;
     readonly attribute IterationCompositeOperation iterationComposite;