Bug 949643 - Implement VTTCue::PositionAlign. r=rillian
authorRick Eyre <rick.eyre@hotmail.com>
Fri, 13 Dec 2013 12:57:48 -0500
changeset 162933 a01d64b4d98570ebc0fcaa7202ffa7474ec7995b
parent 162932 e65b4f1bea8801d617f04d8159cccb76576ae5fb
child 162934 d4bdd22683d92ed9591021f3c98208547fa929bf
push id25975
push userryanvm@gmail.com
push dateFri, 10 Jan 2014 19:46:47 +0000
treeherderautoland@e89afc241513 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs949643
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 949643 - Implement VTTCue::PositionAlign. r=rillian
content/media/TextTrackCue.cpp
content/media/TextTrackCue.h
content/media/test/test_texttrackcue.html
dom/webidl/VTTCue.webidl
--- a/content/media/TextTrackCue.cpp
+++ b/content/media/TextTrackCue.cpp
@@ -31,16 +31,17 @@ NS_INTERFACE_MAP_END_INHERITING(nsDOMEve
 StaticRefPtr<nsIWebVTTParserWrapper> TextTrackCue::sParserWrapper;
 
 // Set cue setting defaults based on step 19 & seq.
 // in http://dev.w3.org/html5/webvtt/#parsing
 void
 TextTrackCue::SetDefaultCueSettings()
 {
   mPosition = 50;
+  mPositionAlign = AlignSetting::Middle;
   mSize = 100;
   mPauseOnExit = false;
   mSnapToLines = true;
   mLine = WEBVTT_AUTO;
   mAlign = AlignSetting::Middle;
   mLineAlign = AlignSetting::Start;
   mVertical = DirectionSetting::_empty;
 }
--- a/content/media/TextTrackCue.h
+++ b/content/media/TextTrackCue.h
@@ -215,16 +215,36 @@ public:
       return;
     }
 
     mReset = true;
     mPosition = aPosition;
     CueChanged();
   }
 
+  AlignSetting PositionAlign() const
+  {
+    return mPositionAlign;
+  }
+
+  void SetPositionAlign(AlignSetting aPositionAlign, ErrorResult& aRv)
+  {
+    if (mPositionAlign == aPositionAlign)
+      return;
+
+    if (aPositionAlign == AlignSetting::Left ||
+        aPositionAlign == AlignSetting::Right) {
+      return aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
+    }
+
+    mReset = true;
+    mPositionAlign = aPositionAlign;
+    CueChanged();
+  }
+
   int32_t Size() const
   {
     return mSize;
   }
 
   void SetSize(int32_t aSize, ErrorResult& aRv)
   {
     if (mSize == aSize) {
@@ -339,16 +359,17 @@ private:
   nsString mText;
   double mStartTime;
   double mEndTime;
 
   nsRefPtr<TextTrack> mTrack;
   nsRefPtr<HTMLTrackElement> mTrackElement;
   nsString mId;
   int32_t mPosition;
+  AlignSetting mPositionAlign;
   int32_t mSize;
   bool mPauseOnExit;
   bool mSnapToLines;
   nsString mRegionId;
   DirectionSetting mVertical;
   int mLine;
   AlignSetting mAlign;
   AlignSetting mLineAlign;
--- a/content/media/test/test_texttrackcue.html
+++ b/content/media/test/test_texttrackcue.html
@@ -99,16 +99,42 @@ SpecialPowers.pushPrefEnv({"set": [["med
 
       cue.lineAlign = "middle";
       is(cue.lineAlign, "middle", "Cue's line align should be middle.");
       cue.lineAlign = "START";
       is(cue.lineAlign, "middle", "Cue's line align should be middle.");
       cue.lineAlign = "end";
       is(cue.lineAlign, "end", "Cue's line align should be end.");
 
+      // Check that cue position align works properly
+      is(cue.positionAlign, "middle", "Cue's default position alignment should be middle.");
+
+      var exceptionHappened = false;
+      try {
+        cue.positionAlign = "left";
+      } catch(e) {
+        exceptionHappened = true;
+        is(e.name, "SyntaxError", "Should have thrown SyntaxError.");
+      }
+      ok(exceptionHappened, "Exception should have happened.");
+
+      exceptionHappened = false;
+      try {
+        cue.positionAlign = "right";
+      } catch(e) {
+        exceptionHappened = true;
+        is(e.name, "SyntaxError", "Should have thrown SyntaxError.");
+      }
+      ok(exceptionHappened, "Exception should have happened.");
+
+      cue.positionAlign = "start";
+      is(cue.positionAlign, "start", "Cue's position align should be start.");
+      cue.positionAlign = "end";
+      is(cue.positionAlign, "end", "Cue's position align should be end.");
+
       // Check that we can create and add new VTTCues
       var vttCue = new VTTCue(3.999, 4, "foo");
       trackElement.track.addCue(vttCue);
       is(cueList.length, 7, "Cue list length should now be 7.");
 
       // Check that new VTTCue was added correctly
       cue = cueList[6];
       is(cue.startTime, 3.999, "Cue's start time should be 3.999.");
--- a/dom/webidl/VTTCue.webidl
+++ b/dom/webidl/VTTCue.webidl
@@ -37,16 +37,18 @@ interface VTTCue : EventTarget {
   attribute boolean snapToLines;
   // XXXhumph: https://www.w3.org/Bugs/Public/show_bug.cgi?id=20651
   // attribute (long or AutoKeyword) line;
   [SetterThrows]
   attribute AlignSetting lineAlign;
   [SetterThrows]
   attribute long position;
   [SetterThrows]
+  attribute AlignSetting positionAlign;
+  [SetterThrows]
   attribute long size;
   attribute AlignSetting align;
   attribute DOMString text;
   DocumentFragment getCueAsHTML();
 
   attribute EventHandler onenter;
 
   attribute EventHandler onexit;