Bug 880064 - Change HTMLTrackElement::Kind to a DOMString value. r=Ms2ger
authorRick Eyre <rick.eyre@hotmail.com>
Thu, 04 Jul 2013 14:16:05 -0400
changeset 143109 c1bb3be506eeb27f6b09e0386cb02f4217cc7e17
parent 143108 9a06d4cd909ca508e0c53e1f6e175787c01fce99
child 143110 f00ecb727d6102f6f40f783b8b59793cdbd7b57c
push id25122
push userryanvm@gmail.com
push dateTue, 20 Aug 2013 02:32:40 +0000
treeherdermozilla-central@bb025b6949e8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
bugs880064
milestone26.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 880064 - Change HTMLTrackElement::Kind to a DOMString value. r=Ms2ger This was originally in the spec as an enumerated value, but due to the current problems with reflecting enumerated values it had to be changed to a DOMString. This has been changed in the HTML5 spec as well.
content/html/content/src/HTMLTrackElement.cpp
content/html/content/src/HTMLTrackElement.h
content/html/content/test/test_track.html
dom/webidl/HTMLTrackElement.webidl
--- a/content/html/content/src/HTMLTrackElement.cpp
+++ b/content/html/content/src/HTMLTrackElement.cpp
@@ -57,16 +57,19 @@ NS_NewHTMLTrackElement(already_AddRefed<
   }
 
   return new mozilla::dom::HTMLTrackElement(aNodeInfo);
 }
 
 namespace mozilla {
 namespace dom {
 
+// The default value for kKindTable is "subtitles"
+static const char* kKindTableDefaultString = kKindTable->tag;
+
 /** HTMLTrackElement */
 HTMLTrackElement::HTMLTrackElement(already_AddRefed<nsINodeInfo> aNodeInfo)
   : nsGenericHTMLElement(aNodeInfo)
   , mReadyState(NONE)
 {
 #ifdef PR_LOGGING
   if (!gTrackElementLog) {
     gTrackElementLog = PR_NewLogModule("nsTrackElement");
@@ -86,16 +89,22 @@ NS_IMPL_RELEASE_INHERITED(HTMLTrackEleme
 NS_IMPL_CYCLE_COLLECTION_INHERITED_4(HTMLTrackElement, nsGenericHTMLElement,
                                      mTrack, mChannel, mMediaParent,
                                      mLoadListener)
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTrackElement)
 NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
 
 void
+HTMLTrackElement::GetKind(DOMString& aKind) const
+{
+  GetEnumAttr(nsGkAtoms::kind, kKindTableDefaultString, aKind);
+}
+
+void
 HTMLTrackElement::OnChannelRedirect(nsIChannel* aChannel,
                                     nsIChannel* aNewChannel,
                                     uint32_t aFlags)
 {
   NS_ASSERTION(aChannel == mChannel, "Channels should match!");
   mChannel = aNewChannel;
 }
 
@@ -125,65 +134,37 @@ HTMLTrackElement::Track()
 }
 
 void
 HTMLTrackElement::CreateTextTrack()
 {
   nsString label, srcLang;
   GetSrclang(srcLang);
   GetLabel(label);
-  mTrack = new TextTrack(OwnerDoc()->GetParentObject(), Kind(), label, srcLang);
+
+  TextTrackKind kind;
+  if (const nsAttrValue* value = GetParsedAttr(nsGkAtoms::kind)) {
+    kind = static_cast<TextTrackKind>(value->GetEnumValue());
+  } else {
+    kind = TextTrackKind::Subtitles;
+  }
+
+  mTrack = new TextTrack(OwnerDoc()->GetParentObject(), kind, label, srcLang);
 
   if (mMediaParent) {
     mMediaParent->AddTextTrack(mTrack);
   }
 }
 
-TextTrackKind
-HTMLTrackElement::Kind() const
-{
-  const nsAttrValue* value = GetParsedAttr(nsGkAtoms::kind);
-  if (!value) {
-    return TextTrackKind::Subtitles;
-  }
-  return static_cast<TextTrackKind>(value->GetEnumValue());
-}
-
-static EnumEntry
-StringFromKind(TextTrackKind aKind)
-{
-  return TextTrackKindValues::strings[static_cast<int>(aKind)];
-}
-
-void
-HTMLTrackElement::SetKind(TextTrackKind aKind, ErrorResult& aError)
-{
-  const EnumEntry& string = StringFromKind(aKind);
-  nsAutoString kind;
-
-  kind.AssignASCII(string.value, string.length);
-  SetHTMLAttr(nsGkAtoms::kind, kind, aError);
-}
-
 bool
 HTMLTrackElement::ParseAttribute(int32_t aNamespaceID,
                                  nsIAtom* aAttribute,
                                  const nsAString& aValue,
                                  nsAttrValue& aResult)
 {
-  // Map html attribute string values to TextTrackKind enums.
-  static const nsAttrValue::EnumTable kKindTable[] = {
-    { "subtitles", static_cast<int16_t>(TextTrackKind::Subtitles) },
-    { "captions", static_cast<int16_t>(TextTrackKind::Captions) },
-    { "descriptions", static_cast<int16_t>(TextTrackKind::Descriptions) },
-    { "chapters", static_cast<int16_t>(TextTrackKind::Chapters) },
-    { "metadata", static_cast<int16_t>(TextTrackKind::Metadata) },
-    { 0 }
-  };
-
   if (aNamespaceID == kNameSpaceID_None && aAttribute == nsGkAtoms::kind) {
     // Case-insensitive lookup, with the first element as the default.
     return aResult.ParseEnumValue(aValue, kKindTable, false, kKindTable);
   }
 
   // Otherwise call the generic implementation.
   return nsGenericHTMLElement::ParseAttribute(aNamespaceID,
                                               aAttribute,
--- a/content/html/content/src/HTMLTrackElement.h
+++ b/content/html/content/src/HTMLTrackElement.h
@@ -16,32 +16,45 @@
 #include "nsIDocument.h"
 #include "nsIDOMHTMLElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsIHttpChannel.h"
 
 namespace mozilla {
 namespace dom {
 
+// Map html attribute string values to TextTrackKind enums.
+static const nsAttrValue::EnumTable kKindTable[] = {
+  { "subtitles", static_cast<int16_t>(TextTrackKind::Subtitles) },
+  { "captions", static_cast<int16_t>(TextTrackKind::Captions) },
+  { "descriptions", static_cast<int16_t>(TextTrackKind::Descriptions) },
+  { "chapters", static_cast<int16_t>(TextTrackKind::Chapters) },
+  { "metadata", static_cast<int16_t>(TextTrackKind::Metadata) },
+  { 0 }
+};
+
 class WebVTTLoadListener;
 
 class HTMLTrackElement MOZ_FINAL : public nsGenericHTMLElement
 {
 public:
   HTMLTrackElement(already_AddRefed<nsINodeInfo> aNodeInfo);
   virtual ~HTMLTrackElement();
 
   // nsISupports
   NS_DECL_ISUPPORTS_INHERITED
   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLTrackElement,
                                            nsGenericHTMLElement)
 
   // HTMLTrackElement WebIDL
-  TextTrackKind Kind() const;
-  void SetKind(TextTrackKind aKind, ErrorResult& aError);
+  void GetKind(DOMString& aKind) const;
+  void SetKind(const nsAString& aKind, ErrorResult& aError)
+  {
+    SetHTMLAttr(nsGkAtoms::kind, aKind, aError);
+  }
 
   void GetSrc(DOMString& aSrc) const
   {
     GetHTMLURIAttr(nsGkAtoms::src, aSrc);
   }
   void SetSrc(const nsAString& aSrc, ErrorResult& aError)
   {
     SetHTMLAttr(nsGkAtoms::src, aSrc, aError);
--- a/content/html/content/test/test_track.html
+++ b/content/html/content/test/test_track.html
@@ -15,24 +15,23 @@ https://bugzilla.mozilla.org/show_bug.cg
 <p id="display"></p>
 <div id="content" style="display: none">
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
 SimpleTest.waitForExplicitFinish();
 SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]},
   function() {
-    /* TODO:: See https://bugzilla.mozilla.org/show_bug.cgi?id=880064 and https://www.w3.org/Bugs/Public/show_bug.cgi?id=22221
     reflectLimitedEnumerated({
       element: document.createElement("track"),
       attribute: "kind",
       validValues: ["subtitles", "captions", "descriptions", "chapters", "metadata"],
       invalidValues: ["foo", "bar", "\u0000", "null", "", "subtitle", "caption", "description", "chapter", "meta"],
       defaultValue: "subtitles"
-    });*/
+    });
     // Default attribute
     reflectBoolean({
       element: document.createElement("track"),
       attribute: "default"
     });
     // Label attribute
     reflectString({
       element: document.createElement("track"),
@@ -50,35 +49,15 @@ SpecialPowers.pushPrefEnv({"set": [["med
       element: document.createElement("track"),
       attribute: "srclang",
       otherValues: ["foo", "bar", "\u0000", "null", ""]
     });
 
     var track = document.createElement("track");
     is(track.readyState, 0, "Default ready state should be 0 (NONE).");
 
-    // Following are manual track.kind tests until the reflect.js problems get
-    // cleared up above.
-    // See: https://bugzilla.mozilla.org/show_bug.cgi?id=880064 and
-    //      https://www.w3.org/Bugs/Public/show_bug.cgi?id=22221
-    is(track.kind, "subtitles", "Default track kind should be subtitles.");
-
-    // Kind should not be able to be set to bogus value.
-    track.kind = "bogus";
-    is(track.kind, "subtitles", "Track kind should not be able to be set to a bogus value.");
-
-    checkKind("captions", "Kind should be set to captions.");
-    checkKind("descriptions", "Kind should be set to descriptions.");
-    checkKind("chapters", "Kind should be set to chapters.");
-    checkKind("metadata", "Kind should be set to metadata.");
-
-    function checkKind(kind, message) {
-      track.kind = kind;
-      is(track.kind, kind, message);
-    }
-
     SimpleTest.finish();
   }
 );
 </script>
 </pre>
 </body>
 </html>
--- a/dom/webidl/HTMLTrackElement.webidl
+++ b/dom/webidl/HTMLTrackElement.webidl
@@ -5,17 +5,17 @@
  *
  * The origin of this IDL file is
  * http://www.whatwg.org/specs/web-apps/current-work/#the-track-element
  */
 
 [Pref="media.webvtt.enabled"]
 interface HTMLTrackElement : HTMLElement {
   [SetterThrows, Pure]
-  attribute TextTrackKind kind;
+  attribute DOMString kind;
   [SetterThrows, Pure]
   attribute DOMString src;
   [SetterThrows, Pure]
   attribute DOMString srclang;
   [SetterThrows, Pure]
   attribute DOMString label;
   [SetterThrows, Pure]
   attribute boolean default;