Skip to content

Commit

Permalink
Bug 1828294 - Simplify SMILSetAnimationFunction r=emilio
Browse files Browse the repository at this point in the history
  • Loading branch information
longsonr committed Apr 17, 2023
1 parent c9075e0 commit c30e3eb
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 93 deletions.
22 changes: 22 additions & 0 deletions dom/smil/SMILAnimationFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ void SMILAnimationFunction::SetAnimationElement(
bool SMILAnimationFunction::SetAttr(nsAtom* aAttribute, const nsAString& aValue,
nsAttrValue& aResult,
nsresult* aParseResult) {
// Some elements such as set and discard don't support all possible attributes
if (IsDisallowedAttribute(aAttribute)) {
aResult.SetTo(aValue);
if (aParseResult) {
*aParseResult = NS_OK;
}
return true;
}

bool foundMatch = true;
nsresult parseResult = NS_OK;

Expand Down Expand Up @@ -111,6 +120,10 @@ bool SMILAnimationFunction::SetAttr(nsAtom* aAttribute, const nsAString& aValue,
}

bool SMILAnimationFunction::UnsetAttr(nsAtom* aAttribute) {
if (IsDisallowedAttribute(aAttribute)) {
return true;
}

bool foundMatch = true;

if (aAttribute == nsGkAtoms::by || aAttribute == nsGkAtoms::from ||
Expand Down Expand Up @@ -641,15 +654,24 @@ double SMILAnimationFunction::ScaleIntervalProgress(double aProgress,
}

bool SMILAnimationFunction::HasAttr(nsAtom* aAttName) const {
if (IsDisallowedAttribute(aAttName)) {
return false;
}
return mAnimationElement->HasAttr(aAttName);
}

const nsAttrValue* SMILAnimationFunction::GetAttr(nsAtom* aAttName) const {
if (IsDisallowedAttribute(aAttName)) {
return nullptr;
}
return mAnimationElement->GetParsedAttr(aAttName);
}

bool SMILAnimationFunction::GetAttr(nsAtom* aAttName,
nsAString& aResult) const {
if (IsDisallowedAttribute(aAttName)) {
return false;
}
return mAnimationElement->GetAttr(aAttName, aResult);
}

Expand Down
12 changes: 7 additions & 5 deletions dom/smil/SMILAnimationFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,9 @@ class SMILAnimationFunction {
void UnsetKeySplines();

// Helpers
virtual bool IsDisallowedAttribute(const nsAtom* aAttribute) const {
return false;
}
virtual nsresult InterpolateResult(const SMILValueArray& aValues,
SMILValue& aResult, SMILValue& aBaseValue);
nsresult AccumulateResult(const SMILValueArray& aValues, SMILValue& aResult);
Expand All @@ -312,11 +315,10 @@ class SMILAnimationFunction {
*/
double ScaleIntervalProgress(double aProgress, uint32_t aIntervalIndex);

// Convenience attribute getters -- use these instead of querying
// mAnimationElement as these may need to be overridden by subclasses
virtual bool HasAttr(nsAtom* aAttName) const;
virtual const nsAttrValue* GetAttr(nsAtom* aAttName) const;
virtual bool GetAttr(nsAtom* aAttName, nsAString& aResult) const;
// Convenience attribute getters
bool HasAttr(nsAtom* aAttName) const;
const nsAttrValue* GetAttr(nsAtom* aAttName) const;
bool GetAttr(nsAtom* aAttName, nsAString& aResult) const;

bool ParseAttr(nsAtom* aAttName, const SMILAttr& aSMILAttr,
SMILValue& aResult, bool& aPreventCachingOfSandwich) const;
Expand Down
55 changes: 1 addition & 54 deletions dom/smil/SMILSetAnimationFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace mozilla {

inline bool SMILSetAnimationFunction::IsDisallowedAttribute(
bool SMILSetAnimationFunction::IsDisallowedAttribute(
const nsAtom* aAttribute) const {
//
// A <set> element is similar to <animate> but lacks:
Expand All @@ -23,57 +23,4 @@ inline bool SMILSetAnimationFunction::IsDisallowedAttribute(
aAttribute == nsGkAtoms::accumulate;
}

bool SMILSetAnimationFunction::SetAttr(nsAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult,
nsresult* aParseResult) {
if (IsDisallowedAttribute(aAttribute)) {
aResult.SetTo(aValue);
if (aParseResult) {
// SMILANIM 4.2 says:
//
// The additive and accumulate attributes are not allowed, and will be
// ignored if specified.
//
// So at least for those two attributes we shouldn't report an error even
// if they're present. For now we'll also just silently ignore other
// attribute types too.
*aParseResult = NS_OK;
}
return true;
}

return SMILAnimationFunction::SetAttr(aAttribute, aValue, aResult,
aParseResult);
}

bool SMILSetAnimationFunction::UnsetAttr(nsAtom* aAttribute) {
if (IsDisallowedAttribute(aAttribute)) {
return true;
}

return SMILAnimationFunction::UnsetAttr(aAttribute);
}

bool SMILSetAnimationFunction::HasAttr(nsAtom* aAttName) const {
if (IsDisallowedAttribute(aAttName)) return false;

return SMILAnimationFunction::HasAttr(aAttName);
}

const nsAttrValue* SMILSetAnimationFunction::GetAttr(nsAtom* aAttName) const {
if (IsDisallowedAttribute(aAttName)) return nullptr;

return SMILAnimationFunction::GetAttr(aAttName);
}

bool SMILSetAnimationFunction::GetAttr(nsAtom* aAttName,
nsAString& aResult) const {
if (IsDisallowedAttribute(aAttName)) return false;

return SMILAnimationFunction::GetAttr(aAttName, aResult);
}

bool SMILSetAnimationFunction::WillReplace() const { return true; }

} // namespace mozilla
34 changes: 3 additions & 31 deletions dom/smil/SMILSetAnimationFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,9 @@ namespace mozilla {
// by a <set> element.
//
class SMILSetAnimationFunction : public SMILAnimationFunction {
public:
/*
* Sets animation-specific attributes (or marks them dirty, in the case
* of from/to/by/values).
*
* @param aAttribute The attribute being set
* @param aValue The updated value of the attribute.
* @param aResult The nsAttrValue object that may be used for storing the
* parsed result.
* @param aParseResult Outparam used for reporting parse errors. Will be set
* to NS_OK if everything succeeds.
* @returns true if aAttribute is a recognized animation-related
* attribute; false otherwise.
*/
bool SetAttr(nsAtom* aAttribute, const nsAString& aValue,
nsAttrValue& aResult, nsresult* aParseResult = nullptr) override;

/*
* Unsets the given attribute.
*
* @returns true if aAttribute is a recognized animation-related
* attribute; false otherwise.
*/
bool UnsetAttr(nsAtom* aAttribute) override;

protected:
bool IsDisallowedAttribute(const nsAtom* aAttribute) const override;

// Although <set> animation might look like to-animation, unlike to-animation,
// it never interpolates values.
// Returning false here will mean this animation function gets treated as
Expand All @@ -53,12 +30,7 @@ class SMILSetAnimationFunction : public SMILAnimationFunction {

// <set> applies the exact same value across the simple duration.
bool IsValueFixedForSimpleDuration() const override { return true; }
bool HasAttr(nsAtom* aAttName) const override;
const nsAttrValue* GetAttr(nsAtom* aAttName) const override;
bool GetAttr(nsAtom* aAttName, nsAString& aResult) const override;
bool WillReplace() const override;

bool IsDisallowedAttribute(const nsAtom* aAttribute) const;
bool WillReplace() const override { return true; }
};

} // namespace mozilla
Expand Down
2 changes: 1 addition & 1 deletion dom/svg/SVGAnimateMotionElement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ bool SVGAnimateMotionElement::GetTargetAttributeName(
int32_t* aNamespaceID, nsAtom** aLocalName) const {
// <animateMotion> doesn't take an attributeName, since it doesn't target an
// 'attribute' per se. We'll use a unique dummy attribute-name so that our
// SMILTargetIdentifier logic (which requires a attribute name) still works.
// SMILTargetIdentifier logic (which requires an attribute name) still works.
*aNamespaceID = kNameSpaceID_None;
*aLocalName = nsGkAtoms::mozAnimateMotionDummyAttr;
return true;
Expand Down
4 changes: 2 additions & 2 deletions dom/svg/SVGAnimateMotionElement.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class SVGAnimateMotionElement final : public SVGAnimationElement {

// SVGAnimationElement
SMILAnimationFunction& AnimationFunction() override;
virtual bool GetTargetAttributeName(int32_t* aNamespaceID,
nsAtom** aLocalName) const override;
bool GetTargetAttributeName(int32_t* aNamespaceID,
nsAtom** aLocalName) const override;

// SVGElement
nsStaticAtom* GetPathDataAttrName() const override { return nsGkAtoms::path; }
Expand Down

0 comments on commit c30e3eb

Please sign in to comment.