Bug 865407 - Part 4: Expose TextTrackCue::DisplayState to chrome JS. r=rillian, r=bz
authorRick Eyre <rick.eyre@hotmail.com>
Thu, 12 Dec 2013 11:27:30 -0500
changeset 163346 401b8593a881f7c98d42129395b7f5abdc6343ba
parent 163345 705f43739079c16edb44d0a91c9063b883d4c7c6
child 163347 9264d50055ea68c141bd00ce7bcb46c861d90490
push id25993
push userkwierso@gmail.com
push dateTue, 14 Jan 2014 23:24:56 +0000
treeherdermozilla-central@4e671e3183c4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, bz
bugs865407
milestone29.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 865407 - Part 4: Expose TextTrackCue::DisplayState to chrome JS. r=rillian, r=bz
content/media/TextTrackCue.cpp
content/media/TextTrackCue.h
dom/webidl/VTTCue.webidl
--- a/content/media/TextTrackCue.cpp
+++ b/content/media/TextTrackCue.cpp
@@ -99,22 +99,23 @@ TextTrackCue::StashDocument(nsISupports*
     return NS_ERROR_NOT_AVAILABLE;
   }
   return NS_OK;
 }
 
 void
 TextTrackCue::CreateCueOverlay()
 {
-  mDocument->CreateElem(NS_LITERAL_STRING("div"), nullptr,
-                        kNameSpaceID_XHTML,
-                        getter_AddRefs(mDisplayState));
-  nsGenericHTMLElement* cueDiv =
-    static_cast<nsGenericHTMLElement*>(mDisplayState.get());
-  cueDiv->SetClassName(NS_LITERAL_STRING("caption-text"));
+  nsCOMPtr<nsINodeInfo> nodeInfo =
+    mDocument->NodeInfoManager()->GetNodeInfo(nsGkAtoms::div,
+                                              nullptr,
+                                              kNameSpaceID_XHTML,
+                                              nsIDOMNode::ELEMENT_NODE);
+  mDisplayState = NS_NewHTMLDivElement(nodeInfo.forget());
+  mDisplayState->SetClassName(NS_LITERAL_STRING("caption-text"));
 }
 
 void
 TextTrackCue::RenderCue()
 {
   nsRefPtr<DocumentFragment> frag = GetCueAsHTML();
   if (!frag || !mTrackElement) {
     return;
@@ -143,17 +144,17 @@ TextTrackCue::RenderCue()
   if (!overlay) {
     return;
   }
 
   ErrorResult rv;
   nsContentUtils::SetNodeTextContent(overlay, EmptyString(), true);
   nsContentUtils::SetNodeTextContent(mDisplayState, EmptyString(), true);
 
-  mDisplayState->AppendChild(*frag, rv);
+  mDisplayState->nsINode::AppendChild(*frag, rv);
   overlay->AppendChild(*mDisplayState, rv);
 }
 
 already_AddRefed<DocumentFragment>
 TextTrackCue::GetCueAsHTML()
 {
   MOZ_ASSERT(mDocument);
 
--- a/content/media/TextTrackCue.h
+++ b/content/media/TextTrackCue.h
@@ -9,16 +9,17 @@
 
 #include "mozilla/dom/DocumentFragment.h"
 #include "mozilla/dom/VTTCueBinding.h"
 #include "nsCycleCollectionParticipant.h"
 #include "nsDOMEventTargetHelper.h"
 #include "nsIWebVTTParserWrapper.h"
 #include "mozilla/StaticPtr.h"
 #include "nsIDocument.h"
+#include "mozilla/dom/HTMLDivElement.h"
 
 namespace mozilla {
 namespace dom {
 
 class HTMLTrackElement;
 class TextTrack;
 
 class TextTrackCue MOZ_FINAL : public nsDOMEventTargetHelper
@@ -291,16 +292,26 @@ public:
     mReset = true;
     mText = aText;
     CueChanged();
   }
 
   IMPL_EVENT_HANDLER(enter)
   IMPL_EVENT_HANDLER(exit)
 
+  HTMLDivElement* GetDisplayState()
+  {
+    return static_cast<HTMLDivElement*>(mDisplayState.get());
+  }
+
+  void SetDisplayState(HTMLDivElement* aDisplayState)
+  {
+    mDisplayState = aDisplayState;
+  }
+
   // Helper functions for implementation.
   bool
   operator==(const TextTrackCue& rhs) const
   {
     return mId.Equals(rhs.mId);
   }
 
   const nsAString& Id() const
@@ -371,17 +382,17 @@ private:
   nsString mRegionId;
   DirectionSetting mVertical;
   int mLine;
   AlignSetting mAlign;
   AlignSetting 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
-  nsCOMPtr<nsIContent> mDisplayState;
+  nsRefPtr<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;
 
   static StaticRefPtr<nsIWebVTTParserWrapper> sParserWrapper;
 };
 
--- a/dom/webidl/VTTCue.webidl
+++ b/dom/webidl/VTTCue.webidl
@@ -48,8 +48,14 @@ interface VTTCue : EventTarget {
   attribute AlignSetting align;
   attribute DOMString text;
   DocumentFragment getCueAsHTML();
 
   attribute EventHandler onenter;
 
   attribute EventHandler onexit;
 };
+
+// Mozilla extensions.
+partial interface VTTCue {
+  [ChromeOnly]
+  attribute HTMLDivElement? displayState;
+};