Bug 1283417 - part2 : notify media element when cue's display states changed. draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 09 Aug 2016 16:58:52 +0800
changeset 398514 b847ba36ec1abdfa0213184a2e6e26a7926d5ae9
parent 398513 3228849189d835a4c4e1c802455b4c1467083e68
child 527684 dff2b288c9931accd8f48214d279d1fda1941d78
push id25556
push useralwu@mozilla.com
push dateTue, 09 Aug 2016 09:00:14 +0000
bugs1283417
milestone51.0a1
Bug 1283417 - part2 : notify media element when cue's display states changed. MozReview-Commit-ID: 4bzS62wveGq
dom/media/TextTrackCue.cpp
dom/media/TextTrackCue.h
--- a/dom/media/TextTrackCue.cpp
+++ b/dom/media/TextTrackCue.cpp
@@ -49,17 +49,19 @@ TextTrackCue::TextTrackCue(nsPIDOMWindow
                            double aStartTime,
                            double aEndTime,
                            const nsAString& aText,
                            ErrorResult& aRv)
   : DOMEventTargetHelper(aOwnerWindow)
   , mText(aText)
   , mStartTime(aStartTime)
   , mEndTime(aEndTime)
-  , mReset(false)
+  , mReset(false, "TextTrackCue::mReset")
+  , mHaveStartedWatcher(false)
+  , mWatchManager(this, AbstractThread::MainThread())
 {
   SetDefaultCueSettings();
   MOZ_ASSERT(aOwnerWindow);
   if (NS_FAILED(StashDocument())) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
   }
 }
 
@@ -69,17 +71,19 @@ TextTrackCue::TextTrackCue(nsPIDOMWindow
                            const nsAString& aText,
                            HTMLTrackElement* aTrackElement,
                            ErrorResult& aRv)
   : DOMEventTargetHelper(aOwnerWindow)
   , mText(aText)
   , mStartTime(aStartTime)
   , mEndTime(aEndTime)
   , mTrackElement(aTrackElement)
-  , mReset(false)
+  , mReset(false, "TextTrackCue::mReset")
+  , mHaveStartedWatcher(false)
+  , mWatchManager(this, AbstractThread::MainThread())
 {
   SetDefaultCueSettings();
   MOZ_ASSERT(aOwnerWindow);
   if (NS_FAILED(StashDocument())) {
     aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
   }
 }
 
--- a/dom/media/TextTrackCue.h
+++ b/dom/media/TextTrackCue.h
@@ -11,16 +11,17 @@
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/VTTCueBinding.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsIWebVTTParserWrapper.h"
 #include "mozilla/StaticPtr.h"
 #include "nsIDocument.h"
 #include "mozilla/dom/HTMLDivElement.h"
 #include "mozilla/dom/TextTrack.h"
+#include "mozilla/StateWatching.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLTrackElement;
 class TextTrackRegion;
 
 class TextTrackCue final : public DOMEventTargetHelper
@@ -318,16 +319,23 @@ public:
   const nsAString& Id() const
   {
     return mId;
   }
 
   void SetTrack(TextTrack* aTextTrack)
   {
     mTrack = aTextTrack;
+    if (!mHaveStartedWatcher && aTextTrack) {
+      mHaveStartedWatcher = true;
+      mWatchManager.Watch(mReset, &TextTrackCue::NotifyDisplayStatesChanged);
+    } else if (mHaveStartedWatcher && !aTextTrack) {
+      mHaveStartedWatcher = false;
+      mWatchManager.Unwatch(mReset, &TextTrackCue::NotifyDisplayStatesChanged);
+    }
   }
 
   /**
    * Produces a tree of anonymous content based on the tree of the processed
    * cue text.
    *
    * Returns a DocumentFragment that is the head of the tree of anonymous
    * content.
@@ -388,19 +396,23 @@ private:
   LineAlignSetting mLineAlign;
 
   // Holds the computed DOM elements that represent the parsed cue text.
   // http://www.whatwg.org/specs/web-apps/current-work/#text-track-cue-display-state
   RefPtr<nsGenericHTMLElement> mDisplayState;
   // Tells whether or not we need to recompute mDisplayState. This is set
   // anytime a property that relates to the display of the TextTrackCue is
   // changed.
-  bool mReset;
+  Watchable<bool> mReset;
 
   bool mActive;
 
   static StaticRefPtr<nsIWebVTTParserWrapper> sParserWrapper;
+
+  // Only start watcher after the cue has text track.
+  bool mHaveStartedWatcher;
+  WatchManager<TextTrackCue> mWatchManager;
 };
 
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_TextTrackCue_h