summaryrefslogtreecommitdiffstats
path: root/dom/animation/ElementAnimationData.cpp
blob: d87caf8a5815b88a306a6937435c591835a5bd96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "ElementAnimationData.h"
#include "mozilla/AnimationCollection.h"
#include "mozilla/TimelineCollection.h"
#include "mozilla/EffectSet.h"
#include "mozilla/dom/CSSTransition.h"
#include "mozilla/dom/CSSAnimation.h"
#include "mozilla/dom/ScrollTimeline.h"
#include "mozilla/dom/ViewTimeline.h"

namespace mozilla {

void ElementAnimationData::Traverse(nsCycleCollectionTraversalCallback& cb) {
  mElementData.Traverse(cb);
  mBeforeData.Traverse(cb);
  mAfterData.Traverse(cb);
  mMarkerData.Traverse(cb);
}

void ElementAnimationData::ClearAllAnimationCollections() {
  for (auto* data : {&mElementData, &mBeforeData, &mAfterData, &mMarkerData}) {
    data->mAnimations = nullptr;
    data->mTransitions = nullptr;
    data->mScrollTimelines = nullptr;
    data->mViewTimelines = nullptr;
    data->mProgressTimelineScheduler = nullptr;
  }
}

ElementAnimationData::PerElementOrPseudoData::PerElementOrPseudoData() =
    default;
ElementAnimationData::PerElementOrPseudoData::~PerElementOrPseudoData() =
    default;

void ElementAnimationData::PerElementOrPseudoData::Traverse(
    nsCycleCollectionTraversalCallback& cb) {
  // We only care about mEffectSet. The animation collections are managed by the
  // pres context and go away when presentation of the document goes away.
  if (mEffectSet) {
    mEffectSet->Traverse(cb);
  }
}

EffectSet& ElementAnimationData::PerElementOrPseudoData::DoEnsureEffectSet() {
  MOZ_ASSERT(!mEffectSet);
  mEffectSet = MakeUnique<EffectSet>();
  return *mEffectSet;
}

CSSTransitionCollection&
ElementAnimationData::PerElementOrPseudoData::DoEnsureTransitions(
    dom::Element& aOwner, PseudoStyleType aType) {
  MOZ_ASSERT(!mTransitions);
  mTransitions = MakeUnique<CSSTransitionCollection>(aOwner, aType);
  return *mTransitions;
}

CSSAnimationCollection&
ElementAnimationData::PerElementOrPseudoData::DoEnsureAnimations(
    dom::Element& aOwner, PseudoStyleType aType) {
  MOZ_ASSERT(!mAnimations);
  mAnimations = MakeUnique<CSSAnimationCollection>(aOwner, aType);
  return *mAnimations;
}

ScrollTimelineCollection&
ElementAnimationData::PerElementOrPseudoData::DoEnsureScrollTimelines(
    dom::Element& aOwner, PseudoStyleType aType) {
  MOZ_ASSERT(!mScrollTimelines);
  mScrollTimelines = MakeUnique<ScrollTimelineCollection>(aOwner, aType);
  return *mScrollTimelines;
}

ViewTimelineCollection&
ElementAnimationData::PerElementOrPseudoData::DoEnsureViewTimelines(
    dom::Element& aOwner, PseudoStyleType aType) {
  MOZ_ASSERT(!mViewTimelines);
  mViewTimelines = MakeUnique<ViewTimelineCollection>(aOwner, aType);
  return *mViewTimelines;
}

dom::ProgressTimelineScheduler&
ElementAnimationData::PerElementOrPseudoData::DoEnsureProgressTimelineScheduler(
    dom::Element& aOwner, PseudoStyleType aType) {
  MOZ_ASSERT(!mProgressTimelineScheduler);
  mProgressTimelineScheduler = MakeUnique<dom::ProgressTimelineScheduler>();
  return *mProgressTimelineScheduler;
}

void ElementAnimationData::PerElementOrPseudoData::DoClearEffectSet() {
  MOZ_ASSERT(mEffectSet);
  mEffectSet = nullptr;
}

void ElementAnimationData::PerElementOrPseudoData::DoClearTransitions() {
  MOZ_ASSERT(mTransitions);
  mTransitions = nullptr;
}

void ElementAnimationData::PerElementOrPseudoData::DoClearAnimations() {
  MOZ_ASSERT(mAnimations);
  mAnimations = nullptr;
}

void ElementAnimationData::PerElementOrPseudoData::DoClearScrollTimelines() {
  MOZ_ASSERT(mScrollTimelines);
  mScrollTimelines = nullptr;
}

void ElementAnimationData::PerElementOrPseudoData::DoClearViewTimelines() {
  MOZ_ASSERT(mViewTimelines);
  mViewTimelines = nullptr;
}

void ElementAnimationData::PerElementOrPseudoData::
    DoClearProgressTimelineScheduler() {
  MOZ_ASSERT(mProgressTimelineScheduler);
  mProgressTimelineScheduler = nullptr;
}

}  // namespace mozilla