Bug 1178664 - Part 4 -Implement Animation.oncancel event. r=bbirtles, r=smaug
authorHiroyuki Ikezoe <hiikezoe@mozilla-japan.org>
Thu, 30 Jul 2015 23:26:00 +0200
changeset 287314 db31cfe558094370503866157f7207b6f0f7c99b
parent 287313 9338f9c7fb959f6af499b638d4a6902f9bbb3e90
child 287315 2162bd0f0411001b6ac6303ea2bc9c9f13b46ab6
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbirtles, smaug
bugs1178664
milestone42.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1178664 - Part 4 -Implement Animation.oncancel event. r=bbirtles, r=smaug
dom/animation/Animation.cpp
dom/animation/Animation.h
dom/animation/test/css-animations/file_animation-oncancel.html
dom/animation/test/css-animations/test_animation-oncancel.html
dom/animation/test/mochitest.ini
dom/base/nsGkAtomList.h
dom/webidl/Animation.webidl
--- a/dom/animation/Animation.cpp
+++ b/dom/animation/Animation.cpp
@@ -473,16 +473,18 @@ Animation::DoCancel()
     }
   }
 
   if (mFinished) {
     mFinished->MaybeReject(NS_ERROR_DOM_ABORT_ERR);
   }
   ResetFinishedPromise();
 
+  DispatchPlaybackEvent(NS_LITERAL_STRING("cancel"));
+
   mHoldTime.SetNull();
   mStartTime.SetNull();
 
   UpdateTiming(SeekFlag::NoSeek, SyncNotifyFlag::Async);
 }
 
 void
 Animation::UpdateRelevance()
