From 1fe94a73b3ec6249a9e7558123ea04fa9eb24079 Mon Sep 17 00:00:00 2001 From: Rick Eyre Date: Wed, 15 Jan 2014 08:04:00 -0800 Subject: [PATCH] Bug 882299 - Implement VTTCue::Line r=smaug,rillian,bz --- content/media/TextTrackCue.cpp | 5 +--- content/media/TextTrackCue.h | 30 +++++++++++++++++------ content/media/test/test_texttrackcue.html | 7 ++++++ dom/bindings/Codegen.py | 4 ++- dom/webidl/VTTCue.webidl | 3 +-- 5 files changed, 35 insertions(+), 14 deletions(-) diff --git a/content/media/TextTrackCue.cpp b/content/media/TextTrackCue.cpp index e249fbddc17..35f5a46ff2e 100644 --- a/content/media/TextTrackCue.cpp +++ b/content/media/TextTrackCue.cpp @@ -8,9 +8,6 @@ #include "nsComponentManagerUtils.h" #include "mozilla/ClearOnShutdown.h" -// Alternate value for the 'auto' keyword. -#define WEBVTT_AUTO -1 - namespace mozilla { namespace dom { @@ -38,7 +35,7 @@ TextTrackCue::SetDefaultCueSettings() mSize = 100; mPauseOnExit = false; mSnapToLines = true; - mLine = WEBVTT_AUTO; + mLineIsAutoKeyword = true; mAlign = AlignSetting::Middle; mLineAlign = AlignSetting::Start; mVertical = DirectionSetting::_empty; diff --git a/content/media/TextTrackCue.h b/content/media/TextTrackCue.h index bda35957497..ab46596d046 100644 --- a/content/media/TextTrackCue.h +++ b/content/media/TextTrackCue.h @@ -15,6 +15,7 @@ #include "mozilla/StaticPtr.h" #include "nsIDocument.h" #include "mozilla/dom/HTMLDivElement.h" +#include "mozilla/dom/UnionTypes.h" namespace mozilla { namespace dom { @@ -168,16 +169,30 @@ public: CueChanged(); } - double Line() const + void GetLine(OwningLongOrAutoKeyword& aLine) const { - return mLine; + if (mLineIsAutoKeyword) { + aLine.SetAsAutoKeyword() = AutoKeyword::Auto; + return; + } + aLine.SetAsLong() = mLineLong; } - void SetLine(double aLine) + void SetLine(const LongOrAutoKeyword& aLine) { - //XXX: TODO Line position can be a keyword auto. bug882299 - mReset = true; - mLine = aLine; + if (aLine.IsLong() && + (mLineIsAutoKeyword || (aLine.GetAsLong() != mLineLong))) { + mLineIsAutoKeyword = false; + mLineLong = aLine.GetAsLong(); + CueChanged(); + mReset = true; + return; + } + if (aLine.IsAutoKeyword() && !mLineIsAutoKeyword) { + mLineIsAutoKeyword = true; + CueChanged(); + mReset = true; + } } AlignSetting LineAlign() const @@ -355,7 +370,8 @@ private: bool mSnapToLines; nsString mRegionId; DirectionSetting mVertical; - int mLine; + bool mLineIsAutoKeyword; + long mLineLong; AlignSetting mAlign; AlignSetting mLineAlign; diff --git a/content/media/test/test_texttrackcue.html b/content/media/test/test_texttrackcue.html index b4145280ca0..907f2bd007b 100644 --- a/content/media/test/test_texttrackcue.html +++ b/content/media/test/test_texttrackcue.html @@ -130,6 +130,13 @@ SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true]]}, cue.positionAlign = "end"; is(cue.positionAlign, "end", "Cue's position align should be end."); + // Check cue.line + is(cue.line, "auto", "Cue's line value should initially be auto."); + cue.line = 12410 + is(cue.line, 12410, "Cue's line value should now be 12410."); + cue.line = "auto"; + is(cue.line, "auto", "Cue's line value should now be auto."); + // Check that we can create and add new VTTCues var vttCue = new VTTCue(3.999, 4, "foo"); trackElement.track.addCue(vttCue); diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 941ad5f2dbb..15701fcb059 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -840,7 +840,9 @@ def UnionTypes(descriptors, dictionaries, callbacks, config): if typeNeedsRooting(f): headers.add("mozilla/dom/RootedDictionary.h") elif f.isEnum(): - headers.add(CGHeaders.getDeclarationFilename(f)) + # Need to see the actual definition of the enum, + # unfortunately. + headers.add(CGHeaders.getDeclarationFilename(f.inner)) map(addInfoForType, getAllTypes(descriptors, dictionaries, callbacks)) diff --git a/dom/webidl/VTTCue.webidl b/dom/webidl/VTTCue.webidl index 60d5f8b190a..fa79c8707bd 100644 --- a/dom/webidl/VTTCue.webidl +++ b/dom/webidl/VTTCue.webidl @@ -35,8 +35,7 @@ interface VTTCue : EventTarget { attribute DOMString regionId; attribute DirectionSetting vertical; attribute boolean snapToLines; - // XXXhumph: https://www.w3.org/Bugs/Public/show_bug.cgi?id=20651 - // attribute (long or AutoKeyword) line; + attribute (long or AutoKeyword) line; [SetterThrows] attribute AlignSetting lineAlign; [SetterThrows]