PassRefPtr<PlatformTextTrack> TextTrack::platformTextTrack() { if (m_platformTextTrack) return m_platformTextTrack; PlatformTextTrack::TrackKind kind = PlatformTextTrack::Caption; if (m_kind == subtitlesKeyword()) kind = PlatformTextTrack::Subtitle; else if (m_kind == captionsKeyword()) kind = PlatformTextTrack::Caption; else if (m_kind == descriptionsKeyword()) kind = PlatformTextTrack::Description; else if (m_kind == chaptersKeyword()) kind = PlatformTextTrack::Chapter; else if (m_kind == metadataKeyword()) kind = PlatformTextTrack::MetaData; PlatformTextTrack::TrackType type = PlatformTextTrack::OutOfBand; if (m_trackType == TrackElement) type = PlatformTextTrack::OutOfBand; else if (m_trackType == AddTrack) type = PlatformTextTrack::Script; else if (m_trackType == InBand) type = PlatformTextTrack::InBand; m_platformTextTrack = PlatformTextTrack::create(this, m_label, m_language, kind, type); return m_platformTextTrack; }
PassRefPtr<PlatformTextTrack> TextTrack::platformTextTrack() { if (m_platformTextTrack) return m_platformTextTrack; PlatformTextTrack::TrackKind platformKind = PlatformTextTrack::Caption; if (kind() == subtitlesKeyword()) platformKind = PlatformTextTrack::Subtitle; else if (kind() == captionsKeyword()) platformKind = PlatformTextTrack::Caption; else if (kind() == descriptionsKeyword()) platformKind = PlatformTextTrack::Description; else if (kind() == chaptersKeyword()) platformKind = PlatformTextTrack::Chapter; else if (kind() == metadataKeyword()) platformKind = PlatformTextTrack::MetaData; else if (kind() == forcedKeyword()) platformKind = PlatformTextTrack::Forced; PlatformTextTrack::TrackType type = PlatformTextTrack::OutOfBand; if (m_trackType == TrackElement) type = PlatformTextTrack::OutOfBand; else if (m_trackType == AddTrack) type = PlatformTextTrack::Script; else if (m_trackType == InBand) type = PlatformTextTrack::InBand; m_platformTextTrack = PlatformTextTrack::create(this, label(), language(), platformKind, type, uniqueId()); return m_platformTextTrack; }
bool TextTrack::isValidKindKeyword(const AtomicString& value) { if (equalIgnoringCase(value, subtitlesKeyword())) return true; if (equalIgnoringCase(value, captionsKeyword())) return true; if (equalIgnoringCase(value, descriptionsKeyword())) return true; if (equalIgnoringCase(value, chaptersKeyword())) return true; if (equalIgnoringCase(value, metadataKeyword())) return true; return false; }
bool TextTrack::isValidKindKeyword(const AtomicString& value) { if (value == subtitlesKeyword()) return true; if (value == captionsKeyword()) return true; if (value == descriptionsKeyword()) return true; if (value == chaptersKeyword()) return true; if (value == metadataKeyword()) return true; return false; }
TextTrack::TextTrack(ScriptExecutionContext* context, TextTrackClient* client, const AtomicString& kind, const AtomicString& id, const AtomicString& label, const AtomicString& language, TextTrackType type) : TrackBase(TrackBase::TextTrack, id, label, language) , m_scriptExecutionContext(context) , m_client(client) , m_trackType(type) , m_trackIndex(invalidTrackIndex) , m_renderedTrackIndex(invalidTrackIndex) { if (kind == captionsKeyword()) m_kind = Kind::Captions; else if (kind == chaptersKeyword()) m_kind = Kind::Chapters; else if (kind == descriptionsKeyword()) m_kind = Kind::Descriptions; else if (kind == forcedKeyword()) m_kind = Kind::Forced; else if (kind == metadataKeyword()) m_kind = Kind::Metadata; }
const AtomicString& TextTrack::kindKeyword() const { switch (m_kind) { case Kind::Captions: return captionsKeyword(); case Kind::Chapters: return chaptersKeyword(); case Kind::Descriptions: return descriptionsKeyword(); case Kind::Forced: return forcedKeyword(); case Kind::Metadata: return metadataKeyword(); case Kind::Subtitles: return subtitlesKeyword(); } ASSERT_NOT_REACHED(); return subtitlesKeyword(); }
void TextTrack::addCue(PassRefPtr<TextTrackCue> prpCue, ExceptionCode& ec) { if (!prpCue) return; RefPtr<TextTrackCue> cue = prpCue; // 4.7.10.12.6 Text tracks exposing in-band metadata // The UA will use DataCue to expose only text track cue objects that belong to a text track that has a text // track kind of metadata. // If a DataCue is added to a TextTrack via the addCue() method but the text track does not have its text // track kind set to metadata, throw a InvalidNodeTypeError exception and don't add the cue to the TextTrackList // of the TextTrack. if (cue->cueType() == TextTrackCue::Data && kind() != metadataKeyword()) { ec = INVALID_NODE_TYPE_ERR; return; } // TODO(93143): Add spec-compliant behavior for negative time values. if (!cue->startMediaTime().isValid() || !cue->endMediaTime().isValid() || cue->startMediaTime() < MediaTime::zeroTime() || cue->endMediaTime() < MediaTime::zeroTime()) return; // 4.8.10.12.5 Text track API // The addCue(cue) method of TextTrack objects, when invoked, must run the following steps: // 1. If the given cue is in a text track list of cues, then remove cue from that text track // list of cues. TextTrack* cueTrack = cue->track(); if (cueTrack && cueTrack != this) cueTrack->removeCue(cue.get(), ASSERT_NO_EXCEPTION); // 2. Add cue to the method's TextTrack object's text track's text track list of cues. cue->setTrack(this); ensureTextTrackCueList()->add(cue); if (m_client) m_client->textTrackAddCue(this, cue.get()); }