Bug 1350821 - Notify the mediaElement to render subtitle when the mCaption was created or re-created. r=rillian
MozReview-Commit-ID: 3RM7u8jumT9
--- 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;