2013-05-21 09:14:00 -07: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 10:10:06 -08:00
|
|
|
#include "mozilla/dom/TextTrackList.h"
|
2013-06-14 13:10:36 -07:00
|
|
|
#include "mozilla/dom/TextTrackCue.h"
|
2013-09-05 13:25:17 -07:00
|
|
|
#include "mozilla/dom/TextTrackCueList.h"
|
2013-09-13 16:44:33 -07:00
|
|
|
#include "mozilla/dom/TextTrackRegion.h"
|
2013-06-14 13:10:36 -07:00
|
|
|
#include "mozilla/dom/HTMLMediaElement.h"
|
2013-10-24 21:14:36 -07:00
|
|
|
#include "mozilla/dom/HTMLTrackElement.h"
|
2013-05-21 09:14:00 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2014-04-25 09:49:00 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_INHERITED(TextTrack,
|
|
|
|
DOMEventTargetHelper,
|
|
|
|
mCueList,
|
|
|
|
mActiveCueList,
|
|
|
|
mTextTrackList,
|
|
|
|
mTrackElement)
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(TextTrack, DOMEventTargetHelper)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(TextTrack, DOMEventTargetHelper)
|
2013-05-21 09:14:00 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(TextTrack)
|
2014-03-31 23:13:50 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(DOMEventTargetHelper)
|
2013-05-21 09:14:00 -07:00
|
|
|
|
2014-04-07 10:58:38 -07:00
|
|
|
TextTrack::TextTrack(nsPIDOMWindow* aOwnerWindow,
|
2014-01-27 12:17:20 -08:00
|
|
|
TextTrackKind aKind,
|
|
|
|
const nsAString& aLabel,
|
2014-02-27 09:47:23 -08:00
|
|
|
const nsAString& aLanguage,
|
2014-03-13 10:18:06 -07:00
|
|
|
TextTrackMode aMode,
|
2014-03-13 11:41:21 -07:00
|
|
|
TextTrackReadyState aReadyState,
|
2014-02-27 09:47:23 -08:00
|
|
|
TextTrackSource aTextTrackSource)
|
2014-04-07 10:58:38 -07:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
2014-03-13 11:58:08 -07:00
|
|
|
, mKind(aKind)
|
|
|
|
, mLabel(aLabel)
|
|
|
|
, mLanguage(aLanguage)
|
|
|
|
, mMode(aMode)
|
|
|
|
, mReadyState(aReadyState)
|
2014-02-27 09:47:23 -08:00
|
|
|
, mTextTrackSource(aTextTrackSource)
|
2013-06-14 13:10:36 -07:00
|
|
|
{
|
|
|
|
SetDefaultSettings();
|
|
|
|
}
|
|
|
|
|
2014-04-07 10:58:38 -07:00
|
|
|
TextTrack::TextTrack(nsPIDOMWindow* aOwnerWindow,
|
2014-01-27 12:17:20 -08:00
|
|
|
TextTrackList* aTextTrackList,
|
2013-05-21 09:14:00 -07:00
|
|
|
TextTrackKind aKind,
|
|
|
|
const nsAString& aLabel,
|
2014-02-27 09:47:23 -08:00
|
|
|
const nsAString& aLanguage,
|
2014-03-13 10:18:06 -07:00
|
|
|
TextTrackMode aMode,
|
2014-03-13 11:41:21 -07:00
|
|
|
TextTrackReadyState aReadyState,
|
2014-02-27 09:47:23 -08:00
|
|
|
TextTrackSource aTextTrackSource)
|
2014-04-07 10:58:38 -07:00
|
|
|
: DOMEventTargetHelper(aOwnerWindow)
|
2014-01-27 12:17:20 -08:00
|
|
|
, mTextTrackList(aTextTrackList)
|
2014-03-13 11:58:08 -07:00
|
|
|
, mKind(aKind)
|
|
|
|
, mLabel(aLabel)
|
|
|
|
, mLanguage(aLanguage)
|
|
|
|
, mMode(aMode)
|
|
|
|
, mReadyState(aReadyState)
|
2014-02-27 09:47:23 -08:00
|
|
|
, mTextTrackSource(aTextTrackSource)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2013-06-14 13:10:36 -07:00
|
|
|
SetDefaultSettings();
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2014-06-14 19:53:52 -07:00
|
|
|
TextTrack::~TextTrack()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-14 13:10:36 -07:00
|
|
|
void
|
|
|
|
TextTrack::SetDefaultSettings()
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2014-04-07 10:58:38 -07:00
|
|
|
nsPIDOMWindow* ownerWindow = GetOwner();
|
|
|
|
mCueList = new TextTrackCueList(ownerWindow);
|
|
|
|
mActiveCueList = new TextTrackCueList(ownerWindow);
|
2013-06-14 13:10:36 -07:00
|
|
|
mCuePos = 0;
|
|
|
|
mDirty = false;
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
JSObject*
|
2014-04-08 15:27:18 -07:00
|
|
|
TextTrack::WrapObject(JSContext* aCx)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
Bug 991742 part 6. Remove the "aScope" argument of binding Wrap() methods. r=bholley
This patch was mostly generated with this command:
find . -name "*.h" -o -name "*.cpp" | xargs sed -e 's/Binding::Wrap(aCx, aScope, this/Binding::Wrap(aCx, this/' -e 's/Binding_workers::Wrap(aCx, aScope, this/Binding_workers::Wrap(aCx, this/' -e 's/Binding::Wrap(cx, scope, this/Binding::Wrap(cx, this/' -i ""
plus a few manual fixes to dom/bindings/Codegen.py, js/xpconnect/src/event_impl_gen.py, and a few C++ files that were not caught in the search-and-replace above.
2014-04-08 15:27:17 -07:00
|
|
|
return TextTrackBinding::Wrap(aCx, this);
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetMode(TextTrackMode aValue)
|
|
|
|
{
|
2013-12-17 21:19:09 -08:00
|
|
|
if (mMode != aValue) {
|
|
|
|
mMode = aValue;
|
2014-01-27 12:17:20 -08:00
|
|
|
if (mTextTrackList) {
|
|
|
|
mTextTrackList->CreateAndDispatchChangeEvent();
|
2013-12-17 21:19:09 -08:00
|
|
|
}
|
|
|
|
}
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2014-03-19 08:27:39 -07: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 09:14:00 -07:00
|
|
|
void
|
|
|
|
TextTrack::AddCue(TextTrackCue& aCue)
|
|
|
|
{
|
|
|
|
mCueList->AddCue(aCue);
|
2014-04-02 09:16:00 -07:00
|
|
|
aCue.SetTrack(this);
|
2014-01-27 12:17:20 -08:00
|
|
|
if (mTextTrackList) {
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
|
|
|
if (mediaElement) {
|
|
|
|
mediaElement->AddCue(aCue);
|
|
|
|
}
|
2014-01-15 08:30:58 -08:00
|
|
|
}
|
2013-06-14 13:10:36 -07:00
|
|
|
SetDirty();
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-06-28 10:31:43 -07:00
|
|
|
TextTrack::RemoveCue(TextTrackCue& aCue, ErrorResult& aRv)
|
2013-05-21 09:14:00 -07:00
|
|
|
{
|
2013-06-28 10:31:43 -07:00
|
|
|
mCueList->RemoveCue(aCue, aRv);
|
2013-06-14 13:10:36 -07:00
|
|
|
SetDirty();
|
2013-05-21 09:14:00 -07:00
|
|
|
}
|
|
|
|
|
2014-04-07 12:42:33 -07:00
|
|
|
void
|
|
|
|
TextTrack::SetCuesDirty()
|
|
|
|
{
|
|
|
|
for (uint32_t i = 0; i < mCueList->Length(); i++) {
|
|
|
|
((*mCueList)[i])->Reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 07:57:21 -08:00
|
|
|
void
|
|
|
|
TextTrack::UpdateActiveCueList()
|
2013-06-14 13:10:36 -07:00
|
|
|
{
|
2014-02-07 10:59:26 -08:00
|
|
|
if (!mTextTrackList) {
|
2014-01-27 12:17:20 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
|
|
|
if (!mediaElement) {
|
2013-12-12 07:57:21 -08:00
|
|
|
return;
|
2013-06-14 13:10:36 -07: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 07:09:33 -08:00
|
|
|
mDirty = false;
|
2013-06-14 13:10:36 -07:00
|
|
|
mActiveCueList->RemoveAll();
|
|
|
|
}
|
|
|
|
|
2014-01-27 12:17:20 -08:00
|
|
|
double playbackTime = mediaElement->CurrentTime();
|
2013-06-14 13:10:36 -07:00
|
|
|
// Remove all the cues from the active cue list whose end times now occur
|
2013-12-13 07:09:33 -08: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 13:10:36 -07: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 07:09:33 -08: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 13:10:36 -07:00
|
|
|
}
|
|
|
|
}
|
2013-12-12 07:57:21 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
TextTrackCueList*
|
|
|
|
TextTrack::GetActiveCues() {
|
2014-02-07 10:59:26 -08:00
|
|
|
if (mMode != TextTrackMode::Disabled) {
|
|
|
|
UpdateActiveCueList();
|
|
|
|
return mActiveCueList;
|
|
|
|
}
|
|
|
|
return nullptr;
|
2013-06-14 13:10:36 -07:00
|
|
|
}
|
|
|
|
|
2013-12-12 07:57:21 -08:00
|
|
|
void
|
|
|
|
TextTrack::GetActiveCueArray(nsTArray<nsRefPtr<TextTrackCue> >& aCues)
|
|
|
|
{
|
2014-02-07 10:59:26 -08:00
|
|
|
if (mMode != TextTrackMode::Disabled) {
|
|
|
|
UpdateActiveCueList();
|
|
|
|
mActiveCueList->GetArray(aCues);
|
|
|
|
}
|
2013-12-12 07:57:21 -08:00
|
|
|
}
|
|
|
|
|
2014-03-13 11:29:32 -07:00
|
|
|
TextTrackReadyState
|
2013-10-24 21:14:36 -07:00
|
|
|
TextTrack::ReadyState() const
|
|
|
|
{
|
|
|
|
return mReadyState;
|
|
|
|
}
|
|
|
|
|
2014-03-14 09:13:41 -07:00
|
|
|
void
|
|
|
|
TextTrack::SetReadyState(uint32_t aReadyState)
|
|
|
|
{
|
|
|
|
if (aReadyState <= TextTrackReadyState::FailedToLoad) {
|
|
|
|
SetReadyState(static_cast<TextTrackReadyState>(aReadyState));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-10-24 21:14:36 -07:00
|
|
|
void
|
2014-03-13 11:29:32 -07:00
|
|
|
TextTrack::SetReadyState(TextTrackReadyState aState)
|
2013-10-24 21:14:36 -07:00
|
|
|
{
|
|
|
|
mReadyState = aState;
|
2014-01-27 12:17:20 -08:00
|
|
|
|
|
|
|
if (!mTextTrackList) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
2014-03-13 11:29:32 -07:00
|
|
|
if (mediaElement && (mReadyState == TextTrackReadyState::Loaded||
|
|
|
|
mReadyState == TextTrackReadyState::FailedToLoad)) {
|
2014-01-27 12:17:20 -08:00
|
|
|
mediaElement->RemoveTextTrack(this, true);
|
2013-10-24 21:14:36 -07:00
|
|
|
}
|
2013-10-24 21:14:36 -07:00
|
|
|
}
|
|
|
|
|
2014-01-27 10:10:06 -08:00
|
|
|
TextTrackList*
|
|
|
|
TextTrack::GetTextTrackList()
|
|
|
|
{
|
|
|
|
return mTextTrackList;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetTextTrackList(TextTrackList* aTextTrackList)
|
|
|
|
{
|
|
|
|
mTextTrackList = aTextTrackList;
|
|
|
|
}
|
|
|
|
|
2014-02-27 11:07:39 -08:00
|
|
|
HTMLTrackElement*
|
|
|
|
TextTrack::GetTrackElement() {
|
|
|
|
return mTrackElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TextTrack::SetTrackElement(HTMLTrackElement* aTrackElement) {
|
|
|
|
mTrackElement = aTrackElement;
|
|
|
|
}
|
|
|
|
|
2013-05-21 09:14:00 -07:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|