Bug 646850. When resetting length to the pre-animation value, make sure to not lose track of our units. r=dholbert

This commit is contained in:
Boris Zbarsky 2011-03-31 15:29:44 -04:00
parent d6a199195e
commit dc3c181623
5 changed files with 64 additions and 15 deletions

View File

@ -447,25 +447,26 @@ nsSVGLength2::GetAnimValueString(nsAString & aValueAsString)
void
nsSVGLength2::SetBaseValue(float aValue, nsSVGElement *aSVGElement)
{
mBaseVal = aValue * GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType);
mIsBaseSet = PR_TRUE;
if (!mIsAnimated) {
mAnimVal = mBaseVal;
}
#ifdef MOZ_SMIL
else {
aSVGElement->AnimationNeedsResample();
}
#endif
aSVGElement->DidChangeLength(mAttrEnum, PR_TRUE);
SetBaseValueInSpecifiedUnits(aValue * GetUnitScaleFactor(aSVGElement,
mSpecifiedUnitType),
aSVGElement);
}
void
nsSVGLength2::SetAnimValueInSpecifiedUnits(float aValue,
nsSVGElement* aSVGElement)
{
mAnimVal = aValue;
mIsAnimated = PR_TRUE;
aSVGElement->DidAnimateLength(mAttrEnum);
}
void
nsSVGLength2::SetAnimValue(float aValue, nsSVGElement *aSVGElement)
{
mAnimVal = aValue * GetUnitScaleFactor(aSVGElement, mSpecifiedUnitType);
mIsAnimated = PR_TRUE;
aSVGElement->DidAnimateLength(mAttrEnum);
SetAnimValueInSpecifiedUnits(aValue * GetUnitScaleFactor(aSVGElement,
mSpecifiedUnitType),
aSVGElement);
}
nsresult
@ -533,7 +534,7 @@ void
nsSVGLength2::SMILLength::ClearAnimValue()
{
if (mVal->mIsAnimated) {
mVal->SetAnimValue(mVal->mBaseVal, mSVGElement);
mVal->SetAnimValueInSpecifiedUnits(mVal->mBaseVal, mSVGElement);
mVal->mIsAnimated = PR_FALSE;
}
}

View File

@ -134,9 +134,11 @@ private:
float GetUnitScaleFactor(nsSVGElement *aSVGElement, PRUint8 aUnitType) const;
float GetUnitScaleFactor(nsSVGSVGElement *aCtx, PRUint8 aUnitType) const;
// SetBaseValue and SetAnimValue set the value in user units
void SetBaseValue(float aValue, nsSVGElement *aSVGElement);
void SetBaseValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement);
void SetAnimValue(float aValue, nsSVGElement *aSVGElement);
void SetAnimValueInSpecifiedUnits(float aValue, nsSVGElement *aSVGElement);
nsresult NewValueSpecifiedUnits(PRUint16 aUnitType, float aValue,
nsSVGElement *aSVGElement);
nsresult ConvertToSpecifiedUnits(PRUint16 aUnitType, nsSVGElement *aSVGElement);

View File

@ -0,0 +1,22 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
class="reftest-wait"
onload="document.documentElement.setCurrentTime(0);
if (document.getElementById('x').width.animVal.value != 0) {
/* fail */
document.documentElement.textContent = '';
}
setTimeAndSnapshot(1, true)">
<title>Test that an animation for a length correctly restores the original
pixel size when the animation is done.</title>
<script xlink:href="smil-util.js" type="text/javascript"/>
<rect width="100%" height="100%" fill="lime"/>
<rect width="100" height="100" fill="red"/>
<rect width="100" height="100" fill="lime" id="x">
<set attributeName="width" to="0" dur="1s" begin="0s"/>
</rect>
</svg>

After

Width:  |  Height:  |  Size: 922 B

View File

@ -0,0 +1,22 @@
<!--
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/licenses/publicdomain/
-->
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
class="reftest-wait"
onload="document.documentElement.setCurrentTime(0);
if (document.getElementById('x').width.animVal.value != 0) {
/* fail */
document.documentElement.textContent = '';
}
setTimeAndSnapshot(1, true)">
<title>Test that an animation for a length correctly restores the original
pixel size when the animation is done.</title>
<script xlink:href="smil-util.js" type="text/javascript"/>
<rect width="100%" height="100%" fill="lime"/>
<rect width="100" height="100" fill="red"/>
<rect width="10em" height="100" fill="lime" font-size="10px" id="x">
<set attributeName="width" to="0" dur="1s" begin="0s"/>
</rect>
</svg>

After

Width:  |  Height:  |  Size: 940 B

View File

@ -86,6 +86,8 @@ fails == anim-fillcolor-1.svg anim-standard-ref.svg # bug 436296
# animate some <length> attributes:
== anim-filter-primitive-size-01.svg lime.svg
== anim-filter-size-01.svg lime.svg
== anim-length-reset-01.svg lime.svg
== anim-nonpixel-length-reset-01.svg lime.svg
# animate some <number> attributes:
== anim-feComponentTransfer-01.svg lime.svg