Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/layout/style/AnimationCollection.cpp
Line
Count
Source (jump to first uncovered line)
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/. */
6
7
#include "mozilla/AnimationCollection.h"
8
9
#include "mozilla/RestyleManager.h"
10
#include "nsAnimationManager.h" // For dom::CSSAnimation
11
#include "nsPresContext.h"
12
#include "nsTransitionManager.h" // For dom::CSSTransition
13
14
namespace mozilla {
15
16
template <class AnimationType>
17
/* static */ void
18
AnimationCollection<AnimationType>::PropertyDtor(void* aObject,
19
                                                 nsAtom* aPropertyName,
20
                                                 void* aPropertyValue,
21
                                                 void* aData)
22
0
{
23
0
  AnimationCollection* collection =
24
0
    static_cast<AnimationCollection*>(aPropertyValue);
25
#ifdef DEBUG
26
  MOZ_ASSERT(!collection->mCalledPropertyDtor, "can't call dtor twice");
27
  collection->mCalledPropertyDtor = true;
28
#endif
29
  {
30
0
    nsAutoAnimationMutationBatch mb(collection->mElement->OwnerDoc());
31
0
32
0
    for (size_t animIdx = collection->mAnimations.Length(); animIdx-- != 0; ) {
33
0
      collection->mAnimations[animIdx]->CancelFromStyle();
34
0
    }
35
0
  }
36
0
  delete collection;
37
0
}
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSAnimation>::PropertyDtor(void*, nsAtom*, void*, void*)
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSTransition>::PropertyDtor(void*, nsAtom*, void*, void*)
38
39
template <class AnimationType>
40
/* static */ AnimationCollection<AnimationType>*
41
AnimationCollection<AnimationType>::GetAnimationCollection(
42
  const dom::Element *aElement,
43
  CSSPseudoElementType aPseudoType)
44
0
{
45
0
  if (!aElement->MayHaveAnimations()) {
46
0
    // Early return for the most common case.
47
0
    return nullptr;
48
0
  }
49
0
50
0
  nsAtom* propName = GetPropertyAtomForPseudoType(aPseudoType);
51
0
  if (!propName) {
52
0
    return nullptr;
53
0
  }
54
0
55
0
  return
56
0
    static_cast<AnimationCollection<AnimationType>*>(aElement->
57
0
                                                     GetProperty(propName));
58
0
}
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSAnimation>::GetAnimationCollection(mozilla::dom::Element const*, mozilla::CSSPseudoElementType)
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSTransition>::GetAnimationCollection(mozilla::dom::Element const*, mozilla::CSSPseudoElementType)
59
60
template <class AnimationType>
61
/* static */ AnimationCollection<AnimationType>*
62
AnimationCollection<AnimationType>::GetAnimationCollection(
63
  const nsIFrame* aFrame)
64
0
{
65
0
  Maybe<NonOwningAnimationTarget> pseudoElement =
66
0
    EffectCompositor::GetAnimationElementAndPseudoForFrame(aFrame);
67
0
  if (!pseudoElement) {
68
0
    return nullptr;
69
0
  }
70
0
71
0
  if (!pseudoElement->mElement->MayHaveAnimations()) {
72
0
    return nullptr;
73
0
  }
74
0
75
0
  return GetAnimationCollection(pseudoElement->mElement,
76
0
                                pseudoElement->mPseudoType);
77
0
}
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSAnimation>::GetAnimationCollection(nsIFrame const*)
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSTransition>::GetAnimationCollection(nsIFrame const*)
78
79
template <class AnimationType>
80
/* static */ AnimationCollection<AnimationType>*
81
AnimationCollection<AnimationType>::GetOrCreateAnimationCollection(
82
  dom::Element* aElement,
83
  CSSPseudoElementType aPseudoType,
84
  bool* aCreatedCollection)
85
0
{
86
0
  MOZ_ASSERT(aCreatedCollection);
87
0
  *aCreatedCollection = false;
88
0
89
0
  nsAtom* propName = GetPropertyAtomForPseudoType(aPseudoType);
90
0
  MOZ_ASSERT(propName, "Should only try to create animations for one of the"
91
0
             " recognized pseudo types");
92
0
93
0
  auto collection = static_cast<AnimationCollection<AnimationType>*>(
94
0
                      aElement->GetProperty(propName));
95
0
  if (!collection) {
96
0
    // FIXME: Consider arena-allocating?
97
0
    collection = new AnimationCollection<AnimationType>(aElement, propName);
98
0
    nsresult rv =
99
0
      aElement->SetProperty(propName, collection,
100
0
                            &AnimationCollection<AnimationType>::PropertyDtor,
101
0
                            false);
102
0
    if (NS_FAILED(rv)) {
103
0
      NS_WARNING("SetProperty failed");
104
0
      // The collection must be destroyed via PropertyDtor, otherwise
105
0
      // mCalledPropertyDtor assertion is triggered in destructor.
106
0
      AnimationCollection<AnimationType>::PropertyDtor(aElement, propName,
107
0
                                                       collection, nullptr);
108
0
      return nullptr;
109
0
    }
110
0
111
0
    *aCreatedCollection = true;
112
0
    aElement->SetMayHaveAnimations();
113
0
  }
114
0
115
0
  return collection;
116
0
}
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSAnimation>::GetOrCreateAnimationCollection(mozilla::dom::Element*, mozilla::CSSPseudoElementType, bool*)
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSTransition>::GetOrCreateAnimationCollection(mozilla::dom::Element*, mozilla::CSSPseudoElementType, bool*)
117
118
119
template<class AnimationType>
120
/*static*/ nsAtom*
121
AnimationCollection<AnimationType>::GetPropertyAtomForPseudoType(
122
  CSSPseudoElementType aPseudoType)
123
0
{
124
0
  nsAtom* propName = nullptr;
125
0
126
0
  if (aPseudoType == CSSPseudoElementType::NotPseudo) {
127
0
    propName = TraitsType::ElementPropertyAtom();
128
0
  } else if (aPseudoType == CSSPseudoElementType::before) {
129
0
    propName = TraitsType::BeforePropertyAtom();
130
0
  } else if (aPseudoType == CSSPseudoElementType::after) {
131
0
    propName = TraitsType::AfterPropertyAtom();
132
0
  }
133
0
134
0
  return propName;
135
0
}
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSAnimation>::GetPropertyAtomForPseudoType(mozilla::CSSPseudoElementType)
Unexecuted instantiation: mozilla::AnimationCollection<mozilla::dom::CSSTransition>::GetPropertyAtomForPseudoType(mozilla::CSSPseudoElementType)
136
137
// Explicit class instantiations
138
139
template class AnimationCollection<dom::CSSAnimation>;
140
template class AnimationCollection<dom::CSSTransition>;
141
142
} // namespace mozilla