Skip to content

Commit c25d407

Browse files
authored
Merge pull request #480 from alancutter/fixPauseHtml
Make pause() on idle animations set their current time according to playbackRate
2 parents 46f41d1 + e44d7c9 commit c25d407

File tree

3 files changed

+19
-19
lines changed

3 files changed

+19
-19
lines changed

src/animation.js

+15-9
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,21 @@
145145
return 'finished';
146146
return 'running';
147147
},
148+
_rewind: function() {
149+
if (this._playbackRate >= 0) {
150+
this._currentTime = 0;
151+
} else if (this._totalDuration < Infinity) {
152+
this._currentTime = this._totalDuration;
153+
} else {
154+
throw new DOMException(
155+
'Unable to rewind negative playback rate animation with infinite duration',
156+
'InvalidStateError');
157+
}
158+
},
148159
play: function() {
149160
this._paused = false;
150161
if (this._isFinished || this._idle) {
151-
if (this._playbackRate >= 0) {
152-
this._currentTime = 0;
153-
} else if (this._totalDuration < Infinity) {
154-
this._currentTime = this._totalDuration;
155-
} else {
156-
throw new DOMException(
157-
'Unable to rewind negative playback rate animation with infinite duration',
158-
'InvalidStateError');
159-
}
162+
this._rewind();
160163
this._startTime = null;
161164
}
162165
this._finishedFlag = false;
@@ -167,6 +170,9 @@
167170
pause: function() {
168171
if (!this._isFinished && !this._paused && !this._idle) {
169172
this._currentTimePending = true;
173+
} else if (this._idle) {
174+
this._rewind();
175+
this._idle = false;
170176
}
171177
this._startTime = null;
172178
this._paused = true;

test/js/animation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,8 @@ suite('animation', function() {
511511
assert.equal(a.startTime, null);
512512
tick(1);
513513
a.pause();
514-
assert.equal(a.playState, 'idle');
515-
assert.equal(a.currentTime, null);
514+
assert.equal(a.playState, 'paused');
515+
assert.equal(a.currentTime, 0);
516516
assert.equal(a.startTime, null);
517517
});
518518
test('Animations ignore NaN times', function() {

test/web-platform-tests-expectations.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,7 @@ module.exports = {
214214

215215
'test/web-platform-tests/web-animations/interfaces/Animation/pause.html': {
216216
'pause() from idle':
217-
'assert_equals: currentTime is set to 0 expected (number) 0 but got (object) null',
218-
219-
'pause() from idle with a negative playbackRate':
220-
'assert_equals: currentTime is set to the effect end expected (number) 1000000 but got (object) null',
221-
222-
'pause() from idle with a negative playbackRate and endless effect':
223-
'assert_throws: Expect InvalidStateError exception on calling pause() from idle with a negative playbackRate and infinite-duration animation function "function () {\n"use strict";\n animation.pause(); }" did not throw',
217+
'assert_equals: initially pause-pending expected "pending" but got "paused"',
224218
},
225219

226220
'test/web-platform-tests/web-animations/interfaces/Animation/playbackRate.html': {
@@ -1435,7 +1429,7 @@ module.exports = {
14351429
'Animation with null timeline is not supported',
14361430

14371431
'Setting the start time resolves a pending pause task':
1438-
'assert_equals: Animation is in pause-pending state expected "pending" but got "idle"',
1432+
'assert_equals: Animation is in pause-pending state expected "pending" but got "paused"',
14391433

14401434
'Setting the start time updates the finished state':
14411435
'assert_equals: Seeked to finished state using the startTime expected "finished" but got "idle"',

0 commit comments

Comments
 (0)