Web Animations: Expose timeline currentTime in IDL

AnimationTimeline has currentTime of type double - the time value for
this timeline.

Web Animations spec, section 5.1 The AnimationTimeline interface
http://dev.w3.org/fxtf/web-animations/#the-animationtimeline-interface


BUG=357432

Review URL: https://codereview.chromium.org/215043007

git-svn-id: svn://svn.chromium.org/blink/trunk@170513 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 513b3312
<!DOCTYPE html>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<body>
<div id='element'></div>
</body>
<script>
var element = document.getElementById('element');
var duration = 1;
var animation = new Animation(element,
[{opacity: '1', offset: 0},
{opacity: '0', offset: 1}],
duration);
test(function() {
var startTime = document.timeline.currentTime;
var player = document.timeline.play(animation);
player.finish();
var finishTime = document.timeline.currentTime;
assert_greater_than_equal(startTime, 0);
assert_equals(startTime, finishTime);
}, 'document.timeline.currentTime should not change within a script block.');
</script>
...@@ -144,11 +144,21 @@ void DocumentTimeline::DocumentTimelineTiming::serviceOnNextFrame() ...@@ -144,11 +144,21 @@ void DocumentTimeline::DocumentTimelineTiming::serviceOnNextFrame()
m_timeline->m_document->view()->scheduleAnimation(); m_timeline->m_document->view()->scheduleAnimation();
} }
double DocumentTimeline::currentTime() double DocumentTimeline::currentTime(bool& isNull)
{ {
if (!m_document) if (!m_document) {
isNull = true;
return std::numeric_limits<double>::quiet_NaN(); return std::numeric_limits<double>::quiet_NaN();
return m_document->animationClock().currentTime() - m_zeroTime; }
double result = m_document->animationClock().currentTime() - m_zeroTime;
isNull = std::isnan(result);
return result;
}
double DocumentTimeline::currentTime()
{
bool isNull;
return currentTime(isNull);
} }
double DocumentTimeline::effectiveTime() double DocumentTimeline::effectiveTime()
......
...@@ -80,6 +80,7 @@ public: ...@@ -80,6 +80,7 @@ public:
bool hasStarted() const { return !isNull(m_zeroTime); } bool hasStarted() const { return !isNull(m_zeroTime); }
bool hasPendingUpdates() const { return !m_playersNeedingUpdate.isEmpty(); } bool hasPendingUpdates() const { return !m_playersNeedingUpdate.isEmpty(); }
double zeroTime() const { return m_zeroTime; } double zeroTime() const { return m_zeroTime; }
double currentTime(bool& isNull);
double currentTime(); double currentTime();
double effectiveTime(); double effectiveTime();
void pauseAnimationsForTesting(double); void pauseAnimationsForTesting(double);
......
...@@ -169,16 +169,21 @@ TEST_F(AnimationDocumentTimelineTest, EmptyForwardsKeyframeAnimation) ...@@ -169,16 +169,21 @@ TEST_F(AnimationDocumentTimelineTest, EmptyForwardsKeyframeAnimation)
TEST_F(AnimationDocumentTimelineTest, ZeroTime) TEST_F(AnimationDocumentTimelineTest, ZeroTime)
{ {
timeline = DocumentTimeline::create(document.get()); timeline = DocumentTimeline::create(document.get());
bool isNull;
document->animationClock().updateTime(100); document->animationClock().updateTime(100);
EXPECT_TRUE(isNull(timeline->currentTime())); EXPECT_TRUE(std::isnan(timeline->currentTime()));
EXPECT_TRUE(std::isnan(timeline->currentTime(isNull)));
EXPECT_TRUE(isNull);
document->animationClock().updateTime(200); document->animationClock().updateTime(200);
EXPECT_TRUE(isNull(timeline->currentTime())); EXPECT_TRUE(std::isnan(timeline->currentTime()));
timeline->setZeroTime(300); timeline->setZeroTime(300);
document->animationClock().updateTime(300); document->animationClock().updateTime(300);
EXPECT_EQ(0, timeline->currentTime()); EXPECT_EQ(0, timeline->currentTime());
EXPECT_EQ(0, timeline->currentTime(isNull));
EXPECT_FALSE(isNull);
document->animationClock().updateTime(400); document->animationClock().updateTime(400);
EXPECT_EQ(100, timeline->currentTime()); EXPECT_EQ(100, timeline->currentTime());
......
...@@ -6,5 +6,6 @@ ...@@ -6,5 +6,6 @@
RuntimeEnabled=WebAnimationsAPI, RuntimeEnabled=WebAnimationsAPI,
ImplementedAs=DocumentTimeline, ImplementedAs=DocumentTimeline,
] interface Timeline { ] interface Timeline {
readonly attribute double? currentTime;
AnimationPlayer play(TimedItem source); AnimationPlayer play(TimedItem source);
}; };
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment