Title: [259577] trunk
Revision
259577
Author
grao...@webkit.org
Date
2020-04-06 10:41:43 -0700 (Mon, 06 Apr 2020)

Log Message

[Web Animations] Move Document.getAnimations() to DocumentOrShadowRoot
https://bugs.webkit.org/show_bug.cgi?id=202192
<rdar://problem/55697775>

Reviewed by Antti Koivisto.

LayoutTests/imported/w3c:

Update the test relevant to DocumentOrShadowRoot.getAnimations() from upstream and record three new PASS results in it. We also get two new PASS from a harness test.

* web-platform-tests/web-animations/idlharness.window-expected.txt:
* web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations-expected.txt:
* web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations.html:
* web-platform-tests/web-animations/testcommon.js:
(async insertFrameAndAwaitLoad):

Source/WebCore:

We remove the getAnimations() declaration from the Document interface and instead move it on the DocumentOrShadowRoot interface.

We add the new method Document::matchingAnimations() which takes a lambda that is provided an animation's effect's target to determine whether
that animation should be found in the list of animations.

In the case of Document::getAnimations(), we filter out animations targeting elements hosted in shadow roots, while in ShadowRoot:getAnimations(),
we filter out animations targeting elements that are not hosted in the shadow root the method was called on.

* dom/Document.cpp:
(WebCore::Document::getAnimations):
(WebCore::Document::matchingAnimations):
* dom/Document.h:
* dom/Document.idl:
* dom/DocumentOrShadowRoot.idl:
* dom/Element.cpp:
(WebCore::Element::getAnimations):
* dom/ShadowRoot.cpp:
(WebCore::ShadowRoot::getAnimations):
* dom/ShadowRoot.h:

Modified Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (259576 => 259577)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2020-04-06 17:41:43 UTC (rev 259577)
@@ -1,3 +1,19 @@
+2020-04-06  Antoine Quint  <grao...@apple.com>
+
+        [Web Animations] Move Document.getAnimations() to DocumentOrShadowRoot
+        https://bugs.webkit.org/show_bug.cgi?id=202192
+        <rdar://problem/55697775>
+
+        Reviewed by Antti Koivisto.
+
+        Update the test relevant to DocumentOrShadowRoot.getAnimations() from upstream and record three new PASS results in it. We also get two new PASS from a harness test.
+
+        * web-platform-tests/web-animations/idlharness.window-expected.txt:
+        * web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations-expected.txt:
+        * web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations.html:
+        * web-platform-tests/web-animations/testcommon.js:
+        (async insertFrameAndAwaitLoad):
+
 2020-04-05  Manuel Rego Casasnovas  <r...@igalia.com>
 
         Computed style for "outline-offset" is wrong when "outline-style" is "none"

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/idlharness.window-expected.txt (259576 => 259577)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/idlharness.window-expected.txt	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/idlharness.window-expected.txt	2020-04-06 17:41:43 UTC (rev 259577)
@@ -140,8 +140,8 @@
 PASS Document interface: operation getAnimations() 
 PASS Document interface: document must inherit property "timeline" with the proper type 
 PASS Document interface: document must inherit property "getAnimations()" with the proper type 
-FAIL ShadowRoot interface: operation getAnimations() assert_own_property: interface prototype object missing non-static operation expected property "getAnimations" missing
-FAIL ShadowRoot interface: shadowRoot must inherit property "getAnimations()" with the proper type assert_inherits: property "getAnimations" not found in prototype chain
+PASS ShadowRoot interface: operation getAnimations() 
+PASS ShadowRoot interface: shadowRoot must inherit property "getAnimations()" with the proper type 
 PASS Element interface: operation animate(object, [object Object],[object Object]) 
 PASS Element interface: operation getAnimations(GetAnimationsOptions) 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations-expected.txt (259576 => 259577)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations-expected.txt	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations-expected.txt	2020-04-06 17:41:43 UTC (rev 259577)
@@ -5,7 +5,9 @@
 PASS Document.getAnimations() does not return a disconnected node 
 PASS Document.getAnimations() does not return an animation with a null target 
 FAIL Document.getAnimations() returns animations on elements inside same-origin iframes assert_equals: expected 1 but got 0
