Bug 1350821 - Notify the mediaElement to render subtitle when the mCaption was created or re-created. r=rillian draft
authorbechen <bechen@mozilla.com>
Tue, 28 Mar 2017 16:48:40 +0800
changeset 552310 2a3ed8f304ac8fdf9c0cc897e2f70bd2d23e8101
parent 552309 11c5d600d121d851c21ebc6cb738e26a4ebb4865
child 621777 0373d4a2f8ee96c66cc6c4f3a28c58941c7eb7aa
push id51311
push userbechen@mozilla.com
push dateTue, 28 Mar 2017 08:50:25 +0000
reviewersrillian
bugs1350821
milestone55.0a1
Bug 1350821 - Notify the mediaElement to render subtitle when the mCaption was created or re-created. r=rillian MozReview-Commit-ID: 3RM7u8jumT9
layout/generic/nsVideoFrame.cpp
layout/generic/nsVideoFrame.h
--- a/layout/generic/nsVideoFrame.cpp
+++ b/layout/generic/nsVideoFrame.cpp
@@ -133,16 +133,17 @@ nsVideoFrame::CreateAnonymousContent(nsT
     NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
     mCaptionDiv = NS_NewHTMLDivElement(nodeInfo.forget());
     NS_ENSURE_TRUE(mCaptionDiv, NS_ERROR_OUT_OF_MEMORY);
     nsGenericHTMLElement* div = static_cast<nsGenericHTMLElement*>(mCaptionDiv.get());
     div->SetClassName(NS_LITERAL_STRING("caption-box"));
 
     if (!aElements.AppendElement(mCaptionDiv))
       return NS_ERROR_OUT_OF_MEMORY;
+    UpdateTextTrack();
   }
 
   // Set up "videocontrols" XUL element which will be XBL-bound to the
   // actual controls.
   nodeInfo = nodeInfoManager->GetNodeInfo(nsGkAtoms::videocontrols,
                                           nullptr,
                                           kNameSpaceID_XUL,
                                           nsIDOMNode::ELEMENT_NODE);
@@ -771,8 +772,16 @@ bool nsVideoFrame::HasVideoData()
 {
   if (!HasVideoElement())
     return false;
   HTMLVideoElement* element = static_cast<HTMLVideoElement*>(GetContent());
   nsIntSize size(0, 0);
   element->GetVideoSize(&size);
   return size != nsIntSize(0,0);
 }
+
+void nsVideoFrame::UpdateTextTrack()
+{
+  HTMLMediaElement* element = static_cast<HTMLMediaElement*>(GetContent());
+  if (element) {
+    element->NotifyCueDisplayStatesChanged();
+  }
+}
--- a/layout/generic/nsVideoFrame.h
+++ b/layout/generic/nsVideoFrame.h
@@ -123,16 +123,19 @@ protected:
   // element for a media which is audio-only.
   bool HasVideoData();
 
   // Sets the mPosterImage's src attribute to be the video's poster attribute,
   // if we're the frame for a video element. Only call on frames for video
   // elements, not for frames for audio elements.
   void UpdatePosterSource(bool aNotify);
 
+  // Notify the mediaElement that the mCaptionDiv was created.
+  void UpdateTextTrack();
+
   virtual ~nsVideoFrame();
 
   // Anonymous child which is bound via XBL to the video controls.
   nsCOMPtr<nsIContent> mVideoControls;
 
   // Anonymous child which is the image element of the poster frame.
   nsCOMPtr<nsIContent> mPosterImage;