Bug 441339 - Simplify number-optional-number parsing. r+sr=roc

This commit is contained in:
Robert Longson 2008-06-24 13:54:11 +01:00
parent f5c57c867f
commit 343cf22257
5 changed files with 93 additions and 190 deletions

View File

@ -316,7 +316,15 @@ nsSVGElement::ParseAttribute(PRInt32 aNamespaceID,
NumberAttributesInfo numberInfo = GetNumberInfo();
for (i = 0; i < numberInfo.mNumberCount; i++) {
if (aAttribute == *numberInfo.mNumberInfo[i].mName) {
rv = numberInfo.mNumbers[i].SetBaseValueString(aValue, this, PR_FALSE);
if (i + 1 < numberInfo.mNumberCount &&
aAttribute == *numberInfo.mNumberInfo[i + 1].mName) {
rv = ParseNumberOptionalNumber(aValue, i, i + 1);
if (NS_FAILED(rv)) {
numberInfo.Reset(i + 1);
}
} else {
rv = numberInfo.mNumbers[i].SetBaseValueString(aValue, this, PR_FALSE);
}
if (NS_FAILED(rv)) {
numberInfo.Reset(i);
}
@ -331,7 +339,15 @@ nsSVGElement::ParseAttribute(PRInt32 aNamespaceID,
IntegerAttributesInfo integerInfo = GetIntegerInfo();
for (i = 0; i < integerInfo.mIntegerCount; i++) {
if (aAttribute == *integerInfo.mIntegerInfo[i].mName) {
rv = integerInfo.mIntegers[i].SetBaseValueString(aValue, this, PR_FALSE);
if (i + 1 < integerInfo.mIntegerCount &&
aAttribute == *integerInfo.mIntegerInfo[i + 1].mName) {
rv = ParseIntegerOptionalInteger(aValue, i, i + 1);
if (NS_FAILED(rv)) {
integerInfo.Reset(i + 1);
}
} else {
rv = integerInfo.mIntegers[i].SetBaseValueString(aValue, this, PR_FALSE);
}
if (NS_FAILED(rv)) {
integerInfo.Reset(i);
}
@ -443,6 +459,7 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
lenInfo.Reset(i);
DidChangeLength(i, PR_FALSE);
foundMatch = PR_TRUE;
break;
}
}
}
@ -453,9 +470,16 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
for (PRUint32 i = 0; i < numInfo.mNumberCount; i++) {
if (aName == *numInfo.mNumberInfo[i].mName) {
if (i + 1 < numInfo.mNumberCount &&
aName == *numInfo.mNumberInfo[i + 1].mName) {
// found a number-optional-number
numInfo.Reset(i + 1);
DidChangeNumber(i + 1, PR_FALSE);
}
numInfo.Reset(i);
DidChangeNumber(i, PR_FALSE);
foundMatch = PR_TRUE;
break;
}
}
}
@ -466,9 +490,16 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
for (PRUint32 i = 0; i < intInfo.mIntegerCount; i++) {
if (aName == *intInfo.mIntegerInfo[i].mName) {
if (i + 1 < intInfo.mIntegerCount &&
aName == *intInfo.mIntegerInfo[i + 1].mName) {
// found a number-optional-number
intInfo.Reset(i + 1);
DidChangeNumber(i + 1, PR_FALSE);
}
intInfo.Reset(i);
DidChangeInteger(i, PR_FALSE);
foundMatch = PR_TRUE;
break;
}
}
}
@ -482,6 +513,7 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
angleInfo.Reset(i);
DidChangeAngle(i, PR_FALSE);
foundMatch = PR_TRUE;
break;
}
}
}
@ -508,6 +540,7 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
enumInfo.Reset(i);
DidChangeEnum(i, PR_FALSE);
foundMatch = PR_TRUE;
break;
}
}
}
@ -523,6 +556,7 @@ nsSVGElement::UnsetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
stringInfo.Reset(i);
DidChangeString(i, PR_FALSE);
foundMatch = PR_TRUE;
break;
}
}
}
@ -1375,104 +1409,87 @@ nsSVGElement::DidChangeString(PRUint8 aAttrEnum, PRBool aDoSetAttr)
info.mStrings[aAttrEnum].GetBaseValue(), PR_TRUE);
}
PRBool
nsSVGElement::ParseNumberOptionalNumber(nsIAtom* aAttribute, const nsAString& aValue,
PRUint32 aIndex1, PRUint32 aIndex2,
nsAttrValue& aResult)
nsresult
nsSVGElement::ParseNumberOptionalNumber(const nsAString& aValue,
PRUint32 aIndex1, PRUint32 aIndex2)
{
NS_ConvertUTF16toUTF8 value(aValue);
const char *str = value.get();
PRBool parseError = NS_IsAsciiWhitespace(*str);
float x, y;
if (NS_IsAsciiWhitespace(*str))
return NS_ERROR_FAILURE;
if (!parseError) {
char *rest;
x = y = float(PR_strtod(str, &rest));
char *rest;
float x = float(PR_strtod(str, &rest));
float y = x;
if (str == rest) {
//first value was illformed
parseError = PR_TRUE;
} else if (*rest != '\0') {
while (NS_IsAsciiWhitespace(*rest)) {
++rest;
}
if (*rest == ',') {
++rest;
}
if (str == rest) {
//first value was illformed
return NS_ERROR_FAILURE;
}
if (*rest != '\0') {
while (NS_IsAsciiWhitespace(*rest)) {
++rest;
}
if (*rest == ',') {
++rest;
}
y = float(PR_strtod(rest, &rest));
if (*rest != '\0') {
//second value was illformed or there was trailing content
parseError = PR_TRUE;
}
y = float(PR_strtod(rest, &rest));
if (*rest != '\0') {
//second value was illformed or there was trailing content
return NS_ERROR_FAILURE;
}
}
NumberAttributesInfo numberInfo = GetNumberInfo();
if (parseError) {
ReportAttributeParseFailure(GetOwnerDoc(), aAttribute, aValue);
x = numberInfo.mNumberInfo[aIndex1].mDefaultValue;
y = numberInfo.mNumberInfo[aIndex2].mDefaultValue;
} else {
aResult.SetTo(aValue);
}
numberInfo.mNumbers[aIndex1].SetBaseValue(x, this, PR_FALSE);
numberInfo.mNumbers[aIndex2].SetBaseValue(y, this, PR_FALSE);
return (!parseError);
return NS_OK;
}
PRBool
nsSVGElement::ParseIntegerOptionalInteger(nsIAtom* aAttribute, const nsAString& aValue,
PRUint32 aIndex1, PRUint32 aIndex2,
nsAttrValue& aResult)
nsresult
nsSVGElement::ParseIntegerOptionalInteger(const nsAString& aValue,
PRUint32 aIndex1, PRUint32 aIndex2)
{
NS_ConvertUTF16toUTF8 value(aValue);
const char *str = value.get();
PRBool parseError = NS_IsAsciiWhitespace(*str);
PRInt32 x, y;
if (NS_IsAsciiWhitespace(*str))
return NS_ERROR_FAILURE;
if (!parseError) {
char *rest;
x = y = strtol(str, &rest, 10);
char *rest;
PRInt32 x = strtol(str, &rest, 10);
PRInt32 y = x;
if (str == rest) {
//first value was illformed
parseError = PR_TRUE;
} else if (*rest != '\0') {
while (NS_IsAsciiWhitespace(*rest)) {
++rest;
}
if (*rest == ',') {
++rest;
}
if (str == rest) {
//first value was illformed
return NS_ERROR_FAILURE;
}
if (*rest != '\0') {
while (NS_IsAsciiWhitespace(*rest)) {
++rest;
}
if (*rest == ',') {
++rest;
}
y = strtol(rest, &rest, 10);
if (*rest != '\0') {
//second value was illformed or there was trailing content
parseError = PR_TRUE;
}
y = strtol(rest, &rest, 10);
if (*rest != '\0') {
//second value was illformed or there was trailing content
return NS_ERROR_FAILURE;
}
}
IntegerAttributesInfo integerInfo = GetIntegerInfo();
if (parseError) {
ReportAttributeParseFailure(GetOwnerDoc(), aAttribute, aValue);
x = integerInfo.mIntegerInfo[aIndex1].mDefaultValue;
y = integerInfo.mIntegerInfo[aIndex2].mDefaultValue;
} else {
aResult.SetTo(aValue);
}
integerInfo.mIntegers[aIndex1].SetBaseValue(x, this, PR_FALSE);
integerInfo.mIntegers[aIndex2].SetBaseValue(y, this, PR_FALSE);
return (!parseError);
return NS_OK;
}
nsresult

View File

@ -310,23 +310,21 @@ protected:
static nsSVGEnumMapping sSVGUnitTypesMap[];
private:
/* read <number-optional-number> */
PRBool
ParseNumberOptionalNumber(nsIAtom* aAttribute, const nsAString& aValue,
PRUint32 aIndex1, PRUint32 aIndex2,
nsAttrValue& aResult);
nsresult
ParseNumberOptionalNumber(const nsAString& aValue,
PRUint32 aIndex1, PRUint32 aIndex2);
/* read <integer-optional-integer> */
PRBool
ParseIntegerOptionalInteger(nsIAtom* aAttribute, const nsAString& aValue,
PRUint32 aIndex1, PRUint32 aIndex2,
nsAttrValue& aResult);
nsresult
ParseIntegerOptionalInteger(const nsAString& aValue,
PRUint32 aIndex1, PRUint32 aIndex2);
static nsresult ReportAttributeParseFailure(nsIDocument* aDocument,
nsIAtom* aAttribute,
const nsAString& aValue);
private:
void ResetOldStyleBaseType(nsISVGValue *svg_value);
nsCOMPtr<nsICSSStyleRule> mContentStyleRule;

View File

@ -175,20 +175,6 @@ nsSVGFilterElement::GetHref(nsIDOMSVGAnimatedString * *aHref)
//----------------------------------------------------------------------
// nsIContent methods
PRBool
nsSVGFilterElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aName == nsGkAtoms::filterRes && aNameSpaceID == kNameSpaceID_None) {
return ParseIntegerOptionalInteger(aName, aValue,
FILTERRES_X, FILTERRES_Y,
aResult);
}
return nsSVGFilterElementBase::ParseAttribute(aNameSpaceID, aName,
aValue, aResult);
}
NS_IMETHODIMP_(PRBool)
nsSVGFilterElement::IsAttributeMapped(const nsIAtom* name) const
{

View File

@ -85,10 +85,6 @@ public:
protected:
virtual PRBool ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult);
virtual LengthAttributesInfo GetLengthInfo();
virtual IntegerAttributesInfo GetIntegerInfo();
virtual EnumAttributesInfo GetEnumInfo();

View File

@ -528,9 +528,6 @@ public:
NS_FORWARD_NSIDOMNODE(nsSVGFEGaussianBlurElementBase::)
NS_FORWARD_NSIDOMELEMENT(nsSVGFEGaussianBlurElementBase::)
virtual PRBool ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
protected:
@ -631,20 +628,6 @@ nsSVGFEGaussianBlurElement::SetStdDeviation(float stdDeviationX, float stdDeviat
return NS_OK;
}
PRBool
nsSVGFEGaussianBlurElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aName == nsGkAtoms::stdDeviation && aNameSpaceID == kNameSpaceID_None) {
return ParseNumberOptionalNumber(aName, aValue,
STD_DEV_X, STD_DEV_Y,
aResult);
}
return nsSVGFEGaussianBlurElementBase::ParseAttribute(aNameSpaceID, aName,
aValue, aResult);
}
void
nsSVGFEGaussianBlurElement::BoxBlurH(PRUint8 *aInput, PRUint8 *aOutput,
PRInt32 aStride, const nsRect &aRegion,
@ -3110,9 +3093,6 @@ public:
NS_FORWARD_NSIDOMNODE(nsSVGFETurbulenceElementBase::)
NS_FORWARD_NSIDOMELEMENT(nsSVGFETurbulenceElementBase::)
virtual PRBool ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
protected:
@ -3307,20 +3287,6 @@ NS_IMETHODIMP nsSVGFETurbulenceElement::GetType(nsIDOMSVGAnimatedEnumeration * *
return mEnumAttributes[TYPE].ToDOMAnimatedEnum(aType, this);
}
PRBool
nsSVGFETurbulenceElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aName == nsGkAtoms::baseFrequency && aNameSpaceID == kNameSpaceID_None) {
return ParseNumberOptionalNumber(aName, aValue,
BASE_FREQ_X, BASE_FREQ_Y,
aResult);
}
return nsSVGFETurbulenceElementBase::ParseAttribute(aNameSpaceID, aName,
aValue, aResult);
}
nsresult
nsSVGFETurbulenceElement::Filter(nsSVGFilterInstance *instance)
{
@ -3638,9 +3604,6 @@ public:
NS_FORWARD_NSIDOMNODE(nsSVGFEMorphologyElementBase::)
NS_FORWARD_NSIDOMELEMENT(nsSVGFEMorphologyElementBase::)
virtual PRBool ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
protected:
@ -3751,20 +3714,6 @@ nsSVGFEMorphologyElement::SetRadius(float rx, float ry)
return NS_OK;
}
PRBool
nsSVGFEMorphologyElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aName == nsGkAtoms::radius && aNameSpaceID == kNameSpaceID_None) {
return ParseNumberOptionalNumber(aName, aValue,
RADIUS_X, RADIUS_Y,
aResult);
}
return nsSVGFEMorphologyElementBase::ParseAttribute(aNameSpaceID, aName,
aValue, aResult);
}
void
nsSVGFEMorphologyElement::GetSourceImageNames(nsTArray<nsSVGString*>* aSources)
{
@ -3972,9 +3921,6 @@ public:
NS_FORWARD_NSIDOMNODE(nsSVGFEConvolveMatrixElementBase::)
NS_FORWARD_NSIDOMELEMENT(nsSVGFEConvolveMatrixElementBase::)
virtual PRBool ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult);
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
protected:
@ -4197,28 +4143,6 @@ nsSVGFEConvolveMatrixElement::ComputeNeededSourceBBoxes(const nsRect& aTargetBBo
// source's output bounding box.
}
PRBool
nsSVGFEConvolveMatrixElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aNameSpaceID == kNameSpaceID_None) {
if (aName == nsGkAtoms::order) {
return ParseIntegerOptionalInteger(aName, aValue,
ORDER_X, ORDER_Y,
aResult);
}
if (aName == nsGkAtoms::kernelUnitLength) {
return ParseNumberOptionalNumber(aName, aValue,
KERNEL_UNIT_LENGTH_X, KERNEL_UNIT_LENGTH_Y,
aResult);
}
}
return nsSVGFEConvolveMatrixElementBase::ParseAttribute(aNameSpaceID, aName,
aValue, aResult);
}
static PRInt32 BoundInterval(PRInt32 aVal, PRInt32 aMax)
{
aVal = PR_MAX(aVal, 0);
@ -4770,9 +4694,6 @@ public:
NS_IMETHOD_(PRBool) IsAttributeMapped(const nsIAtom* aAttribute) const;
virtual PRBool ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult);
protected:
virtual void
LightPixel(const float *N, const float *L,
@ -4830,21 +4751,6 @@ nsSVGFELightingElement::IsAttributeMapped(const nsIAtom* name) const
nsSVGFELightingElementBase::IsAttributeMapped(name);
}
PRBool
nsSVGFELightingElement::ParseAttribute(PRInt32 aNameSpaceID, nsIAtom* aName,
const nsAString& aValue,
nsAttrValue& aResult)
{
if (aName == nsGkAtoms::kernelUnitLength && aNameSpaceID == kNameSpaceID_None) {
return ParseNumberOptionalNumber(aName, aValue,
KERNEL_UNIT_LENGTH_X, KERNEL_UNIT_LENGTH_Y,
aResult);
}
return nsSVGFELightingElementBase::ParseAttribute(aNameSpaceID, aName,
aValue, aResult);
}
void
nsSVGFELightingElement::GetSourceImageNames(nsTArray<nsSVGString*>* aSources)
{