-FAIL ShadowRoot.getAnimations() return all animations in the shadow tree div.shadowRoot.getAnimations is not a function. (In 'div.shadowRoot.getAnimations()', 'div.shadowRoot.getAnimations' is undefined)
-FAIL Document.getAnimations() does NOT return animations in shadow trees assert_array_equals: getAnimations() called on Document does not return animations from shadow trees lengths differ, expected 0 got 1
+FAIL iframe.contentDocument.getAnimations() returns animations on elements inside same-origin Document assert_equals: expected 1 but got 0
+PASS ShadowRoot.getAnimations() return all animations in the shadow tree 
+PASS Document.getAnimations() does NOT return animations in shadow trees 
+PASS ShadowRoot.getAnimations() does NOT return animations in parent document 
 PASS Document.getAnimations() triggers a style change event 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations.html (259576 => 259577)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations.html	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/interfaces/DocumentOrShadowRoot/getAnimations.html	2020-04-06 17:41:43 UTC (rev 259577)
@@ -68,15 +68,8 @@
 
 promise_test(async t => {
   const iframe = document.createElement('iframe');
+  await insertFrameAndAwaitLoad(t, iframe, document)
 
-  const eventWatcher = new EventWatcher(t, iframe, ['load']);
-  const event_promise = eventWatcher.wait_for('load');
-
-  document.body.appendChild(iframe);
-  t.add_cleanup(() => { document.body.removeChild(iframe); });
-
-  await event_promise;
-
   const div = createDiv(t, iframe.contentDocument)
   const effect = new KeyframeEffect(div, null, 100 * MS_PER_SEC);
   const anim = new Animation(effect, document.timeline);
@@ -91,6 +84,52 @@
 }, 'Document.getAnimations() returns animations on elements inside same-origin'
    + ' iframes');
 
+promise_test(async t => {
+  const iframe1 = document.createElement('iframe');
+  const iframe2 = document.createElement('iframe');
+
+  await insertFrameAndAwaitLoad(t, iframe1, document);
+  await insertFrameAndAwaitLoad(t, iframe2, document);
+
+  const div_frame1 = createDiv(t, iframe1.contentDocument)
+  const div_main_frame = createDiv(t)
+  const effect1 = new KeyframeEffect(div_frame1, null, 100 * MS_PER_SEC);
+  const anim1 = new Animation(effect1, document.timeline);
+  anim1.play();
+  // Animation of div_frame1 is in iframe with main timeline.
+  // The animation's timeline is from the iframe, but the effect's target
+  // element is part of the iframe's document.
+  assert_equals(document.getAnimations().length, 0);
+  assert_equals(iframe1.contentDocument.getAnimations().length, 1);
+  anim1.finish();
+
+   // animation of div_frame1 in iframe1 with iframe timeline
+  const effect2 = new KeyframeEffect(div_frame1, null, 100 * MS_PER_SEC);
+  const anim2 = new Animation(effect2, iframe1.contentDocument.timeline);
+  anim2.play();
+  assert_equals(document.getAnimations().length, 0);
+  assert_equals(iframe1.contentDocument.getAnimations().length, 1);
+  anim2.finish();
+
+  //animation of div_main_frame in main frame with iframe timeline
+  const effect3 = new KeyframeEffect(div_main_frame, null, 100 * MS_PER_SEC);
+  const anim3 = new Animation(effect3, iframe1.contentDocument.timeline);
+  anim3.play();
+  assert_equals(document.getAnimations().length, 1);
+  assert_equals(iframe1.contentDocument.getAnimations().length, 0);
+  anim3.finish();
+
+  //animation of div_frame1 in iframe1 with another iframe's timeline
+  const effect4 = new KeyframeEffect(div_frame1, null, 100 * MS_PER_SEC);
+  const anim4 = new Animation(effect4, iframe2.contentDocument.timeline);
+  anim4.play();
+  assert_equals(document.getAnimations().length, 0);
+  assert_equals(iframe1.contentDocument.getAnimations().length, 1);
+  assert_equals(iframe2.contentDocument.getAnimations().length, 0);
+  anim4.finish();
+}, 'iframe.contentDocument.getAnimations() returns animations on elements '
+   + 'inside same-origin Document');
+
 test(t => {
   const div = createDiv(t);
   const shadow = div.attachShadow({ mode: 'open' });
@@ -149,6 +188,20 @@
   );
 }, 'Document.getAnimations() does NOT return animations in shadow trees');
 
+test(t => {
+  const div = createDiv(t);
+  const shadow = div.attachShadow({ mode: 'open' });
+
+  div.animate(gKeyFrames, 100 * MS_PER_SEC)
+
+  assert_array_equals(
+    div.shadowRoot.getAnimations(),
+    [],
+    'getAnimations() called on ShadowRoot does not return animations from'
+    + ' Document'
+  );
+}, 'ShadowRoot.getAnimations() does NOT return animations in parent document');
+
 promise_test(async t => {
   const div = createDiv(t);
   const watcher = EventWatcher(t, div, 'transitionrun');

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/testcommon.js (259576 => 259577)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/testcommon.js	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/web-animations/testcommon.js	2020-04-06 17:41:43 UTC (rev 259577)
@@ -180,6 +180,16 @@
   });
 }
 
