2013-05-21 20:14:00 +04:00
|
|
|
/* -*- 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"
|
2016-06-14 13:47:32 +03:00
|
|
|
#include "mozilla/dom/TextTrackList.h"
|
2014-03-11 21:33:58 +04:00
|
|
|
#include "mozilla/dom/TextTrackRegion.h"
|
2013-09-19 19:26:00 +04:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2013-09-24 23:17:15 +04:00
|
|
|
#include "mozilla/ClearOnShutdown.h"
|
2013-07-10 04:02:00 +04:00
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-25 20:49:00 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrackCue,
|
|
|
|
DOMEventTargetHelper,
|
|
|
|
mDocument,
|
|
|
|
mTrack,
|
|
|
|
mTrackElement,
|
|
|
|
mDisplayState,
|
|
|
|
mRegion)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TextTrackCue, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TextTrackCue, DOMEventTargetHelper)
|
2013-05-21 20:14:00 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextTrackCue)
|
2014-04-01 10:13:50 +04:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-05-21 20:14:00 +04:00
|
|
|
|
2013-09-19 19:26:00 +04:00
|
|
|
StaticRefPtr<nsIWebVTTParserWrapper> TextTrackCue::sParserWrapper;
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
// Set cue setting defaults based on step 19 & seq.
|
|
|
|
// in http://dev.w3.org/html5/webvtt/#parsing
|
|
|
|
void
|
|
|
|
TextTrackCue::SetDefaultCueSettings()
|
|
|
|
{
|
2016-06-15 18:51:17 +03:00
|
|
|
mPositionIsAutoKeyword = true;
|
2016-06-02 05:40:23 +03:00
|
|
|
mPositionAlign = PositionAlignSetting::Center;
|
2016-06-14 13:51:40 +03:00
|
|
|
mSize = 100.0;
|
2013-05-21 20:14:00 +04:00
|
|
|
mPauseOnExit = false;
|
|
|
|
mSnapToLines = true;
|
2014-01-15 20:04:00 +04:00
|
|
|
mLineIsAutoKeyword = true;
|
2016-06-14 16:39:29 +03:00
|
|
|
mAlign = AlignSetting::Center;
|
2016-06-06 04:53:16 +03:00
|
|
|
mLineAlign = LineAlignSetting::Start;
|
2013-09-12 18:07:14 +04:00
|
|
|
mVertical = DirectionSetting::_empty;
|
2016-06-01 08:35:53 +03:00
|
|
|
mActive = false;
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TextTrackCue::TextTrackCue(nsPIDOMWindowInner* aOwnerWindow,
|
2013-05-21 20:14:00 +04:00
|
|
|
double aStartTime,
|
|
|
|
double aEndTime,
|
2013-07-17 09:14:40 +04:00
|
|
|
const nsAString& aText,
|
|
|
|
ErrorResult& aRv)
|
2014-04-07 21:58:38 +04:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
|
|
|
, mText(aText)
|
2013-05-21 20:14:00 +04:00
|
|
|
, mStartTime(aStartTime)
|
|
|
|
, mEndTime(aEndTime)
|
2016-08-09 11:58:52 +03:00
|
|
|
, mReset(false, "TextTrackCue::mReset")
|
|
|
|
, mHaveStartedWatcher(false)
|
2016-11-29 08:03:36 +03:00
|
|
|
, mWatchManager(this, GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other))
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
|
|
|
SetDefaultCueSettings();
|
2014-04-07 21:58:38 +04:00
|
|
|
MOZ_ASSERT(aOwnerWindow);
|
|
|
|
if (NS_FAILED(StashDocument())) {
|
2013-07-17 09:14:40 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
TextTrackCue::TextTrackCue(nsPIDOMWindowInner* aOwnerWindow,
|
2013-05-21 20:14:00 +04:00
|
|
|
double aStartTime,
|
|
|
|
double aEndTime,
|
|
|
|
const nsAString& aText,
|
|
|
|
HTMLTrackElement* aTrackElement,
|
2013-07-17 09:14:40 +04:00
|
|
|
ErrorResult& aRv)
|
2014-04-07 21:58:38 +04:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
|
|
|
, mText(aText)
|
2013-05-21 20:14:00 +04:00
|
|
|
, mStartTime(aStartTime)
|
|
|
|
, mEndTime(aEndTime)
|
|
|
|
, mTrackElement(aTrackElement)
|
2016-08-09 11:58:52 +03:00
|
|
|
, mReset(false, "TextTrackCue::mReset")
|
|
|
|
, mHaveStartedWatcher(false)
|
2016-11-29 08:03:36 +03:00
|
|
|
, mWatchManager(this, GetOwnerGlobal()->AbstractMainThreadFor(TaskCategory::Other))
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
|
|
|
SetDefaultCueSettings();
|
2014-04-07 21:58:38 +04:00
|
|
|
MOZ_ASSERT(aOwnerWindow);
|
|
|
|
if (NS_FAILED(StashDocument())) {
|
2013-07-17 09:14:40 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
|
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-06-12 19:31:18 +04:00
|
|
|
TextTrackCue::~TextTrackCue()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-02-14 22:00:00 +04:00
|
|
|
/** Save a reference to our creating document so we don't have to
|
|
|
|
* keep getting it from our window.
|
2013-07-17 09:14:40 +04:00
|
|
|
*/
|
|
|
|
nsresult
|
2014-04-07 21:58:38 +04:00
|
|
|
TextTrackCue::StashDocument()
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* window = GetOwner();
|
2013-07-17 09:14:40 +04:00
|
|
|
if (!window) {
|
|
|
|
return NS_ERROR_NO_INTERFACE;
|
2013-06-19 22:02:04 +04:00
|
|
|
}
|
2013-07-17 09:14:40 +04:00
|
|
|
mDocument = window->GetDoc();
|
|
|
|
if (!mDocument) {
|
|
|
|
return NS_ERROR_NOT_AVAILABLE;
|
2013-06-19 22:02:04 +04:00
|
|
|
}
|
2013-07-17 09:14:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2013-06-10 19:30:00 +04:00
|
|
|
already_AddRefed<DocumentFragment>
|
|
|
|
TextTrackCue::GetCueAsHTML()
|
|
|
|
{
|
2014-02-14 22:00:00 +04:00
|
|
|
// mDocument may be null during cycle collector shutdown.
|
|
|
|
// See bug 941701.
|
|
|
|
if (!mDocument) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2013-06-10 19:30:00 +04:00
|
|
|
|
2013-09-19 19:26:00 +04:00
|
|
|
if (!sParserWrapper) {
|
|
|
|
nsresult rv;
|
|
|
|
nsCOMPtr<nsIWebVTTParserWrapper> parserWrapper =
|
|
|
|
do_CreateInstance(NS_WEBVTTPARSERWRAPPER_CONTRACTID, &rv);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return mDocument->CreateDocumentFragment();
|
|
|
|
}
|
|
|
|
sParserWrapper = parserWrapper;
|
2013-09-24 23:17:15 +04:00
|
|
|
ClearOnShutdown(&sParserWrapper);
|
2013-09-19 19:26:00 +04:00
|
|
|
}
|
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* window = mDocument->GetInnerWindow();
|
2013-09-19 19:26:00 +04:00
|
|
|
if (!window) {
|
|
|
|
return mDocument->CreateDocumentFragment();
|
|
|
|
}
|
|
|
|
|
2017-03-01 10:01:52 +03:00
|
|
|
nsCOMPtr<nsIDOMDocumentFragment> frag;
|
2013-09-19 19:26:00 +04:00
|
|
|
sParserWrapper->ConvertCueToDOMTree(window, this,
|
2017-03-01 10:01:52 +03:00
|
|
|
getter_AddRefs(frag));
|
2017-03-16 10:25:56 +03:00
|
|
|
if (!frag) {
|
|
|
|
return mDocument->CreateDocumentFragment();
|
|
|
|
}
|
2017-03-01 10:01:52 +03:00
|
|
|
return frag.forget().downcast<DocumentFragment>();
|
2013-09-19 19:26:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrackCue::SetTrackElement(HTMLTrackElement* aTrackElement)
|
|
|
|
{
|
|
|
|
mTrackElement = aTrackElement;
|
2013-06-10 19:30:00 +04:00
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
TextTrackCue::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-05-21 20:14:00 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return VTTCueBinding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 20:14:00 +04:00
|
|
|
}
|
|
|
|
|
2014-03-11 21:33:58 +04:00
|
|
|
TextTrackRegion*
|
|
|
|
TextTrackCue::GetRegion()
|
|
|
|
{
|
|
|
|
return mRegion;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrackCue::SetRegion(TextTrackRegion* aRegion)
|
|
|
|
{
|
|
|
|
if (mRegion == aRegion) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mRegion = aRegion;
|
|
|
|
mReset = true;
|
|
|
|
}
|
|
|
|
|
2016-06-14 13:47:32 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-06-15 18:51:17 +03:00
|
|
|
double
|
|
|
|
TextTrackCue::ComputedPosition()
|
|
|
|
{
|
|
|
|
// See spec https://w3c.github.io/webvtt/#cue-computed-position
|
|
|
|
if (!mPositionIsAutoKeyword) {
|
|
|
|
return mPosition;
|
|
|
|
} else if (mAlign == AlignSetting::Left) {
|
|
|
|
return 0.0;
|
|
|
|
} else if (mAlign == AlignSetting::Right) {
|
|
|
|
return 100.0;
|
|
|
|
}
|
|
|
|
return 50.0;
|
|
|
|
}
|
|
|
|
|
2016-06-02 05:40:23 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-09 11:43:07 +03:00
|
|
|
void
|
|
|
|
TextTrackCue::NotifyDisplayStatesChanged()
|
|
|
|
{
|
|
|
|
if (!mReset) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mTrack ||
|
|
|
|
!mTrack->GetTextTrackList() ||
|
|
|
|
!mTrack->GetTextTrackList()->GetMediaElement()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mTrack->GetTextTrackList()->GetMediaElement()->NotifyCueDisplayStatesChanged();
|
|
|
|
}
|
|
|
|
|
2013-05-21 20:14:00 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|