2013-05-21 16:14:00 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 et tw=78: */
|
|
|
|
/* 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/TextTrack.h"
|
|
|
|
#include "mozilla/dom/TextTrackBinding.h"
|
2014-01-27 18:10:06 +00:00
|
|
|
#include "mozilla/dom/TextTrackList.h"
|
2013-06-14 20:10:36 +00:00
|
|
|
#include "mozilla/dom/TextTrackCue.h"
|
2013-09-05 20:25:17 +00:00
|
|
|
#include "mozilla/dom/TextTrackCueList.h"
|
2013-09-13 23:44:33 +00:00
|
|
|
#include "mozilla/dom/TextTrackRegion.h"
|
2013-06-14 20:10:36 +00:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2013-10-25 04:14:36 +00:00
|
|
|
#include "mozilla/dom/HTMLTrackElement.h"
|
2013-05-21 16:14:00 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-25 16:49:00 +00:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrack,
|
|
|
|
DOMEventTargetHelper,
|
|
|
|
mCueList,
|
|
|
|
mActiveCueList,
|
|
|
|
mTextTrackList,
|
|
|
|
mTrackElement)
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TextTrack, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TextTrack, DOMEventTargetHelper)
|
2013-05-21 16:14:00 +00:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextTrack)
|
2014-04-01 06:13:50 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-05-21 16:14:00 +00:00
|
|
|
|
2014-04-07 17:58:38 +00:00
|
|
|
TextTrack::TextTrack(nsPIDOMWindow* aOwnerWindow,
|
2014-01-27 20:17:20 +00:00
|
|
|
TextTrackKind aKind,
|
|
|
|
const nsAString& aLabel,
|
2014-02-27 17:47:23 +00:00
|
|
|
const nsAString& aLanguage,
|
2014-03-13 17:18:06 +00:00
|
|
|
TextTrackMode aMode,
|
2014-03-13 18:41:21 +00:00
|
|
|
TextTrackReadyState aReadyState,
|
2014-02-27 17:47:23 +00:00
|
|
|
TextTrackSource aTextTrackSource)
|
2014-04-07 17:58:38 +00:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
2014-03-13 18:58:08 +00:00
|
|
|
, mKind(aKind)
|
|
|
|
, mLabel(aLabel)
|
|
|
|
, mLanguage(aLanguage)
|
|
|
|
, mMode(aMode)
|
|
|
|
, mReadyState(aReadyState)
|
2014-02-27 17:47:23 +00:00
|
|
|
, mTextTrackSource(aTextTrackSource)
|
2013-06-14 20:10:36 +00:00
|
|
|
{
|
|
|
|
SetDefaultSettings();
|
|
|
|
}
|
|
|
|
|
2014-04-07 17:58:38 +00:00
|
|
|
TextTrack::TextTrack(nsPIDOMWindow* aOwnerWindow,
|
2014-01-27 20:17:20 +00:00
|
|
|
TextTrackList* aTextTrackList,
|
2013-05-21 16:14:00 +00:00
|
|
|
TextTrackKind aKind,
|
|
|
|
const nsAString& aLabel,
|
2014-02-27 17:47:23 +00:00
|
|
|
const nsAString& aLanguage,
|
2014-03-13 17:18:06 +00:00
|
|
|
TextTrackMode aMode,
|
2014-03-13 18:41:21 +00:00
|
|
|
TextTrackReadyState aReadyState,
|
2014-02-27 17:47:23 +00:00
|
|
|
TextTrackSource aTextTrackSource)
|
2014-04-07 17:58:38 +00:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
2014-01-27 20:17:20 +00:00
|
|
|
, mTextTrackList(aTextTrackList)
|
2014-03-13 18:58:08 +00:00
|
|
|
, mKind(aKind)
|
|
|
|
, mLabel(aLabel)
|
|
|
|
, mLanguage(aLanguage)
|
|
|
|
, mMode(aMode)
|
|
|
|
, mReadyState(aReadyState)
|
2014-02-27 17:47:23 +00:00
|
|
|
, mTextTrackSource(aTextTrackSource)
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2013-06-14 20:10:36 +00:00
|
|
|
SetDefaultSettings();
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-15 02:53:52 +00:00
|
|
|
TextTrack::~TextTrack()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-14 20:10:36 +00:00
|
|
|
void
|
|
|
|
TextTrack::SetDefaultSettings()
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2014-04-07 17:58:38 +00:00
|
|
|
nsPIDOMWindow* ownerWindow = GetOwner();
|
|
|
|
mCueList = new TextTrackCueList(ownerWindow);
|
|
|
|
mActiveCueList = new TextTrackCueList(ownerWindow);
|
2013-06-14 20:10:36 +00:00
|
|
|
mCuePos = 0;
|
|
|
|
mDirty = false;
|
2013-05-21 16:14:00 +00: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 14:13:33 +00:00
|
|
|
TextTrack::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-05-21 16:14:00 +00: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 14:13:33 +00:00
|
|
|
return TextTrackBinding::Wrap(aCx, this, aGivenProto);
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetMode(TextTrackMode aValue)
|
|
|
|
{
|
2013-12-18 05:19:09 +00:00
|
|
|
if (mMode != aValue) {
|
|
|
|
mMode = aValue;
|
2014-01-27 20:17:20 +00:00
|
|
|
if (mTextTrackList) {
|
|
|
|
mTextTrackList->CreateAndDispatchChangeEvent();
|
2013-12-18 05:19:09 +00:00
|
|
|
}
|
|
|
|
}
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
2014-03-19 15:27:39 +00:00
|
|
|
void
|
|
|
|
TextTrack::GetId(nsAString& aId) const
|
|
|
|
{
|
|
|
|
// If the track has a track element then its id should be the same as the
|
|
|
|
// track element's id.
|
|
|
|
if (mTrackElement) {
|
|
|
|
mTrackElement->GetAttribute(NS_LITERAL_STRING("id"), aId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-21 16:14:00 +00:00
|
|
|
void
|
|
|
|
TextTrack::AddCue(TextTrackCue& aCue)
|
|
|
|
{
|
|
|
|
mCueList->AddCue(aCue);
|
2014-04-02 16:16:00 +00:00
|
|
|
aCue.SetTrack(this);
|
2014-01-27 20:17:20 +00:00
|
|
|
if (mTextTrackList) {
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
|
|
|
if (mediaElement) {
|
|
|
|
mediaElement->AddCue(aCue);
|
|
|
|
}
|
2014-01-15 16:30:58 +00:00
|
|
|
}
|
2013-06-14 20:10:36 +00:00
|
|
|
SetDirty();
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-28 17:31:43 +00:00
|
|
|
TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
|
2013-05-21 16:14:00 +00:00
|
|
|
{
|
2013-06-28 17:31:43 +00:00
|
|
|
mCueList->RemoveCue(aCue, aRv);
|
2013-06-14 20:10:36 +00:00
|
|
|
SetDirty();
|
2013-05-21 16:14:00 +00:00
|
|
|
}
|
|
|
|
|
2014-04-07 19:42:33 +00:00
|
|
|
void
|
|
|
|
TextTrack::SetCuesDirty()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mCueList->Length(); i++) {
|
|
|
|
((*mCueList)[i])->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:57:21 +00:00
|
|
|
void
|
|
|
|
TextTrack::UpdateActiveCueList()
|
2013-06-14 20:10:36 +00:00
|
|
|
{
|
2014-02-07 18:59:26 +00:00
|
|
|
if (!mTextTrackList) {
|
2014-01-27 20:17:20 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
|
|
|
if (!mediaElement) {
|
2013-12-12 15:57:21 +00:00
|
|
|
return;
|
2013-06-14 20:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// If we are dirty, i.e. an event happened that may cause the sorted mCueList
|
|
|
|
// to have changed like a seek or an insert for a cue, than we need to rebuild
|
|
|
|
// the active cue list from scratch.
|
|
|
|
if (mDirty) {
|
|
|
|
mCuePos = 0;
|
2013-12-13 15:09:33 +00:00
|
|
|
mDirty = false;
|
2013-06-14 20:10:36 +00:00
|
|
|
mActiveCueList->RemoveAll();
|
|
|
|
}
|
|
|
|
|
2014-01-27 20:17:20 +00:00
|
|
|
double playbackTime = mediaElement->CurrentTime();
|
2013-06-14 20:10:36 +00:00
|
|
|
// Remove all the cues from the active cue list whose end times now occur
|
2013-12-13 15:09:33 +00:00
|
|
|
// earlier then the current playback time.
|
|
|
|
for (uint32_t i = mActiveCueList->Length(); i > 0; i--) {
|
|
|
|
if ((*mActiveCueList)[i - 1]->EndTime() < playbackTime) {
|
|
|
|
mActiveCueList->RemoveCueAt(i - 1);
|
|
|
|
}
|
2013-06-14 20:10:36 +00:00
|
|
|
}
|
|
|
|
// Add all the cues, starting from the position of the last cue that was
|
|
|
|
// added, that have valid start and end times for the current playback time.
|
|
|
|
// We can stop iterating safely once we encounter a cue that does not have
|
2013-12-13 15:09:33 +00:00
|
|
|
// a valid start time as the cue list is sorted.
|
|
|
|
for (; mCuePos < mCueList->Length() &&
|
|
|
|
(*mCueList)[mCuePos]->StartTime() <= playbackTime; mCuePos++) {
|
|
|
|
if ((*mCueList)[mCuePos]->EndTime() >= playbackTime) {
|
|
|
|
mActiveCueList->AddCue(*(*mCueList)[mCuePos]);
|
2013-06-14 20:10:36 +00:00
|
|
|
}
|
|
|
|
}
|
2013-12-12 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TextTrackCueList*
|
|
|
|
TextTrack::GetActiveCues() {
|
2014-02-07 18:59:26 +00:00
|
|
|
if (mMode != TextTrackMode::Disabled) {
|
|
|
|
UpdateActiveCueList();
|
|
|
|
return mActiveCueList;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2013-06-14 20:10:36 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 15:57:21 +00:00
|
|
|
void
|
|
|
|
TextTrack::GetActiveCueArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues)
|
|
|
|
{
|
2014-02-07 18:59:26 +00:00
|
|
|
if (mMode != TextTrackMode::Disabled) {
|
|
|
|
UpdateActiveCueList();
|
|
|
|
mActiveCueList->GetArray(aCues);
|
|
|
|
}
|
2013-12-12 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
2014-03-13 18:29:32 +00:00
|
|
|
TextTrackReadyState
|
2013-10-25 04:14:36 +00:00
|
|
|
TextTrack::ReadyState() const
|
|
|
|
{
|
|
|
|
return mReadyState;
|
|
|
|
}
|
|
|
|
|
2014-03-14 16:13:41 +00:00
|
|
|
void
|
|
|
|
TextTrack::SetReadyState(uint32_t aReadyState)
|
|
|
|
{
|
|
|
|
if (aReadyState <= TextTrackReadyState::FailedToLoad) {
|
|
|
|
SetReadyState(static_cast<TextTrackReadyState>(aReadyState));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-25 04:14:36 +00:00
|
|
|
void
|
2014-03-13 18:29:32 +00:00
|
|
|
TextTrack::SetReadyState(TextTrackReadyState aState)
|
2013-10-25 04:14:36 +00:00
|
|
|
{
|
|
|
|
mReadyState = aState;
|
2014-01-27 20:17:20 +00:00
|
|
|
|
|
|
|
if (!mTextTrackList) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
2014-03-13 18:29:32 +00:00
|
|
|
if (mediaElement && (mReadyState == TextTrackReadyState::Loaded||
|
|
|
|
mReadyState == TextTrackReadyState::FailedToLoad)) {
|
2014-01-27 20:17:20 +00:00
|
|
|
mediaElement->RemoveTextTrack(this, true);
|
2013-10-25 04:14:36 +00:00
|
|
|
}
|
2013-10-25 04:14:36 +00:00
|
|
|
}
|
|
|
|
|
2014-01-27 18:10:06 +00:00
|
|
|
TextTrackList*
|
|
|
|
TextTrack::GetTextTrackList()
|
|
|
|
{
|
|
|
|
return mTextTrackList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetTextTrackList(TextTrackList* aTextTrackList)
|
|
|
|
{
|
|
|
|
mTextTrackList = aTextTrackList;
|
|
|
|
}
|
|
|
|
|
2014-02-27 19:07:39 +00:00
|
|
|
HTMLTrackElement*
|
|
|
|
TextTrack::GetTrackElement() {
|
|
|
|
return mTrackElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetTrackElement(HTMLTrackElement* aTrackElement) {
|
|
|
|
mTrackElement = aTrackElement;
|
|
|
|
}
|
|
|
|
|
2013-05-21 16:14:00 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|