mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 865407 - Part 1: Add TextTrackManager class r=cpearce
This class will manage everything to do with TextTracks for the HTMLMediaElement.
This commit is contained in:
parent
a8adf340f8
commit
e6fbe932a1
@ -17,7 +17,7 @@
|
||||
#include "DecoderTraits.h"
|
||||
#include "nsIAudioChannelAgent.h"
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/dom/TextTrackList.h"
|
||||
#include "mozilla/dom/TextTrackManager.h"
|
||||
|
||||
// Define to output information on decoding and painting framerate
|
||||
/* #define DEBUG_FRAME_RATE 1 */
|
||||
@ -50,6 +50,7 @@ namespace dom {
|
||||
|
||||
class MediaError;
|
||||
class MediaSource;
|
||||
class TextTrackList;
|
||||
|
||||
class HTMLMediaElement : public nsGenericHTMLElement,
|
||||
public nsIObserver,
|
||||
@ -526,12 +527,14 @@ public:
|
||||
const nsAString& aLanguage);
|
||||
|
||||
void AddTextTrack(TextTrack* aTextTrack) {
|
||||
mTextTracks->AddTextTrack(aTextTrack);
|
||||
if (mTextTrackManager) {
|
||||
mTextTrackManager->AddTextTrack(aTextTrack);
|
||||
}
|
||||
}
|
||||
|
||||
void RemoveTextTrack(TextTrack* aTextTrack) {
|
||||
if (mTextTracks) {
|
||||
mTextTracks->RemoveTextTrack(*aTextTrack);
|
||||
if (mTextTrackManager) {
|
||||
mTextTrackManager->RemoveTextTrack(aTextTrack);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1148,8 +1151,7 @@ protected:
|
||||
// An agent used to join audio channel service.
|
||||
nsCOMPtr<nsIAudioChannelAgent> mAudioChannelAgent;
|
||||
|
||||
// List of our attached text track objects.
|
||||
nsRefPtr<TextTrackList> mTextTracks;
|
||||
nsRefPtr<TextTrackManager> mTextTrackManager;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
|
@ -425,7 +425,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLMediaElement, nsGenericHTM
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mOutputStreams[i].mStream);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mPlayed);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTextTracks);
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTextTrackManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement, nsGenericHTMLElement)
|
||||
@ -445,7 +445,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLMediaElement, nsGenericHTMLE
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mOutputStreams[i].mStream);
|
||||
}
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mPlayed);
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTextTracks);
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTextTrackManager)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLMediaElement)
|
||||
@ -1999,7 +1999,7 @@ HTMLMediaElement::HTMLMediaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
|
||||
RegisterFreezableElement();
|
||||
NotifyOwnerDocumentActivityChanged();
|
||||
|
||||
mTextTracks = new TextTrackList(OwnerDoc()->GetParentObject());
|
||||
mTextTrackManager = new TextTrackManager(this);
|
||||
}
|
||||
|
||||
HTMLMediaElement::~HTMLMediaElement()
|
||||
@ -2979,7 +2979,9 @@ void HTMLMediaElement::SeekCompleted()
|
||||
DispatchAsyncEvent(NS_LITERAL_STRING("seeked"));
|
||||
// We changed whether we're seeking so we need to AddRemoveSelfReference
|
||||
AddRemoveSelfReference();
|
||||
mTextTracks->DidSeek();
|
||||
if (mTextTrackManager) {
|
||||
mTextTrackManager->DidSeek();
|
||||
}
|
||||
}
|
||||
|
||||
void HTMLMediaElement::NotifySuspendedByCache(bool aIsSuspended)
|
||||
@ -3668,11 +3670,11 @@ void HTMLMediaElement::FireTimeUpdate(bool aPeriodic)
|
||||
}
|
||||
|
||||
// Update visible text tracks.
|
||||
// Here mTextTracks can be null if the cycle collector has unlinked
|
||||
// Here mTextTrackManager can be null if the cycle collector has unlinked
|
||||
// us before our parent. In that case UnbindFromTree will call us
|
||||
// when our parent is unlinked.
|
||||
if (mTextTracks) {
|
||||
mTextTracks->Update(time);
|
||||
if (mTextTrackManager) {
|
||||
mTextTrackManager->Update(time);
|
||||
}
|
||||
}
|
||||
|
||||
@ -3905,7 +3907,7 @@ NS_IMETHODIMP HTMLMediaElement::CanPlayChanged(int32_t canPlay)
|
||||
TextTrackList*
|
||||
HTMLMediaElement::TextTracks() const
|
||||
{
|
||||
return mTextTracks;
|
||||
return mTextTrackManager ? mTextTrackManager->TextTracks() : nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<TextTrack>
|
||||
@ -3913,7 +3915,9 @@ HTMLMediaElement::AddTextTrack(TextTrackKind aKind,
|
||||
const nsAString& aLabel,
|
||||
const nsAString& aLanguage)
|
||||
{
|
||||
return mTextTracks->AddTextTrack(this, aKind, aLabel, aLanguage);
|
||||
return mTextTrackManager ? mTextTrackManager->AddTextTrack(aKind, aLabel,
|
||||
aLanguage)
|
||||
: nullptr;
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
|
68
content/html/content/src/TextTrackManager.cpp
Normal file
68
content/html/content/src/TextTrackManager.cpp
Normal file
@ -0,0 +1,68 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=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/TextTrackManager.h"
|
||||
#include "mozilla/dom/HTMLMediaElement.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
NS_IMPL_CYCLE_COLLECTION_1(TextTrackManager, mTextTracks)
|
||||
NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(TextTrackManager, AddRef)
|
||||
NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(TextTrackManager, Release)
|
||||
|
||||
TextTrackManager::TextTrackManager(HTMLMediaElement *aMediaElement)
|
||||
: mMediaElement(aMediaElement)
|
||||
{
|
||||
MOZ_COUNT_CTOR(TextTrackManager);
|
||||
mTextTracks = new TextTrackList(mMediaElement->OwnerDoc()->GetParentObject());
|
||||
}
|
||||
|
||||
TextTrackManager::~TextTrackManager()
|
||||
{
|
||||
MOZ_COUNT_DTOR(TextTrackManager);
|
||||
}
|
||||
|
||||
TextTrackList*
|
||||
TextTrackManager::TextTracks() const
|
||||
{
|
||||
return mTextTracks;
|
||||
}
|
||||
|
||||
already_AddRefed<TextTrack>
|
||||
TextTrackManager::AddTextTrack(TextTrackKind aKind, const nsAString& aLabel,
|
||||
const nsAString& aLanguage)
|
||||
{
|
||||
return mTextTracks->AddTextTrack(mMediaElement, aKind, aLabel, aLanguage);
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::AddTextTrack(TextTrack* aTextTrack)
|
||||
{
|
||||
mTextTracks->AddTextTrack(aTextTrack);
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::RemoveTextTrack(TextTrack* aTextTrack)
|
||||
{
|
||||
mTextTracks->RemoveTextTrack(*aTextTrack);
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::DidSeek()
|
||||
{
|
||||
mTextTracks->DidSeek();
|
||||
}
|
||||
|
||||
void
|
||||
TextTrackManager::Update(double aTime)
|
||||
{
|
||||
mTextTracks->Update(aTime);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
53
content/html/content/src/TextTrackManager.h
Normal file
53
content/html/content/src/TextTrackManager.h
Normal file
@ -0,0 +1,53 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=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/. */
|
||||
|
||||
#ifndef mozilla_dom_TextTrackManager_h
|
||||
#define mozilla_dom_TextTrackManager_h
|
||||
|
||||
#include "mozilla/dom/TextTrack.h"
|
||||
#include "mozilla/dom/TextTrackList.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class HTMLMediaElement;
|
||||
|
||||
class TextTrackManager
|
||||
{
|
||||
public:
|
||||
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(TextTrackManager)
|
||||
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(TextTrackManager);
|
||||
|
||||
TextTrackManager(HTMLMediaElement *aMediaElement);
|
||||
~TextTrackManager();
|
||||
|
||||
TextTrackList* TextTracks() const;
|
||||
already_AddRefed<TextTrack> AddTextTrack(TextTrackKind aKind,
|
||||
const nsAString& aLabel,
|
||||
const nsAString& aLanguage);
|
||||
void AddTextTrack(TextTrack* aTextTrack);
|
||||
void RemoveTextTrack(TextTrack* aTextTrack);
|
||||
void DidSeek();
|
||||
|
||||
// Update the display of cues on the video as per the current play back time
|
||||
// of aTime.
|
||||
void Update(double aTime);
|
||||
|
||||
private:
|
||||
// The HTMLMediaElement that this TextTrackManager manages the TextTracks of.
|
||||
// This is a weak reference as the life time of TextTrackManager is dependent
|
||||
// on the HTMLMediaElement, so it should not be trying to hold the
|
||||
// HTMLMediaElement alive.
|
||||
HTMLMediaElement* mMediaElement;
|
||||
// List of the TextTrackManager's owning HTMLMediaElement's TextTracks.
|
||||
nsRefPtr<TextTrackList> mTextTracks;
|
||||
};
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // mozilla_dom_TextTrackManager_h
|
@ -71,6 +71,7 @@ EXPORTS.mozilla.dom += [
|
||||
'HTMLTrackElement.h',
|
||||
'HTMLUnknownElement.h',
|
||||
'MediaError.h',
|
||||
'TextTrackManager.h',
|
||||
'TimeRanges.h',
|
||||
'UndoManager.h',
|
||||
'ValidityState.h',
|
||||
@ -141,6 +142,7 @@ CPP_SOURCES += [
|
||||
'HTMLUnknownElement.cpp',
|
||||
'HTMLVideoElement.cpp',
|
||||
'MediaError.cpp',
|
||||
'TextTrackManager.cpp',
|
||||
'TimeRanges.cpp',
|
||||
'UndoManager.cpp',
|
||||
'ValidityState.cpp',
|
||||
|
Loading…
Reference in New Issue
Block a user