Bug 1067769 - Part 9: Wrap RequestRestyle and UnregisterTarget. r=birtles
We will need to request a restyle and unregister the current target in
SetTarget(), and there are many duplicate code segments for them now, so wrap
them for reusing the code.
MozReview-Commit-ID: 33XoNspZme3
--- a/dom/animation/KeyframeEffect.cpp
+++ b/dom/animation/KeyframeEffect.cpp
@@ -4,17 +4,16 @@
* 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 "mozilla/dom/KeyframeEffect.h"
#include "mozilla/dom/AnimatableBinding.h"
#include "mozilla/dom/KeyframeEffectBinding.h"
#include "mozilla/AnimationUtils.h"
-#include "mozilla/EffectCompositor.h"
#include "mozilla/FloatingPoint.h"
#include "mozilla/LookAndFeel.h" // For LookAndFeel::GetInt
#include "mozilla/KeyframeUtils.h"
#include "mozilla/StyleAnimationValue.h"
#include "Layers.h" // For Layer
#include "nsComputedDOMStyle.h" // nsComputedDOMStyle::GetStyleContextForElement
#include "nsCSSPropertySet.h"
#include "nsCSSProps.h" // For nsCSSProps::PropHasFlags
@@ -184,22 +183,17 @@ KeyframeEffectReadOnly::NotifyAnimationT
//
// Bug 1216843: When we implement iteration composite modes, we need to
// also detect if the current iteration has changed.
if (mAnimation && GetComputedTiming().mProgress != mProgressOnLastCompose) {
EffectCompositor::RestyleType restyleType =
CanThrottle() ?
EffectCompositor::RestyleType::Throttled :
EffectCompositor::RestyleType::Standard;
- nsPresContext* presContext = GetPresContext();
- if (presContext && mTarget) {
- presContext->EffectCompositor()->
- RequestRestyle(mTarget->mElement, mTarget->mPseudoType, restyleType,
- mAnimation->CascadeLevel());
- }
+ RequestRestyle(restyleType);
// If we're not relevant, we will have been removed from the EffectSet.
// As a result, when the restyle we requested above is fulfilled, our
// ComposeStyle will not get called and mProgressOnLastCompose will not
// be updated. Instead, we need to manually clear it.
if (!isRelevant) {
mProgressOnLastCompose.SetNull();
}
@@ -562,25 +556,17 @@ KeyframeEffectReadOnly::UpdateProperties
if (mTarget) {
EffectSet* effectSet = EffectSet::GetEffectSet(mTarget->mElement,
mTarget->mPseudoType);
if (effectSet) {
effectSet->MarkCascadeNeedsUpdate();
}
- if (mAnimation) {
- nsPresContext* presContext = GetPresContext();
- if (presContext) {
- presContext->EffectCompositor()->
- RequestRestyle(mTarget->mElement, mTarget->mPseudoType,
- EffectCompositor::RestyleType::Layer,
- mAnimation->CascadeLevel());
- }
- }
+ RequestRestyle(EffectCompositor::RestyleType::Layer);
}
}
void
KeyframeEffectReadOnly::ComposeStyle(RefPtr<AnimValuesStyleRule>& aStyleRule,
nsCSSPropertySet& aSetProperties)
{
ComputedTiming computedTiming = GetComputedTiming();
@@ -803,27 +789,45 @@ KeyframeEffectReadOnly::UpdateTargetRegi
MOZ_ASSERT(isRelevant == IsCurrent() || IsInEffect(),
"Out of date Animation::IsRelevant value");
if (isRelevant) {
EffectSet* effectSet =
EffectSet::GetOrCreateEffectSet(mTarget->mElement, mTarget->mPseudoType);
effectSet->AddEffect(*this);
} else {
- EffectSet* effectSet = EffectSet::GetEffectSet(mTarget->mElement,
- mTarget->mPseudoType);
- if (effectSet) {
- effectSet->RemoveEffect(*this);
- if (effectSet->IsEmpty()) {
- EffectSet::DestroyEffectSet(mTarget->mElement, mTarget->mPseudoType);
- }
+ UnregisterTarget();
+ }
+}
+
+void
+KeyframeEffectReadOnly::UnregisterTarget()
+{
+ EffectSet* effectSet =
+ EffectSet::GetEffectSet(mTarget->mElement, mTarget->mPseudoType);
+ if (effectSet) {
+ effectSet->RemoveEffect(*this);
+ if (effectSet->IsEmpty()) {
+ EffectSet::DestroyEffectSet(mTarget->mElement, mTarget->mPseudoType);
}
}
}
+void
+KeyframeEffectReadOnly::RequestRestyle(
+ EffectCompositor::RestyleType aRestyleType)
+{
+ nsPresContext* presContext = GetPresContext();
+ if (presContext && mTarget && mAnimation) {
+ presContext->EffectCompositor()->
+ RequestRestyle(mTarget->mElement, mTarget->mPseudoType,
+ aRestyleType, mAnimation->CascadeLevel());
+ }
+}
+
#ifdef DEBUG
void
DumpAnimationProperties(nsTArray<AnimationProperty>& aAnimationProperties)
{
for (auto& p : aAnimationProperties) {
printf("%s\n", nsCSSProps::GetStringValue(p.mProperty).get());
for (auto& s : p.mSegments) {
nsString fromValue, toValue;
@@ -1367,37 +1371,32 @@ KeyframeEffect::Constructor(
JS::Handle<JSObject*> aFrames,
const UnrestrictedDoubleOrKeyframeAnimationOptions& aOptions,
ErrorResult& aRv)
{
return ConstructKeyframeEffect<KeyframeEffect>(aGlobal, aTarget, aFrames,
aOptions, aRv);
}
-void KeyframeEffect::NotifySpecifiedTimingUpdated()
+void
+KeyframeEffect::NotifySpecifiedTimingUpdated()
{
// Use the same document for a pseudo element and its parent element.
// Use nullptr if we don't have mTarget, so disable the mutation batch.
nsAutoAnimationMutationBatch mb(mTarget ? mTarget->mElement->OwnerDoc()
: nullptr);
if (mAnimation) {
mAnimation->NotifyEffectTimingUpdated();
if (mAnimation->IsRelevant()) {
nsNodeUtils::AnimationChanged(mAnimation);
}
- nsPresContext* presContext = GetPresContext();
- if (presContext && mTarget) {
- presContext->EffectCompositor()->
- RequestRestyle(mTarget->mElement, mTarget->mPseudoType,
- EffectCompositor::RestyleType::Layer,
- mAnimation->CascadeLevel());
- }
+ RequestRestyle(EffectCompositor::RestyleType::Layer);
}
}
void
KeyframeEffect::SetTarget(const Nullable<ElementOrCSSPseudoElement>& aTarget)
{
// TODO: fix in next patch
}
--- a/dom/animation/KeyframeEffect.h
+++ b/dom/animation/KeyframeEffect.h
@@ -13,16 +13,17 @@
#include "nsCycleCollectionParticipant.h"
#include "nsTArray.h"
#include "nsWrapperCache.h"
#include "mozilla/AnimationPerformanceWarning.h"
#include "mozilla/AnimationTarget.h"
#include "mozilla/Attributes.h"
#include "mozilla/ComputedTiming.h"
#include "mozilla/ComputedTimingFunction.h"
+#include "mozilla/EffectCompositor.h"
#include "mozilla/LayerAnimationInfo.h" // LayerAnimations::kRecords
#include "mozilla/Maybe.h"
#include "mozilla/OwningNonNull.h" // OwningNonNull<...>
#include "mozilla/StickyTimeDuration.h"
#include "mozilla/StyleAnimationValue.h"
#include "mozilla/TimeStamp.h"
#include "mozilla/TimingParams.h"
#include "mozilla/dom/AnimationEffectReadOnly.h"
@@ -359,16 +360,21 @@ protected:
// (b) It is "relevant" (i.e. yet to finish but not idle, or finished but
// filling forwards)
//
// As a result, we need to make sure this gets called whenever anything
// changes with regards to this effects's timing including changes to the
// owning Animation's timing.
void UpdateTargetRegistration();
+ // Remove the current effect target from its EffectSet.
+ void UnregisterTarget();
+
+ void RequestRestyle(EffectCompositor::RestyleType aRestyleType);
+
Maybe<OwningAnimationTarget> mTarget;
RefPtr<Animation> mAnimation;
RefPtr<AnimationEffectTimingReadOnly> mTiming;
// The specified keyframes.
nsTArray<Keyframe> mFrames;