Bug 629200 part 10 - Remove unnecessary serialisation from setting nsSVGNumber2; r=jwatt

This commit is contained in:
Brian Birtles 2012-02-16 08:40:45 +09:00
parent b950210d56
commit 6ff2b4dd52
7 changed files with 43 additions and 13 deletions

View File

@ -325,6 +325,17 @@ nsAttrValue::SetTo(PRInt16 aInt)
SetIntValueAndType(aInt, eInteger, nsnull);
}
void
nsAttrValue::SetTo(double aValue, const nsAString* aSerialized)
{
if (EnsureEmptyMiscContainer()) {
MiscContainer* cont = GetMiscContainer();
cont->mDoubleValue = aValue;
cont->mType = eDoubleValue;
SetMiscAtomOrString(aSerialized);
}
}
void
nsAttrValue::SetTo(css::StyleRule* aValue, const nsAString* aSerialized)
{

View File

@ -141,6 +141,7 @@ public:
void SetTo(const nsAString& aValue);
void SetTo(nsIAtom* aValue);
void SetTo(PRInt16 aInt);
void SetTo(double aValue, const nsAString* aSerialized);
void SetTo(mozilla::css::StyleRule* aValue, const nsAString* aSerialized);
void SetTo(const nsIntMargin& aValue);
void SetTo(const nsSVGLength2& aValue, const nsAString* aSerialized);

View File

@ -394,6 +394,9 @@ nsSVGElement::ParseAttribute(PRInt32 aNamespaceID,
rv = numberInfo.mNumbers[i].SetBaseValueString(aValue, this);
if (NS_FAILED(rv)) {
numberInfo.Reset(i);
} else {
aResult.SetTo(numberInfo.mNumbers[i].GetBaseValue(), &aValue);
didSetResult = true;
}
foundMatch = true;
break;
@ -662,7 +665,6 @@ nsSVGElement::UnsetAttrInternal(PRInt32 aNamespaceID, nsIAtom* aName,
for (PRUint32 i = 0; i < numInfo.mNumberCount; i++) {
if (aName == *numInfo.mNumberInfo[i].mName) {
numInfo.Reset(i);
DidChangeNumber(i, false);
return;
}
}
@ -1798,22 +1800,17 @@ void nsSVGElement::NumberAttributesInfo::Reset(PRUint8 aAttrEnum)
}
void
nsSVGElement::DidChangeNumber(PRUint8 aAttrEnum, bool aDoSetAttr)
nsSVGElement::DidChangeNumber(PRUint8 aAttrEnum)
{
if (!aDoSetAttr)
return;
NumberAttributesInfo info = GetNumberInfo();
NS_ASSERTION(info.mNumberCount > 0,
"DidChangeNumber on element with no number attribs");
NS_ASSERTION(aAttrEnum < info.mNumberCount, "aAttrEnum out of range");
nsAutoString serializedValue;
info.mNumbers[aAttrEnum].GetBaseValueString(serializedValue);
nsAttrValue attrValue;
attrValue.SetTo(info.mNumbers[aAttrEnum].GetBaseValue(), nsnull);
nsAttrValue attrValue(serializedValue);
SetParsedAttr(kNameSpaceID_None, *info.mNumberInfo[aAttrEnum].mName, nsnull,
attrValue, true);
}

View File

@ -174,7 +174,7 @@ public:
nsAttrValue WillChangeLengthList(PRUint8 aAttrEnum);
void DidChangeLength(PRUint8 aAttrEnum, const nsAttrValue& aEmptyOrOldValue);
virtual void DidChangeNumber(PRUint8 aAttrEnum, bool aDoSetAttr);
void DidChangeNumber(PRUint8 aAttrEnum);
virtual void DidChangeNumberPair(PRUint8 aAttrEnum, bool aDoSetAttr);
virtual void DidChangeInteger(PRUint8 aAttrEnum, bool aDoSetAttr);
virtual void DidChangeIntegerPair(PRUint8 aAttrEnum, bool aDoSetAttr);

View File

@ -149,9 +149,12 @@ nsSVGNumber2::GetBaseValueString(nsAString & aValueAsString)
}
void
nsSVGNumber2::SetBaseValue(float aValue,
nsSVGElement *aSVGElement)
nsSVGNumber2::SetBaseValue(float aValue, nsSVGElement *aSVGElement)
{
if (mIsBaseSet && aValue == mBaseVal) {
return;
}
mBaseVal = aValue;
mIsBaseSet = true;
if (!mIsAnimated) {
@ -160,7 +163,7 @@ nsSVGNumber2::SetBaseValue(float aValue,
else {
aSVGElement->AnimationNeedsResample();
}
aSVGElement->DidChangeNumber(mAttrEnum, true);
aSVGElement->DidChangeNumber(mAttrEnum);
}
void

View File

@ -72,6 +72,11 @@ function runTests()
is(convolve.divisor.animVal, 7.5, "number animVal");
is(convolve.getAttribute("divisor"), "7.5", "number attribute");
convolve.setAttribute("divisor", "");
ok(convolve.getAttribute("divisor") === "", "empty number attribute");
convolve.removeAttribute("divisor");
ok(convolve.getAttribute("divisor") === null, "removed number attribute");
// number-optional-number attribute
blur.setAttribute("stdDeviation", "20.5");

View File

@ -64,6 +64,19 @@ function runTests()
marker.markerWidth.baseVal.newValueSpecifiedUnits(
SVGLength.SVG_LENGTHTYPE_NUMBER, 8);
// number attribute
eventChecker.watchAttr(convolve, "divisor");
eventChecker.expect("add modify remove add");
convolve.setAttribute("divisor", "12.5");
convolve.divisor.baseVal = 6;
convolve.removeAttribute("divisor");
convolve.divisor.baseVal = 8;
eventChecker.expect("");
convolve.divisor.baseVal = 8;
convolve.setAttribute("divisor", "8");
// enum attribute
eventChecker.watchAttr(convolve, "edgeMode");