This source file includes following definitions.
- m_isDefault
- clearTrackElement
- setMode
- scheduleLoad
- loadTimerFired
- newCuesAvailable
- cueLoadingCompleted
- newRegionsAvailable
- trackElementIndex
#include "config.h"
#include "core/html/track/LoadableTextTrack.h"
#include "core/dom/ElementTraversal.h"
#include "core/html/HTMLMediaElement.h"
#include "core/html/HTMLTrackElement.h"
#include "core/html/track/TextTrackCueList.h"
#include "core/html/track/vtt/VTTRegionList.h"
namespace WebCore {
using namespace HTMLNames;
LoadableTextTrack::LoadableTextTrack(HTMLTrackElement* track)
: TextTrack(track->document(), emptyAtom, emptyAtom, emptyAtom, emptyAtom, TrackElement)
, m_trackElement(track)
, m_loadTimer(this, &LoadableTextTrack::loadTimerFired)
, m_isDefault(false)
{
}
LoadableTextTrack::~LoadableTextTrack()
{
ASSERT(!m_trackElement);
}
void LoadableTextTrack::clearTrackElement()
{
m_trackElement = 0;
}
void LoadableTextTrack::setMode(const AtomicString& mode)
{
TextTrack::setMode(mode);
if (!m_trackElement)
return;
if (m_trackElement->readyState() == HTMLTrackElement::NONE)
m_trackElement->scheduleLoad();
}
void LoadableTextTrack::scheduleLoad(const KURL& url)
{
if (url == m_url) {
ASSERT(m_loader && m_trackElement);
if (m_loader->loadState() < TextTrackLoader::Finished)
return;
cueLoadingCompleted(m_loader.get(), m_loader->loadState() == TextTrackLoader::Failed);
return;
}
m_url = url;
if (!m_loadTimer.isActive())
m_loadTimer.startOneShot(0, FROM_HERE);
}
void LoadableTextTrack::loadTimerFired(Timer<LoadableTextTrack>*)
{
if (m_loader)
m_loader->cancelLoad();
if (!m_trackElement)
return;
m_loader = TextTrackLoader::create(*this, m_trackElement->document());
if (!m_loader->load(m_url, m_trackElement->mediaElementCrossOriginAttribute()))
m_trackElement->didCompleteLoad(HTMLTrackElement::Failure);
}
void LoadableTextTrack::newCuesAvailable(TextTrackLoader* loader)
{
ASSERT_UNUSED(loader, m_loader == loader);
Vector<RefPtr<VTTCue> > newCues;
m_loader->getNewCues(newCues);
if (!m_cues)
m_cues = TextTrackCueList::create();
for (size_t i = 0; i < newCues.size(); ++i) {
newCues[i]->setTrack(this);
m_cues->add(newCues[i]);
}
if (mediaElement())
mediaElement()->textTrackAddCues(this, m_cues.get());
}
void LoadableTextTrack::cueLoadingCompleted(TextTrackLoader* loader, bool loadingFailed)
{
ASSERT_UNUSED(loader, m_loader == loader);
if (!m_trackElement)
return;
m_trackElement->didCompleteLoad(loadingFailed ? HTMLTrackElement::Failure : HTMLTrackElement::Success);
}
void LoadableTextTrack::newRegionsAvailable(TextTrackLoader* loader)
{
ASSERT_UNUSED(loader, m_loader == loader);
Vector<RefPtr<VTTRegion> > newRegions;
m_loader->getNewRegions(newRegions);
for (size_t i = 0; i < newRegions.size(); ++i) {
newRegions[i]->setTrack(this);
regions()->add(newRegions[i]);
}
}
size_t LoadableTextTrack::trackElementIndex()
{
ASSERT(m_trackElement);
ASSERT(m_trackElement->parentNode());
size_t index = 0;
for (HTMLTrackElement* track = Traversal<HTMLTrackElement>::firstChild(*m_trackElement->parentNode()); track; track = Traversal<HTMLTrackElement>::nextSibling(*track)) {
if (!track->parentNode())
continue;
if (track == m_trackElement)
return index;
++index;
}
ASSERT_NOT_REACHED();
return 0;
}
}