Bug 1033144 - Part 1: Dispatch 'cuechange' event on TextTracks. r=rillian,bz
authorRuxton <ruxton@thefrontiergroup.com.au>
Wed, 02 Mar 2016 10:34:02 -0800
changeset 286504 8935a32269a5b5b05afabe744ea3ca8a170fce67
parent 286503 d7608e766470baae63b7f5f963ffdd6e8cf0e6fa
child 286505 e1d06acdeb7b712be0725469026543cc8180ff46
push id30050
push usercbook@mozilla.com
push dateThu, 03 Mar 2016 10:54:59 +0000
treeherdermozilla-central@2b5237c178ea [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, bz
bugs1033144
milestone47.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 1033144 - Part 1: Dispatch 'cuechange' event on TextTracks. r=rillian,bz
dom/media/TextTrack.cpp
dom/webidl/TextTrack.webidl
--- a/dom/media/TextTrack.cpp
+++ b/dom/media/TextTrack.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 et tw=78: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "mozilla/AsyncEventDispatcher.h"
 #include "mozilla/dom/TextTrack.h"
 #include "mozilla/dom/TextTrackBinding.h"
 #include "mozilla/dom/TextTrackList.h"
 #include "mozilla/dom/TextTrackCue.h"
 #include "mozilla/dom/TextTrackCueList.h"
 #include "mozilla/dom/TextTrackRegion.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "mozilla/dom/HTMLTrackElement.h"
@@ -143,41 +144,56 @@ TextTrack::UpdateActiveCueList()
     return;
   }
 
   HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
   if (!mediaElement) {
     return;
   }
 
+  // Flag that indicates whether or not this call of UpdateActiveCueList has
+  // changed the activeCueList.
+  bool hasChanged = false;
+
   // If we are dirty, i.e. an event happened that may cause the sorted mCueList
   // to have changed like a seek or an insert for a cue, than we need to rebuild
   // the active cue list from scratch.
   if (mDirty) {
     mCuePos = 0;
     mDirty = false;
     mActiveCueList->RemoveAll();
   }
 
   double playbackTime = mediaElement->CurrentTime();
   // Remove all the cues from the active cue list whose end times now occur
   // earlier then the current playback time.
   for (uint32_t i = mActiveCueList->Length(); i > 0; i--) {
     if ((*mActiveCueList)[i - 1]->EndTime() < playbackTime) {
       mActiveCueList->RemoveCueAt(i - 1);
+      hasChanged = true;
     }
   }
   // Add all the cues, starting from the position of the last cue that was
   // added, that have valid start and end times for the current playback time.
   // We can stop iterating safely once we encounter a cue that does not have
   // a valid start time as the cue list is sorted.
   for (; mCuePos < mCueList->Length() &&
          (*mCueList)[mCuePos]->StartTime() <= playbackTime; mCuePos++) {
     if ((*mCueList)[mCuePos]->EndTime() >= playbackTime) {
       mActiveCueList->AddCue(*(*mCueList)[mCuePos]);
+      hasChanged = true;
+      }
+    }
+
+    if (hasChanged) {
+      RefPtr<AsyncEventDispatcher> asyncDispatcher =
+        new AsyncEventDispatcher(this, NS_LITERAL_STRING("cuechange"), false);
+      asyncDispatcher->PostDOMEvent();
+      if (mTrackElement) {
+        mTrackElement->DispatchTrackRunnable(NS_LITERAL_STRING("cuechange"));
     }
   }
 }
 
 TextTrackCueList*
 TextTrack::GetActiveCues() {
   if (mMode != TextTrackMode::Disabled) {
     UpdateActiveCueList();
--- a/dom/webidl/TextTrack.webidl
+++ b/dom/webidl/TextTrack.webidl
@@ -34,16 +34,16 @@ interface TextTrack : EventTarget {
 
   readonly attribute TextTrackCueList? cues;
   readonly attribute TextTrackCueList? activeCues;
 
   void addCue(VTTCue cue);
   [Throws]
   void removeCue(VTTCue cue);
 
-           //(Not implemented)attribute EventHandler oncuechange;
+           attribute EventHandler oncuechange;
 };
 
 // Mozilla Extensions
 partial interface TextTrack {
   [ChromeOnly]
   readonly attribute TextTrackList? textTrackList;
 };