From ac80b91953bb6b013605454c4f947dbd86531f3b Mon Sep 17 00:00:00 2001 From: Rick Eyre Date: Thu, 13 Mar 2014 14:29:32 -0400 Subject: [PATCH] Bug 983293 - Part 3: Rename the READY_STATE enum to TextTrackReadyState. r=cpearce - This allows us to pass around ReadyState values. It also makes the type explicit which will save us from potentially shooting ourselves in the foot. - I also renamed 'READY_STATE_NONE' and 'READY_STATE_ERROR' to 'NotLoaded' and 'FailedToLoad' respectively in the enum. This is to avoid some name collision errors we were having. It also makes it more clear where in the spec this is as these names are the spec's names for the TextTrack enum. --- content/html/content/src/HTMLTrackElement.cpp | 2 +- content/html/content/src/TextTrackManager.cpp | 4 ++-- content/media/TextTrack.cpp | 10 ++++----- content/media/TextTrack.h | 21 ++++++++++--------- content/media/WebVTTListener.cpp | 6 +++--- 5 files changed, 22 insertions(+), 21 deletions(-) diff --git a/content/html/content/src/HTMLTrackElement.cpp b/content/html/content/src/HTMLTrackElement.cpp index 8965527490dc..2ac28c738b73 100644 --- a/content/html/content/src/HTMLTrackElement.cpp +++ b/content/html/content/src/HTMLTrackElement.cpp @@ -317,7 +317,7 @@ uint16_t HTMLTrackElement::ReadyState() const { if (!mTrack) { - return TextTrack::READY_STATE_NONE; + return TextTrackReadyState::NotLoaded; } return mTrack->ReadyState(); diff --git a/content/html/content/src/TextTrackManager.cpp b/content/html/content/src/TextTrackManager.cpp index 0e0bd8d3bd58..083e33218d47 100644 --- a/content/html/content/src/TextTrackManager.cpp +++ b/content/html/content/src/TextTrackManager.cpp @@ -121,7 +121,7 @@ TextTrackManager::AddTextTrack(TextTrackKind aKind, const nsAString& aLabel, nsRefPtr ttrack = mTextTracks->AddTextTrack(aKind, aLabel, aLanguage, aMode, aTextTrackSource, CompareTextTracks(mMediaElement)); - ttrack->SetReadyState(TextTrack::READY_STATE_LOADED); + ttrack->SetReadyState(TextTrackReadyState::Loaded); AddCues(ttrack); return ttrack.forget(); } @@ -218,7 +218,7 @@ TextTrackManager::PopulatePendingList() for (uint32_t index = 0; index < len; ++index) { TextTrack* ttrack = mTextTracks->IndexedGetter(index, dummy); if (ttrack && ttrack->Mode() != TextTrackMode::Disabled && - ttrack->ReadyState() == TextTrack::READY_STATE_LOADING) { + ttrack->ReadyState() == TextTrackReadyState::Loading) { mPendingTextTracks->AddTextTrack(ttrack, CompareTextTracks(mMediaElement)); } diff --git a/content/media/TextTrack.cpp b/content/media/TextTrack.cpp index c636ee801249..73a334953d2c 100644 --- a/content/media/TextTrack.cpp +++ b/content/media/TextTrack.cpp @@ -74,7 +74,7 @@ TextTrack::SetDefaultSettings() mActiveCueList = new TextTrackCueList(mParent); mCuePos = 0; mDirty = false; - mReadyState = TextTrack::READY_STATE_NONE; + mReadyState = TextTrackReadyState::NotLoaded; } JSObject* @@ -179,14 +179,14 @@ TextTrack::GetActiveCueArray(nsTArray >& aCues) } } -uint16_t +TextTrackReadyState TextTrack::ReadyState() const { return mReadyState; } void -TextTrack::SetReadyState(uint16_t aState) +TextTrack::SetReadyState(TextTrackReadyState aState) { mReadyState = aState; @@ -195,8 +195,8 @@ TextTrack::SetReadyState(uint16_t aState) } HTMLMediaElement* mediaElement = mTextTrackList->GetMediaElement(); - if (mediaElement && (mReadyState == TextTrack::READY_STATE_LOADED || - mReadyState == TextTrack::READY_STATE_ERROR)) { + if (mediaElement && (mReadyState == TextTrackReadyState::Loaded|| + mReadyState == TextTrackReadyState::FailedToLoad)) { mediaElement->RemoveTextTrack(this, true); } } diff --git a/content/media/TextTrack.h b/content/media/TextTrack.h index c0f8e9002d4c..860db57aa57e 100644 --- a/content/media/TextTrack.h +++ b/content/media/TextTrack.h @@ -28,6 +28,14 @@ enum TextTrackSource { MediaResourceSpecific }; +// Constants for numeric readyState property values. +enum TextTrackReadyState { + NotLoaded = 0U, + Loading = 1U, + Loaded = 2U, + FailedToLoad = 3U +}; + class TextTrack MOZ_FINAL : public nsDOMEventTargetHelper { public: @@ -96,15 +104,8 @@ public: TextTrackCueList* GetActiveCues(); void GetActiveCueArray(nsTArray >& aCues); - // Constants for numeric readyState property values. - enum { - READY_STATE_NONE = 0U, - READY_STATE_LOADING = 1U, - READY_STATE_LOADED = 2U, - READY_STATE_ERROR = 3U - }; - uint16_t ReadyState() const; - void SetReadyState(uint16_t aState); + TextTrackReadyState ReadyState() const; + void SetReadyState(TextTrackReadyState aState); void AddCue(TextTrackCue& aCue); void RemoveCue(TextTrackCue& aCue, ErrorResult& aRv); @@ -141,7 +142,7 @@ private: nsRefPtr mTrackElement; uint32_t mCuePos; - uint16_t mReadyState; + TextTrackReadyState mReadyState; bool mDirty; // An enum that represents where the track was sourced from. diff --git a/content/media/WebVTTListener.cpp b/content/media/WebVTTListener.cpp index 88ae600d0fba..8d04d0967f71 100644 --- a/content/media/WebVTTListener.cpp +++ b/content/media/WebVTTListener.cpp @@ -78,7 +78,7 @@ WebVTTListener::LoadResource() rv = mParserWrapper->Watch(this); NS_ENSURE_SUCCESS(rv, rv); - mElement->mTrack->SetReadyState(TextTrack::READY_STATE_LOADING); + mElement->mTrack->SetReadyState(TextTrackReadyState::Loading); return NS_OK; } @@ -106,9 +106,9 @@ WebVTTListener::OnStopRequest(nsIRequest* aRequest, nsISupports* aContext, nsresult aStatus) { - if (mElement->ReadyState() != TextTrack::READY_STATE_ERROR) { + if (mElement->ReadyState() != TextTrackReadyState::FailedToLoad) { TextTrack* track = mElement->Track(); - track->SetReadyState(TextTrack::READY_STATE_LOADED); + track->SetReadyState(TextTrackReadyState::Loaded); } // Attempt to parse any final data the parser might still have. mParserWrapper->Flush();