2016-02-24 10:08:20 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_AnimationCollection_h
|
|
|
|
#define mozilla_AnimationCollection_h
|
|
|
|
|
|
|
|
#include "mozilla/dom/Animation.h"
|
|
|
|
#include "mozilla/dom/Element.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/LinkedList.h"
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "nsCSSPseudoElements.h"
|
|
|
|
#include "nsDOMMutationObserver.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
class nsIAtom;
|
|
|
|
class nsPresContext;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
// Traits class to define the specific atoms used when storing specializations
|
|
|
|
// of AnimationCollection as a property on an Element (e.g. which atom
|
|
|
|
// to use when storing an AnimationCollection<CSSAnimation> for a ::before
|
|
|
|
// pseudo-element).
|
|
|
|
template <class AnimationType>
|
|
|
|
struct AnimationTypeTraits { };
|
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
template <class AnimationType>
|
|
|
|
class AnimationCollection
|
|
|
|
: public LinkedListElement<AnimationCollection<AnimationType>>
|
2016-02-24 10:08:20 +03:00
|
|
|
{
|
2016-03-09 06:55:39 +03:00
|
|
|
typedef AnimationCollection<AnimationType> SelfType;
|
|
|
|
typedef AnimationTypeTraits<AnimationType> TraitsType;
|
2016-03-09 06:55:39 +03:00
|
|
|
|
2016-02-24 10:08:56 +03:00
|
|
|
AnimationCollection(dom::Element* aElement, nsIAtom* aElementProperty)
|
2016-02-24 10:08:20 +03:00
|
|
|
: mElement(aElement)
|
|
|
|
, mElementProperty(aElementProperty)
|
|
|
|
, mCheckGeneration(0)
|
|
|
|
#ifdef DEBUG
|
|
|
|
, mCalledPropertyDtor(false)
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(AnimationCollection);
|
|
|
|
}
|
2016-03-09 06:55:39 +03:00
|
|
|
|
|
|
|
public:
|
2016-02-24 10:08:20 +03:00
|
|
|
~AnimationCollection()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCalledPropertyDtor,
|
|
|
|
"must call destructor through element property dtor");
|
|
|
|
MOZ_COUNT_DTOR(AnimationCollection);
|
2016-03-09 06:55:39 +03:00
|
|
|
LinkedListElement<SelfType>::remove();
|
2016-02-24 10:08:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void Destroy()
|
|
|
|
{
|
|
|
|
// This will call our destructor.
|
|
|
|
mElement->DeleteProperty(mElementProperty);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PropertyDtor(void *aObject, nsIAtom *aPropertyName,
|
|
|
|
void *aPropertyValue, void *aData);
|
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
// Get the collection of animations for the given |aElement| and
|
|
|
|
// |aPseudoType|.
|
2016-03-09 06:55:39 +03:00
|
|
|
static AnimationCollection<AnimationType>*
|
|
|
|
GetAnimationCollection(dom::Element* aElement,
|
2016-03-09 06:55:39 +03:00
|
|
|
CSSPseudoElementType aPseudoType);
|
2016-03-09 06:55:39 +03:00
|
|
|
|
|
|
|
// Given the frame |aFrame| with possibly animated content, finds its
|
|
|
|
// associated collection of animations. If |aFrame| is a generated content
|
|
|
|
// frame, this function may examine the parent frame to search for such
|
|
|
|
// animations.
|
|
|
|
static AnimationCollection<AnimationType>* GetAnimationCollection(
|
|
|
|
const nsIFrame* aFrame);
|
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
// Get the collection of animations for the given |aElement| and
|
|
|
|
// |aPseudoType| or create it if it does not already exist.
|
|
|
|
//
|
|
|
|
// We'll set the outparam |aCreatedCollection| to true if we have
|
|
|
|
// to create the collection and we successfully do so. Otherwise,
|
|
|
|
// we'll set it to false.
|
|
|
|
static AnimationCollection<AnimationType>*
|
|
|
|
GetOrCreateAnimationCollection(dom::Element* aElement,
|
|
|
|
CSSPseudoElementType aPseudoType,
|
|
|
|
bool* aCreatedCollection);
|
|
|
|
|
2016-02-24 10:08:20 +03:00
|
|
|
bool IsForElement() const { // rather than for a pseudo-element
|
2016-03-09 06:55:39 +03:00
|
|
|
return mElementProperty == TraitsType::ElementPropertyAtom();
|
2016-02-24 10:08:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsForBeforePseudo() const {
|
2016-03-09 06:55:39 +03:00
|
|
|
return mElementProperty == TraitsType::BeforePropertyAtom();
|
2016-02-24 10:08:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsForAfterPseudo() const {
|
2016-03-09 06:55:39 +03:00
|
|
|
return mElementProperty == TraitsType::AfterPropertyAtom();
|
2016-02-24 10:08:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
CSSPseudoElementType PseudoElementType() const
|
|
|
|
{
|
|
|
|
if (IsForElement()) {
|
|
|
|
return CSSPseudoElementType::NotPseudo;
|
|
|
|
}
|
|
|
|
if (IsForBeforePseudo()) {
|
|
|
|
return CSSPseudoElementType::before;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(IsForAfterPseudo(),
|
|
|
|
"::before & ::after should be the only pseudo-elements here");
|
|
|
|
return CSSPseudoElementType::after;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsString PseudoTypeAsString(CSSPseudoElementType aPseudoType);
|
|
|
|
|
|
|
|
dom::Element *mElement;
|
|
|
|
|
|
|
|
// the atom we use in mElement's prop table (must be a static atom,
|
|
|
|
// i.e., in an atom list)
|
|
|
|
nsIAtom *mElementProperty;
|
|
|
|
|
2016-03-09 06:55:39 +03:00
|
|
|
InfallibleTArray<RefPtr<AnimationType>> mAnimations;
|
2016-02-24 10:08:20 +03:00
|
|
|
|
|
|
|
// For CSS transitions only, we record the most recent generation
|
|
|
|
// for which we've done the transition update, so that we avoid doing
|
|
|
|
// it more than once per style change.
|
|
|
|
// (Note that we also store an animation generation on each EffectSet in
|
|
|
|
// order to track when we need to update animations on layers.)
|
|
|
|
uint64_t mCheckGeneration;
|
|
|
|
|
|
|
|
// Update mCheckGeneration to RestyleManager's count
|
|
|
|
void UpdateCheckGeneration(nsPresContext* aPresContext);
|
|
|
|
|
|
|
|
private:
|
2016-03-09 06:55:39 +03:00
|
|
|
static nsIAtom* GetPropertyAtomForPseudoType(
|
|
|
|
CSSPseudoElementType aPseudoType);
|
|
|
|
|
2016-02-24 10:08:20 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool mCalledPropertyDtor;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_AnimationCollection_h
|