зеркало из https://github.com/mozilla/gecko-dev.git
Bug 629200 part 17 - Remove unnecessary serialisation from setting nsSVGPreserveAspectRatio; r=jwatt
This commit is contained in:
Родитель
05b3affab8
Коммит
e740b47772
|
@ -55,6 +55,7 @@
|
||||||
#include "nsSVGIntegerPair.h"
|
#include "nsSVGIntegerPair.h"
|
||||||
#include "nsSVGLength2.h"
|
#include "nsSVGLength2.h"
|
||||||
#include "nsSVGNumberPair.h"
|
#include "nsSVGNumberPair.h"
|
||||||
|
#include "SVGAnimatedPreserveAspectRatio.h"
|
||||||
#include "SVGLengthList.h"
|
#include "SVGLengthList.h"
|
||||||
|
|
||||||
namespace css = mozilla::css;
|
namespace css = mozilla::css;
|
||||||
|
@ -294,6 +295,11 @@ nsAttrValue::SetTo(const nsAttrValue& aOther)
|
||||||
cont->mSVGNumberPair = otherCont->mSVGNumberPair;
|
cont->mSVGNumberPair = otherCont->mSVGNumberPair;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case eSVGPreserveAspectRatio:
|
||||||
|
{
|
||||||
|
cont->mSVGPreserveAspectRatio = otherCont->mSVGPreserveAspectRatio;
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
NS_NOTREACHED("unknown type stored in MiscContainer");
|
NS_NOTREACHED("unknown type stored in MiscContainer");
|
||||||
|
@ -451,6 +457,18 @@ nsAttrValue::SetTo(const nsSVGNumberPair& aValue, const nsAString* aSerialized)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsAttrValue::SetTo(const mozilla::SVGAnimatedPreserveAspectRatio& aValue,
|
||||||
|
const nsAString* aSerialized)
|
||||||
|
{
|
||||||
|
if (EnsureEmptyMiscContainer()) {
|
||||||
|
MiscContainer* cont = GetMiscContainer();
|
||||||
|
cont->mSVGPreserveAspectRatio = &aValue;
|
||||||
|
cont->mType = eSVGPreserveAspectRatio;
|
||||||
|
SetMiscAtomOrString(aSerialized);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
nsAttrValue::SwapValueWith(nsAttrValue& aOther)
|
nsAttrValue::SwapValueWith(nsAttrValue& aOther)
|
||||||
{
|
{
|
||||||
|
@ -573,6 +591,11 @@ nsAttrValue::ToString(nsAString& aResult) const
|
||||||
GetMiscContainer()->mSVGNumberPair->GetBaseValueString(aResult);
|
GetMiscContainer()->mSVGNumberPair->GetBaseValueString(aResult);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case eSVGPreserveAspectRatio:
|
||||||
|
{
|
||||||
|
GetMiscContainer()->mSVGPreserveAspectRatio->GetBaseValueString(aResult);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
aResult.Truncate();
|
aResult.Truncate();
|
||||||
|
@ -777,6 +800,10 @@ nsAttrValue::HashValue() const
|
||||||
{
|
{
|
||||||
return NS_PTR_TO_INT32(cont->mSVGNumberPair);
|
return NS_PTR_TO_INT32(cont->mSVGNumberPair);
|
||||||
}
|
}
|
||||||
|
case eSVGPreserveAspectRatio:
|
||||||
|
{
|
||||||
|
return NS_PTR_TO_INT32(cont->mSVGPreserveAspectRatio);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
NS_NOTREACHED("unknown type stored in MiscContainer");
|
NS_NOTREACHED("unknown type stored in MiscContainer");
|
||||||
|
@ -889,6 +916,11 @@ nsAttrValue::Equals(const nsAttrValue& aOther) const
|
||||||
{
|
{
|
||||||
return thisCont->mSVGNumberPair == otherCont->mSVGNumberPair;
|
return thisCont->mSVGNumberPair == otherCont->mSVGNumberPair;
|
||||||
}
|
}
|
||||||
|
case eSVGPreserveAspectRatio:
|
||||||
|
{
|
||||||
|
return thisCont->mSVGPreserveAspectRatio ==
|
||||||
|
otherCont->mSVGPreserveAspectRatio;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
NS_NOTREACHED("unknown type stored in MiscContainer");
|
NS_NOTREACHED("unknown type stored in MiscContainer");
|
||||||
|
|
|
@ -67,6 +67,7 @@ namespace mozilla {
|
||||||
namespace css {
|
namespace css {
|
||||||
class StyleRule;
|
class StyleRule;
|
||||||
}
|
}
|
||||||
|
class SVGAnimatedPreserveAspectRatio;
|
||||||
class SVGLengthList;
|
class SVGLengthList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,6 +138,7 @@ public:
|
||||||
,eSVGLength = 0x16
|
,eSVGLength = 0x16
|
||||||
,eSVGLengthList = 0x17
|
,eSVGLengthList = 0x17
|
||||||
,eSVGNumberPair = 0x18
|
,eSVGNumberPair = 0x18
|
||||||
|
,eSVGPreserveAspectRatio = 0x19
|
||||||
};
|
};
|
||||||
|
|
||||||
ValueType Type() const;
|
ValueType Type() const;
|
||||||
|
@ -157,6 +159,8 @@ public:
|
||||||
void SetTo(const mozilla::SVGLengthList& aValue,
|
void SetTo(const mozilla::SVGLengthList& aValue,
|
||||||
const nsAString* aSerialized);
|
const nsAString* aSerialized);
|
||||||
void SetTo(const nsSVGNumberPair& aValue, const nsAString* aSerialized);
|
void SetTo(const nsSVGNumberPair& aValue, const nsAString* aSerialized);
|
||||||
|
void SetTo(const mozilla::SVGAnimatedPreserveAspectRatio& aValue,
|
||||||
|
const nsAString* aSerialized);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this object with the string or atom representation of aValue.
|
* Sets this object with the string or atom representation of aValue.
|
||||||
|
@ -393,6 +397,7 @@ private:
|
||||||
const nsSVGLength2* mSVGLength;
|
const nsSVGLength2* mSVGLength;
|
||||||
const mozilla::SVGLengthList* mSVGLengthList;
|
const mozilla::SVGLengthList* mSVGLengthList;
|
||||||
const nsSVGNumberPair* mSVGNumberPair;
|
const nsSVGNumberPair* mSVGNumberPair;
|
||||||
|
const mozilla::SVGAnimatedPreserveAspectRatio* mSVGPreserveAspectRatio;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -174,6 +174,7 @@ EXPORTS = \
|
||||||
nsSVGLength2.h \
|
nsSVGLength2.h \
|
||||||
nsSVGNumberPair.h \
|
nsSVGNumberPair.h \
|
||||||
nsSVGRect.h \
|
nsSVGRect.h \
|
||||||
|
SVGAnimatedPreserveAspectRatio.h \
|
||||||
SVGLength.h \
|
SVGLength.h \
|
||||||
SVGLengthList.h \
|
SVGLengthList.h \
|
||||||
$(NULL)
|
$(NULL)
|
||||||
|
|
|
@ -250,7 +250,8 @@ SVGAnimatedPreserveAspectRatio::SetBaseValueString(
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SVGAnimatedPreserveAspectRatio::GetBaseValueString(nsAString & aValueAsString)
|
SVGAnimatedPreserveAspectRatio::GetBaseValueString(
|
||||||
|
nsAString& aValueAsString) const
|
||||||
{
|
{
|
||||||
nsAutoString tmpString;
|
nsAutoString tmpString;
|
||||||
|
|
||||||
|
@ -276,12 +277,17 @@ nsresult
|
||||||
SVGAnimatedPreserveAspectRatio::SetBaseAlign(PRUint16 aAlign,
|
SVGAnimatedPreserveAspectRatio::SetBaseAlign(PRUint16 aAlign,
|
||||||
nsSVGElement *aSVGElement)
|
nsSVGElement *aSVGElement)
|
||||||
{
|
{
|
||||||
|
if (mIsBaseSet && mBaseVal.GetAlign() == aAlign) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangePreserveAspectRatio();
|
||||||
nsresult rv = mBaseVal.SetAlign(aAlign);
|
nsresult rv = mBaseVal.SetAlign(aAlign);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
mIsBaseSet = true;
|
mIsBaseSet = true;
|
||||||
|
|
||||||
mAnimVal.mAlign = mBaseVal.mAlign;
|
mAnimVal.mAlign = mBaseVal.mAlign;
|
||||||
aSVGElement->DidChangePreserveAspectRatio(true);
|
aSVGElement->DidChangePreserveAspectRatio(emptyOrOldValue);
|
||||||
if (mIsAnimated) {
|
if (mIsAnimated) {
|
||||||
aSVGElement->AnimationNeedsResample();
|
aSVGElement->AnimationNeedsResample();
|
||||||
}
|
}
|
||||||
|
@ -293,12 +299,17 @@ nsresult
|
||||||
SVGAnimatedPreserveAspectRatio::SetBaseMeetOrSlice(PRUint16 aMeetOrSlice,
|
SVGAnimatedPreserveAspectRatio::SetBaseMeetOrSlice(PRUint16 aMeetOrSlice,
|
||||||
nsSVGElement *aSVGElement)
|
nsSVGElement *aSVGElement)
|
||||||
{
|
{
|
||||||
|
if (mIsBaseSet && mBaseVal.GetMeetOrSlice() == aMeetOrSlice) {
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsAttrValue emptyOrOldValue = aSVGElement->WillChangePreserveAspectRatio();
|
||||||
nsresult rv = mBaseVal.SetMeetOrSlice(aMeetOrSlice);
|
nsresult rv = mBaseVal.SetMeetOrSlice(aMeetOrSlice);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
mIsBaseSet = true;
|
mIsBaseSet = true;
|
||||||
|
|
||||||
mAnimVal.mMeetOrSlice = mBaseVal.mMeetOrSlice;
|
mAnimVal.mMeetOrSlice = mBaseVal.mMeetOrSlice;
|
||||||
aSVGElement->DidChangePreserveAspectRatio(true);
|
aSVGElement->DidChangePreserveAspectRatio(emptyOrOldValue);
|
||||||
if (mIsAnimated) {
|
if (mIsAnimated) {
|
||||||
aSVGElement->AnimationNeedsResample();
|
aSVGElement->AnimationNeedsResample();
|
||||||
}
|
}
|
||||||
|
|
|
@ -118,7 +118,7 @@ public:
|
||||||
|
|
||||||
nsresult SetBaseValueString(const nsAString& aValue,
|
nsresult SetBaseValueString(const nsAString& aValue,
|
||||||
nsSVGElement *aSVGElement);
|
nsSVGElement *aSVGElement);
|
||||||
void GetBaseValueString(nsAString& aValue);
|
void GetBaseValueString(nsAString& aValue) const;
|
||||||
|
|
||||||
nsresult SetBaseAlign(PRUint16 aAlign, nsSVGElement *aSVGElement);
|
nsresult SetBaseAlign(PRUint16 aAlign, nsSVGElement *aSVGElement);
|
||||||
nsresult SetBaseMeetOrSlice(PRUint16 aMeetOrSlice, nsSVGElement *aSVGElement);
|
nsresult SetBaseMeetOrSlice(PRUint16 aMeetOrSlice, nsSVGElement *aSVGElement);
|
||||||
|
|
|
@ -558,6 +558,9 @@ nsSVGElement::ParseAttribute(PRInt32 aNamespaceID,
|
||||||
rv = preserveAspectRatio->SetBaseValueString(aValue, this);
|
rv = preserveAspectRatio->SetBaseValueString(aValue, this);
|
||||||
if (NS_FAILED(rv)) {
|
if (NS_FAILED(rv)) {
|
||||||
preserveAspectRatio->Init();
|
preserveAspectRatio->Init();
|
||||||
|
} else {
|
||||||
|
aResult.SetTo(*preserveAspectRatio, &aValue);
|
||||||
|
didSetResult = true;
|
||||||
}
|
}
|
||||||
foundMatch = true;
|
foundMatch = true;
|
||||||
}
|
}
|
||||||
|
@ -763,10 +766,9 @@ nsSVGElement::UnsetAttrInternal(PRInt32 aNamespaceID, nsIAtom* aName,
|
||||||
if (aName == nsGkAtoms::preserveAspectRatio) {
|
if (aName == nsGkAtoms::preserveAspectRatio) {
|
||||||
SVGAnimatedPreserveAspectRatio *preserveAspectRatio =
|
SVGAnimatedPreserveAspectRatio *preserveAspectRatio =
|
||||||
GetPreserveAspectRatio();
|
GetPreserveAspectRatio();
|
||||||
|
|
||||||
if (preserveAspectRatio) {
|
if (preserveAspectRatio) {
|
||||||
|
MaybeSerializeAttrBeforeRemoval(aName, aNotify);
|
||||||
preserveAspectRatio->Init();
|
preserveAspectRatio->Init();
|
||||||
DidChangePreserveAspectRatio(false);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2192,24 +2194,26 @@ nsSVGElement::GetPreserveAspectRatio()
|
||||||
return nsnull;
|
return nsnull;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
nsAttrValue
|
||||||
nsSVGElement::DidChangePreserveAspectRatio(bool aDoSetAttr)
|
nsSVGElement::WillChangePreserveAspectRatio()
|
||||||
{
|
{
|
||||||
if (!aDoSetAttr)
|
return WillChangeValue(nsGkAtoms::preserveAspectRatio);
|
||||||
return;
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nsSVGElement::DidChangePreserveAspectRatio(const nsAttrValue& aEmptyOrOldValue)
|
||||||
|
{
|
||||||
SVGAnimatedPreserveAspectRatio *preserveAspectRatio =
|
SVGAnimatedPreserveAspectRatio *preserveAspectRatio =
|
||||||
GetPreserveAspectRatio();
|
GetPreserveAspectRatio();
|
||||||
|
|
||||||
NS_ASSERTION(preserveAspectRatio,
|
NS_ASSERTION(preserveAspectRatio,
|
||||||
"DidChangePreserveAspectRatio on element with no preserveAspectRatio attrib");
|
"DidChangePreserveAspectRatio on element with no "
|
||||||
|
"preserveAspectRatio attrib");
|
||||||
|
|
||||||
nsAutoString serializedValue;
|
nsAttrValue newValue;
|
||||||
preserveAspectRatio->GetBaseValueString(serializedValue);
|
newValue.SetTo(*preserveAspectRatio, nsnull);
|
||||||
|
|
||||||
nsAttrValue attrValue(serializedValue);
|
DidChangeValue(nsGkAtoms::preserveAspectRatio, aEmptyOrOldValue, newValue);
|
||||||
SetParsedAttr(kNameSpaceID_None, nsGkAtoms::preserveAspectRatio, nsnull,
|
|
||||||
attrValue, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -174,6 +174,7 @@ public:
|
||||||
nsAttrValue WillChangeNumberPair(PRUint8 aAttrEnum);
|
nsAttrValue WillChangeNumberPair(PRUint8 aAttrEnum);
|
||||||
nsAttrValue WillChangeIntegerPair(PRUint8 aAttrEnum);
|
nsAttrValue WillChangeIntegerPair(PRUint8 aAttrEnum);
|
||||||
nsAttrValue WillChangeAngle(PRUint8 aAttrEnum);
|
nsAttrValue WillChangeAngle(PRUint8 aAttrEnum);
|
||||||
|
nsAttrValue WillChangePreserveAspectRatio();
|
||||||
nsAttrValue WillChangeLengthList(PRUint8 aAttrEnum);
|
nsAttrValue WillChangeLengthList(PRUint8 aAttrEnum);
|
||||||
|
|
||||||
void DidChangeLength(PRUint8 aAttrEnum, const nsAttrValue& aEmptyOrOldValue);
|
void DidChangeLength(PRUint8 aAttrEnum, const nsAttrValue& aEmptyOrOldValue);
|
||||||
|
@ -187,7 +188,7 @@ public:
|
||||||
void DidChangeBoolean(PRUint8 aAttrEnum);
|
void DidChangeBoolean(PRUint8 aAttrEnum);
|
||||||
void DidChangeEnum(PRUint8 aAttrEnum);
|
void DidChangeEnum(PRUint8 aAttrEnum);
|
||||||
virtual void DidChangeViewBox(bool aDoSetAttr);
|
virtual void DidChangeViewBox(bool aDoSetAttr);
|
||||||
virtual void DidChangePreserveAspectRatio(bool aDoSetAttr);
|
void DidChangePreserveAspectRatio(const nsAttrValue& aEmptyOrOldValue);
|
||||||
virtual void DidChangeNumberList(PRUint8 aAttrEnum, bool aDoSetAttr);
|
virtual void DidChangeNumberList(PRUint8 aAttrEnum, bool aDoSetAttr);
|
||||||
void DidChangeLengthList(PRUint8 aAttrEnum,
|
void DidChangeLengthList(PRUint8 aAttrEnum,
|
||||||
const nsAttrValue& aEmptyOrOldValue);
|
const nsAttrValue& aEmptyOrOldValue);
|
||||||
|
|
|
@ -235,6 +235,13 @@ function runTests()
|
||||||
is(basePreserveAspectRatio.meetOrSlice, 2, "preserveAspectRatio.meetOrSlice baseVal");
|
is(basePreserveAspectRatio.meetOrSlice, 2, "preserveAspectRatio.meetOrSlice baseVal");
|
||||||
is(animPreserveAspectRatio.meetOrSlice, 2, "preserveAspectRatio.meetOrSlice animVal");
|
is(animPreserveAspectRatio.meetOrSlice, 2, "preserveAspectRatio.meetOrSlice animVal");
|
||||||
|
|
||||||
|
marker.setAttribute("preserveAspectRatio", "");
|
||||||
|
ok(marker.getAttribute("preserveAspectRatio") === "",
|
||||||
|
"empty preserveAspectRatio attribute");
|
||||||
|
marker.removeAttribute("preserveAspectRatio");
|
||||||
|
ok(marker.getAttribute("preserveAspectRatio") === null,
|
||||||
|
"removed preserveAspectRatio attribute");
|
||||||
|
|
||||||
// viewBox attribute
|
// viewBox attribute
|
||||||
var baseViewBox = marker.viewBox.baseVal;
|
var baseViewBox = marker.viewBox.baseVal;
|
||||||
var animViewBox = marker.viewBox.animVal;
|
var animViewBox = marker.viewBox.animVal;
|
||||||
|
|
|
@ -201,6 +201,22 @@ function runTests()
|
||||||
convolve.setAttribute("result", "bar");
|
convolve.setAttribute("result", "bar");
|
||||||
convolve.result.baseVal = "bar";
|
convolve.result.baseVal = "bar";
|
||||||
|
|
||||||
|
// preserveAspectRatio attribute
|
||||||
|
|
||||||
|
eventChecker.watchAttr(marker, "preserveAspectRatio");
|
||||||
|
eventChecker.expect("add modify remove add");
|
||||||
|
marker.setAttribute("preserveAspectRatio", "xMaxYMid slice");
|
||||||
|
marker.preserveAspectRatio.baseVal.align =
|
||||||
|
SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMAXYMAX;
|
||||||
|
marker.removeAttribute("preserveAspectRatio");
|
||||||
|
marker.preserveAspectRatio.baseVal.align =
|
||||||
|
SVGPreserveAspectRatio.SVG_PRESERVEASPECTRATIO_XMIDYMIN;
|
||||||
|
|
||||||
|
eventChecker.expect("");
|
||||||
|
marker.preserveAspectRatio.baseVal.meetOrSlice =
|
||||||
|
SVGPreserveAspectRatio.SVG_MEETORSLICE_MEET;
|
||||||
|
marker.setAttribute("preserveAspectRatio", "xMidYMin meet");
|
||||||
|
|
||||||
eventChecker.finish();
|
eventChecker.finish();
|
||||||
|
|
||||||
SimpleTest.finish();
|
SimpleTest.finish();
|
||||||
|
|
Загрузка…
Ссылка в новой задаче