Bug 395667 - New style nsSVGInteger. r=tor,sr=roc,a=roc

This commit is contained in:
longsonr%gmail.com 2007-09-18 12:09:27 +00:00
Родитель c7f6900d35
Коммит b63ae34a65
11 изменённых файлов: 398 добавлений и 189 удалений

Просмотреть файл

@ -73,7 +73,6 @@ CPPSRCS = \
nsSVGAngle.cpp \
nsSVGAnimatedAngle.cpp \
nsSVGAnimatedBoolean.cpp \
nsSVGAnimatedInteger.cpp \
nsSVGAnimatedLengthList.cpp \
nsSVGAnimatedNumberList.cpp \
nsSVGAnimatedRect.cpp \
@ -97,6 +96,7 @@ CPPSRCS = \
nsSVGGradientElement.cpp \
nsSVGGraphicElement.cpp \
nsSVGImageElement.cpp \
nsSVGInteger.cpp \
nsSVGLength.cpp \
nsSVGLength2.cpp \
nsSVGLengthList.cpp \

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -67,6 +67,7 @@
#include "nsSVGUtils.h"
#include "nsSVGLength2.h"
#include "nsSVGNumber2.h"
#include "nsSVGInteger.h"
#include "nsSVGEnum.h"
#include "nsIDOMSVGUnitTypes.h"
#include "nsIDOMSVGAngle.h"
@ -123,6 +124,12 @@ nsSVGElement::Init()
numberInfo.mNumbers[i].Init(i, numberInfo.mNumberInfo[i].mDefaultValue);
}
IntegerAttributesInfo integerInfo = GetIntegerInfo();
for (i = 0; i < integerInfo.mIntegerCount; i++) {
integerInfo.mIntegers[i].Init(i, integerInfo.mIntegerInfo[i].mDefaultValue);
}
EnumAttributesInfo enumInfo = GetEnumInfo();
for (i = 0; i < enumInfo.mEnumCount; i++) {
@ -261,6 +268,15 @@ nsSVGElement::ParseAttribute(PRInt32 aNamespaceID,
}
}
// Check for nsSVGInteger attribute
IntegerAttributesInfo integerInfo = GetIntegerInfo();
for (PRUint32 i = 0; i < integerInfo.mIntegerCount && !foundMatch; i++) {
if (aAttribute == *integerInfo.mIntegerInfo[i].mName) {
rv = integerInfo.mIntegers[i].SetBaseValueString(aValue, this, PR_FALSE);
foundMatch = PR_TRUE;
}
}
// Check for nsSVGEnum attribute
EnumAttributesInfo enumInfo = GetEnumInfo();
for (PRUint32 i = 0; i < enumInfo.mEnumCount && !foundMatch; i++) {
@ -312,7 +328,6 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
lenInfo.mLengthInfo[i].mDefaultValue,
lenInfo.mLengthInfo[i].mDefaultUnitType);
DidChangeLength(i, PR_FALSE);
break;
}
}
// Check if this is a number attribute going away
@ -322,18 +337,26 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
if (aName == *numInfo.mNumberInfo[i].mName) {
numInfo.mNumbers[i].Init(i, numInfo.mNumberInfo[i].mDefaultValue);
DidChangeNumber(i, PR_FALSE);
break;
}
}
// Check if this is a number attribute going away
// Check if this is an integer attribute going away
IntegerAttributesInfo intInfo = GetIntegerInfo();
for (i = 0; i < intInfo.mIntegerCount; i++) {
if (aName == *intInfo.mIntegerInfo[i].mName) {
intInfo.mIntegers[i].Init(i, intInfo.mIntegerInfo[i].mDefaultValue);
DidChangeInteger(i, PR_FALSE);
}
}
// Check if this is an enum attribute going away
EnumAttributesInfo enumInfo = GetEnumInfo();
for (i = 0; i < enumInfo.mEnumCount; i++) {
if (aName == *enumInfo.mEnumInfo[i].mName) {
enumInfo.mEnums[i].Init(i, enumInfo.mEnumInfo[i].mDefaultValue);
DidChangeEnum(i, PR_FALSE);
break;
}
}
@ -347,9 +370,6 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
nsCOMPtr<nsIDOMSVGAnimatedBoolean> b = do_QueryInterface(svg_value);
NS_ASSERTION(!b, "must provide element processing for unset boolean");
nsCOMPtr<nsIDOMSVGAnimatedInteger> i = do_QueryInterface(svg_value);
NS_ASSERTION(!i, "must provide element processing for unset integer");
#endif
nsCOMPtr<nsIDOMSVGAnimatedRect> r = do_QueryInterface(svg_value);
@ -973,6 +993,53 @@ nsSVGElement::GetAnimatedNumberValues(float *aFirst, ...)
va_end(args);
}
nsSVGElement::IntegerAttributesInfo
nsSVGElement::GetIntegerInfo()
{
return IntegerAttributesInfo(nsnull, nsnull, 0);
}
void
nsSVGElement::DidChangeInteger(PRUint8 aAttrEnum, PRBool aDoSetAttr)
{
if (!aDoSetAttr)
return;
IntegerAttributesInfo info = GetIntegerInfo();
NS_ASSERTION(info.mIntegerCount > 0,
"DidChangeInteger on element with no integer attribs");
NS_ASSERTION(aAttrEnum < info.mIntegerCount, "aAttrEnum out of range");
nsAutoString newStr;
info.mIntegers[aAttrEnum].GetBaseValueString(newStr);
SetAttr(kNameSpaceID_None, *info.mIntegerInfo[aAttrEnum].mName,
newStr, PR_TRUE);
}
void
nsSVGElement::GetAnimatedIntegerValues(PRInt32 *aFirst, ...)
{
IntegerAttributesInfo info = GetIntegerInfo();
NS_ASSERTION(info.mIntegerCount > 0,
"GetAnimatedIntegerValues on element with no integer attribs");
PRInt32 *n = aFirst;
PRUint32 i = 0;
va_list args;
va_start(args, aFirst);
while (n && i < info.mIntegerCount) {
*n = info.mIntegers[i++].GetAnimValue();
n = va_arg(args, PRInt32*);
}
va_end(args);
}
nsSVGElement::EnumAttributesInfo
nsSVGElement::GetEnumInfo()
{
@ -988,7 +1055,7 @@ nsSVGElement::DidChangeEnum(PRUint8 aAttrEnum, PRBool aDoSetAttr)
EnumAttributesInfo info = GetEnumInfo();
NS_ASSERTION(info.mEnumCount > 0,
"DidChangeNumber on element with no number attribs");
"DidChangeEnum on element with no enum attribs");
NS_ASSERTION(aAttrEnum < info.mEnumCount, "aAttrEnum out of range");