@@ -1113,17 +1115,19 @@ Animation::DoFinishNotificationImmediate
   DispatchPlaybackEvent(NS_LITERAL_STRING("finish"));
 }
 
 void
 Animation::DispatchPlaybackEvent(const nsAString& aName)
 {
   AnimationPlaybackEventInit init;
 
-  init.mCurrentTime = GetCurrentTimeAsDouble();
+  if (aName.EqualsLiteral("finish")) {
+    init.mCurrentTime = GetCurrentTimeAsDouble();
+  }
   if (mTimeline) {
     init.mTimelineTime = mTimeline->GetCurrentTimeAsDouble();
   }
 
   nsRefPtr<AnimationPlaybackEvent> event =
     AnimationPlaybackEvent::Constructor(this, aName, init);
   event->SetTrusted(true);
 
--- a/dom/animation/Animation.h
+++ b/dom/animation/Animation.h
@@ -107,16 +107,17 @@ public:
   virtual Promise* GetFinished(ErrorResult& aRv);
   void Cancel();
   virtual void Finish(ErrorResult& aRv);
   virtual void Play(ErrorResult& aRv, LimitBehavior aLimitBehavior);
   virtual void Pause(ErrorResult& aRv);
   virtual void Reverse(ErrorResult& aRv);
   bool IsRunningOnCompositor() const { return mIsRunningOnCompositor; }
   IMPL_EVENT_HANDLER(finish);
+  IMPL_EVENT_HANDLER(cancel);
 
   // Wrapper functions for Animation DOM methods when called
   // from script.
   //
   // We often use the same methods internally and from script but when called
   // from script we (or one of our subclasses) perform extra steps such as
   // flushing style or converting the return type.
   Nullable<double> GetStartTimeAsDouble() const;
new file mode 100644
--- /dev/null
+++ b/dom/animation/test/css-animations/file_animation-oncancel.html
@@ -0,0 +1,35 @@
+<!doctype html>
+<meta charset=utf-8>
+<script src="../testcommon.js"></script>
+<style>
+@keyframes abc {
+  to { transform: translate(10px) }
+}
+</style>
+<body>
+<script>
+'use strict';
+
+async_test(function(t) {
+  var div = addDiv(t, {'style': 'animation: abc 100s'});
+  var animation = div.getAnimations()[0];
+
+  var finishedTimelineTime;
+  animation.finished.then().catch(function() {
+    finishedTimelineTime = animation.timeline.currentTime;
+  });
+
+  animation.oncancel = t.step_func_done(function(event) {
+    assert_equals(event.currentTime, null,
+      'event.currentTime should be null');
+    assert_equals(event.timelineTime, finishedTimelineTime,
+      'event.timelineTime should equal to the animation timeline ' +
+      'when finished promise is rejected');
+  });
+
+  animation.cancel();
+}, 'oncancel event is fired when animation.cancel()');
+
+done();
+</script>
+</body>
new file mode 100644
--- /dev/null
+++ b/dom/animation/test/css-animations/test_animation-oncancel.html
@@ -0,0 +1,15 @@
+<!doctype html>
+<meta charset=utf-8>
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<div id="log"></div>
+<script>
+'use strict';
+setup({explicit_done: true});
+SpecialPowers.pushPrefEnv(
+  { "set": [["dom.animations-api.core.enabled", true]]},
+  function() {
+    window.open("file_animation-oncancel.html");
+  });
+</script>
+</html>
--- a/dom/animation/test/mochitest.ini
+++ b/dom/animation/test/mochitest.ini
@@ -7,16 +7,18 @@ support-files = css-animations/file_anim
 [css-animations/test_animation-cancel.html]
 support-files = css-animations/file_animation-cancel.html
 [css-animations/test_animation-currenttime.html]
 support-files = css-animations/file_animation-currenttime.html
 [css-animations/test_animation-finish.html]
 support-files = css-animations/file_animation-finish.html
 [css-animations/test_animation-finished.html]
 support-files = css-animations/file_animation-finished.html
+[css-animations/test_animation-oncancel.html]
+support-files = css-animations/file_animation-oncancel.html
 [css-animations/test_animation-onfinish.html]
 support-files = css-animations/file_animation-onfinish.html
 [css-animations/test_animation-pausing.html]
 support-files = css-animations/file_animation-pausing.html
 [css-animations/test_animation-play.html]
 support-files = css-animations/file_animation-play.html
 [css-animations/test_animation-playbackrate.html]
 support-files = css-animations/file_animation-playbackrate.html
--- a/dom/base/nsGkAtomList.h
+++ b/dom/base/nsGkAtomList.h
@@ -691,16 +691,17 @@ GK_ATOM(onbeforeprint, "onbeforeprint")
 GK_ATOM(onbeforescriptexecute, "onbeforescriptexecute")
 GK_ATOM(onbeforeunload, "onbeforeunload")
 GK_ATOM(onblocked, "onblocked")
 GK_ATOM(onblur, "onblur")
 GK_ATOM(onbroadcast, "onbroadcast")
 GK_ATOM(onbusy, "onbusy")
 GK_ATOM(oncached, "oncached")
 GK_ATOM(oncallschanged, "oncallschanged")
+GK_ATOM(oncancel, "oncancel")
 GK_ATOM(oncardstatechange, "oncardstatechange")
 GK_ATOM(oncfstatechange, "oncfstatechange")
 GK_ATOM(onchange, "onchange")
 GK_ATOM(oncharacteristicchanged, "oncharacteristicchanged")
 GK_ATOM(onchargingchange, "onchargingchange")
 GK_ATOM(onchargingtimechange, "onchargingtimechange")
 GK_ATOM(onchecking, "onchecking")
 GK_ATOM(onclick, "onclick")
--- a/dom/webidl/Animation.webidl
+++ b/dom/webidl/Animation.webidl
@@ -26,16 +26,17 @@ interface Animation : EventTarget {
            attribute double             playbackRate;
   [BinaryName="playStateFromJS"]
   readonly attribute AnimationPlayState playState;
   [Throws]
   readonly attribute Promise<Animation> ready;
   [Throws]
   readonly attribute Promise<Animation> finished;
            attribute EventHandler       onfinish;
+           attribute EventHandler       oncancel;
   void cancel ();
   [Throws]
   void finish ();
   [Throws, BinaryName="playFromJS"]
   void play ();
   [Throws, BinaryName="pauseFromJS"]
   void pause ();
   [Throws]