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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_EffectSet_h
|
|
|
|
#define mozilla_EffectSet_h
|
|
|
|
|
2016-01-06 05:04:06 +03:00
|
|
|
#include "mozilla/AnimValuesStyleRule.h"
|
2016-01-15 09:15:47 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
2016-01-06 05:04:06 +03:00
|
|
|
#include "mozilla/EffectCompositor.h"
|
|
|
|
#include "mozilla/EnumeratedArray.h"
|
2016-01-13 01:54:54 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-11-26 10:53:53 +03:00
|
|
|
#include "nsHashKeys.h" // For nsPtrHashKey
|
|
|
|
#include "nsTHashtable.h" // For nsTHashtable
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2016-01-06 05:04:05 +03:00
|
|
|
class nsPresContext;
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
2015-11-26 10:53:53 +03:00
|
|
|
class KeyframeEffectReadOnly;
|
2015-11-26 10:53:53 +03:00
|
|
|
} // namespace dom
|
|
|
|
|
2016-02-17 23:37:00 +03:00
|
|
|
enum class CSSPseudoElementType : uint8_t;
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
// A wrapper around a hashset of AnimationEffect objects to handle
|
|
|
|
// storing the set as a property of an element.
|
|
|
|
class EffectSet
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EffectSet()
|
2016-01-06 05:04:04 +03:00
|
|
|
: mCascadeNeedsUpdate(false)
|
2016-01-06 05:04:05 +03:00
|
|
|
, mAnimationGeneration(0)
|
2015-11-26 10:53:53 +03:00
|
|
|
#ifdef DEBUG
|
2016-02-26 18:52:06 +03:00
|
|
|
, mActiveIterators(0)
|
2016-01-06 05:04:04 +03:00
|
|
|
, mCalledPropertyDtor(false)
|
2015-11-26 10:53:53 +03:00
|
|
|
#endif
|
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(EffectSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
~EffectSet()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mCalledPropertyDtor,
|
|
|
|
"must call destructor through element property dtor");
|
2016-01-15 09:15:47 +03:00
|
|
|
MOZ_ASSERT(mActiveIterators == 0,
|
|
|
|
"Effect set should not be destroyed while it is being "
|
|
|
|
"enumerated");
|
2015-11-26 10:53:53 +03:00
|
|
|
MOZ_COUNT_DTOR(EffectSet);
|
|
|
|
}
|
|
|
|
static void PropertyDtor(void* aObject, nsIAtom* aPropertyName,
|
|
|
|
void* aPropertyValue, void* aData);
|
|
|
|
|
2015-11-26 10:53:54 +03:00
|
|
|
// Methods for supporting cycle-collection
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback& aCallback);
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
static EffectSet* GetEffectSet(dom::Element* aElement,
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType);
|
2015-12-04 02:32:52 +03:00
|
|
|
static EffectSet* GetEffectSet(const nsIFrame* aFrame);
|
2015-11-26 10:53:53 +03:00
|
|
|
static EffectSet* GetOrCreateEffectSet(dom::Element* aElement,
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType);
|
2016-01-15 09:15:47 +03:00
|
|
|
static void DestroyEffectSet(dom::Element* aElement,
|
2016-02-17 23:37:00 +03:00
|
|
|
CSSPseudoElementType aPseudoType);
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
void AddEffect(dom::KeyframeEffectReadOnly& aEffect);
|
|
|
|
void RemoveEffect(dom::KeyframeEffectReadOnly& aEffect);
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
private:
|
2015-11-26 10:53:54 +03:00
|
|
|
typedef nsTHashtable<nsRefPtrHashKey<dom::KeyframeEffectReadOnly>>
|
|
|
|
OwningEffectSet;
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
public:
|
|
|
|
// A simple iterator to support iterating over the effects in this object in
|
|
|
|
// range-based for loops.
|
|
|
|
//
|
|
|
|
// This allows us to avoid exposing mEffects directly and saves the
|
|
|
|
// caller from having to dereference hashtable iterators using
|
|
|
|
// the rather complicated: iter.Get()->GetKey().
|
|
|
|
class Iterator
|
|
|
|
{
|
|
|
|
public:
|
2016-01-15 09:15:47 +03:00
|
|
|
explicit Iterator(EffectSet& aEffectSet)
|
|
|
|
: mEffectSet(aEffectSet)
|
|
|
|
, mHashIterator(mozilla::Move(aEffectSet.mEffects.Iter()))
|
|
|
|
, mIsEndIterator(false)
|
|
|
|
{
|
2016-02-26 18:52:06 +03:00
|
|
|
#ifdef DEBUG
|
2016-01-15 09:15:47 +03:00
|
|
|
mEffectSet.mActiveIterators++;
|
2016-02-26 18:52:06 +03:00
|
|
|
#endif
|
2016-01-15 09:15:47 +03:00
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
Iterator(Iterator&& aOther)
|
2016-01-15 09:15:47 +03:00
|
|
|
: mEffectSet(aOther.mEffectSet)
|
|
|
|
, mHashIterator(mozilla::Move(aOther.mHashIterator))
|
|
|
|
, mIsEndIterator(aOther.mIsEndIterator)
|
|
|
|
{
|
2016-02-26 18:52:06 +03:00
|
|
|
#ifdef DEBUG
|
2016-01-15 09:15:47 +03:00
|
|
|
mEffectSet.mActiveIterators++;
|
2016-02-26 18:52:06 +03:00
|
|
|
#endif
|
2016-01-15 09:15:47 +03:00
|
|
|
}
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2016-01-15 09:15:47 +03:00
|
|
|
static Iterator EndIterator(EffectSet& aEffectSet)
|
2015-11-26 10:53:53 +03:00
|
|
|
{
|
2016-01-15 09:15:47 +03:00
|
|
|
Iterator result(aEffectSet);
|
2015-11-26 10:53:53 +03:00
|
|
|
result.mIsEndIterator = true;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-01-15 09:15:47 +03:00
|
|
|
~Iterator()
|
|
|
|
{
|
2016-02-26 18:52:06 +03:00
|
|
|
#ifdef DEBUG
|
2016-01-15 09:15:47 +03:00
|
|
|
MOZ_ASSERT(mEffectSet.mActiveIterators > 0);
|
|
|
|
mEffectSet.mActiveIterators--;
|
2016-02-26 18:52:06 +03:00
|
|
|
#endif
|
2016-01-15 09:15:47 +03:00
|
|
|
}
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
bool operator!=(const Iterator& aOther) const {
|
|
|
|
if (Done() || aOther.Done()) {
|
|
|
|
return Done() != aOther.Done();
|
|
|
|
}
|
|
|
|
return mHashIterator.Get() != aOther.mHashIterator.Get();
|
|
|
|
}
|
|
|
|
|
|
|
|
Iterator& operator++() {
|
|
|
|
MOZ_ASSERT(!Done());
|
|
|
|
mHashIterator.Next();
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom::KeyframeEffectReadOnly* operator* ()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!Done());
|
|
|
|
return mHashIterator.Get()->GetKey();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Iterator() = delete;
|
|
|
|
Iterator(const Iterator&) = delete;
|
|
|
|
Iterator& operator=(const Iterator&) = delete;
|
|
|
|
Iterator& operator=(const Iterator&&) = delete;
|
|
|
|
|
|
|
|
bool Done() const {
|
|
|
|
return mIsEndIterator || mHashIterator.Done();
|
|
|
|
}
|
|
|
|
|
2016-01-15 09:15:47 +03:00
|
|
|
EffectSet& mEffectSet;
|
2015-11-26 10:53:54 +03:00
|
|
|
OwningEffectSet::Iterator mHashIterator;
|
2015-11-26 10:53:53 +03:00
|
|
|
bool mIsEndIterator;
|
|
|
|
};
|
|
|
|
|
2016-01-15 09:15:47 +03:00
|
|
|
friend class Iterator;
|
|
|
|
|
|
|
|
Iterator begin() { return Iterator(*this); }
|
|
|
|
Iterator end() { return Iterator::EndIterator(*this); }
|
|
|
|
#ifdef DEBUG
|
|
|
|
bool IsBeingEnumerated() const { return mActiveIterators != 0; }
|
|
|
|
#endif
|
|
|
|
|
2015-12-10 00:28:10 +03:00
|
|
|
bool IsEmpty() const { return mEffects.IsEmpty(); }
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2016-01-06 05:04:06 +03:00
|
|
|
RefPtr<AnimValuesStyleRule>& AnimationRule(EffectCompositor::CascadeLevel
|
|
|
|
aCascadeLevel)
|
|
|
|
{
|
|
|
|
return mAnimationRule[aCascadeLevel];
|
|
|
|
}
|
|
|
|
|
2016-01-13 01:54:54 +03:00
|
|
|
const TimeStamp& AnimationRuleRefreshTime(EffectCompositor::CascadeLevel
|
|
|
|
aCascadeLevel) const
|
|
|
|
{
|
|
|
|
return mAnimationRuleRefreshTime[aCascadeLevel];
|
|
|
|
}
|
|
|
|
void UpdateAnimationRuleRefreshTime(EffectCompositor::CascadeLevel
|
|
|
|
aCascadeLevel,
|
|
|
|
const TimeStamp& aRefreshTime)
|
|
|
|
{
|
|
|
|
mAnimationRuleRefreshTime[aCascadeLevel] = aRefreshTime;
|
|
|
|
}
|
|
|
|
|
2016-01-06 05:04:04 +03:00
|
|
|
bool CascadeNeedsUpdate() const { return mCascadeNeedsUpdate; }
|
|
|
|
void MarkCascadeNeedsUpdate() { mCascadeNeedsUpdate = true; }
|
|
|
|
void MarkCascadeUpdated() { mCascadeNeedsUpdate = false; }
|
|
|
|
|
2016-01-06 05:04:05 +03:00
|
|
|
void UpdateAnimationGeneration(nsPresContext* aPresContext);
|
|
|
|
uint64_t GetAnimationGeneration() const { return mAnimationGeneration; }
|
|
|
|
|
2015-11-26 10:53:54 +03:00
|
|
|
static nsIAtom** GetEffectSetPropertyAtoms();
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
private:
|
2016-02-17 23:37:00 +03:00
|
|
|
static nsIAtom* GetEffectSetPropertyAtom(CSSPseudoElementType aPseudoType);
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2015-11-26 10:53:54 +03:00
|
|
|
OwningEffectSet mEffects;
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2016-01-06 05:04:06 +03:00
|
|
|
// These style rules contain the style data for currently animating
|
|
|
|
// values. They only match when styling with animation. When we
|
|
|
|
// style without animation, we need to not use them so that we can
|
|
|
|
// detect any new changes; if necessary we restyle immediately
|
|
|
|
// afterwards with animation.
|
|
|
|
EnumeratedArray<EffectCompositor::CascadeLevel,
|
|
|
|
EffectCompositor::CascadeLevel(
|
|
|
|
EffectCompositor::kCascadeLevelCount),
|
|
|
|
RefPtr<AnimValuesStyleRule>> mAnimationRule;
|
|
|
|
|
2016-01-13 01:54:54 +03:00
|
|
|
// A parallel array to mAnimationRule that records the refresh driver
|
|
|
|
// timestamp when the rule was last updated. This is used for certain
|
|
|
|
// animations which are updated only periodically (e.g. transform animations
|
|
|
|
// running on the compositor that affect the scrollable overflow region).
|
|
|
|
EnumeratedArray<EffectCompositor::CascadeLevel,
|
|
|
|
EffectCompositor::CascadeLevel(
|
|
|
|
EffectCompositor::kCascadeLevelCount),
|
|
|
|
TimeStamp> mAnimationRuleRefreshTime;
|
|
|
|
|
2016-01-06 05:04:04 +03:00
|
|
|
// Dirty flag to represent when the mWinsInCascade flag on effects in
|
|
|
|
// this set might need to be updated.
|
|
|
|
//
|
|
|
|
// Set to true any time the set of effects is changed or when
|
|
|
|
// one the effects goes in or out of the "in effect" state.
|
|
|
|
bool mCascadeNeedsUpdate;
|
|
|
|
|
2016-01-06 05:04:05 +03:00
|
|
|
// RestyleManager keeps track of the number of animation restyles.
|
|
|
|
// 'mini-flushes' (see nsTransitionManager::UpdateAllThrottledStyles()).
|
|
|
|
// mAnimationGeneration is the sequence number of the last flush where a
|
|
|
|
// transition/animation changed. We keep a similar count on the
|
|
|
|
// corresponding layer so we can check that the layer is up to date with
|
|
|
|
// the animation manager.
|
|
|
|
uint64_t mAnimationGeneration;
|
|
|
|
|
2016-02-26 18:52:06 +03:00
|
|
|
#ifdef DEBUG
|
2016-01-15 09:15:47 +03:00
|
|
|
// Track how many iterators are referencing this effect set when we are
|
|
|
|
// destroyed, we can assert that nothing is still pointing to us.
|
2016-02-26 18:52:06 +03:00
|
|
|
uint64_t mActiveIterators;
|
2016-01-15 09:15:47 +03:00
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
bool mCalledPropertyDtor;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_EffectSet_h
|