Bug 976580 - Set cue state to dirty when video resize happens. r=rillian, r=bz
authorRick Eyre <rick.eyre@hotmail.com>
Mon, 07 Apr 2014 15:42:33 -0400
changeset 196783 c7f3704c420cadb85182aa59283b7cccc7c35063
parent 196782 9994446a104a60c61dcd5d32bffe60f775dcb354
child 196784 0a9161c20a4d1c9b5825cbadccfa38075f0f36ac
push id3624
push userasasaki@mozilla.com
push dateMon, 09 Jun 2014 21:49:01 +0000
treeherdermozilla-beta@b1a5da15899a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, bz
bugs976580
milestone31.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 976580 - Set cue state to dirty when video resize happens. r=rillian, r=bz This way when the video is resized the rendering algorithm for the cues will run again and hence, the caption size will be increased/decreased for the new size of the video.
content/html/content/src/HTMLMediaElement.cpp
content/html/content/src/TextTrackManager.cpp
content/html/content/src/TextTrackManager.h
content/media/TextTrack.cpp
content/media/TextTrack.h
content/media/TextTrackCue.h
--- a/content/html/content/src/HTMLMediaElement.cpp
+++ b/content/html/content/src/HTMLMediaElement.cpp
@@ -3922,16 +3922,17 @@ HTMLMediaElement::PopulatePendingTextTra
   }
 }
 
 TextTrackManager*
 HTMLMediaElement::GetOrCreateTextTrackManager()
 {
   if (!mTextTrackManager) {
     mTextTrackManager = new TextTrackManager(this);
+    mTextTrackManager->AddListeners();
   }
   return mTextTrackManager;
 }
 
 AudioChannel
 HTMLMediaElement::MozAudioChannelType() const
 {
   switch (mAudioChannelType) {
--- a/content/html/content/src/TextTrackManager.cpp
+++ b/content/html/content/src/TextTrackManager.cpp
@@ -3,18 +3,20 @@
 
 /* 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/dom/TextTrackManager.h"
 #include "mozilla/dom/HTMLMediaElement.h"
 #include "mozilla/dom/HTMLTrackElement.h"
+#include "mozilla/dom/HTMLVideoElement.h"
 #include "mozilla/dom/TextTrack.h"
 #include "mozilla/dom/TextTrackCue.h"
+#include "mozilla/dom/Event.h"
 #include "mozilla/ClearOnShutdown.h"
 #include "nsComponentManagerUtils.h"
 #include "nsVideoFrame.h"
 #include "nsIFrame.h"
 #include "nsTArrayHelpers.h"
 #include "nsIWebVTTParserWrapper.h"
 
 namespace mozilla {
@@ -70,27 +72,30 @@ CompareTextTracks::LessThan(TextTrack* a
       // No rules for Media Resource Specific tracks yet.
       break;
   }
   return true;
 }
 
 NS_IMPL_CYCLE_COLLECTION_4(TextTrackManager, mMediaElement, mTextTracks,
                            mPendingTextTracks, mNewCues)
-NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(TextTrackManager, AddRef)
-NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(TextTrackManager, Release)
+
+NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(TextTrackManager)
+  NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
+NS_INTERFACE_MAP_END
+
+NS_IMPL_CYCLE_COLLECTING_ADDREF(TextTrackManager)
+NS_IMPL_CYCLE_COLLECTING_RELEASE(TextTrackManager)
 
 StaticRefPtr<nsIWebVTTParserWrapper> TextTrackManager::sParserWrapper;
 
 TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
   : mMediaElement(aMediaElement)
   , performedTrackSelection(false)
 {
-  MOZ_COUNT_CTOR(TextTrackManager);
-
   bool hasHadScriptObject = true;
   nsIScriptGlobalObject* scriptObject =
     mMediaElement->OwnerDoc()->GetScriptHandlingObject(hasHadScriptObject);
 
   NS_ENSURE_TRUE_VOID(scriptObject || !hasHadScriptObject);
 
   nsCOMPtr<nsPIDOMWindow> window = do_QueryInterface(scriptObject);
   mNewCues = new TextTrackCueList(window);
@@ -100,21 +105,16 @@ TextTrackManager::TextTrackManager(HTMLM
   if (!sParserWrapper) {
     nsCOMPtr<nsIWebVTTParserWrapper> parserWrapper =
       do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID);
     sParserWrapper = parserWrapper;
     ClearOnShutdown(&sParserWrapper);
   }
 }
 
-TextTrackManager::~TextTrackManager()
-{
-  MOZ_COUNT_DTOR(TextTrackManager);
-}
-
 TextTrackList*
 TextTrackManager::TextTracks() const
 {
   return mTextTracks;
 }
 
 already_AddRefed<TextTrack>
 TextTrackManager::AddTextTrack(TextTrackKind aKind, const nsAString& aLabel,
@@ -251,16 +251,25 @@ TextTrackManager::PopulatePendingList()
         ttrack->ReadyState() == TextTrackReadyState::Loading) {
       mPendingTextTracks->AddTextTrack(ttrack,
                                        CompareTextTracks(mMediaElement));
     }
   }
 }
 
 void
+TextTrackManager::AddListeners()
+{
+  if (mMediaElement) {
+    mMediaElement->AddEventListener(NS_LITERAL_STRING("resizevideocontrols"),
+                                    this, false, false);
+  }
+}
+
+void
 TextTrackManager::HonorUserPreferencesForTrackSelection()
 {
   if (performedTrackSelection || !mTextTracks) {
     return;
   }
 
   TextTrackKind ttKinds[] = { TextTrackKind::Captions,
                               TextTrackKind::Subtitles };
@@ -347,10 +356,27 @@ TextTrackManager::GetTextTracksOfKind(Te
   for (uint32_t i = 0; i < mTextTracks->Length(); i++) {
     TextTrack* textTrack = (*mTextTracks)[i];
     if (textTrack->Kind() == aTextTrackKind) {
       aTextTracks.AppendElement(textTrack);
     }
   }
 }
 
+NS_IMETHODIMP
+TextTrackManager::HandleEvent(nsIDOMEvent* aEvent)
+{
+  if (!mTextTracks) {
+    return NS_OK;
+  }
+
+  nsAutoString type;
+  aEvent->GetType(type);
+  if (type.EqualsLiteral("resizevideocontrols")) {
+    for (uint32_t i = 0; i< mTextTracks->Length(); i++) {
+      ((*mTextTracks)[i])->SetCuesDirty();
+    }
+  }
+  return NS_OK;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/content/html/content/src/TextTrackManager.h
+++ b/content/html/content/src/TextTrackManager.h
@@ -28,24 +28,25 @@ public:
   int32_t TrackChildPosition(TextTrack* aTrack) const;
   bool Equals(TextTrack* aOne, TextTrack* aTwo) const;
   bool LessThan(TextTrack* aOne, TextTrack* aTwo) const;
 };
 
 class TextTrack;
 class TextTrackCue;
 
-class TextTrackManager
+class TextTrackManager MOZ_FINAL : public nsIDOMEventListener
 {
 public:
-  NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(TextTrackManager)
-  NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(TextTrackManager);
+  NS_DECL_CYCLE_COLLECTING_ISUPPORTS
+  NS_DECL_CYCLE_COLLECTION_CLASS(TextTrackManager)
+
+  NS_DECL_NSIDOMEVENTLISTENER
 
   TextTrackManager(HTMLMediaElement *aMediaElement);
-  ~TextTrackManager();
 
   TextTrackList* TextTracks() const;
   already_AddRefed<TextTrack> AddTextTrack(TextTrackKind aKind,
                                            const nsAString& aLabel,
                                            const nsAString& aLanguage,
                                            TextTrackMode aMode,
                                            TextTrackReadyState aReadyState,
                                            TextTrackSource aTextTrackSource);
@@ -83,16 +84,18 @@ public:
   /**
    * Converts the TextTrackCue's cuetext into a tree of DOM objects and attaches
    * it to a div on it's owning TrackElement's MediaElement's caption overlay.
    */
   void UpdateCueDisplay();
 
   void PopulatePendingList();
 
+  void AddListeners();
+
   // The HTMLMediaElement that this TextTrackManager manages the TextTracks of.
   nsRefPtr<HTMLMediaElement> mMediaElement;
 private:
   // List of the TextTrackManager's owning HTMLMediaElement's TextTracks.
   nsRefPtr<TextTrackList> mTextTracks;
   // List of text track objects awaiting loading.
   nsRefPtr<TextTrackList> mPendingTextTracks;
   // List of newly introduced Text Track cues.
--- a/content/media/TextTrack.cpp
+++ b/content/media/TextTrack.cpp
@@ -120,16 +120,24 @@ TextTrack::AddCue(TextTrackCue& aCue)
 void
 TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
 {
   mCueList->RemoveCue(aCue, aRv);
   SetDirty();
 }
 
 void
+TextTrack::SetCuesDirty()
+{
+  for (uint32_t i = 0; i < mCueList->Length(); i++) {
+    ((*mCueList)[i])->Reset();
+  }
+}
+
+void
 TextTrack::UpdateActiveCueList()
 {
   if (!mTextTrackList) {
     return;
   }
 
   HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
   if (!mediaElement) {
--- a/content/media/TextTrack.h
+++ b/content/media/TextTrack.h
@@ -100,16 +100,17 @@ public:
 
   TextTrackReadyState ReadyState() const;
   void SetReadyState(TextTrackReadyState aState);
   void SetReadyState(uint32_t aReadyState);
 
   void AddCue(TextTrackCue& aCue);
   void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv);
   void SetDirty() { mDirty = true; }
+  void SetCuesDirty();
 
   TextTrackList* GetTextTrackList();
   void SetTextTrackList(TextTrackList* aTextTrackList);
 
   IMPL_EVENT_HANDLER(cuechange)
 
   HTMLTrackElement* GetTrackElement();
   void SetTrackElement(HTMLTrackElement* aTrackElement);
--- a/content/media/TextTrackCue.h
+++ b/content/media/TextTrackCue.h
@@ -290,16 +290,21 @@ public:
   }
 
   void SetDisplayState(HTMLDivElement* aDisplayState)
   {
     mDisplayState = aDisplayState;
     mReset = false;
   }
 
+  void Reset()
+  {
+    mReset = true;
+  }
+
   bool HasBeenReset()
   {
     return mReset;
   }
 
   // Helper functions for implementation.
   bool
   operator==(const TextTrackCue& rhs) const