Bug 1276129 - part1 : introduce PositionAlignSetting. r=rillian,smaug
authorAlastor Wu <alwu@mozilla.com>
Thu, 02 Jun 2016 10:40:23 +0800
changeset 341313 d3cf9f70e5feb246ea2fea7bb10e493651a1409a
parent 341312 30a1d2e8e043b12528839525e119565bec135fbe
child 341314 1d7eb0adafc69c70c285a7db7a9bf069889cf2ce
push id1183
push userraliiev@mozilla.com
push dateMon, 05 Sep 2016 20:01:49 +0000
treeherdermozilla-release@3148731bed45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, smaug
bugs1276129
milestone49.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 1276129 - part1 : introduce PositionAlignSetting. r=rillian,smaug MozReview-Commit-ID: AWzNCPLPdYw
dom/media/TextTrackCue.cpp
dom/media/TextTrackCue.h
dom/webidl/VTTCue.webidl
--- a/dom/media/TextTrackCue.cpp
+++ b/dom/media/TextTrackCue.cpp
@@ -28,17 +28,17 @@ NS_INTERFACE_MAP_END_INHERITING(DOMEvent
 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;
+  mPositionAlign = PositionAlignSetting::Center;
   mSize = 100;
   mPauseOnExit = false;
   mSnapToLines = true;
   mLineIsAutoKeyword = true;
   mAlign = AlignSetting::Middle;
   mLineAlign = AlignSetting::Start;
   mVertical = DirectionSetting::_empty;
   mActive = false;
@@ -164,10 +164,24 @@ TextTrackCue::SetRegion(TextTrackRegion*
 {
   if (mRegion == aRegion) {
     return;
   }
   mRegion = aRegion;
   mReset = true;
 }
 
+PositionAlignSetting
+TextTrackCue::ComputedPositionAlign()
+{
+  // See spec https://w3c.github.io/webvtt/#cue-computed-position-alignment
+  if (mPositionAlign != PositionAlignSetting::Auto) {
+    return mPositionAlign;
+  } else if (mAlign == AlignSetting::Left) {
+    return PositionAlignSetting::Line_left;
+  } else if (mAlign == AlignSetting::Right) {
+    return PositionAlignSetting::Line_right;
+  }
+  return PositionAlignSetting::Center;
+}
+
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/TextTrackCue.h
+++ b/dom/media/TextTrackCue.h
@@ -206,29 +206,25 @@ public:
       aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
       return;
     }
 
     mReset = true;
     mPosition = aPosition;
   }
 
-  AlignSetting PositionAlign() const
+  PositionAlignSetting PositionAlign() const
   {
     return mPositionAlign;
   }
 
-  void SetPositionAlign(AlignSetting aPositionAlign, ErrorResult& aRv)
+  void SetPositionAlign(PositionAlignSetting aPositionAlign, ErrorResult& aRv)
   {
-    if (mPositionAlign == aPositionAlign)
+    if (mPositionAlign == aPositionAlign) {
       return;
-
-    if (aPositionAlign == AlignSetting::Left ||
-        aPositionAlign == AlignSetting::Right) {
-      return aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
     }
 
     mReset = true;
     mPositionAlign = aPositionAlign;
   }
 
   int32_t Size() const
   {
@@ -299,16 +295,18 @@ public:
     mReset = true;
   }
 
   bool HasBeenReset()
   {
     return mReset;
   }
 
+  PositionAlignSetting ComputedPositionAlign();
+
   // Helper functions for implementation.
   bool
   operator==(const TextTrackCue& rhs) const
   {
     return mId.Equals(rhs.mId);
   }
 
   const nsAString& Id() const
@@ -352,17 +350,17 @@ private:
   nsString mText;
   double mStartTime;
   double mEndTime;
 
   RefPtr<TextTrack> mTrack;
   RefPtr<HTMLTrackElement> mTrackElement;
   nsString mId;
   int32_t mPosition;
-  AlignSetting mPositionAlign;
+  PositionAlignSetting mPositionAlign;
   int32_t mSize;
   bool mPauseOnExit;
   bool mSnapToLines;
   RefPtr<TextTrackRegion> mRegion;
   DirectionSetting mVertical;
   bool mLineIsAutoKeyword;
   long mLineLong;
   AlignSetting mAlign;
--- a/dom/webidl/VTTCue.webidl
+++ b/dom/webidl/VTTCue.webidl
@@ -4,16 +4,23 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * The origin of this IDL file is
  * http://dev.w3.org/html5/webvtt/#the-vttcue-interface
  */
 
 enum AutoKeyword { "auto" };
 
+enum PositionAlignSetting {
+  "line-left",
+  "center",
+  "line-right",
+  "auto"
+};
+
 enum AlignSetting {
   "start",
   "middle",
   "end",
   "left",
   "right"
 };
 
@@ -31,23 +38,25 @@ interface VTTCue : TextTrackCue {
   attribute DirectionSetting vertical;
   attribute boolean snapToLines;
   attribute (long or AutoKeyword) line;
   [SetterThrows]
   attribute AlignSetting lineAlign;
   [SetterThrows]
   attribute long position;
   [SetterThrows]
-  attribute AlignSetting positionAlign;
+  attribute PositionAlignSetting positionAlign;
   [SetterThrows]
   attribute long size;
   attribute AlignSetting align;
   attribute DOMString text;
   DocumentFragment getCueAsHTML();
 };
 
 // Mozilla extensions.
 partial interface VTTCue {
   [ChromeOnly]
   attribute HTMLDivElement? displayState;
   [ChromeOnly]
   readonly attribute boolean hasBeenReset;
+  [ChromeOnly]
+  readonly attribute PositionAlignSetting computedPositionAlign;
 };