Backed out 8 changesets (bug 1873776) for causing vendor failures. CLOSED TREE
[gecko.git] / dom / animation / EffectSet.cpp
blobc1fed19ae8597391a1ad2f380bbe5336db27b505
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/. */
7 #include "EffectSet.h"
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"
17 namespace mozilla {
19 void EffectSet::Traverse(nsCycleCollectionTraversalCallback& aCallback) {
20 for (const auto& key : mEffects) {
21 CycleCollectionNoteChild(aCallback, key, "EffectSet::mEffects[]",
22 aCallback.Flags());
26 /* static */
27 EffectSet* EffectSet::Get(const dom::Element* aElement,
28 PseudoStyleType aPseudoType) {
29 if (auto* data = aElement->GetAnimationData()) {
30 return data->GetEffectSetFor(aPseudoType);
32 return nullptr;
35 /* static */
36 EffectSet* EffectSet::GetOrCreate(dom::Element* aElement,
37 PseudoStyleType aPseudoType) {
38 return &aElement->EnsureAnimationData().EnsureEffectSetFor(aPseudoType);
41 /* static */
42 EffectSet* EffectSet::GetForFrame(const nsIFrame* aFrame,
43 const nsCSSPropertyIDSet& aProperties) {
44 MOZ_ASSERT(aFrame);
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()) {
53 return nullptr;
55 frameToQuery = nsLayoutUtils::GetStyleFrame(aFrame);
56 } else {
57 MOZ_ASSERT(
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 if (!target) {
68 return nullptr;
71 return Get(target->mElement, target->mPseudoType);
74 /* static */
75 EffectSet* EffectSet::GetForFrame(const nsIFrame* aFrame,
76 DisplayItemType aDisplayItemType) {
77 return EffectSet::GetForFrame(
78 aFrame, LayerAnimationInfo::GetCSSPropertiesFor(aDisplayItemType));
81 /* static */
82 EffectSet* EffectSet::GetForStyleFrame(const nsIFrame* aStyleFrame) {
83 Maybe<NonOwningAnimationTarget> target =
84 EffectCompositor::GetAnimationElementAndPseudoForFrame(aStyleFrame);
86 if (!target) {
87 return nullptr;
90 return Get(target->mElement, target->mPseudoType);
93 /* static */
94 EffectSet* EffectSet::GetForEffect(const dom::KeyframeEffect* aEffect) {
95 NonOwningAnimationTarget target = aEffect->GetAnimationTarget();
96 if (!target) {
97 return nullptr;
100 return EffectSet::Get(target.mElement, target.mPseudoType);
103 /* static */
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)) {
118 return;
121 MarkCascadeNeedsUpdate();
124 void EffectSet::RemoveEffect(dom::KeyframeEffect& aEffect) {
125 if (!mEffects.EnsureRemoved(&aEffect)) {
126 return;
129 MarkCascadeNeedsUpdate();
132 } // namespace mozilla