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 ***** */
#include "nsSVGClass.h"
#include "nsSVGStylableElement.h"
#ifdef MOZ_SMIL
#include "nsSMILValue.h"
#include "SMILStringType.h"
@ -59,7 +60,7 @@ NS_INTERFACE_MAP_END
void
nsSVGClass::SetBaseValue(const nsAString& aValue,
nsSVGElement *aSVGElement,
nsSVGStylableElement *aSVGElement,
bool aDoSetAttr)
{
NS_ASSERTION(aSVGElement, "Null element passed to SetBaseValue");
@ -76,7 +77,13 @@ nsSVGClass::SetBaseValue(const nsAString& aValue,
}
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) {
aResult = *mAnimVal;
@ -87,7 +94,7 @@ nsSVGClass::GetAnimValue(nsAString& aResult, const nsSVGElement *aSVGElement) co
}
void
nsSVGClass::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement)
nsSVGClass::SetAnimValue(const nsAString& aValue, nsSVGStylableElement *aSVGElement)
{
if (!mAnimVal) {
mAnimVal = new nsString();
@ -99,7 +106,7 @@ nsSVGClass::SetAnimValue(const nsAString& aValue, nsSVGElement *aSVGElement)
nsresult
nsSVGClass::ToDOMAnimatedString(nsIDOMSVGAnimatedString **aResult,
nsSVGElement *aSVGElement)
nsSVGStylableElement *aSVGElement)
{
*aResult = new DOMAnimatedString(this, aSVGElement);
NS_ADDREF(*aResult);
@ -108,11 +115,21 @@ nsSVGClass::ToDOMAnimatedString(nsIDOMSVGAnimatedString **aResult,
#ifdef MOZ_SMIL
nsISMILAttr*
nsSVGClass::ToSMILAttr(nsSVGElement *aSVGElement)
nsSVGClass::ToSMILAttr(nsSVGStylableElement *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
nsSVGClass::SMILString::ValueFromString(const nsAString& aStr,
const nsISMILAnimationElement* /*aSrcElement*/,

View File

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

View File

@ -76,7 +76,6 @@
#include "nsSVGEnum.h"
#include "nsSVGViewBox.h"
#include "nsSVGString.h"
#include "nsSVGClass.h"
#include "SVGAnimatedNumberList.h"
#include "SVGAnimatedLengthList.h"
#include "SVGAnimatedPointList.h"
@ -516,14 +515,6 @@ nsSVGElement::ParseAttribute(PRInt32 aNamespaceID,
}
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;
}
}
// 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
@ -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
nsSVGElement::ReportAttributeParseFailure(nsIDocument* aDocument,
nsIAtom* aAttribute,
@ -2282,11 +2246,6 @@ nsSVGElement::GetAnimatedAttr(PRInt32 aNamespaceID, nsIAtom* aName)
preserveAspectRatio->ToSMILAttr(this) : nsnull;
}
if (aName == nsGkAtoms::_class) {
nsSVGClass *svgClass = GetClass();
return svgClass ? svgClass->ToSMILAttr(this) : nsnull;
}
// NumberLists:
{
NumberListAttributesInfo info = GetNumberListInfo();

View File

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

View File

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

View File

@ -70,6 +70,31 @@ nsSVGStylableElement::DoGetClasses() const
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
@ -126,6 +151,14 @@ nsSVGStylableElement::DidAnimateClass()
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);
}
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:
virtual nsSVGClass *GetClass()
{
return &mClassAttribute;
}
virtual void DidAnimateClass();
nsSVGClass mClassAttribute;
nsAutoPtr<nsAttrValue> mClassAnimAttr;
};