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/PseudoStyleType.h" // For PseudoStyleRequest
10 #include "mozilla/RestyleManager.h"
11 #include "mozilla/LayerAnimationInfo.h"
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 const PseudoStyleRequest
& aPseudoRequest
) {
29 if (auto* data
= aElement
->GetAnimationData()) {
30 return data
->GetEffectSetFor(aPseudoRequest
);
36 EffectSet
* EffectSet::GetOrCreate(dom::Element
* aElement
,
37 const PseudoStyleRequest
& aPseudoRequest
) {
38 return &aElement
->EnsureAnimationData().EnsureEffectSetFor(aPseudoRequest
);
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
);
67 return target
? Get(*target
) : nullptr;
71 EffectSet
* EffectSet::GetForFrame(const nsIFrame
* aFrame
,
72 DisplayItemType aDisplayItemType
) {
73 return EffectSet::GetForFrame(
74 aFrame
, LayerAnimationInfo::GetCSSPropertiesFor(aDisplayItemType
));
78 EffectSet
* EffectSet::GetForStyleFrame(const nsIFrame
* aStyleFrame
) {
79 Maybe
<NonOwningAnimationTarget
> target
=
80 EffectCompositor::GetAnimationElementAndPseudoForFrame(aStyleFrame
);
81 return target
? Get(*target
) : nullptr;
85 EffectSet
* EffectSet::GetForEffect(const dom::KeyframeEffect
* aEffect
) {
86 NonOwningAnimationTarget target
= aEffect
->GetAnimationTarget();
87 return target
? Get(target
) : nullptr;
91 void EffectSet::DestroyEffectSet(dom::Element
* aElement
,
92 const PseudoStyleRequest
& aPseudoRequest
) {
93 if (auto* data
= aElement
->GetAnimationData()) {
94 data
->ClearEffectSetFor(aPseudoRequest
);
98 void EffectSet::UpdateAnimationGeneration(nsPresContext
* aPresContext
) {
99 mAnimationGeneration
=
100 aPresContext
->RestyleManager()->GetAnimationGeneration();
103 void EffectSet::AddEffect(dom::KeyframeEffect
& aEffect
) {
104 if (!mEffects
.EnsureInserted(&aEffect
)) {
108 MarkCascadeNeedsUpdate();
111 void EffectSet::RemoveEffect(dom::KeyframeEffect
& aEffect
) {
112 if (!mEffects
.EnsureRemoved(&aEffect
)) {
116 MarkCascadeNeedsUpdate();
119 } // namespace mozilla