Bug 1315874 - Factor out nsSMILCompositor::IsCSSPropertyAnimation helper method; r?dholbert
In a later patch in this series we willl create a method to check if we're
likely to need to resolve base styles or not, and for that we need to extract
the check for whether or not we're animating a CSS property.
This method doesn't necessarily need to be public, but since it's a static
method there doesn't seem to be any harm in making it so.
MozReview-Commit-ID: 9Ybsi91fro8
--- a/dom/smil/nsSMILCompositor.cpp
+++ b/dom/smil/nsSMILCompositor.cpp
@@ -118,37 +118,52 @@ nsSMILCompositor::ClearAnimationEffects(
UniquePtr<nsISMILAttr> smilAttr{CreateSMILAttr()};
if (!smilAttr) {
// Target attribute not found (or, out of memory)
return;
}
smilAttr->ClearAnimValue();
}
+/*static*/ bool
+nsSMILCompositor::IsCSSPropertyAnimation(nsIAtom* aAttributeName,
+ nsCSSPropertyID aPropID,
+ mozilla::dom::Element* aTargetElement)
+{
+ MOZ_ASSERT(aAttributeName);
+ MOZ_ASSERT(aTargetElement);
+
+ if (!nsSMILCSSProperty::IsPropertyAnimatable(aPropID)) {
+ return false;
+ }
+
+ // If we are animating the 'width' or 'height' of an outer SVG
+ // element we should animate it as a CSS property, but for other elements
+ // (e.g. <rect>) we should animate it as a length attribute.
+ // The easiest way to test for an outer SVG element, is to see if it is an
+ // SVG-namespace element mapping its width/height attribute to style.
+ bool animateAsAttr = (aAttributeName == nsGkAtoms::width ||
+ aAttributeName == nsGkAtoms::height) &&
+ aTargetElement->GetNameSpaceID() == kNameSpaceID_SVG &&
+ !aTargetElement->IsAttributeMapped(aAttributeName);
+
+ return !animateAsAttr;
+}
+
// Protected Helper Functions
// --------------------------
UniquePtr<nsISMILAttr>
nsSMILCompositor::CreateSMILAttr()
{
nsCSSPropertyID propID =
nsCSSProps::LookupProperty(nsDependentAtomString(mKey.mAttributeName),
CSSEnabledState::eForAllContent);
- if (nsSMILCSSProperty::IsPropertyAnimatable(propID)) {
- // If we are animating the 'width' or 'height' of an outer SVG
- // element we should animate it as a CSS property, but for other elements
- // (e.g. <rect>) we should animate it as a length attribute.
- // The easiest way to test for an outer SVG element, is to see if it is an
- // SVG-namespace element mapping its width/height attribute to style.
- bool animateAsAttr = (mKey.mAttributeName == nsGkAtoms::width ||
- mKey.mAttributeName == nsGkAtoms::height) &&
- mKey.mElement->GetNameSpaceID() == kNameSpaceID_SVG &&
- !mKey.mElement->IsAttributeMapped(mKey.mAttributeName);
- if (!animateAsAttr) {
- return MakeUnique<nsSMILCSSProperty>(propID, mKey.mElement.get());
- }
+
+ if (IsCSSPropertyAnimation(mKey.mAttributeName, propID, mKey.mElement)) {
+ return MakeUnique<nsSMILCSSProperty>(propID, mKey.mElement.get());
}
return mKey.mElement->GetAnimatedAttr(mKey.mAttributeNamespaceID,
mKey.mAttributeName);
}
uint32_t
nsSMILCompositor::GetFirstFuncToAffectSandwich()
--- a/dom/smil/nsSMILCompositor.h
+++ b/dom/smil/nsSMILCompositor.h
@@ -67,16 +67,27 @@ public:
// optimizations) when we hit ComposeAttribute.
void ToggleForceCompositing() { mForceCompositing = true; }
// Transfers |aOther|'s mCachedBaseValue to |this|
void StealCachedBaseValue(nsSMILCompositor* aOther) {
mCachedBaseValue = mozilla::Move(aOther->mCachedBaseValue);
}
+ // Returns true if, given an attributeName and corresponding property ID,
+ // an animation targetting |aTargetElement| will animate the corresponding CSS
+ // property rather than an attribute.
+ //
+ // (The property ID could be derived from |aAttributeName| but is passed as
+ // a separate argument here as an optimization since call sites of this
+ // method may require |aPropID| beyond the scope of this function.)
+ static bool IsCSSPropertyAnimation(nsIAtom* aAttributeName,
+ nsCSSPropertyID aPropID,
+ mozilla::dom::Element* aTargetElement);
+
private:
// Create a nsISMILAttr for my target, on the heap.
UniquePtr<nsISMILAttr> CreateSMILAttr();
// Finds the index of the first function that will affect our animation
// sandwich. Also toggles the 'mForceCompositing' flag if it finds that any
// (used) functions have changed.
uint32_t GetFirstFuncToAffectSandwich();