1 /* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27 #ifndef TextTrack_h 28 #define TextTrack_h 29 30 #include "core/events/EventTarget.h" 31 #include "core/html/track/TrackBase.h" 32 #include "platform/heap/Handle.h" 33 #include "wtf/text/WTFString.h" 34 35 namespace blink { 36 37 class ExceptionState; 38 class HTMLMediaElement; 39 class TextTrack; 40 class TextTrackCue; 41 class TextTrackCueList; 42 class TextTrackList; 43 class VTTRegion; 44 class VTTRegionList; 45 46 class TextTrack : public TrackBase, public EventTargetWithInlineData { 47 DEFINE_WRAPPERTYPEINFO(); 48 REFCOUNTED_EVENT_TARGET(TrackBase); 49 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TextTrack); 50 public: create(const AtomicString & kind,const AtomicString & label,const AtomicString & language)51 static PassRefPtrWillBeRawPtr<TextTrack> create(const AtomicString& kind, const AtomicString& label, const AtomicString& language) 52 { 53 return adoptRefWillBeNoop(new TextTrack(kind, label, language, emptyAtom, AddTrack)); 54 } 55 virtual ~TextTrack(); 56 57 virtual void setTrackList(TextTrackList*); trackList()58 TextTrackList* trackList() { return m_trackList; } 59 60 virtual void setKind(const AtomicString&) OVERRIDE; 61 62 static const AtomicString& subtitlesKeyword(); 63 static const AtomicString& captionsKeyword(); 64 static const AtomicString& descriptionsKeyword(); 65 static const AtomicString& chaptersKeyword(); 66 static const AtomicString& metadataKeyword(); 67 static bool isValidKindKeyword(const AtomicString&); 68 69 static const AtomicString& disabledKeyword(); 70 static const AtomicString& hiddenKeyword(); 71 static const AtomicString& showingKeyword(); 72 mode()73 AtomicString mode() const { return m_mode; } 74 virtual void setMode(const AtomicString&); 75 76 enum ReadinessState { NotLoaded = 0, Loading = 1, Loaded = 2, FailedToLoad = 3 }; readinessState()77 ReadinessState readinessState() const { return m_readinessState; } setReadinessState(ReadinessState state)78 void setReadinessState(ReadinessState state) { m_readinessState = state; } 79 80 TextTrackCueList* cues(); 81 TextTrackCueList* activeCues() const; 82 83 HTMLMediaElement* mediaElement() const; 84 Node* owner() const; 85 86 void addCue(PassRefPtrWillBeRawPtr<TextTrackCue>); 87 void removeCue(TextTrackCue*, ExceptionState&); 88 89 VTTRegionList* regions(); 90 void addRegion(PassRefPtrWillBeRawPtr<VTTRegion>); 91 void removeRegion(VTTRegion*, ExceptionState&); 92 93 void cueWillChange(TextTrackCue*); 94 void cueDidChange(TextTrackCue*); 95 96 DEFINE_ATTRIBUTE_EVENT_LISTENER(cuechange); 97 98 enum TextTrackType { TrackElement, AddTrack, InBand }; trackType()99 TextTrackType trackType() const { return m_trackType; } 100 101 int trackIndex(); 102 void invalidateTrackIndex(); 103 104 bool isRendered(); 105 int trackIndexRelativeToRenderedTracks(); 106 hasBeenConfigured()107 bool hasBeenConfigured() const { return m_hasBeenConfigured; } setHasBeenConfigured(bool flag)108 void setHasBeenConfigured(bool flag) { m_hasBeenConfigured = flag; } 109 isDefault()110 virtual bool isDefault() const { return false; } setIsDefault(bool)111 virtual void setIsDefault(bool) { } 112 113 void removeAllCues(); 114 115 // EventTarget methods 116 virtual const AtomicString& interfaceName() const OVERRIDE; 117 virtual ExecutionContext* executionContext() const OVERRIDE; 118 119 virtual void trace(Visitor*) OVERRIDE; 120 121 protected: 122 TextTrack(const AtomicString& kind, const AtomicString& label, const AtomicString& language, const AtomicString& id, TextTrackType); 123 isValidKind(const AtomicString & kind)124 virtual bool isValidKind(const AtomicString& kind) const OVERRIDE { return isValidKindKeyword(kind); } defaultKind()125 virtual AtomicString defaultKind() const OVERRIDE { return subtitlesKeyword(); } 126 127 RefPtrWillBeMember<TextTrackCueList> m_cues; 128 129 private: 130 VTTRegionList* ensureVTTRegionList(); 131 RefPtrWillBeMember<VTTRegionList> m_regions; 132 133 TextTrackCueList* ensureTextTrackCueList(); 134 135 RawPtrWillBeMember<TextTrackList> m_trackList; 136 AtomicString m_mode; 137 TextTrackType m_trackType; 138 ReadinessState m_readinessState; 139 int m_trackIndex; 140 int m_renderedTrackIndex; 141 bool m_hasBeenConfigured; 142 }; 143 144 DEFINE_TRACK_TYPE_CASTS(TextTrack, TrackBase::TextTrack); 145 146 } // namespace blink 147 148 #endif // TextTrack_h 149