Bug 693145 - Simplify class animation processing. r=dholbert

This commit is contained in:
Robert Longson 2011-10-18 13:43:57 +01:00
parent 81548b004b
commit e91a17958d
7 changed files with 85 additions and 78 deletions

View File

@ -35,6 +35,7 @@
* ***** END LICENSE BLOCK ***** */ * ***** END LICENSE BLOCK ***** */
#include "nsSVGClass.h" #include "nsSVGClass.h"
#include "nsSVGStylableElement.h"
#ifdef MOZ_SMIL #ifdef MOZ_SMIL
#include "nsSMILValue.h" #include "nsSMILValue.h"
#include "SMILStringType.h" #include "SMILStringType.h"
@ -59,7 +60,7 @@ NS_INTERFACE_MAP_END
void void
nsSVGClass::SetBaseValue(const nsAString& aValue, nsSVGClass::SetBaseValue(const nsAString& aValue,
nsSVGElement *aSVGElement, nsSVGStylableElement *aSVGElement,
bool aDoSetAttr) bool aDoSetAttr)
{ {
NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue"); NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue");
@ -76,7 +77,13 @@ nsSVGClass::SetBaseValue(const nsAString& aValue,
} }
void void
nsSVGClass::GetAnimValue(nsAString& aResult, const nsSVGElement *aSVGElement) const nsSVGClass::GetBaseValue(nsAString& aValue, const nsSVGStylableElement *aSVGElement) const
{
aSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aValue);
}
void
nsSVGClass::GetAnimValue(nsAString& aResult, const nsSVGStylableElement *aSVGElement) const
{ {
if (mAnimVal) { if (mAnimVal) {
aResult = *mAnimVal; aResult = *mAnimVal;
@ -87,7 +94,7 @@ nsSVGClass::GetAnimValue(nsAString& aResult, const nsSVGElement *aSVGElement) co
} }
void void
nsSVGClass::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement) nsSVGClass::SetAnimValue(const nsAString& aValue, nsSVGStylableElement *aSVGElement)
{ {
if (!mAnimVal) { if (!mAnimVal) {
mAnimVal = new nsString(); mAnimVal = new nsString();
@ -99,7 +106,7 @@ nsSVGClass::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement)
nsresult nsresult
nsSVGClass::ToDOMAnimatedString(nsIDOMSVGAnimatedString **aResult, nsSVGClass::ToDOMAnimatedString(nsIDOMSVGAnimatedString **aResult,
nsSVGElement *aSVGElement) nsSVGStylableElement *aSVGElement)
{ {
*aResult = new DOMAnimatedString(this, aSVGElement); *aResult = new DOMAnimatedString(this, aSVGElement);
NS_ADDREF(*aResult); NS_ADDREF(*aResult);
@ -108,11 +115,21 @@ nsSVGClass::ToDOMAnimatedString(nsIDOMSVGAnimatedString **aResult,
#ifdef MOZ_SMIL #ifdef MOZ_SMIL
nsISMILAttr* nsISMILAttr*
nsSVGClass::ToSMILAttr(nsSVGElement *aSVGElement) nsSVGClass::ToSMILAttr(nsSVGStylableElement *aSVGElement)
{ {
return new SMILString(this, aSVGElement); return new SMILString(this, aSVGElement);
} }
NS_IMETHODIMP
nsSVGClass::DOMAnimatedString::GetAnimVal(nsAString& aResult)
{
#ifdef MOZ_SMIL
mSVGElement->FlushAnimations();
#endif
mVal->GetAnimValue(aResult, mSVGElement);
return NS_OK;
}
nsresult nsresult
nsSVGClass::SMILString::ValueFromString(const nsAString& aStr, nsSVGClass::SMILString::ValueFromString(const nsAString& aStr,
const nsISMILAnimationElement* /*aSrcElement*/, const nsISMILAnimationElement* /*aSrcElement*/,

View File

@ -38,9 +38,14 @@
#define __NS_SVGCLASS_H__ #define __NS_SVGCLASS_H__
#include "nsIDOMSVGAnimatedString.h" #include "nsIDOMSVGAnimatedString.h"
#include "nsSVGElement.h" #include "nsAutoPtr.h"
#include "nsCycleCollectionParticipant.h"
#include "nsString.h"
#include "nsISMILAttr.h"
#include "nsDOMError.h" #include "nsDOMError.h"
class nsSVGStylableElement;
class nsSVGClass class nsSVGClass
{ {
@ -50,21 +55,20 @@ public:
} }
void SetBaseValue(const nsAString& aValue, void SetBaseValue(const nsAString& aValue,
nsSVGElement *aSVGElement, nsSVGStylableElement *aSVGElement,
bool aDoSetAttr); bool aDoSetAttr);
void GetBaseValue(nsAString& aValue, nsSVGElement *aSVGElement) const void GetBaseValue(nsAString& aValue, const nsSVGStylableElement *aSVGElement) const;
{ aSVGElement->GetAttr(kNameSpaceID_None, nsGkAtoms::_class, aValue); }
void SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement); void SetAnimValue(const nsAString& aValue, nsSVGStylableElement *aSVGElement);
void GetAnimValue(nsAString& aValue, const nsSVGElement *aSVGElement) const; void GetAnimValue(nsAString& aValue, const nsSVGStylableElement *aSVGElement) const;
bool IsAnimated() const bool IsAnimated() const
{ return !!mAnimVal; } { return !!mAnimVal; }
nsresult ToDOMAnimatedString(nsIDOMSVGAnimatedString **aResult, nsresult ToDOMAnimatedString(nsIDOMSVGAnimatedString **aResult,
nsSVGElement *aSVGElement); nsSVGStylableElement *aSVGElement);
#ifdef MOZ_SMIL #ifdef MOZ_SMIL
// Returns a new nsISMILAttr object that the caller must delete // Returns a new nsISMILAttr object that the caller must delete
nsISMILAttr* ToSMILAttr(nsSVGElement *aSVGElement); nsISMILAttr* ToSMILAttr(nsSVGStylableElement *aSVGElement);
#endif // MOZ_SMIL #endif // MOZ_SMIL
private: private:
@ -77,38 +81,31 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedString) NS_DECL_CYCLE_COLLECTION_CLASS(DOMAnimatedString)
DOMAnimatedString(nsSVGClass *aVal, nsSVGElement *aSVGElement) DOMAnimatedString(nsSVGClass *aVal, nsSVGStylableElement *aSVGElement)
: mVal(aVal), mSVGElement(aSVGElement) {} : mVal(aVal), mSVGElement(aSVGElement) {}
nsSVGClass* mVal; // kept alive because it belongs to content nsSVGClass* mVal; // kept alive because it belongs to content
nsRefPtr<nsSVGElement> mSVGElement; nsRefPtr<nsSVGStylableElement> mSVGElement;
NS_IMETHOD GetBaseVal(nsAString& aResult) NS_IMETHOD GetBaseVal(nsAString& aResult)
{ mVal->GetBaseValue(aResult, mSVGElement); return NS_OK; } { mVal->GetBaseValue(aResult, mSVGElement); return NS_OK; }
NS_IMETHOD SetBaseVal(const nsAString& aValue) NS_IMETHOD SetBaseVal(const nsAString& aValue)
{ mVal->SetBaseValue(aValue, mSVGElement, true); return NS_OK; } { mVal->SetBaseValue(aValue, mSVGElement, true); return NS_OK; }
NS_IMETHOD GetAnimVal(nsAString& aResult) NS_IMETHOD GetAnimVal(nsAString& aResult);
{
#ifdef MOZ_SMIL
mSVGElement->FlushAnimations();
#endif
mVal->GetAnimValue(aResult, mSVGElement); return NS_OK;
}
}; };
#ifdef MOZ_SMIL #ifdef MOZ_SMIL
struct SMILString : public nsISMILAttr struct SMILString : public nsISMILAttr
{ {
public: public:
SMILString(nsSVGClass *aVal, nsSVGElement *aSVGElement) SMILString(nsSVGClass *aVal, nsSVGStylableElement *aSVGElement)
: mVal(aVal), mSVGElement(aSVGElement) {} : mVal(aVal), mSVGElement(aSVGElement) {}
// These will stay alive because a nsISMILAttr only lives as long // These will stay alive because a nsISMILAttr only lives as long
// as the Compositing step, and DOM elements don't get a chance to // as the Compositing step, and DOM elements don't get a chance to
// die during that. // die during that.
nsSVGClass* mVal; nsSVGClass* mVal;
nsSVGElement* mSVGElement; nsSVGStylableElement* mSVGElement;
// nsISMILAttr methods // nsISMILAttr methods
virtual nsresult ValueFromString(const nsAString& aStr, virtual nsresult ValueFromString(const nsAString& aStr,

View File

@ -76,7 +76,6 @@
#include "nsSVGEnum.h" #include "nsSVGEnum.h"
#include "nsSVGViewBox.h" #include "nsSVGViewBox.h"
#include "nsSVGString.h" #include "nsSVGString.h"
#include "nsSVGClass.h"
#include "SVGAnimatedNumberList.h" #include "SVGAnimatedNumberList.h"
#include "SVGAnimatedLengthList.h" #include "SVGAnimatedLengthList.h"
#include "SVGAnimatedPointList.h" #include "SVGAnimatedPointList.h"
@ -516,14 +515,6 @@ nsSVGElement::ParseAttribute(PRInt32 aNamespaceID,
} }
foundMatch = true; foundMatch = true;
} }
// Check for class attribute
} else if (aAttribute == nsGkAtoms::_class) {
nsSVGClass *svgClass = GetClass();
if (svgClass) {
svgClass->SetBaseValue(aValue, this, false);
aResult.ParseAtomArray(aValue);
return true;
}
} }
} }
} }
@ -735,16 +726,6 @@ nsSVGElement::UnsetAttrInternal(PRInt32 aNamespaceID, nsIAtom* aName,
return; return;
} }
} }
// Check if this is a class attribute going away
if (aName == nsGkAtoms::_class) {
nsSVGClass *svgClass = GetClass();
if (svgClass) {
svgClass->Init();
return;
}
}
} }
// Check if this is a string attribute going away // Check if this is a string attribute going away
@ -2121,23 +2102,6 @@ nsSVGElement::DidAnimateString(PRUint8 aAttrEnum)
} }
} }
nsSVGClass *
nsSVGElement::GetClass()
{
return nsnull;
}
void
nsSVGElement::DidAnimateClass()
{
nsIFrame* frame = GetPrimaryFrame();
if (frame) {
frame->AttributeChanged(kNameSpaceID_None, nsGkAtoms::_class,
nsIDOMMutationEvent::MODIFICATION);
}
}
nsresult nsresult
nsSVGElement::ReportAttributeParseFailure(nsIDocument* aDocument, nsSVGElement::ReportAttributeParseFailure(nsIDocument* aDocument,
nsIAtom* aAttribute, nsIAtom* aAttribute,
@ -2282,11 +2246,6 @@ nsSVGElement::GetAnimatedAttr(PRInt32 aNamespaceID, nsIAtom* aName)
preserveAspectRatio->ToSMILAttr(this) : nsnull; preserveAspectRatio->ToSMILAttr(this) : nsnull;
} }
if (aName == nsGkAtoms::_class) {
nsSVGClass *svgClass = GetClass();
return svgClass ? svgClass->ToSMILAttr(this) : nsnull;
}
// NumberLists: // NumberLists:
{ {
NumberListAttributesInfo info = GetNumberListInfo(); NumberListAttributesInfo info = GetNumberListInfo();

View File

@ -68,7 +68,6 @@ class nsSVGEnum;
struct nsSVGEnumMapping; struct nsSVGEnumMapping;
class nsSVGViewBox; class nsSVGViewBox;
class nsSVGString; class nsSVGString;
class nsSVGClass;
struct gfxMatrix; struct gfxMatrix;
namespace mozilla { namespace mozilla {
class SVGAnimatedNumberList; class SVGAnimatedNumberList;
@ -197,7 +196,6 @@ public:
virtual void DidAnimatePathSegList(); virtual void DidAnimatePathSegList();
virtual void DidAnimateTransformList(); virtual void DidAnimateTransformList();
virtual void DidAnimateString(PRUint8 aAttrEnum); virtual void DidAnimateString(PRUint8 aAttrEnum);
virtual void DidAnimateClass();
void GetAnimatedLengthValues(float *aFirst, ...); void GetAnimatedLengthValues(float *aFirst, ...);
void GetAnimatedNumberValues(float *aFirst, ...); void GetAnimatedNumberValues(float *aFirst, ...);
@ -514,7 +512,6 @@ protected:
virtual NumberListAttributesInfo GetNumberListInfo(); virtual NumberListAttributesInfo GetNumberListInfo();
virtual LengthListAttributesInfo GetLengthListInfo(); virtual LengthListAttributesInfo GetLengthListInfo();
virtual StringAttributesInfo GetStringInfo(); virtual StringAttributesInfo GetStringInfo();
virtual nsSVGClass *GetClass();
static nsSVGEnumMapping sSVGUnitTypesMap[]; static nsSVGEnumMapping sSVGUnitTypesMap[];

View File

@ -54,7 +54,7 @@ public:
void SetBaseValue(const nsAString& aValue, void SetBaseValue(const nsAString& aValue,
nsSVGElement *aSVGElement, nsSVGElement *aSVGElement,
bool aDoSetAttr); bool aDoSetAttr);
void GetBaseValue(nsAString& aValue, nsSVGElement *aSVGElement) const void GetBaseValue(nsAString& aValue, const nsSVGElement *aSVGElement) const
{ aSVGElement->GetStringBaseValue(mAttrEnum, aValue); } { aSVGElement->GetStringBaseValue(mAttrEnum, aValue); }
void SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement); void SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement);

View File

@ -70,6 +70,31 @@ nsSVGStylableElement::DoGetClasses() const
return nsSVGStylableElementBase::DoGetClasses(); return nsSVGStylableElementBase::DoGetClasses();
} }
bool
nsSVGStylableElement::ParseAttribute(PRInt32 aNamespaceID,
nsIAtom* aAttribute,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aNamespaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::_class) {
mClassAttribute.SetBaseValue(aValue, this, false);
aResult.ParseAtomArray(aValue);
return true;
}
return nsSVGStylableElementBase::ParseAttribute(aNamespaceID, aAttribute, aValue,
aResult);
}
nsresult
nsSVGStylableElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
bool aNotify)
{
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::_class) {
mClassAttribute.Init();
}
return nsSVGStylableElementBase::UnsetAttr(aNamespaceID, aName, aNotify);
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
// nsIDOMSVGStylable methods // nsIDOMSVGStylable methods
@ -126,6 +151,14 @@ nsSVGStylableElement::DidAnimateClass()
shell->RestyleForAnimation(this, eRestyle_Self); shell->RestyleForAnimation(this, eRestyle_Self);
} }
} }
}
nsSVGStylableElementBase::DidAnimateClass();
nsISMILAttr*
nsSVGStylableElement::GetAnimatedAttr(PRInt32 aNamespaceID, nsIAtom* aName)
{
if (aNamespaceID == kNameSpaceID_None &&
aName == nsGkAtoms::_class) {
return mClassAttribute.ToSMILAttr(this);
}
return nsSVGStylableElementBase::GetAnimatedAttr(aNamespaceID, aName);
} }

View File

@ -64,14 +64,18 @@ public:
{ {
return nsSVGStylableElementBase::GetStyle(retval); return nsSVGStylableElementBase::GetStyle(retval);
} }
virtual bool ParseAttribute(PRInt32 aNamespaceID, nsIAtom* aAttribute,
const nsAString& aValue, nsAttrValue& aResult);
virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
bool aNotify);
#ifdef MOZ_SMIL
virtual nsISMILAttr* GetAnimatedAttr(PRInt32 aNamespaceID, nsIAtom* aName);
#endif
void DidAnimateClass();
protected: protected:
virtual nsSVGClass *GetClass()
{
return &mClassAttribute;
}
virtual void DidAnimateClass();
nsSVGClass mClassAttribute; nsSVGClass mClassAttribute;
nsAutoPtr<nsAttrValue> mClassAnimAttr; nsAutoPtr<nsAttrValue> mClassAnimAttr;
}; };