+async function insertFrameAndAwaitLoad(test, iframe, doc) {
+  const eventWatcher = new EventWatcher(test, iframe, ['load']);
+  const event_promise = eventWatcher.wait_for('load');
+
+  doc.body.appendChild(iframe);
+  test.add_cleanup(() => { doc.body.removeChild(iframe); });
+
+  await event_promise;
+}
+
 // Returns 'matrix()' or 'matrix3d()' function string generated from an array.
 function createMatrixFromArray(array) {
   return (array.length == 16 ? 'matrix3d' : 'matrix') + `(${array.join()})`;

Modified: trunk/Source/WebCore/ChangeLog (259576 => 259577)


--- trunk/Source/WebCore/ChangeLog	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/Source/WebCore/ChangeLog	2020-04-06 17:41:43 UTC (rev 259577)
@@ -1,3 +1,31 @@
+2020-04-06  Antoine Quint  <grao...@apple.com>
+
+        [Web Animations] Move Document.getAnimations() to DocumentOrShadowRoot
+        https://bugs.webkit.org/show_bug.cgi?id=202192
+        <rdar://problem/55697775>
+
+        Reviewed by Antti Koivisto.
+
+        We remove the getAnimations() declaration from the Document interface and instead move it on the DocumentOrShadowRoot interface.
+
+        We add the new method Document::matchingAnimations() which takes a lambda that is provided an animation's effect's target to determine whether
+        that animation should be found in the list of animations.
+
+        In the case of Document::getAnimations(), we filter out animations targeting elements hosted in shadow roots, while in ShadowRoot:getAnimations(),
+        we filter out animations targeting elements that are not hosted in the shadow root the method was called on.
+
+        * dom/Document.cpp:
+        (WebCore::Document::getAnimations):
+        (WebCore::Document::matchingAnimations):
+        * dom/Document.h:
+        * dom/Document.idl:
+        * dom/DocumentOrShadowRoot.idl:
+        * dom/Element.cpp:
+        (WebCore::Element::getAnimations):
+        * dom/ShadowRoot.cpp:
+        (WebCore::ShadowRoot::getAnimations):
+        * dom/ShadowRoot.h:
+
 2020-04-04  Darin Adler  <da...@apple.com>
 
         Stop using live ranges in DocumentMarkerController

Modified: trunk/Source/WebCore/dom/Document.cpp (259576 => 259577)


--- trunk/Source/WebCore/dom/Document.cpp	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/Source/WebCore/dom/Document.cpp	2020-04-06 17:41:43 UTC (rev 259577)
@@ -8103,13 +8103,30 @@
 
 Vector<RefPtr<WebAnimation>> Document::getAnimations()
 {
+    return matchingAnimations([] (Element& target) -> bool {
+        return !target.containingShadowRoot();
+    });
+}
+
+Vector<RefPtr<WebAnimation>> Document::matchingAnimations(const WTF::Function<bool(Element&)>& function)
+{
     // For the list of animations to be current, we need to account for any pending CSS changes,
     // such as updates to CSS Animations and CSS Transitions.
     updateStyleIfNeeded();
 
-    if (m_timeline)
-        return m_timeline->getAnimations();
-    return { };
+    if (!m_timeline)
+        return { };
+
+    Vector<RefPtr<WebAnimation>> animations;
+    for (auto& animation : m_timeline->getAnimations()) {
+        auto* effect = animation->effect();
+        ASSERT(is<KeyframeEffect>(animation->effect()));
+        auto* target = downcast<KeyframeEffect>(*effect).target();
+        ASSERT(target);
+        if (function(*target))
+            animations.append(animation);
+    }
+    return animations;
 }
 
 #if ENABLE(ATTACHMENT_ELEMENT)

Modified: trunk/Source/WebCore/dom/Document.h (259576 => 259577)


--- trunk/Source/WebCore/dom/Document.h	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/Source/WebCore/dom/Document.h	2020-04-06 17:41:43 UTC (rev 259577)
@@ -1485,7 +1485,8 @@
     WEBCORE_EXPORT DocumentTimeline& timeline();
     DocumentTimeline* existingTimeline() const { return m_timeline.get(); }
     Vector<RefPtr<WebAnimation>> getAnimations();
-        
+    Vector<RefPtr<WebAnimation>> matchingAnimations(const WTF::Function<bool(Element&)>&);
+
 #if ENABLE(ATTACHMENT_ELEMENT)
     void registerAttachmentIdentifier(const String&);
     void didInsertAttachmentElement(HTMLAttachmentElement&);

Modified: trunk/Source/WebCore/dom/Document.idl (259576 => 259577)


--- trunk/Source/WebCore/dom/Document.idl	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/Source/WebCore/dom/Document.idl	2020-04-06 17:41:43 UTC (rev 259577)
@@ -190,7 +190,6 @@
     [Replaceable] readonly attribute HTMLAllCollection all; /* [SameObject] */
 
     [EnabledAtRuntime=WebAnimations] readonly attribute DocumentTimeline timeline;
-    [EnabledAtRuntime=WebAnimations] sequence<WebAnimation> getAnimations();
 };
 
 enum DocumentReadyState { "loading", "interactive", "complete" };

