Bug 1276832 - part1 : modify VTTCue's line to double. r=rillian,smaug
authorAlastor Wu <alwu@mozilla.com>
Tue, 14 Jun 2016 11:47:32 +0100
changeset 326800 581aeb0a9dbe5a7c076b0b1208ba93dfb5e7f2b3
parent 326799 5e3d8982f1a5646e65fcc4fc151b0280ce4a6248
child 326801 c3f20d18028cbeab418161eeed38b3eb94e16311
push id9858
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 14:37:10 +0000
treeherdermozilla-aurora@203106ef6cb6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian, smaug
bugs1276832
milestone50.0a1
Bug 1276832 - part1 : modify VTTCue's line to double. r=rillian,smaug MozReview-Commit-ID: 7P79SO5TI0K
dom/media/TextTrackCue.cpp
dom/media/TextTrackCue.h
dom/webidl/VTTCue.webidl
--- a/dom/media/TextTrackCue.cpp
+++ b/dom/media/TextTrackCue.cpp
@@ -1,15 +1,16 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/HTMLTrackElement.h"
 #include "mozilla/dom/TextTrackCue.h"
+#include "mozilla/dom/TextTrackList.h"
 #include "mozilla/dom/TextTrackRegion.h"
 #include "nsComponentManagerUtils.h"
 #include "mozilla/ClearOnShutdown.h"
 
 namespace mozilla {
 namespace dom {
 
 NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrackCue,
@@ -164,16 +165,50 @@ TextTrackCue::SetRegion(TextTrackRegion*
 {
   if (mRegion == aRegion) {
     return;
   }
   mRegion = aRegion;
   mReset = true;
 }
 
+double
+TextTrackCue::ComputedLine()
+{
+  // See spec https://w3c.github.io/webvtt/#cue-computed-line
+  if (!mLineIsAutoKeyword && !mSnapToLines &&
+      (mLine < 0.0 || mLine > 100.0)) {
+    return 100.0;
+  } else if (!mLineIsAutoKeyword) {
+    return mLine;
+  } else if (mLineIsAutoKeyword && !mSnapToLines) {
+    return 100.0;
+  } else if (!mTrack ||
+             !mTrack->GetTextTrackList() ||
+             !mTrack->GetTextTrackList()->GetMediaElement()) {
+    return -1.0;
+  }
+
+  RefPtr<TextTrackList> trackList = mTrack->GetTextTrackList();
+  bool dummy;
+  uint32_t showingTracksNum = 0;
+  for (uint32_t idx = 0; idx < trackList->Length(); idx++) {
+    RefPtr<TextTrack> track = trackList->IndexedGetter(idx, dummy);
+    if (track->Mode() == TextTrackMode::Showing) {
+      showingTracksNum++;
+    }
+
+    if (mTrack == track) {
+      break;
+    }
+  }
+
+  return (-1.0) * showingTracksNum;
+}
+
 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;
--- a/dom/media/TextTrackCue.h
+++ b/dom/media/TextTrackCue.h
@@ -146,31 +146,31 @@ public:
     if (mSnapToLines == aSnapToLines) {
       return;
     }
 
     mReset = true;
     mSnapToLines = aSnapToLines;
   }
 
-  void GetLine(OwningLongOrAutoKeyword& aLine) const
+  void GetLine(OwningDoubleOrAutoKeyword& aLine) const
   {
     if (mLineIsAutoKeyword) {
       aLine.SetAsAutoKeyword() = AutoKeyword::Auto;
       return;
     }
-    aLine.SetAsLong() = mLineLong;
+    aLine.SetAsDouble() = mLine;
   }
 
-  void SetLine(const LongOrAutoKeyword& aLine)
+  void SetLine(const DoubleOrAutoKeyword& aLine)
   {
-    if (aLine.IsLong() &&
-        (mLineIsAutoKeyword || (aLine.GetAsLong() != mLineLong))) {
+    if (aLine.IsDouble() &&
+        (mLineIsAutoKeyword || (aLine.GetAsDouble() != mLine))) {
       mLineIsAutoKeyword = false;
-      mLineLong = aLine.GetAsLong();
+      mLine = aLine.GetAsDouble();
       mReset = true;
       return;
     }
     if (aLine.IsAutoKeyword() && !mLineIsAutoKeyword) {
       mLineIsAutoKeyword = true;
       mReset = true;
     }
   }
@@ -294,16 +294,17 @@ public:
     mReset = true;
   }
 
   bool HasBeenReset()
   {
     return mReset;
   }
 
+  double ComputedLine();
   PositionAlignSetting ComputedPositionAlign();
 
   // Helper functions for implementation.
   bool
   operator==(const TextTrackCue& rhs) const
   {
     return mId.Equals(rhs.mId);
   }
@@ -362,17 +363,17 @@ private:
   int32_t mPosition;
   PositionAlignSetting mPositionAlign;
   int32_t mSize;
   bool mPauseOnExit;
   bool mSnapToLines;
   RefPtr<TextTrackRegion> mRegion;
   DirectionSetting mVertical;
   bool mLineIsAutoKeyword;
-  long mLineLong;
+  double mLine;
   AlignSetting mAlign;
   LineAlignSetting mLineAlign;
 
   // Holds the computed DOM elements that represent the parsed cue text.
   // http://www.whatwg.org/specs/web-apps/current-work/#text-track-cue-display-state
   RefPtr<nsGenericHTMLElement> mDisplayState;
   // Tells whether or not we need to recompute mDisplayState. This is set
   // anytime a property that relates to the display of the TextTrackCue is
--- a/dom/webidl/VTTCue.webidl
+++ b/dom/webidl/VTTCue.webidl
@@ -38,17 +38,17 @@ enum DirectionSetting {
 
 [Constructor(double startTime, double endTime, DOMString text),
  Pref="media.webvtt.enabled"]
 interface VTTCue : TextTrackCue {
   [Pref="media.webvtt.regions.enabled"]
   attribute VTTRegion? region;
   attribute DirectionSetting vertical;
   attribute boolean snapToLines;
-  attribute (long or AutoKeyword) line;
+  attribute (double or AutoKeyword) line;
   [SetterThrows]
   attribute LineAlignSetting lineAlign;
   [SetterThrows]
   attribute long position;
   [SetterThrows]
   attribute PositionAlignSetting positionAlign;
   [SetterThrows]
   attribute long size;
@@ -59,10 +59,12 @@ interface VTTCue : TextTrackCue {
 
 // Mozilla extensions.
 partial interface VTTCue {
   [ChromeOnly]
   attribute HTMLDivElement? displayState;
   [ChromeOnly]
   readonly attribute boolean hasBeenReset;
   [ChromeOnly]
+  readonly attribute double computedLine;
+  [ChromeOnly]
   readonly attribute PositionAlignSetting computedPositionAlign;
 };