Просмотреть файл

@ -57,6 +57,7 @@
class nsSVGSVGElement;
class nsSVGLength2;
class nsSVGNumber2;
class nsSVGInteger;
class nsSVGEnum;
struct nsSVGEnumMapping;
@ -118,10 +119,12 @@ public:
virtual void DidChangeLength(PRUint8 aAttrEnum, PRBool aDoSetAttr);
virtual void DidChangeNumber(PRUint8 aAttrEnum, PRBool aDoSetAttr);
virtual void DidChangeInteger(PRUint8 aAttrEnum, PRBool aDoSetAttr);
virtual void DidChangeEnum(PRUint8 aAttrEnum, PRBool aDoSetAttr);
void GetAnimatedLengthValues(float *aFirst, ...);
void GetAnimatedNumberValues(float *aFirst, ...);
void GetAnimatedIntegerValues(PRInt32 *aFirst, ...);
virtual void RecompileScriptEventListeners();
@ -143,9 +146,7 @@ protected:
static nsIAtom* GetEventNameForAttr(nsIAtom* aAttr);
// The following two structures should be protected, but VC6
// doesn't allow children of nsSVGElement to access them.
public:
protected:
struct LengthInfo {
nsIAtom** mName;
float mDefaultValue;
@ -182,6 +183,25 @@ public:
{}
};
struct IntegerInfo {
nsIAtom** mName;
PRInt32 mDefaultValue;
};
struct IntegerAttributesInfo {
nsSVGInteger* mIntegers;
IntegerInfo* mIntegerInfo;
PRUint32 mIntegerCount;
IntegerAttributesInfo(nsSVGInteger *aIntegers,
IntegerInfo *aIntegerInfo,
PRUint32 aIntegerCount) :
mIntegers(aIntegers), mIntegerInfo(aIntegerInfo), mIntegerCount(aIntegerCount)
{}
};
friend class nsSVGEnum;
struct EnumInfo {
nsIAtom** mName;
nsSVGEnumMapping* mMapping;
@ -205,6 +225,7 @@ public:
protected:
virtual LengthAttributesInfo GetLengthInfo();
virtual NumberAttributesInfo GetNumberInfo();
virtual IntegerAttributesInfo GetIntegerInfo();
static nsresult ReportAttributeParseFailure(nsIDocument* aDocument,
nsIAtom* aAttribute,

Просмотреть файл

@ -37,7 +37,6 @@
#include "nsGkAtoms.h"
#include "nsSVGLength.h"
#include "nsCOMPtr.h"
#include "nsSVGAnimatedInteger.h"
#include "nsSVGAnimatedString.h"
#include "nsSVGFilterElement.h"
@ -49,6 +48,12 @@ nsSVGElement::LengthInfo nsSVGFilterElement::sLengthInfo[4] =
{ &nsGkAtoms::height, 120, nsIDOMSVGLength::SVG_LENGTHTYPE_PERCENTAGE, nsSVGUtils::Y },
};
nsSVGElement::IntegerInfo nsSVGFilterElement::sIntegerInfo[2] =
{
{ &nsGkAtoms::filterRes, 0 },
{ &nsGkAtoms::filterRes, 0 }
};
nsSVGElement::EnumInfo nsSVGFilterElement::sEnumInfo[2] =
{
{ &nsGkAtoms::filterUnits,
@ -94,18 +99,6 @@ nsSVGFilterElement::Init()
// Create mapped properties:
// DOM property: filterResX , #IMPLIED attrib: filterRes
{
rv = NS_NewSVGAnimatedInteger(getter_AddRefs(mFilterResX), 0);
NS_ENSURE_SUCCESS(rv,rv);
}
// DOM property: filterResY , #IMPLIED attrib: filterRes
{
rv = NS_NewSVGAnimatedInteger(getter_AddRefs(mFilterResY), 0);
NS_ENSURE_SUCCESS(rv,rv);
}
// nsIDOMSVGURIReference properties
// DOM property: href , #REQUIRED attrib: xlink:href
@ -169,17 +162,13 @@ NS_IMETHODIMP nsSVGFilterElement::GetPrimitiveUnits(nsIDOMSVGAnimatedEnumeration
/* readonly attribute nsIDOMSVGAnimatedEnumeration filterResY; */
NS_IMETHODIMP nsSVGFilterElement::GetFilterResX(nsIDOMSVGAnimatedInteger * *aFilterResX)
{
*aFilterResX = mFilterResX;
NS_IF_ADDREF(*aFilterResX);
return NS_OK;
return mIntegerAttributes[FILTERRES_X].ToDOMAnimatedInteger(aFilterResX, this);
}
/* readonly attribute nsIDOMSVGAnimatedEnumeration filterResY; */
NS_IMETHODIMP nsSVGFilterElement::GetFilterResY(nsIDOMSVGAnimatedInteger * *aFilterResY)
{
*aFilterResY = mFilterResY;
NS_IF_ADDREF(*aFilterResY);
return NS_OK;
return mIntegerAttributes[FILTERRES_Y].ToDOMAnimatedInteger(aFilterResY, this);
}
/* void setFilterRes (in unsigned long filterResX, in unsigned long filterResY);
@ -187,8 +176,8 @@ NS_IMETHODIMP nsSVGFilterElement::GetFilterResY(nsIDOMSVGAnimatedInteger * *aFil
NS_IMETHODIMP
nsSVGFilterElement::SetFilterRes(PRUint32 filterResX, PRUint32 filterResY)
{
mFilterResX->SetBaseVal(filterResX);
mFilterResY->SetBaseVal(filterResY);
mIntegerAttributes[FILTERRES_X].SetBaseValue(filterResX, this, PR_FALSE);
mIntegerAttributes[FILTERRES_Y].SetBaseValue(filterResY, this, PR_FALSE);
return NS_OK;
}
@ -222,12 +211,12 @@ nsSVGFilterElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
int num = sscanf(str, "%d %d\n", &resX, &resY);
switch (num) {
case 2:
mFilterResX->SetBaseVal(resX);
mFilterResY->SetBaseVal(resY);
mIntegerAttributes[FILTERRES_X].SetBaseValue(resX, this, PR_FALSE);
mIntegerAttributes[FILTERRES_Y].SetBaseValue(resY, this, PR_FALSE);
break;
case 1:
mFilterResX->SetBaseVal(resX);
mFilterResY->SetBaseVal(resX);
mIntegerAttributes[FILTERRES_X].SetBaseValue(resX, this, PR_FALSE);
mIntegerAttributes[FILTERRES_Y].SetBaseValue(resX, this, PR_FALSE);
break;
default:
break;
@ -238,20 +227,6 @@ nsSVGFilterElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
return rv;
}
nsresult
nsSVGFilterElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
PRBool aNotify)
{
if (aName == nsGkAtoms::filterRes && aNamespaceID == kNameSpaceID_None) {
mFilterResX->SetBaseVal(0);
mFilterResY->SetBaseVal(0);
return nsGenericElement::UnsetAttr(aNamespaceID, aName, aNotify);
}
return nsSVGFilterElementBase::UnsetAttr(aNamespaceID, aName, aNotify);
}
NS_IMETHODIMP_(PRBool)
nsSVGFilterElement::IsAttributeMapped(const nsIAtom* name) const
{
@ -279,6 +254,13 @@ nsSVGFilterElement::GetLengthInfo()
NS_ARRAY_LENGTH(sLengthInfo));
}
nsSVGElement::IntegerAttributesInfo
nsSVGFilterElement::GetIntegerInfo()
{
return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
NS_ARRAY_LENGTH(sIntegerInfo));
}
nsSVGElement::EnumAttributesInfo
nsSVGFilterElement::GetEnumInfo()
{

Просмотреть файл

@ -42,6 +42,7 @@
#include "nsIDOMSVGURIReference.h"
#include "nsIDOMSVGUnitTypes.h"
#include "nsSVGLength2.h"
#include "nsSVGInteger.h"
#include "nsSVGEnum.h"
typedef nsSVGGraphicElement nsSVGFilterElementBase;
@ -79,8 +80,6 @@ public:
virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
nsIAtom* aPrefix, const nsAString& aValue,
PRBool aNotify);
virtual nsresult UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
PRBool aNotify);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
@ -88,18 +87,21 @@ public:
protected:
virtual LengthAttributesInfo GetLengthInfo();
virtual IntegerAttributesInfo GetIntegerInfo();
virtual EnumAttributesInfo GetEnumInfo();
enum { X, Y, WIDTH, HEIGHT };
nsSVGLength2 mLengthAttributes[4];
static LengthInfo sLengthInfo[4];
enum { FILTERRES_X, FILTERRES_Y };
nsSVGInteger mIntegerAttributes[2];
static IntegerInfo sIntegerInfo[2];
enum { FILTERUNITS, PRIMITIVEUNITS };
nsSVGEnum mEnumAttributes[2];
static EnumInfo sEnumInfo[2];
nsCOMPtr<nsIDOMSVGAnimatedInteger> mFilterResX;
nsCOMPtr<nsIDOMSVGAnimatedInteger> mFilterResY;
nsCOMPtr<nsIDOMSVGAnimatedString> mHref;
};

Просмотреть файл

@ -39,6 +39,7 @@
#include "nsSVGLength.h"
#include "nsGkAtoms.h"
#include "nsSVGNumber2.h"
#include "nsSVGInteger.h"
#include "nsIDOMSVGFilters.h"
#include "nsCOMPtr.h"
#include "nsISVGFilter.h"
@ -57,7 +58,6 @@
#include "nsStyleContext.h"
#include "nsIDocument.h"
#include "nsIFrame.h"
#include "nsSVGAnimatedInteger.h"
#include "gfxContext.h"
#include "nsSVGAnimatedBoolean.h"
#include "nsSVGLengthList.h"
@ -334,10 +334,14 @@ nsSVGFE::ScanDualValueAttribute(const nsAString& aValue, nsIAtom* aAttribute,
ReportAttributeParseFailure(GetOwnerDoc(), aAttribute, aValue);
x = aInfo1->mDefaultValue;
y = aInfo2->mDefaultValue;
return PR_FALSE;
}
aNum1->SetBaseValue(x, this, PR_FALSE);
aNum2->SetBaseValue(y, this, PR_FALSE);
if (parseError)
return PR_FALSE;
aResult.SetTo(aValue);
return PR_TRUE;
}
@ -1971,13 +1975,6 @@ nsSVGComponentTransferFunctionElement::Init()
return NS_OK;
}
nsSVGElement::EnumAttributesInfo
nsSVGComponentTransferFunctionElement::GetEnumInfo()
{
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
NS_ARRAY_LENGTH(sEnumInfo));
}
//----------------------------------------------------------------------
// nsIDOMSVGComponentTransferFunctionElement methods
@ -2122,6 +2119,13 @@ nsSVGComponentTransferFunctionElement::GenerateLookupTable(PRUint8 *aTable)
//----------------------------------------------------------------------
// nsSVGElement methods
nsSVGElement::EnumAttributesInfo
nsSVGComponentTransferFunctionElement::GetEnumInfo()
{
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
NS_ARRAY_LENGTH(sEnumInfo));
}
nsSVGElement::NumberAttributesInfo
nsSVGComponentTransferFunctionElement::GetNumberInfo()
{
@ -2983,7 +2987,6 @@ class nsSVGFETurbulenceElement : public nsSVGFETurbulenceElementBase,
protected:
nsSVGFETurbulenceElement(nsINodeInfo* aNodeInfo)
: nsSVGFETurbulenceElementBase(aNodeInfo) {}
nsresult Init();
public:
virtual PRBool SubregionIsUnionOfRegions() { return PR_FALSE; }
@ -3010,25 +3013,26 @@ public:
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
virtual nsresult UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
PRBool aNotify);
protected:
virtual NumberAttributesInfo GetNumberInfo();
virtual IntegerAttributesInfo GetIntegerInfo();
virtual EnumAttributesInfo GetEnumInfo();
enum { BASE_FREQ_X, BASE_FREQ_Y, SEED}; // floating point seed?!
nsSVGNumber2 mNumberAttributes[3];
static NumberInfo sNumberInfo[3];
enum { OCTAVES };
nsSVGInteger mIntegerAttributes[1];
static IntegerInfo sIntegerInfo[1];
enum { STITCHTILES, TYPE };
nsSVGEnum mEnumAttributes[2];
static nsSVGEnumMapping sStitchTilesMap[];
static nsSVGEnumMapping sTypeMap[];
static EnumInfo sEnumInfo[2];
nsCOMPtr<nsIDOMSVGAnimatedInteger> mNumOctaves;
private:
/* The turbulence calculation code is an adapted version of what
@ -3082,7 +3086,7 @@ private:
int mWrapY;
};
void Init(PRInt32 aSeed);
void InitSeed(PRInt32 aSeed);
double Noise2(int aColorChannel, double aVec[2], StitchInfo *aStitchInfo);
double
Turbulence(int aColorChannel, double *aPoint, double aBaseFreqX,
@ -3098,6 +3102,11 @@ nsSVGElement::NumberInfo nsSVGFETurbulenceElement::sNumberInfo[3] =
{ &nsGkAtoms::seed, 0 }
};
nsSVGElement::IntegerInfo nsSVGFETurbulenceElement::sIntegerInfo[1] =
{
{ &nsGkAtoms::numOctaves, 1 }
};
nsSVGEnumMapping nsSVGFETurbulenceElement::sTypeMap[] = {
{&nsGkAtoms::fractalNoise,
nsIDOMSVGFETurbulenceElement::SVG_TURBULENCE_TYPE_FRACTALNOISE},
@ -3144,35 +3153,6 @@ NS_INTERFACE_MAP_BEGIN(nsSVGFETurbulenceElement)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGFETurbulenceElement)
NS_INTERFACE_MAP_END_INHERITING(nsSVGFETurbulenceElementBase)
//----------------------------------------------------------------------
// Implementation
nsresult
nsSVGFETurbulenceElement::Init()
{
nsresult rv = nsSVGFETurbulenceElementBase::Init();
NS_ENSURE_SUCCESS(rv,rv);
// Create mapped properties:
// DOM property: numOctaves , #IMPLIED attrib: numOctaves
{
rv = NS_NewSVGAnimatedInteger(getter_AddRefs(mNumOctaves), 1);
NS_ENSURE_SUCCESS(rv,rv);
rv = AddMappedSVGValue(nsGkAtoms::numOctaves, mNumOctaves);
NS_ENSURE_SUCCESS(rv,rv);
}
return rv;
}
nsSVGElement::EnumAttributesInfo
nsSVGFETurbulenceElement::GetEnumInfo()
{
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
NS_ARRAY_LENGTH(sEnumInfo));
}
//----------------------------------------------------------------------
// nsIDOMNode methods
@ -3196,9 +3176,7 @@ NS_IMETHODIMP nsSVGFETurbulenceElement::GetBaseFrequencyY(nsIDOMSVGAnimatedNumbe
/* readonly attribute nsIDOMSVGAnimatedInteger numOctaves; */
NS_IMETHODIMP nsSVGFETurbulenceElement::GetNumOctaves(nsIDOMSVGAnimatedInteger * *aNum)
{
*aNum = mNumOctaves;
NS_IF_ADDREF(*aNum);
return NS_OK;
return mIntegerAttributes[OCTAVES].ToDOMAnimatedInteger(aNum, this);
}
/* readonly attribute nsIDOMSVGAnimatedNumber seed; */
@ -3236,18 +3214,6 @@ nsSVGFETurbulenceElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
aValue, aResult);
}
nsresult
nsSVGFETurbulenceElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
PRBool aNotify)
{
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::numOctaves) {
mNumOctaves->SetBaseVal(1);
return nsGenericElement::UnsetAttr(aNamespaceID, aName, aNotify);
}
return nsSVGFETurbulenceElementBase::UnsetAttr(aNamespaceID, aName, aNotify);
}
NS_IMETHODIMP
nsSVGFETurbulenceElement::Filter(nsSVGFilterInstance *instance)
{
@ -3276,9 +3242,9 @@ nsSVGFETurbulenceElement::Filter(nsSVGFilterInstance *instance)
PRUint16 stitch = mEnumAttributes[STITCHTILES].GetAnimValue();
GetAnimatedNumberValues(&fX, &fY, &seed, nsnull);
mNumOctaves->GetAnimVal(&octaves);
GetAnimatedIntegerValues(&octaves, nsnull);
Init((PRInt32)seed);
InitSeed((PRInt32)seed);
float filterX, filterY, filterWidth, filterHeight;
instance->GetFilterBox(&filterX, &filterY, &filterWidth, &filterHeight);
@ -3350,7 +3316,7 @@ nsSVGFETurbulenceElement::GetRequirements(PRUint32 *aRequirements)
}
void
nsSVGFETurbulenceElement::Init(PRInt32 aSeed)
nsSVGFETurbulenceElement::InitSeed(PRInt32 aSeed)
{
double s;
int i, j, k;
@ -3514,6 +3480,20 @@ nsSVGFETurbulenceElement::GetNumberInfo()
NS_ARRAY_LENGTH(sNumberInfo));
}
nsSVGElement::IntegerAttributesInfo
nsSVGFETurbulenceElement::GetIntegerInfo()
{
return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
NS_ARRAY_LENGTH(sIntegerInfo));
}
nsSVGElement::EnumAttributesInfo
nsSVGFETurbulenceElement::GetEnumInfo()
{
return EnumAttributesInfo(mEnumAttributes, sEnumInfo,
NS_ARRAY_LENGTH(sEnumInfo));
}
//---------------------Morphology------------------------
typedef nsSVGFE nsSVGFEMorphologyElementBase;
@ -3860,21 +3840,22 @@ protected:
}
virtual NumberAttributesInfo GetNumberInfo();
virtual IntegerAttributesInfo GetIntegerInfo();
virtual EnumAttributesInfo GetEnumInfo();
enum { DIVISOR, BIAS, KERNEL_UNIT_LENGTH_X, KERNEL_UNIT_LENGTH_Y };
nsSVGNumber2 mNumberAttributes[4];
static NumberInfo sNumberInfo[4];
enum { ORDER_X, ORDER_Y, TARGET_X, TARGET_Y };
nsSVGInteger mIntegerAttributes[4];
static IntegerInfo sIntegerInfo[4];
enum { EDGEMODE };
nsSVGEnum mEnumAttributes[1];
static nsSVGEnumMapping sEdgeModeMap[];
static EnumInfo sEnumInfo[1];
nsCOMPtr<nsIDOMSVGAnimatedInteger> mOrderX;
nsCOMPtr<nsIDOMSVGAnimatedInteger> mOrderY;
nsCOMPtr<nsIDOMSVGAnimatedInteger> mTargetX;
nsCOMPtr<nsIDOMSVGAnimatedInteger> mTargetY;
nsCOMPtr<nsIDOMSVGAnimatedNumberList> mKernelMatrix;
nsCOMPtr<nsIDOMSVGAnimatedBoolean> mPreserveAlpha;
@ -3889,6 +3870,14 @@ nsSVGElement::NumberInfo nsSVGFEConvolveMatrixElement::sNumberInfo[4] =
{ &nsGkAtoms::kernelUnitLength, 0 }
};
nsSVGElement::IntegerInfo nsSVGFEConvolveMatrixElement::sIntegerInfo[4] =
{
{ &nsGkAtoms::order, 0 },
{ &nsGkAtoms::order, 0 },
{ &nsGkAtoms::targetX, 0 },
{ &nsGkAtoms::targetY, 0 }
};
nsSVGEnumMapping nsSVGFEConvolveMatrixElement::sEdgeModeMap[] = {
{&nsGkAtoms::duplicate, nsSVGFEConvolveMatrixElement::SVG_EDGEMODE_DUPLICATE},
{&nsGkAtoms::wrap, nsSVGFEConvolveMatrixElement::SVG_EDGEMODE_WRAP},
@ -3944,29 +3933,6 @@ nsSVGFEConvolveMatrixElement::Init()
NS_ENSURE_SUCCESS(rv,rv);
}
{
rv = NS_NewSVGAnimatedInteger(getter_AddRefs(mOrderX), 0);
NS_ENSURE_SUCCESS(rv,rv);
rv = NS_NewSVGAnimatedInteger(getter_AddRefs(mOrderY), 0);
NS_ENSURE_SUCCESS(rv,rv);
}
// DOM property: targetX , #IMPLIED attrib: targetX
{
rv = NS_NewSVGAnimatedInteger(getter_AddRefs(mTargetX), 0);
NS_ENSURE_SUCCESS(rv,rv);
rv = AddMappedSVGValue(nsGkAtoms::targetX, mTargetX);
NS_ENSURE_SUCCESS(rv,rv);
}
// DOM property: targetY , #IMPLIED attrib: targetY
{
rv = NS_NewSVGAnimatedInteger(getter_AddRefs(mTargetY), 0);
NS_ENSURE_SUCCESS(rv,rv);
rv = AddMappedSVGValue(nsGkAtoms::targetY, mTargetY);
NS_ENSURE_SUCCESS(rv,rv);
}
// DOM property: preserveAlpha , #IMPLIED attrib: preserveAlpha
{
rv = NS_NewSVGAnimatedBoolean(getter_AddRefs(mPreserveAlpha), PR_FALSE);
@ -4003,16 +3969,12 @@ NS_IMETHODIMP nsSVGFEConvolveMatrixElement::GetIn1(nsIDOMSVGAnimatedString * *aI
NS_IMETHODIMP nsSVGFEConvolveMatrixElement::GetOrderX(nsIDOMSVGAnimatedInteger * *aOrderX)
{
*aOrderX = mOrderX;
NS_IF_ADDREF(*aOrderX);
return NS_OK;
return mIntegerAttributes[ORDER_X].ToDOMAnimatedInteger(aOrderX, this);
}
NS_IMETHODIMP nsSVGFEConvolveMatrixElement::GetOrderY(nsIDOMSVGAnimatedInteger * *aOrderY)
{
*aOrderY = mOrderY;
NS_IF_ADDREF(*aOrderY);
return NS_OK;
return mIntegerAttributes[ORDER_Y].ToDOMAnimatedInteger(aOrderY, this);
}
NS_IMETHODIMP nsSVGFEConvolveMatrixElement::GetKernelMatrix(nsIDOMSVGAnimatedNumberList * *aKernelMatrix)
@ -4024,16 +3986,12 @@ NS_IMETHODIMP nsSVGFEConvolveMatrixElement::GetKernelMatrix(nsIDOMSVGAnimatedNum
NS_IMETHODIMP nsSVGFEConvolveMatrixElement::GetTargetX(nsIDOMSVGAnimatedInteger * *aTargetX)
{
*aTargetX = mTargetX;
NS_IF_ADDREF(*aTargetX);
return NS_OK;
return mIntegerAttributes[TARGET_X].ToDOMAnimatedInteger(aTargetX, this);
}
NS_IMETHODIMP nsSVGFEConvolveMatrixElement::GetTargetY(nsIDOMSVGAnimatedInteger * *aTargetY)
{
*aTargetY = mTargetY;
NS_IF_ADDREF(*aTargetY);
return NS_OK;
return mIntegerAttributes[TARGET_Y].ToDOMAnimatedInteger(aTargetY, this);
}
NS_IMETHODIMP nsSVGFEConvolveMatrixElement::GetEdgeMode(nsIDOMSVGAnimatedEnumeration * *aEdgeMode)
@ -4111,13 +4069,18 @@ nsSVGFEConvolveMatrixElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aNam
}
}
mOrderX->SetBaseVal(x);
mOrderY->SetBaseVal(y);
if (parseError) {
ReportAttributeParseFailure(GetOwnerDoc(), aName, aValue);
return PR_FALSE;
x = sIntegerInfo[ORDER_X].mDefaultValue;
y = sIntegerInfo[ORDER_Y].mDefaultValue;
}
mIntegerAttributes[ORDER_X].SetBaseValue(x, this, PR_FALSE);
mIntegerAttributes[ORDER_Y].SetBaseValue(y, this, PR_FALSE);
if (parseError)
return PR_FALSE;
aResult.SetTo(aValue);
return PR_TRUE;
}
@ -4137,28 +4100,11 @@ nsSVGFEConvolveMatrixElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aNam
nsresult
nsSVGFEConvolveMatrixElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
PRBool aNotify)
PRBool aNotify)
{
if (aNamespaceID == kNameSpaceID_None) {
PRBool processed = PR_FALSE;
if (aName == nsGkAtoms::order) {
mOrderX->SetBaseVal(0);
mOrderY->SetBaseVal(0);
processed = PR_TRUE;
} else if (aName == nsGkAtoms::targetX) {
mTargetX->SetBaseVal(0);
processed = PR_TRUE;
} else if (aName == nsGkAtoms::targetY) {
mTargetY->SetBaseVal(0);
processed = PR_TRUE;
} else if (aName == nsGkAtoms::preserveAlpha) {
mPreserveAlpha->SetBaseVal(PR_FALSE);
processed = PR_TRUE;
}
if (processed) {
return nsGenericElement::UnsetAttr(aNamespaceID, aName, aNotify);
}
if (aNamespaceID == kNameSpaceID_None && aName == nsGkAtoms::preserveAlpha) {
mPreserveAlpha->SetBaseVal(PR_FALSE);
return nsGenericElement::UnsetAttr(aNamespaceID, aName, aNotify);
}
return nsSVGFEConvolveMatrixElementBase::UnsetAttr(aNamespaceID, aName, aNotify);
@ -4247,23 +4193,21 @@ nsSVGFEConvolveMatrixElement::Filter(nsSVGFilterInstance *instance)
}
PRInt32 orderX, orderY;
mOrderX->GetAnimVal(&orderX);
mOrderY->GetAnimVal(&orderY);
PRInt32 targetX, targetY;
GetAnimatedIntegerValues(&orderX, &orderY, &targetX, &targetY, nsnull);
if (orderX <= 0 || orderY <= 0 ||
static_cast<PRUint32>(orderX * orderY) != num) {
return NS_ERROR_FAILURE;
}
PRInt32 targetX, targetY;
if (HasAttr(kNameSpaceID_None, nsGkAtoms::targetX)) {
mTargetX->GetAnimVal(&targetX);
if (targetX < 0 || targetX >= orderX)
return NS_ERROR_FAILURE;
} else {
targetX = orderX / 2;
}
if (HasAttr(kNameSpaceID_None, nsGkAtoms::targetY)) {
mTargetY->GetAnimVal(&targetY);
if (targetY < 0 || targetY >= orderY)
return NS_ERROR_FAILURE;
} else {
@ -4355,6 +4299,13 @@ nsSVGFEConvolveMatrixElement::GetNumberInfo()
NS_ARRAY_LENGTH(sNumberInfo));
}
nsSVGElement::IntegerAttributesInfo
nsSVGFEConvolveMatrixElement::GetIntegerInfo()
{
return IntegerAttributesInfo(mIntegerAttributes, sIntegerInfo,
NS_ARRAY_LENGTH(sIntegerInfo));
}
nsSVGElement::EnumAttributesInfo
nsSVGFEConvolveMatrixElement::GetEnumInfo()
{

Просмотреть файл

@ -0,0 +1,95 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla SVG project.
*
* The Initial Developer of the Original Code is Robert Longson.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#include "nsSVGInteger.h"
#include "nsTextFormatter.h"
#include "prdtoa.h"
NS_IMPL_ADDREF(nsSVGInteger::DOMAnimatedInteger)
NS_IMPL_RELEASE(nsSVGInteger::DOMAnimatedInteger)
NS_INTERFACE_MAP_BEGIN(nsSVGInteger::DOMAnimatedInteger)
NS_INTERFACE_MAP_ENTRY(nsIDOMSVGAnimatedInteger)
NS_INTERFACE_MAP_ENTRY(nsISupports)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(SVGAnimatedInteger)
NS_INTERFACE_MAP_END
/* Implementation */
nsresult
nsSVGInteger::SetBaseValueString(const nsAString &aValueAsString,
nsSVGElement *aSVGElement,
PRBool aDoSetAttr)
{
nsAutoString s;
s.Assign(aValueAsString);
PRInt32 err;
PRInt32 val = s.ToInteger(&err);
nsresult rv = static_cast<nsresult>(err);
NS_ENSURE_SUCCESS(rv, rv);
mBaseVal = mAnimVal = val;
return NS_OK;
}
void
nsSVGInteger::GetBaseValueString(nsAString & aValueAsString)
{
nsAutoString s;
s.AppendInt(mBaseVal);
aValueAsString.Assign(s);
}
void
nsSVGInteger::SetBaseValue(int aValue,
nsSVGElement *aSVGElement,
PRBool aDoSetAttr)
{
mAnimVal = mBaseVal = aValue;
aSVGElement->DidChangeInteger(mAttrEnum, aDoSetAttr);
}
nsresult
nsSVGInteger::ToDOMAnimatedInteger(nsIDOMSVGAnimatedInteger **aResult,
nsSVGElement *aSVGElement)
{
*aResult = new DOMAnimatedInteger(this, aSVGElement);
if (!*aResult)
return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(*aResult);
return NS_OK;
}

Просмотреть файл

@ -0,0 +1,93 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Mozilla SVG project.
*
* The Initial Developer of the Original Code is Robert Longson.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later (the "GPL"),
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
#ifndef __NS_SVGINTEGER_H__
#define __NS_SVGINTEGER_H__
#include "nsIDOMSVGAnimatedInteger.h"
#include "nsSVGElement.h"
#include "nsDOMError.h"
class nsSVGInteger
{
public:
void Init(PRUint8 aAttrEnum = 0xff, PRInt32 aValue = 0) {
mAnimVal = mBaseVal = aValue;
mAttrEnum = aAttrEnum;
}
nsresult SetBaseValueString(const nsAString& aValue,
nsSVGElement *aSVGElement,
PRBool aDoSetAttr);
void GetBaseValueString(nsAString& aValue);
void SetBaseValue(PRInt32 aValue, nsSVGElement *aSVGElement, PRBool aDoSetAttr);
PRInt32 GetBaseValue() const
{ return mBaseVal; }
PRInt32 GetAnimValue() const
{ return mAnimVal; }
nsresult ToDOMAnimatedInteger(nsIDOMSVGAnimatedInteger **aResult,
nsSVGElement* aSVGElement);
private:
PRInt32 mAnimVal;
PRInt32 mBaseVal;
PRUint8 mAttrEnum; // element specified tracking for attribute
struct DOMAnimatedInteger : public nsIDOMSVGAnimatedInteger
{
NS_DECL_ISUPPORTS
DOMAnimatedInteger(nsSVGInteger* aVal, nsSVGElement *aSVGElement)
: mVal(aVal), mSVGElement(aSVGElement) {}
nsSVGInteger* mVal; // kept alive because it belongs to content
nsRefPtr<nsSVGElement> mSVGElement;
NS_IMETHOD GetBaseVal(PRInt32* aResult)
{ *aResult = mVal->GetBaseValue(); return NS_OK; }
NS_IMETHOD SetBaseVal(PRInt32 aValue)
{ mVal->SetBaseValue(aValue, mSVGElement, PR_TRUE); return NS_OK; }
NS_IMETHOD GetAnimVal(PRInt32* aResult)
{ *aResult = mVal->GetAnimValue(); return NS_OK; }
};
};
#endif //__NS_SVGINTEGER_H__

Просмотреть файл

@ -41,7 +41,6 @@
#include "nsSVGOuterSVGFrame.h"
#include "nsISVGFilter.h"
#include "nsGkAtoms.h"
#include "nsIDOMSVGAnimatedInteger.h"
#include "nsSVGUtils.h"
#include "nsSVGFilterElement.h"
#include "nsSVGFilterInstance.h"
@ -170,8 +169,7 @@ nsSVGFilterFrame::FilterPaint(nsSVGRenderState *aContext,
if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::filterRes)) {
PRInt32 filterResX, filterResY;
filter->mFilterResX->GetAnimVal(&filterResX);
filter->mFilterResY->GetAnimVal(&filterResY);
filter->GetAnimatedIntegerValues(&filterResX, &filterResY, nsnull);
filterRes =
nsSVGUtils::ConvertToSurfaceSize(gfxSize(filterResX, filterResY),