Bug 1278136 - Part 1: Add nsLayoutUtils::HasRelevantAnimationOfProperty. r?birtles
We want to know that an nsIFrame has a transform or opacity animations
regardless of its state, e.g., running on the main-thead, paused or
finished but in fill:forwards state, to create a stacking context
for the animation.
MozReview-Commit-ID: mNYsd5RO3u
--- a/layout/base/nsLayoutUtils.cpp
+++ b/layout/base/nsLayoutUtils.cpp
@@ -449,70 +449,80 @@ BackgroundClipTextEnabledPrefChangeCallb
if (sIndexOfTextInBGClipTable >= 0) {
nsCSSProps::kBackgroundClipKTable[sIndexOfTextInBGClipTable].mKeyword =
isBGClipTextEnabled ? eCSSKeyword_text : eCSSKeyword_UNKNOWN;
}
}
template<typename TestType>
static bool
-HasMatchingCurrentAnimations(const nsIFrame* aFrame, TestType&& aTest)
+HasMatchingAnimations(const nsIFrame* aFrame, TestType&& aTest)
{
EffectSet* effects = EffectSet::GetEffectSet(aFrame);
if (!effects) {
return false;
}
for (KeyframeEffectReadOnly* effect : *effects) {
- if (!effect->IsCurrent()) {
- continue;
- }
-
if (aTest(*effect)) {
return true;
}
}
return false;
}
bool
nsLayoutUtils::HasCurrentAnimationOfProperty(const nsIFrame* aFrame,
nsCSSProperty aProperty)
{
- return HasMatchingCurrentAnimations(aFrame,
+ return HasMatchingAnimations(aFrame,
[&aProperty](KeyframeEffectReadOnly& aEffect)
{
- return aEffect.HasAnimationOfProperty(aProperty);
+ return aEffect.IsCurrent() && aEffect.HasAnimationOfProperty(aProperty);
}
);
}
bool
nsLayoutUtils::HasCurrentTransitions(const nsIFrame* aFrame)
{
- return HasMatchingCurrentAnimations(aFrame,
+ return HasMatchingAnimations(aFrame,
[](KeyframeEffectReadOnly& aEffect)
{
// Since |aEffect| is current, it must have an associated Animation
// so we don't need to null-check the result of GetAnimation().
- return aEffect.GetAnimation()->AsCSSTransition();
+ return aEffect.IsCurrent() && aEffect.GetAnimation()->AsCSSTransition();
}
);
}
bool
nsLayoutUtils::HasCurrentAnimationsForProperties(const nsIFrame* aFrame,
const nsCSSProperty* aProperties,
size_t aPropertyCount)
{
- return HasMatchingCurrentAnimations(aFrame,
+ return HasMatchingAnimations(aFrame,
[&aProperties, &aPropertyCount](KeyframeEffectReadOnly& aEffect)
{
- return aEffect.HasAnimationOfProperties(aProperties, aPropertyCount);
+ return aEffect.IsCurrent() &&
+ aEffect.HasAnimationOfProperties(aProperties, aPropertyCount);
+ }
+ );
+}
+
+bool
+nsLayoutUtils::HasRelevantAnimationOfProperty(const nsIFrame* aFrame,
+ nsCSSProperty aProperty)
+{
+ return HasMatchingAnimations(aFrame,
+ [&aProperty](KeyframeEffectReadOnly& aEffect)
+ {
+ return (aEffect.IsInEffect() || aEffect.IsCurrent()) &&
+ aEffect.HasAnimationOfProperty(aProperty);
}
);
}
static float
GetSuitableScale(float aMaxScale, float aMinScale,
nscoord aVisibleDimension, nscoord aDisplayDimension)
{
--- a/layout/base/nsLayoutUtils.h
+++ b/layout/base/nsLayoutUtils.h
@@ -2249,16 +2249,24 @@ public:
* Returns true if the frame has any current animations or transitions
* for any of the specified properties.
*/
static bool HasCurrentAnimationsForProperties(const nsIFrame* aFrame,
const nsCSSProperty* aProperties,
size_t aPropertyCount);
/**
+ * Returns true if the frame has current or in-effect (i.e. in before phase,
+ * running or filling) animations or transitions for the
+ * property.
+ */
+ static bool HasRelevantAnimationOfProperty(const nsIFrame* aFrame,
+ nsCSSProperty aProperty);
+
+ /**
* Checks if off-main-thread animations are enabled.
*/
static bool AreAsyncAnimationsEnabled();
/**
* Checks if we should warn about animations that can't be async
*/
static bool IsAnimationLoggingEnabled();