зеркало из https://github.com/mozilla/gecko-dev.git
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.
This commit is contained in:
Родитель
da2109a8bb
Коммит
41f3e30fc7
|
@ -62,6 +62,9 @@ NS_NewHTMLTrackElement(already_AddRefed<nsINodeInfo> 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)
|
||||
|
@ -90,6 +93,12 @@ NS_IMPL_CYCLE_COLLECTION_INHERITED_4(HTMLTrackElement, nsGenericHTMLElement,
|
|||
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,
|
||||
|
@ -130,55 +139,27 @@ 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);
|
||||
|
|
|
@ -21,6 +21,16 @@
|
|||
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
|
||||
|
@ -35,8 +45,11 @@ public:
|
|||
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
|
||||
{
|
||||
|
|
|
@ -20,14 +20,13 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=833386
|
|||
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"),
|
||||
|
@ -55,26 +54,6 @@ SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]},
|
|||
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();
|
||||
}
|
||||
);
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
[Pref="media.webvtt.enabled"]
|
||||
interface HTMLTrackElement : HTMLElement {
|
||||
[SetterThrows, Pure]
|
||||
attribute TextTrackKind kind;
|
||||
attribute DOMString kind;
|
||||
[SetterThrows, Pure]
|
||||
attribute DOMString src;
|
||||
[SetterThrows, Pure]
|
||||
|
|
Загрузка…
Ссылка в новой задаче