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
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "mozilla/dom/Element.h" // For Element
9 #include "mozilla/RestyleManager.h"
10 #include "mozilla/LayerAnimationInfo.h"
11 #include "nsCSSPseudoElements.h" // For PseudoStyleType
12 #include "nsCycleCollectionNoteChild.h" // For CycleCollectionNoteChild
13 #include "nsPresContext.h"
14 #include "nsLayoutUtils.h"
15 #include "ElementAnimationData.h"
19 void EffectSet::Traverse(nsCycleCollectionTraversalCallback
& aCallback
) {
20 for (const auto& key
: mEffects
) {
21 CycleCollectionNoteChild(aCallback
, key
, "EffectSet::mEffects[]",
27 EffectSet
* EffectSet::Get(const dom::Element
* aElement
,
28 PseudoStyleType aPseudoType
) {
29 if (auto* data
= aElement
->GetAnimationData()) {
30 return data
->GetEffectSetFor(aPseudoType
);
36 EffectSet
* EffectSet::GetOrCreate(dom::Element
* aElement
,
37 PseudoStyleType aPseudoType
) {
38 return &aElement
->EnsureAnimationData().EnsureEffectSetFor(aPseudoType
);
42 EffectSet
* EffectSet::GetForFrame(const nsIFrame
* aFrame
,
43 const nsCSSPropertyIDSet
& aProperties
) {
46 // Transform animations are run on the primary frame (but stored on the
47 // content associated with the style frame).
48 const nsIFrame
* frameToQuery
= nullptr;
49 if (aProperties
.IsSubsetOf(nsCSSPropertyIDSet::TransformLikeProperties())) {
50 // Make sure to return nullptr if we're looking for transform animations on
51 // the inner table frame.
52 if (!aFrame
->SupportsCSSTransforms()) {
55 frameToQuery
= nsLayoutUtils::GetStyleFrame(aFrame
);
58 !aProperties
.Intersects(nsCSSPropertyIDSet::TransformLikeProperties()),
59 "We should have only transform properties or no transform properties");
60 // We don't need to explicitly return nullptr when |aFrame| is NOT the style
61 // frame since there will be no effect set in that case.
62 frameToQuery
= aFrame
;
65 Maybe
<NonOwningAnimationTarget
> target
=
66 EffectCompositor::GetAnimationElementAndPseudoForFrame(frameToQuery
);
71 return Get(target
->mElement
, target
->mPseudoType
);
75 EffectSet
* EffectSet::GetForFrame(const nsIFrame
* aFrame
,
76 DisplayItemType aDisplayItemType
) {
77 return EffectSet::GetForFrame(
78 aFrame
, LayerAnimationInfo::GetCSSPropertiesFor(aDisplayItemType
));
82 EffectSet
* EffectSet::GetForStyleFrame(const nsIFrame
* aStyleFrame
) {
83 Maybe
<NonOwningAnimationTarget
> target
=
84 EffectCompositor::GetAnimationElementAndPseudoForFrame(aStyleFrame
);
90 return Get(target
->mElement
, target
->mPseudoType
);
94 EffectSet
* EffectSet::GetForEffect(const dom::KeyframeEffect
* aEffect
) {
95 NonOwningAnimationTarget target
= aEffect
->GetAnimationTarget();
100 return EffectSet::Get(target
.mElement
, target
.mPseudoType
);
104 void EffectSet::DestroyEffectSet(dom::Element
* aElement
,
105 PseudoStyleType aPseudoType
) {
106 if (auto* data
= aElement
->GetAnimationData()) {
107 data
->ClearEffectSetFor(aPseudoType
);
111 void EffectSet::UpdateAnimationGeneration(nsPresContext
* aPresContext
) {
112 mAnimationGeneration
=
113 aPresContext
->RestyleManager()->GetAnimationGeneration();
116 void EffectSet::AddEffect(dom::KeyframeEffect
& aEffect
) {
117 if (!mEffects
.EnsureInserted(&aEffect
)) {
121 MarkCascadeNeedsUpdate();
124 void EffectSet::RemoveEffect(dom::KeyframeEffect
& aEffect
) {
125 if (!mEffects
.EnsureRemoved(&aEffect
)) {
129 MarkCascadeNeedsUpdate();
132 } // namespace mozilla