Bug 521705 - SVG SMIL: Update getStartTime to match behaviour in SVG 1.1 SE r=roc

--HG--
extra : rebase_source : ccb167188b6c3be499e75ef3b7d65ec24d266388
This commit is contained in:
Brian Birtles 2009-10-13 10:14:08 +11:00
Родитель 1723f1cb7d
Коммит 7a531f32da
8 изменённых файлов: 64 добавлений и 59 удалений

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

@ -164,29 +164,9 @@ nsSMILTimedElement::EndElementAt(double aOffsetSeconds,
nsSMILTimeValue
nsSMILTimedElement::GetStartTime() const
{
nsSMILTimeValue startTime;
switch (mElementState)
{
case STATE_STARTUP:
case STATE_ACTIVE:
startTime = mCurrentInterval.mBegin;
break;
case STATE_WAITING:
case STATE_POSTACTIVE:
if (!mOldIntervals.IsEmpty()) {
startTime = mOldIntervals[mOldIntervals.Length() - 1].mBegin;
} else {
startTime = mCurrentInterval.mBegin;
}
}
if (!startTime.IsResolved()) {
startTime.SetIndefinite();
}
return startTime;
return mElementState == STATE_WAITING || mElementState == STATE_ACTIVE
? mCurrentInterval.mBegin
: nsSMILTimeValue();
}
//----------------------------------------------------------------------

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

@ -97,26 +97,13 @@ public:
*/
/**
* According to SVG 1.1 this is supposed to return the start time for the
* animation but at this stage no one seems to know what that means.
* According to SVG 1.1 SE this returns
*
* For now we have adopted Opera's behaviour which seems to be:
* the begin time, in seconds, for this animation element's current
* interval, if it exists, regardless of whether the interval has begun yet.
*
* (i) If the animation is in the active state, return the start of the
* current interval
* (ii) Otherwise, if there is a previous interval, return the start of the
* previous interval
* (iii) Otherwise, if there is a future resolved interval, the the start of
* the next interval
* (iv) Otherwise, return 0.
*
* As this method represents a SMIL interface which is called by the SVG
* interface, instead of returning 0 in case (iv) we return 'indefinite' and
* then allow the SVG interface to decide what to do with it. That is, we
* don't throw away information until the last moment.
*
* @return the start time as defined above in milliseconds or 'indefinite' if
* there is no resolved start time for this element (case iv).
* @return the start time as defined above in milliseconds or an unresolved
* time if there is no current interval.
*/
nsSMILTimeValue GetStartTime() const;

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

@ -28,7 +28,15 @@ SimpleTest.waitForExplicitFinish();
function main() {
// indefinite
is(anim.getStartTime(), 0, "Unexpected start time with indefinite begin");
var exceptionCaught = false;
try {
anim.getStartTime();
} catch(e) {
exceptionCaught = true;
is(e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code from getStartTime.");
}
ok(exceptionCaught, "No exception thrown for indefinite start time.");
// 1s
anim.setAttribute("begin", "1s");
@ -53,13 +61,21 @@ function main() {
is(anim.getStartTime(), 1, "Unexpected start time during first interval");
svg.setCurrentTime(2);
is(anim.getStartTime(), 1, "Unexpected start time after first interval");
is(anim.getStartTime(), 3, "Unexpected start time after first interval");
svg.setCurrentTime(3);
is(anim.getStartTime(), 3, "Unexpected start time during second interval");
svg.setCurrentTime(4);
is(anim.getStartTime(), 3, "Unexpected start time after second interval");
exceptionCaught = false;
try {
anim.getStartTime();
} catch(e) {
exceptionCaught = true;
is(e.code, DOMException.INVALID_STATE_ERR,
"Unexpected exception code from getStartTime.");
}
ok(exceptionCaught, "No exception thrown for in postactive state.");
SimpleTest.finish();
}

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

@ -40,7 +40,14 @@ SimpleTest.waitForExplicitFinish();
function tryRestart(elem, state, expected) {
var restartTime = svg.getCurrentTime();
elem.beginElement();
var restart = (elem.getStartTime() === restartTime);
var restart = false;
try {
restart = (elem.getStartTime() === restartTime);
} catch (e) {
if (e.code != DOMException.INVALID_STATE_ERR)
throw e;
restart = false;
}
if (expected) {
var msg = elem.id + " can't restart in " + state + " state";
ok(restart, msg);

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

@ -82,7 +82,10 @@ function testChangeBaseVal(anim) {
// frozen
// preconditions -- element should have ended
ok(anim.getStartTime() + anim.getSimpleDuration() <= svg.getCurrentTime());
try {
anim.getStartTime();
ok(false, "Element has not ended yet.");
} catch (e) { }
// check frozen value is applied
var target = anim.targetElement;

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

@ -144,7 +144,10 @@ function testZeroDurationIntervalsF(anim) {
checkSample(0,-100);
checkSample(1,0);
checkSample(2,0);
is(anim.getStartTime(),1);
try {
anim.getStartTime();
ok(false, "Failed to throw exception when there's no current interval.");
} catch (e) { }
}
function testZeroDurationIntervalsG(anim) {
@ -230,7 +233,10 @@ function testZeroDurationIntervalsM(anim) {
anim.setAttribute('begin', '0s');
anim.setAttribute('end', '0s');
anim.setAttribute('fill', 'freeze');
is(anim.getStartTime(),0);
try {
anim.getStartTime();
ok(false, "Failed to throw exception when there's no current interval.");
} catch (e) { }
checkSample(0,0);
checkSample(1,0);
}
@ -240,7 +246,10 @@ function testZeroDurationIntervalsN(anim) {
anim.setAttribute('begin', '0s');
anim.setAttribute('repeatDur', '0s');
anim.setAttribute('fill', 'freeze');
is(anim.getStartTime(),0);
try {
anim.getStartTime();
ok(false, "Failed to throw exception when there's no current interval.");
} catch (e) { }
checkSample(0,0);
checkSample(1,0);
}
@ -260,7 +269,10 @@ function testZeroDurationIntervalsO(anim) {
checkSample(1,0);
checkSample(1.5,0);
checkSample(3,0);
is(anim.getStartTime(),2);
try {
anim.getStartTime();
ok(false, "Failed to throw exception when there's no current interval.");
} catch (e) { }
}
window.addEventListener("load", main, false);

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

@ -176,18 +176,17 @@ nsSVGAnimationElement::GetTargetElement(nsIDOMSVGElement** aTarget)
return NS_OK;
}
/* float getStartTime(); */
/* float getStartTime() raises( DOMException ); */
NS_IMETHODIMP
nsSVGAnimationElement::GetStartTime(float* retval)
{
FlushAnimations();
nsSMILTimeValue startTime = mTimedElement.GetStartTime();
if (startTime.IsResolved()) {
*retval = double(startTime.GetMillis()) / PR_MSEC_PER_SEC;
} else {
*retval = 0.f;
}
if (!startTime.IsResolved())
return NS_ERROR_DOM_INVALID_STATE_ERR;
*retval = float(double(startTime.GetMillis()) / PR_MSEC_PER_SEC);
return NS_OK;
}
@ -200,7 +199,7 @@ nsSVGAnimationElement::GetCurrentTime(float* retval)
nsSMILTimeContainer* root = GetTimeContainer();
if (root) {
*retval = double(root->GetCurrentTime()) / PR_MSEC_PER_SEC;
*retval = float(double(root->GetCurrentTime()) / PR_MSEC_PER_SEC);
} else {
*retval = 0.f;
}
@ -219,7 +218,7 @@ nsSVGAnimationElement::GetSimpleDuration(float* retval)
return NS_ERROR_DOM_NOT_SUPPORTED_ERR;
}
*retval = double(simpleDur.GetMillis()) / PR_MSEC_PER_SEC;
*retval = float(double(simpleDur.GetMillis()) / PR_MSEC_PER_SEC);
return NS_OK;
}

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

@ -56,7 +56,8 @@ interface nsIDOMSVGAnimationElement
{
readonly attribute nsIDOMSVGElement targetElement;
float getStartTime();
// raises ( DOMException )
float getCurrentTime();
float getSimpleDuration();
// raises (nsIDOMDOMException)
// raises ( DOMException )
};