From 77a0fd63cff68dbf43c681a778d2df600457228b Mon Sep 17 00:00:00 2001 From: Boris Chiou Date: Tue, 2 May 2023 22:47:29 +0000 Subject: [PATCH] Bug 1808410 - Part 3: Create timeline for view(). r=emilio Also, I add some similar tests but they don't use Named Timeline Range, which is not supported by Gecko now (Bug 1824875). Differential Revision: https://phabricator.services.mozilla.com/D173905 --- dom/animation/ViewTimeline.cpp | 20 +- dom/animation/ViewTimeline.h | 7 + layout/style/nsAnimationManager.cpp | 7 +- ...iew-functional-notation.tentative.html.ini | 9 + ...ne-view-functional-notation.tentative.html | 211 ++++++++++++++++++ 5 files changed, 248 insertions(+), 6 deletions(-) diff --git a/dom/animation/ViewTimeline.cpp b/dom/animation/ViewTimeline.cpp index bb877ac9b505..5727c5f08e71 100644 --- a/dom/animation/ViewTimeline.cpp +++ b/dom/animation/ViewTimeline.cpp @@ -28,10 +28,22 @@ already_AddRefed ViewTimeline::MakeNamed( auto scroller = Scroller::Nearest(const_cast(element), pseudo); // 2. Create timeline. - return RefPtr( - new ViewTimeline(aDocument, scroller, aStyleTimeline.GetAxis(), - aSubject, aPseudoType, aStyleTimeline.GetInset())) - .forget(); + return MakeAndAddRef(aDocument, scroller, + aStyleTimeline.GetAxis(), aSubject, + aPseudoType, aStyleTimeline.GetInset()); +} + +/* static */ +already_AddRefed ViewTimeline::MakeAnonymous( + Document* aDocument, const NonOwningAnimationTarget& aTarget, + StyleScrollAxis aAxis, const StyleViewTimelineInset& aInset) { + // view() finds the nearest scroll container from the animation target. + auto [element, pseudo] = + FindNearestScroller(aTarget.mElement, aTarget.mPseudoType); + Scroller scroller = Scroller::Nearest(const_cast(element), pseudo); + return MakeAndAddRef(aDocument, scroller, aAxis, + aTarget.mElement, aTarget.mPseudoType, + aInset); } void ViewTimeline::ReplacePropertiesWith(Element* aSubjectElement, diff --git a/dom/animation/ViewTimeline.h b/dom/animation/ViewTimeline.h index 53861c016b4e..a5ede6345d61 100644 --- a/dom/animation/ViewTimeline.h +++ b/dom/animation/ViewTimeline.h @@ -18,6 +18,9 @@ namespace mozilla::dom { * is a special case of ScrollTimeline. */ class ViewTimeline final : public ScrollTimeline { + template + friend already_AddRefed mozilla::MakeAndAddRef(Args&&... aArgs); + public: NS_DECL_ISUPPORTS_INHERITED NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ViewTimeline, ScrollTimeline) @@ -30,6 +33,10 @@ class ViewTimeline final : public ScrollTimeline { Document* aDocument, Element* aSubject, PseudoStyleType aPseudoType, const StyleViewTimeline& aStyleTimeline); + static already_AddRefed MakeAnonymous( + Document* aDocument, const NonOwningAnimationTarget& aTarget, + StyleScrollAxis aAxis, const StyleViewTimelineInset& aInset); + JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override { return nullptr; diff --git a/layout/style/nsAnimationManager.cpp b/layout/style/nsAnimationManager.cpp index 3550e2586b45..f03e00ff2aa3 100644 --- a/layout/style/nsAnimationManager.cpp +++ b/layout/style/nsAnimationManager.cpp @@ -270,8 +270,11 @@ static already_AddRefed GetTimeline( return ScrollTimeline::MakeAnonymous(aPresContext->Document(), aTarget, scroll.axis, scroll.scroller); } - case StyleAnimationTimeline::Tag::View: - // TODO: Support this in this patch series. Treat it as auto for now. + case StyleAnimationTimeline::Tag::View: { + const auto& view = aStyleTimeline.AsView(); + return ViewTimeline::MakeAnonymous(aPresContext->Document(), aTarget, + view.axis, view.inset); + } case StyleAnimationTimeline::Tag::Auto: return do_AddRef(aTarget.mElement->OwnerDoc()->Timeline()); } diff --git a/testing/web-platform/meta/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html.ini b/testing/web-platform/meta/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html.ini index 41bd86cfc893..3af0d0ddb0a3 100644 --- a/testing/web-platform/meta/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html.ini +++ b/testing/web-platform/meta/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html.ini @@ -1,27 +1,36 @@ [animation-timeline-view-functional-notation.tentative.html] [animation-timeline: view()] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 [animation-timeline: view(50px)] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 [animation-timeline: view(auto 50px)] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 [animation-timeline: view(inline)] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 [animation-timeline: view(horizontal)] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 [animation-timeline: view(vertical)] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 [animation-timeline: view(horizontal 50px)] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 [animation-timeline: view(), view(inline)] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 [animation-timeline: view(inline) changes to view(inline 50px)] expected: FAIL + bug: https://bugzilla.mozilla.org/show_bug.cgi?id=1824875 diff --git a/testing/web-platform/tests/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html b/testing/web-platform/tests/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html index 70891c6ccf8a..745d76c72943 100644 --- a/testing/web-platform/tests/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html +++ b/testing/web-platform/tests/scroll-animations/css/animation-timeline-view-functional-notation.tentative.html @@ -8,6 +8,20 @@