1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_ViewTimeline_h
8 #define mozilla_dom_ViewTimeline_h
10 #include "mozilla/dom/ScrollTimeline.h"
13 class ScrollContainerFrame
;
14 } // namespace mozilla
16 namespace mozilla::dom
{
19 * A view progress timeline is a segment of a scroll progress timeline that are
20 * scoped to the scroll positions in which any part of the associated element’s
21 * principal box intersects its nearest ancestor scrollport. So ViewTimeline
22 * is a special case of ScrollTimeline.
24 class ViewTimeline final
: public ScrollTimeline
{
25 template <typename T
, typename
... Args
>
26 friend already_AddRefed
<T
> mozilla::MakeAndAddRef(Args
&&... aArgs
);
29 NS_DECL_ISUPPORTS_INHERITED
30 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ViewTimeline
, ScrollTimeline
)
32 ViewTimeline() = delete;
34 // Note: |aSubject| is used as the subject which specifies view-timeline-name
35 // property, and we use this subject to look up its nearest scroll container.
36 static already_AddRefed
<ViewTimeline
> MakeNamed(
37 Document
* aDocument
, Element
* aSubject
, PseudoStyleType aPseudoType
,
38 const StyleViewTimeline
& aStyleTimeline
);
40 static already_AddRefed
<ViewTimeline
> MakeAnonymous(
41 Document
* aDocument
, const NonOwningAnimationTarget
& aTarget
,
42 StyleScrollAxis aAxis
, const StyleViewTimelineInset
& aInset
);
44 JSObject
* WrapObject(JSContext
* aCx
,
45 JS::Handle
<JSObject
*> aGivenProto
) override
{
49 bool IsViewTimeline() const override
{ return true; }
51 void ReplacePropertiesWith(Element
* aSubjectElement
,
52 PseudoStyleType aPseudoType
,
53 const StyleViewTimeline
& aNew
);
56 ~ViewTimeline() = default;
57 ViewTimeline(Document
* aDocument
, const Scroller
& aScroller
,
58 StyleScrollAxis aAxis
, Element
* aSubject
,
59 PseudoStyleType aSubjectPseudoType
,
60 const StyleViewTimelineInset
& aInset
)
61 : ScrollTimeline(aDocument
, aScroller
, aAxis
),
63 mSubjectPseudoType(aSubjectPseudoType
),
66 Maybe
<ScrollOffsets
> ComputeOffsets(
67 const ScrollContainerFrame
* aScrollContainerFrame
,
68 layers::ScrollDirection aOrientation
) const override
;
70 ScrollOffsets
ComputeInsets(const ScrollContainerFrame
* aScrollContainerFrame
,
71 layers::ScrollDirection aOrientation
) const;
73 // The subject element.
74 // 1. For view(), the subject element is the animation target.
75 // 2. For view-timeline property, the subject element is the element who
76 // defines this property.
77 RefPtr
<Element
> mSubject
;
78 PseudoStyleType mSubjectPseudoType
;
80 // FIXME: Bug 1817073. view-timeline-inset is an animatable property. However,
81 // the inset from view() is not animatable, so for named view timeline, this
82 // value depends on the animation style. Therefore, we have to check its style
83 // value when using it. For now, in order to simplify the implementation, we
84 // make |mInset| be fixed.
85 StyleViewTimelineInset mInset
;
88 } // namespace mozilla::dom
90 #endif // mozilla_dom_ViewTimeline_h