2015-11-26 10:53:53 +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/. */
|
|
|
|
|
|
|
|
#include "EffectSet.h"
|
|
|
|
#include "mozilla/dom/Element.h" // For Element
|
2017-02-13 06:21:33 +03:00
|
|
|
#include "mozilla/RestyleManager.h"
|
|
|
|
#include "mozilla/RestyleManagerInlines.h"
|
2016-02-17 23:37:00 +03:00
|
|
|
#include "nsCSSPseudoElements.h" // For CSSPseudoElementType
|
2015-11-26 10:53:54 +03:00
|
|
|
#include "nsCycleCollectionNoteChild.h" // For CycleCollectionNoteChild
|
2016-01-06 05:04:05 +03:00
|
|
|
#include "nsPresContext.h"
|
2016-02-07 19:43:49 +03:00
|
|
|
#include "nsLayoutUtils.h"
|
2015-11-26 10:53:53 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
/* static */ void
|
|
|
|
EffectSet::PropertyDtor(void* aObject, nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue, void* aData)
|
|
|
|
{
|
|
|
|
EffectSet* effectSet = static_cast<EffectSet*>(aPropertyValue);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
MOZ_ASSERT(!effectSet->mCalledPropertyDtor, "Should not call dtor twice");
|
|
|
|
effectSet->mCalledPropertyDtor = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
delete effectSet;
|
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:54 +03:00
|
|
|
void
|
|
|
|
EffectSet::Traverse(nsCycleCollectionTraversalCallback& aCallback)
|
|
|
|
{
|
|
|
|
for (auto iter = mEffects.Iter(); !iter.Done(); iter.Next()) {
|
|
|
|
CycleCollectionNoteChild(aCallback, iter.Get()->GetKey(),
|
|
|
|
"EffectSet::mEffects[]", aCallback.Flags());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
/* static */ EffectSet*
|
2017-01-13 12:06:35 +03:00
|
|
|
EffectSet::GetEffectSet(const dom::Element* aElement,
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType)
|
2015-11-26 10:53:53 +03:00
|
|
|
{
|
|
|
|
nsIAtom* propName = GetEffectSetPropertyAtom(aPseudoType);
|
|
|
|
return static_cast<EffectSet*>(aElement->GetProperty(propName));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ EffectSet*
|
2015-12-04 02:32:52 +03:00
|
|
|
EffectSet::GetEffectSet(const nsIFrame* aFrame)
|
|
|
|
{
|
2016-06-01 10:24:34 +03:00
|
|
|
Maybe<NonOwningAnimationTarget> target =
|
|
|
|
EffectCompositor::GetAnimationElementAndPseudoForFrame(aFrame);
|
2015-12-04 02:32:52 +03:00
|
|
|
|
2016-06-01 10:24:34 +03:00
|
|
|
if (!target) {
|
|
|
|
return nullptr;
|
2015-12-04 02:32:52 +03:00
|
|
|
}
|
|
|
|
|
2016-06-01 10:24:34 +03:00
|
|
|
if (!target->mElement->MayHaveAnimations()) {
|
2016-01-18 07:40:12 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-06-01 10:24:34 +03:00
|
|
|
return GetEffectSet(target->mElement, target->mPseudoType);
|
2015-12-04 02:32:52 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* static */ EffectSet*
|
2015-11-26 10:53:53 +03:00
|
|
|
EffectSet::GetOrCreateEffectSet(dom::Element* aElement,
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType)
|
2015-11-26 10:53:53 +03:00
|
|
|
{
|
|
|
|
EffectSet* effectSet = GetEffectSet(aElement, aPseudoType);
|
|
|
|
if (effectSet) {
|
|
|
|
return effectSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom* propName = GetEffectSetPropertyAtom(aPseudoType);
|
|
|
|
effectSet = new EffectSet();
|
|
|
|
|
|
|
|
nsresult rv = aElement->SetProperty(propName, effectSet,
|
2015-11-26 10:53:54 +03:00
|
|
|
&EffectSet::PropertyDtor, true);
|
2015-11-26 10:53:53 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_WARNING("SetProperty failed");
|
|
|
|
// The set must be destroyed via PropertyDtor, otherwise
|
|
|
|
// mCalledPropertyDtor assertion is triggered in destructor.
|
|
|
|
EffectSet::PropertyDtor(aElement, propName, effectSet, nullptr);
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2016-01-18 07:40:12 +03:00
|
|
|
aElement->SetMayHaveAnimations();
|
2015-11-26 10:53:53 +03:00
|
|
|
|
|
|
|
return effectSet;
|
|
|
|
}
|
|
|
|
|
2016-01-15 09:15:47 +03:00
|
|
|
/* static */ void
|
|
|
|
EffectSet::DestroyEffectSet(dom::Element* aElement,
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType)
|
2016-01-15 09:15:47 +03:00
|
|
|
{
|
|
|
|
nsIAtom* propName = GetEffectSetPropertyAtom(aPseudoType);
|
|
|
|
EffectSet* effectSet =
|
|
|
|
static_cast<EffectSet*>(aElement->GetProperty(propName));
|
|
|
|
if (!effectSet) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(!effectSet->IsBeingEnumerated(),
|
|
|
|
"Should not destroy an effect set while it is being enumerated");
|
|
|
|
effectSet = nullptr;
|
|
|
|
|
|
|
|
aElement->DeleteProperty(propName);
|
|
|
|
}
|
|
|
|
|
2016-01-06 05:04:05 +03:00
|
|
|
void
|
|
|
|
EffectSet::UpdateAnimationGeneration(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
mAnimationGeneration =
|
2017-03-09 12:15:08 +03:00
|
|
|
aPresContext->RestyleManager()->GetAnimationGeneration();
|
2016-01-06 05:04:05 +03:00
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:54 +03:00
|
|
|
/* static */ nsIAtom**
|
|
|
|
EffectSet::GetEffectSetPropertyAtoms()
|
|
|
|
{
|
|
|
|
static nsIAtom* effectSetPropertyAtoms[] =
|
|
|
|
{
|
|
|
|
nsGkAtoms::animationEffectsProperty,
|
|
|
|
nsGkAtoms::animationEffectsForBeforeProperty,
|
|
|
|
nsGkAtoms::animationEffectsForAfterProperty,
|
|
|
|
nullptr
|
|
|
|
};
|
|
|
|
|
|
|
|
return effectSetPropertyAtoms;
|
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
/* static */ nsIAtom*
|
2016-02-17 23:37:00 +03:00
|
|
|
EffectSet::GetEffectSetPropertyAtom(CSSPseudoElementType aPseudoType)
|
2015-11-26 10:53:53 +03:00
|
|
|
{
|
|
|
|
switch (aPseudoType) {
|
2016-02-17 01:07:00 +03:00
|
|
|
case CSSPseudoElementType::NotPseudo:
|
2015-11-26 10:53:53 +03:00
|
|
|
return nsGkAtoms::animationEffectsProperty;
|
|
|
|
|
2016-02-17 01:07:00 +03:00
|
|
|
case CSSPseudoElementType::before:
|
2015-11-26 10:53:53 +03:00
|
|
|
return nsGkAtoms::animationEffectsForBeforeProperty;
|
|
|
|
|
2016-02-17 01:07:00 +03:00
|
|
|
case CSSPseudoElementType::after:
|
2015-11-26 10:53:53 +03:00
|
|
|
return nsGkAtoms::animationEffectsForAfterProperty;
|
|
|
|
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("Should not try to get animation effects for a pseudo "
|
|
|
|
"other that :before or :after");
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
void
|
|
|
|
EffectSet::AddEffect(dom::KeyframeEffectReadOnly& aEffect)
|
|
|
|
{
|
2016-01-06 05:04:04 +03:00
|
|
|
if (mEffects.Contains(&aEffect)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
mEffects.PutEntry(&aEffect);
|
2016-01-06 05:04:04 +03:00
|
|
|
MarkCascadeNeedsUpdate();
|
2015-11-26 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
EffectSet::RemoveEffect(dom::KeyframeEffectReadOnly& aEffect)
|
|
|
|
{
|
2016-01-06 05:04:04 +03:00
|
|
|
if (!mEffects.Contains(&aEffect)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
mEffects.RemoveEntry(&aEffect);
|
2016-01-06 05:04:04 +03:00
|
|
|
MarkCascadeNeedsUpdate();
|
2015-11-26 10:53:53 +03:00
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
} // namespace mozilla
|