mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 881976 - Part 3: Refactor TextTrack classes. r=rillian
Change the way they store references to eachother to make more sense. A Track will never belong to a MediaElement directly. It will always belong to one through a TextTrackList.
This commit is contained in:
parent
3c33886b48
commit
bbede675f5
@ -123,9 +123,7 @@ TextTrack*
|
||||
HTMLTrackElement::Track()
|
||||
{
|
||||
if (!mTrack) {
|
||||
// We're expected to always have an internal TextTrack so create
|
||||
// an empty object to return if we don't already have one.
|
||||
mTrack = new TextTrack(OwnerDoc()->GetParentObject(), mMediaParent);
|
||||
CreateTextTrack();
|
||||
}
|
||||
|
||||
return mTrack;
|
||||
@ -145,8 +143,7 @@ HTMLTrackElement::CreateTextTrack()
|
||||
kind = TextTrackKind::Subtitles;
|
||||
}
|
||||
|
||||
mTrack = new TextTrack(OwnerDoc()->GetParentObject(), mMediaParent, kind,
|
||||
label, srcLang);
|
||||
mTrack = new TextTrack(OwnerDoc()->GetParentObject(), kind, label, srcLang);
|
||||
|
||||
if (mMediaParent) {
|
||||
mMediaParent->AddTextTrack(mTrack);
|
||||
|
@ -61,7 +61,7 @@ TextTrackManager::AddTextTrack(TextTrackKind aKind, const nsAString& aLabel,
|
||||
const nsAString& aLanguage)
|
||||
{
|
||||
nsRefPtr<TextTrack> ttrack =
|
||||
mTextTracks->AddTextTrack(mMediaElement, aKind, aLabel, aLanguage);
|
||||
mTextTracks->AddTextTrack(aKind, aLabel, aLanguage);
|
||||
ttrack->SetReadyState(HTMLTrackElement::READY_STATE_LOADED);
|
||||
AddCues(ttrack);
|
||||
return ttrack.forget();
|
||||
|
@ -17,10 +17,9 @@
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED_6(TextTrack,
|
||||
NS_IMPL_CYCLE_COLLECTION_INHERITED_5(TextTrack,
|
||||
nsDOMEventTargetHelper,
|
||||
mParent,
|
||||
mMediaElement,
|
||||
mCueList,
|
||||
mActiveCueList,
|
||||
mRegionList,
|
||||
@ -38,21 +37,26 @@ TextTrack::TextTrack(nsISupports* aParent)
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
TextTrack::TextTrack(nsISupports* aParent, HTMLMediaElement* aMediaElement)
|
||||
: mParent(aParent)
|
||||
, mMediaElement(aMediaElement)
|
||||
{
|
||||
SetDefaultSettings();
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
TextTrack::TextTrack(nsISupports* aParent,
|
||||
HTMLMediaElement* aMediaElement,
|
||||
TextTrackKind aKind,
|
||||
const nsAString& aLabel,
|
||||
const nsAString& aLanguage)
|
||||
: mParent(aParent)
|
||||
, mMediaElement(aMediaElement)
|
||||
{
|
||||
SetDefaultSettings();
|
||||
mKind = aKind;
|
||||
mLabel = aLabel;
|
||||
mLanguage = aLanguage;
|
||||
SetIsDOMBinding();
|
||||
}
|
||||
|
||||
TextTrack::TextTrack(nsISupports* aParent,
|
||||
TextTrackList* aTextTrackList,
|
||||
TextTrackKind aKind,
|
||||
const nsAString& aLabel,
|
||||
const nsAString& aLanguage)
|
||||
: mParent(aParent)
|
||||
, mTextTrackList(aTextTrackList)
|
||||
{
|
||||
SetDefaultSettings();
|
||||
mKind = aKind;
|
||||
@ -85,8 +89,8 @@ TextTrack::SetMode(TextTrackMode aValue)
|
||||
{
|
||||
if (mMode != aValue) {
|
||||
mMode = aValue;
|
||||
if (mMediaElement) {
|
||||
mMediaElement->TextTracks()->CreateAndDispatchChangeEvent();
|
||||
if (mTextTrackList) {
|
||||
mTextTrackList->CreateAndDispatchChangeEvent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -95,8 +99,11 @@ void
|
||||
TextTrack::AddCue(TextTrackCue& aCue)
|
||||
{
|
||||
mCueList->AddCue(aCue);
|
||||
if (mMediaElement) {
|
||||
mMediaElement->AddCue(aCue);
|
||||
if (mTextTrackList) {
|
||||
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
||||
if (mediaElement) {
|
||||
mediaElement->AddCue(aCue);
|
||||
}
|
||||
}
|
||||
SetDirty();
|
||||
}
|
||||
@ -141,7 +148,12 @@ TextTrack::RemoveRegion(const TextTrackRegion& aRegion, ErrorResult& aRv)
|
||||
void
|
||||
TextTrack::UpdateActiveCueList()
|
||||
{
|
||||
if (mMode == TextTrackMode::Disabled || !mMediaElement) {
|
||||
if (mMode == TextTrackMode::Disabled || !mTextTrackList) {
|
||||
return;
|
||||
}
|
||||
|
||||
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
||||
if (!mediaElement) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -154,7 +166,7 @@ TextTrack::UpdateActiveCueList()
|
||||
mActiveCueList->RemoveAll();
|
||||
}
|
||||
|
||||
double playbackTime = mMediaElement->CurrentTime();
|
||||
double playbackTime = mediaElement->CurrentTime();
|
||||
// Remove all the cues from the active cue list whose end times now occur
|
||||
// earlier then the current playback time.
|
||||
for (uint32_t i = mActiveCueList->Length(); i > 0; i--) {
|
||||
@ -197,9 +209,15 @@ void
|
||||
TextTrack::SetReadyState(uint16_t aState)
|
||||
{
|
||||
mReadyState = aState;
|
||||
if (mMediaElement && (mReadyState == HTMLTrackElement::READY_STATE_LOADED ||
|
||||
|
||||
if (!mTextTrackList) {
|
||||
return;
|
||||
}
|
||||
|
||||
HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement();
|
||||
if (mediaElement && (mReadyState == HTMLTrackElement::READY_STATE_LOADED ||
|
||||
mReadyState == HTMLTrackElement::READY_STATE_ERROR)) {
|
||||
mMediaElement->RemoveTextTrack(this, true);
|
||||
mediaElement->RemoveTextTrack(this, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,6 @@ class TextTrackCue;
|
||||
class TextTrackCueList;
|
||||
class TextTrackRegion;
|
||||
class TextTrackRegionList;
|
||||
class HTMLMediaElement;
|
||||
|
||||
class TextTrack MOZ_FINAL : public nsDOMEventTargetHelper
|
||||
{
|
||||
@ -31,9 +30,11 @@ public:
|
||||
|
||||
TextTrack(nsISupports* aParent);
|
||||
TextTrack(nsISupports* aParent,
|
||||
HTMLMediaElement* aMediaElement);
|
||||
TextTrackKind aKind,
|
||||
const nsAString& aLabel,
|
||||
const nsAString& aLanguage);
|
||||
TextTrack(nsISupports* aParent,
|
||||
HTMLMediaElement* aMediaElement,
|
||||
TextTrackList* aTextTrackList,
|
||||
TextTrackKind aKind,
|
||||
const nsAString& aLabel,
|
||||
const nsAString& aLanguage);
|
||||
@ -114,7 +115,6 @@ private:
|
||||
void UpdateActiveCueList();
|
||||
|
||||
nsCOMPtr<nsISupports> mParent;
|
||||
nsRefPtr<HTMLMediaElement> mMediaElement;
|
||||
nsRefPtr<TextTrackList> mTextTrackList;
|
||||
|
||||
TextTrackKind mKind;
|
||||
|
@ -62,16 +62,13 @@ TextTrackList::IndexedGetter(uint32_t aIndex, bool& aFound)
|
||||
}
|
||||
|
||||
already_AddRefed<TextTrack>
|
||||
TextTrackList::AddTextTrack(HTMLMediaElement* aMediaElement,
|
||||
TextTrackKind aKind,
|
||||
TextTrackList::AddTextTrack(TextTrackKind aKind,
|
||||
const nsAString& aLabel,
|
||||
const nsAString& aLanguage)
|
||||
{
|
||||
nsRefPtr<TextTrack> track = new TextTrack(mGlobal, aMediaElement, aKind,
|
||||
aLabel, aLanguage);
|
||||
nsRefPtr<TextTrack> track = new TextTrack(mGlobal, this, aKind, aLabel, aLanguage);
|
||||
if (mTextTracks.AppendElement(track)) {
|
||||
CreateAndDispatchTrackEventRunner(track, NS_LITERAL_STRING("addtrack"));
|
||||
track->SetTextTrackList(this);
|
||||
}
|
||||
|
||||
return track.forget();
|
||||
|
@ -46,8 +46,7 @@ public:
|
||||
|
||||
TextTrack* IndexedGetter(uint32_t aIndex, bool& aFound);
|
||||
|
||||
already_AddRefed<TextTrack> AddTextTrack(HTMLMediaElement* aMediaElement,
|
||||
TextTrackKind aKind,
|
||||
already_AddRefed<TextTrack> AddTextTrack(TextTrackKind aKind,
|
||||
const nsAString& aLabel,
|
||||
const nsAString& aLanguage);
|
||||
TextTrack* GetTrackById(const nsAString& aId);
|
||||
|
Loading…
Reference in New Issue
Block a user