RESOLVED FIXED 202192
[Web Animations] Move Document.getAnimations() to DocumentOrShadowRoot
https://bugs.webkit.org/show_bug.cgi?id=202192
Summary [Web Animations] Move Document.getAnimations() to DocumentOrShadowRoot
Antoine Quint
Reported 2019-09-25 02:56:19 PDT
This method moved to also apply to shadow roots, see https://drafts.csswg.org/web-animations/#dom-documentorshadowroot-getanimations.
Attachments
Patch (17.60 KB, patch)
2020-04-06 07:25 PDT, Antoine Quint
no flags
Patch (17.29 KB, patch)
2020-04-06 09:43 PDT, Antoine Quint
koivisto: review+
Radar WebKit Bug Importer
Comment 1 2019-09-25 02:56:44 PDT
Antoine Quint
Comment 2 2020-04-06 07:25:34 PDT
Antti Koivisto
Comment 3 2020-04-06 07:42:18 PDT
Comment on attachment 395563 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=395563&action=review > Source/WebCore/dom/Document.cpp:8104 > -Vector<RefPtr<WebAnimation>> Document::getAnimations() > +Vector<RefPtr<WebAnimation>> Document::getAnimations(IncludeAnimationsTargetingElementsInShadowRoot includeAnimationsTargetingElementsInShadowRoot) It might be cleaner to have a separate internal function that takes the argument and have the argument-free getAnimations() just call that. Internal clients would all switch to the new function. > Source/WebCore/dom/Document.cpp:8120 > + for (auto& animation : m_timeline->getAnimations()) { > + auto* effect = animation->effect(); > + ASSERT(is<KeyframeEffect>(animation->effect())); > + auto* target = downcast<KeyframeEffect>(*effect).target(); Couldn't getAnimations()/new internal function just return a list of KeyframeEffects is those are the only things it can contain? > Source/WebCore/dom/Document.h:1488 > + Vector<RefPtr<WebAnimation>> getAnimations(IncludeAnimationsTargetingElementsInShadowRoot = IncludeAnimationsTargetingElementsInShadowRoot::No); Then you wouldn't need a default parameter either.
Antti Koivisto
Comment 4 2020-04-06 07:44:06 PDT
Comment on attachment 395563 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=395563&action=review > Source/WebCore/dom/ShadowRoot.cpp:384 > +Vector<RefPtr<WebAnimation>> ShadowRoot::getAnimations() > +{ > + Vector<RefPtr<WebAnimation>> animations; > + for (auto& animation : document().getAnimations(Document::IncludeAnimationsTargetingElementsInShadowRoot::Yes)) { > + auto* effect = animation->effect(); > + ASSERT(is<KeyframeEffect>(animation->effect())); > + auto* target = downcast<KeyframeEffect>(*effect).target(); > + ASSERT(target); > + if (target->containingShadowRoot() == this) > + animations.append(animation); > + } > + return animations; > +} You can put code shared between Document and ShadowRoot to TreeScope.
Antoine Quint
Comment 5 2020-04-06 08:38:14 PDT
(In reply to Antti Koivisto from comment #3) > Comment on attachment 395563 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=395563&action=review > > > Source/WebCore/dom/Document.cpp:8104 > > -Vector<RefPtr<WebAnimation>> Document::getAnimations() > > +Vector<RefPtr<WebAnimation>> Document::getAnimations(IncludeAnimationsTargetingElementsInShadowRoot includeAnimationsTargetingElementsInShadowRoot) > > It might be cleaner to have a separate internal function that takes the > argument and have the argument-free getAnimations() just call that. > > Internal clients would all switch to the new function. > > > Source/WebCore/dom/Document.cpp:8120 > > + for (auto& animation : m_timeline->getAnimations()) { > > + auto* effect = animation->effect(); > > + ASSERT(is<KeyframeEffect>(animation->effect())); > > + auto* target = downcast<KeyframeEffect>(*effect).target(); > > Couldn't getAnimations()/new internal function just return a list of > KeyframeEffects is those are the only things it can contain? > > > Source/WebCore/dom/Document.h:1488 > > + Vector<RefPtr<WebAnimation>> getAnimations(IncludeAnimationsTargetingElementsInShadowRoot = IncludeAnimationsTargetingElementsInShadowRoot::No); > > Then you wouldn't need a default parameter either. All of these are useful comments! I think Document::getAnimations() will implement the API and call a new internal method Document::filterAnimations() which will take an optional lambda that will run for each Element targeted by an animation to filter it out.
Antoine Quint
Comment 6 2020-04-06 09:43:08 PDT
Antti Koivisto
Comment 7 2020-04-06 09:55:42 PDT
Comment on attachment 395573 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=395573&action=review > Source/WebCore/dom/Document.cpp:8111 > +Vector<RefPtr<WebAnimation>> Document::getMatchingAnimations(const WTF::Function<bool(Element&)>& function) We don't usually name functions getSomething. API functions like getAnimations() are the exception. Maybe just matchingAnimations()? > Source/WebCore/dom/Document.cpp:8129 > + 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; This function doesn't really have much to do with Document. Maybe it could live in DocumentTimeline instead?
Antoine Quint
Comment 8 2020-04-06 10:08:24 PDT
(In reply to Antti Koivisto from comment #7) > Comment on attachment 395573 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=395573&action=review > > > Source/WebCore/dom/Document.cpp:8111 > > +Vector<RefPtr<WebAnimation>> Document::getMatchingAnimations(const WTF::Function<bool(Element&)>& function) > > We don't usually name functions getSomething. API functions like > getAnimations() are the exception. Maybe just matchingAnimations()? Good point. I'll change the method name. > > Source/WebCore/dom/Document.cpp:8129 > > + 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; > > This function doesn't really have much to do with Document. Maybe it could > live in DocumentTimeline instead? While we don't support that well yet, eventually we should return animations for all timelines associated with the provided document, so it belongs on Document.
Antoine Quint
Comment 9 2020-04-06 10:41:53 PDT
Note You need to log in before you can comment on or make changes to this bug.