Modified: trunk/Source/WebCore/dom/DocumentOrShadowRoot.idl (259576 => 259577)


--- trunk/Source/WebCore/dom/DocumentOrShadowRoot.idl	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/Source/WebCore/dom/DocumentOrShadowRoot.idl	2020-04-06 17:41:43 UTC (rev 259577)
@@ -43,4 +43,7 @@
 
     // Extensions from Picture-in-Picture API (https://wicg.github.io/picture-in-picture/#documentorshadowroot-extension)
     [Conditional=PICTURE_IN_PICTURE_API, EnabledBySetting=PictureInPictureAPI] readonly attribute Element? pictureInPictureElement;
+
+    // Extension from Web Animations API (https://drafts.csswg.org/web-animations-1/#extensions-to-the-documentorshadowroot-interface-mixin)
+    [EnabledAtRuntime=WebAnimations] sequence<WebAnimation> getAnimations();
 };

Modified: trunk/Source/WebCore/dom/Element.cpp (259576 => 259577)


--- trunk/Source/WebCore/dom/Element.cpp	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/Source/WebCore/dom/Element.cpp	2020-04-06 17:41:43 UTC (rev 259577)
@@ -4534,19 +4534,11 @@
     // animations targeting that are not registered on this element, one of its pseudo elements or a child's
     // pseudo element.
     if (options && options->subtree) {
-        Vector<RefPtr<WebAnimation>> animations;
-        for (auto& animation : document().getAnimations()) {
-            auto* effect = animation->effect();
-            ASSERT(is<KeyframeEffect>(animation->effect()));
-            auto* target = downcast<KeyframeEffect>(*effect).target();
-            ASSERT(target);
-            if (is<PseudoElement>(target)) {
-                if (contains(downcast<PseudoElement>(*target).hostElement()))
-                    animations.append(animation);
-            } else if (contains(target))
-                animations.append(animation);
-        }
-        return animations;
+        return document().matchingAnimations([&] (Element& target) -> bool {
+            if (is<PseudoElement>(target))
+                return contains(downcast<PseudoElement>(target).hostElement());
+            return contains(&target);
+        });
     }
 
     // For the list of animations to be current, we need to account for any pending CSS changes,

Modified: trunk/Source/WebCore/dom/ShadowRoot.cpp (259576 => 259577)


--- trunk/Source/WebCore/dom/ShadowRoot.cpp	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/Source/WebCore/dom/ShadowRoot.cpp	2020-04-06 17:41:43 UTC (rev 259577)
@@ -367,4 +367,11 @@
 }
 #endif
 
+Vector<RefPtr<WebAnimation>> ShadowRoot::getAnimations()
+{
+    return document().matchingAnimations([&] (Element& target) -> bool {
+        return target.containingShadowRoot() == this;
+    });
 }
+
+}

Modified: trunk/Source/WebCore/dom/ShadowRoot.h (259576 => 259577)


--- trunk/Source/WebCore/dom/ShadowRoot.h	2020-04-06 17:35:44 UTC (rev 259576)
+++ trunk/Source/WebCore/dom/ShadowRoot.h	2020-04-06 17:41:43 UTC (rev 259577)
@@ -40,6 +40,7 @@
 class HTMLSlotElement;
 class SlotAssignment;
 class StyleSheetList;
+class WebAnimation;
 
 class ShadowRoot final : public DocumentFragment, public TreeScope {
     WTF_MAKE_ISO_ALLOCATED(ShadowRoot);
@@ -111,6 +112,8 @@
     HTMLVideoElement* pictureInPictureElement() const;
 #endif
 
+    Vector<RefPtr<WebAnimation>> getAnimations();
+
 private:
     ShadowRoot(Document&, ShadowRootMode, DelegatesFocus);
     ShadowRoot(Document&, std::unique_ptr<SlotAssignment>&&);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to