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-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"
|
2018-05-07 05:07:06 +03:00
|
|
|
#include "mozilla/dom/KeyframeEffect.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;
|
2019-04-22 22:57:59 +03:00
|
|
|
enum class DisplayItemType : uint8_t;
|
2016-01-06 05:04:05 +03:00
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
} // namespace dom
|
|
|
|
|
2019-02-19 16:44:33 +03:00
|
|
|
enum class PseudoStyleType : uint8_t;
|
2016-02-17 23:37:00 +03:00
|
|
|
|
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
|
2017-05-16 14:11:04 +03:00
|
|
|
,
|
|
|
|
mMayHaveOpacityAnim(false),
|
|
|
|
mMayHaveTransformAnim(false) {
|
2015-11-26 10:53:53 +03:00
|
|
|
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);
|
|
|
|
}
|
2017-10-03 01:05:19 +03:00
|
|
|
static void PropertyDtor(void* aObject, nsAtom* aPropertyName,
|
2015-11-26 10:53:53 +03:00
|
|
|
void* aPropertyValue, void* aData);
|
|
|
|
|
2015-11-26 10:53:54 +03:00
|
|
|
// Methods for supporting cycle-collection
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback& aCallback);
|
|
|
|
|
2017-01-13 12:06:35 +03:00
|
|
|
static EffectSet* GetEffectSet(const dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2015-11-26 10:53:53 +03:00
|
|
|
static EffectSet* GetOrCreateEffectSet(dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2019-03-18 07:10:30 +03:00
|
|
|
|
|
|
|
static EffectSet* GetEffectSetForFrame(const nsIFrame* aFrame,
|
|
|
|
const nsCSSPropertyIDSet& aProperties);
|
|
|
|
static EffectSet* GetEffectSetForFrame(const nsIFrame* aFrame,
|
|
|
|
DisplayItemType aDisplayItemType);
|
2019-03-18 07:12:14 +03:00
|
|
|
// Gets the EffectSet associated with the specified frame's content.
|
|
|
|
//
|
|
|
|
// Typically the specified frame should be a "style frame".
|
|
|
|
//
|
|
|
|
// That is because display:table content:
|
|
|
|
//
|
|
|
|
// - makes a distinction between the primary frame and style frame,
|
|
|
|
// - associates the EffectSet with the style frame's content,
|
|
|
|
// - applies transform animations to the primary frame.
|
|
|
|
//
|
|
|
|
// In such a situation, passing in the primary frame here will return nullptr
|
|
|
|
// despite the fact that it has a transform animation applied to it.
|
|
|
|
//
|
|
|
|
// GetEffectSetForFrame, above, handles this by automatically looking up the
|
|
|
|
// EffectSet on the corresponding style frame when querying transform
|
|
|
|
// properties. Unless you are sure you know what you are doing, you should
|
|
|
|
// try using GetEffectSetForFrame first.
|
|
|
|
//
|
|
|
|
// If you decide to use this, consider documenting why you are sure it is ok
|
|
|
|
// to use this.
|
|
|
|
static EffectSet* GetEffectSetForStyleFrame(const nsIFrame* aStyleFrame);
|
2019-03-18 07:10:30 +03:00
|
|
|
|
2016-01-15 09:15:47 +03:00
|
|
|
static void DestroyEffectSet(dom::Element* aElement,
|
2019-02-19 16:44:33 +03:00
|
|
|
PseudoStyleType aPseudoType);
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
void AddEffect(dom::KeyframeEffect& aEffect);
|
|
|
|
void RemoveEffect(dom::KeyframeEffect& aEffect);
|
2015-11-26 10:53:53 +03:00
|
|
|
|
2017-05-16 14:11:04 +03:00
|
|
|
void SetMayHaveOpacityAnimation() { mMayHaveOpacityAnim = true; }
|
|
|
|
bool MayHaveOpacityAnimation() const { return mMayHaveOpacityAnim; }
|
|
|
|
void SetMayHaveTransformAnimation() { mMayHaveTransformAnim = true; }
|
|
|
|
bool MayHaveTransformAnimation() const { return mMayHaveTransformAnim; }
|
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
private:
|
2018-05-07 05:08:59 +03:00
|
|
|
typedef nsTHashtable<nsRefPtrHashKey<dom::KeyframeEffect>> 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),
|
2018-06-01 18:59:07 +03:00
|
|
|
mHashIterator(aEffectSet.mEffects.Iter()),
|
2016-01-15 09:15:47 +03:00
|
|
|
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),
|
2018-05-30 22:15:35 +03:00
|
|
|
mHashIterator(std::move(aOther.mHashIterator)),
|
2016-01-15 09:15:47 +03:00
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-05-07 05:08:59 +03:00
|
|
|
dom::KeyframeEffect* operator*() {
|
2015-11-26 10:53:53 +03:00
|
|
|
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-10-05 08:26:32 +03:00
|
|
|
size_t Count() const { return mEffects.Count(); }
|
|
|
|
|
2018-06-25 03:12:21 +03:00
|
|
|
const TimeStamp& LastOverflowAnimationSyncTime() const {
|
|
|
|
return mLastOverflowAnimationSyncTime;
|
2016-01-13 01:54:54 +03:00
|
|
|
}
|
2018-06-25 03:12:21 +03:00
|
|
|
void UpdateLastOverflowAnimationSyncTime(const TimeStamp& aRefreshTime) {
|
|
|
|
mLastOverflowAnimationSyncTime = aRefreshTime;
|
2016-01-13 01:54:54 +03:00
|
|
|
}
|
|
|
|
|
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; }
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
static nsAtom** GetEffectSetPropertyAtoms();
|
2015-11-26 10:53:54 +03:00
|
|
|
|
2018-11-13 13:22:26 +03:00
|
|
|
const nsCSSPropertyIDSet& PropertiesWithImportantRules() const {
|
|
|
|
return mPropertiesWithImportantRules;
|
|
|
|
}
|
2016-10-05 08:42:56 +03:00
|
|
|
nsCSSPropertyIDSet& PropertiesWithImportantRules() {
|
|
|
|
return mPropertiesWithImportantRules;
|
|
|
|
}
|
|
|
|
nsCSSPropertyIDSet& PropertiesForAnimationsLevel() {
|
|
|
|
return mPropertiesForAnimationsLevel;
|
|
|
|
}
|
Bug 1339704 - Part 2 - Filter out unwanted CascadeLevel::Transitions. r=birtles,hiro
We always call TElement::get_animation_rules() for both cascade levels while
there are animations or transitions, so we want to handle the following cases:
1. Have both CascadeLevel::Animations and CascadeLevel::Transitions:
* We use EffectSet::mPropertiesForAnimationsLevel to filter out
CascadeLevel::Transitions because transitions are suppressed when both
are presented.
2. Have CascadeLevel::Animations, but don't have CascadeLevel::Transitions:
* We also use EffectSet::mPropertiesForAnimationsLevel to filter out
the unwanted CascadeLevel::Transitions.
3. Don't Have CascadeLevel::Animations, but have CascadeLevel::Transitions:
* EffectSet::mPropertiesForAnimationsLevel doesn't work for this case.
In Gecko, mElementsToRestyle can help us to filter out the unwanted
CascadeLevel::Animations, However, mElementsToRestyle is cleared in
Pre-Traversal, so now we rely on the cascade ordering of transitions to
override animations. I think we still need to optimize this eventually.
4. No animations:
* EffectSet helps us to check if there is any animations/transitions.
Therefore, we need to call MaybeUpdateCascadeResults(), which updates
mPropertiesForAnimationsLevel, in Pre-Traversal.
MozReview-Commit-ID: IHYw56EX7Ta
--HG--
extra : rebase_source : 4d5eb1335cdce9bf54c9646db1fba72ca3f2c70b
2017-03-13 16:09:50 +03:00
|
|
|
nsCSSPropertyIDSet PropertiesForAnimationsLevel() const {
|
|
|
|
return mPropertiesForAnimationsLevel;
|
|
|
|
}
|
2016-10-05 08:42:56 +03:00
|
|
|
|
2015-11-26 10:53:53 +03:00
|
|
|
private:
|
2019-02-19 16:44:33 +03:00
|
|
|
static nsAtom* GetEffectSetPropertyAtom(PseudoStyleType 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
|
|
|
|
2018-06-25 03:12:21 +03:00
|
|
|
// Refresh driver timestamp from the moment when the animations which produce
|
|
|
|
// overflow change hints in this effect set were last updated.
|
|
|
|
|
|
|
|
// This is used for animations whose main-thread restyling is throttled either
|
|
|
|
// because they are running on the compositor or because they are not visible.
|
|
|
|
// We still need to update them on the main thread periodically, however (e.g.
|
|
|
|
// so scrollbars can be updated), so this tracks the last time we did that.
|
|
|
|
TimeStamp mLastOverflowAnimationSyncTime;
|
2016-01-13 01:54:54 +03:00
|
|
|
|
2016-10-05 08:48:05 +03:00
|
|
|
// Dirty flag to represent when the mPropertiesWithImportantRules and
|
|
|
|
// mPropertiesForAnimationsLevel on effects in this set might need to be
|
|
|
|
// updated.
|
2016-01-06 05:04:04 +03:00
|
|
|
//
|
|
|
|
// 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-10-05 08:42:56 +03:00
|
|
|
// Specifies the compositor-animatable properties that are overridden by
|
|
|
|
// !important rules.
|
|
|
|
nsCSSPropertyIDSet mPropertiesWithImportantRules;
|
|
|
|
// Specifies the properties for which the result will be added to the
|
|
|
|
// animations level of the cascade and hence should be skipped when we are
|
|
|
|
// composing the animation style for the transitions level of the cascede.
|
|
|
|
nsCSSPropertyIDSet mPropertiesForAnimationsLevel;
|
|
|
|
|
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
|
2017-05-16 14:11:04 +03:00
|
|
|
|
2017-05-23 16:47:46 +03:00
|
|
|
bool mMayHaveOpacityAnim;
|
|
|
|
bool mMayHaveTransformAnim;
|
2015-11-26 10:53:53 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_EffectSet_h
|