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 "bindings/v8/ScriptWrappable.h" 31 #include "core/html/track/TrackBase.h" 32 #include "wtf/text/WTFString.h" 33 34 namespace WebCore { 35 36 class Document; 37 class ExceptionState; 38 class HTMLMediaElement; 39 class TextTrack; 40 class TextTrackCue; 41 class TextTrackCueList; 42 class VTTRegion; 43 class VTTRegionList; 44 45 class TextTrackClient { 46 public: 47 virtual ~TextTrackClient() { } 48 virtual void textTrackKindChanged(TextTrack*) = 0; 49 virtual void textTrackModeChanged(TextTrack*) = 0; 50 virtual void textTrackAddCues(TextTrack*, const TextTrackCueList*) = 0; 51 virtual void textTrackRemoveCues(TextTrack*, const TextTrackCueList*) = 0; 52 virtual void textTrackAddCue(TextTrack*, PassRefPtr<TextTrackCue>) = 0; 53 virtual void textTrackRemoveCue(TextTrack*, PassRefPtr<TextTrackCue>) = 0; 54 }; 55 56 class TextTrack : public TrackBase, public ScriptWrappable { 57 public: 58 static PassRefPtr<TextTrack> create(Document& document, TextTrackClient* client, const AtomicString& kind, const AtomicString& label, const AtomicString& language) 59 { 60 return adoptRef(new TextTrack(document, client, kind, label, language, emptyAtom, AddTrack)); 61 } 62 virtual ~TextTrack(); 63 64 void setMediaElement(HTMLMediaElement* element) { m_mediaElement = element; } 65 HTMLMediaElement* mediaElement() { return m_mediaElement; } 66 67 const AtomicString& kind() const { return m_kind; } 68 void setKind(const AtomicString&); 69 70 static const AtomicString& subtitlesKeyword(); 71 static const AtomicString& captionsKeyword(); 72 static const AtomicString& descriptionsKeyword(); 73 static const AtomicString& chaptersKeyword(); 74 static const AtomicString& metadataKeyword(); 75 static bool isValidKindKeyword(const AtomicString&); 76 77 AtomicString label() const { return m_label; } 78 void setLabel(const AtomicString& label) { m_label = label; } 79 80 AtomicString language() const { return m_language; } 81 void setLanguage(const AtomicString& language) { m_language = language; } 82 83 AtomicString id() const { return m_id; } 84 void setId(const AtomicString& id) { m_id = id; } 85 86 static const AtomicString& disabledKeyword(); 87 static const AtomicString& hiddenKeyword(); 88 static const AtomicString& showingKeyword(); 89 90 AtomicString mode() const { return m_mode; } 91 void setMode(const AtomicString&); 92 93 enum ReadinessState { NotLoaded = 0, Loading = 1, Loaded = 2, FailedToLoad = 3 }; 94 ReadinessState readinessState() const { return m_readinessState; } 95 void setReadinessState(ReadinessState state) { m_readinessState = state; } 96 97 TextTrackCueList* cues(); 98 TextTrackCueList* activeCues() const; 99 100 void clearClient() { m_client = 0; } 101 TextTrackClient* client() { return m_client; } 102 103 void addCue(PassRefPtr<TextTrackCue>); 104 void removeCue(TextTrackCue*, ExceptionState&); 105 106 VTTRegionList* regions(); 107 void addRegion(PassRefPtr<VTTRegion>); 108 void removeRegion(VTTRegion*, ExceptionState&); 109 110 void cueWillChange(TextTrackCue*); 111 void cueDidChange(TextTrackCue*); 112 113 DEFINE_ATTRIBUTE_EVENT_LISTENER(cuechange); 114 115 enum TextTrackType { TrackElement, AddTrack, InBand }; 116 TextTrackType trackType() const { return m_trackType; } 117 118 int trackIndex(); 119 void invalidateTrackIndex(); 120 121 bool isRendered(); 122 int trackIndexRelativeToRenderedTracks(); 123 124 bool hasBeenConfigured() const { return m_hasBeenConfigured; } 125 void setHasBeenConfigured(bool flag) { m_hasBeenConfigured = flag; } 126 127 virtual bool isDefault() const { return false; } 128 virtual void setIsDefault(bool) { } 129 130 void removeAllCues(); 131 132 Document& document() const { return *m_document; } 133 134 // EventTarget methods 135 virtual const AtomicString& interfaceName() const OVERRIDE; 136 virtual ExecutionContext* executionContext() const OVERRIDE; 137 138 protected: 139 TextTrack(Document&, TextTrackClient*, const AtomicString& kind, const AtomicString& label, const AtomicString& language, const AtomicString& id, TextTrackType); 140 141 RefPtr<TextTrackCueList> m_cues; 142 143 private: 144 VTTRegionList* ensureVTTRegionList(); 145 RefPtr<VTTRegionList> m_regions; 146 147 TextTrackCueList* ensureTextTrackCueList(); 148 149 // FIXME: Remove this pointer and get the Document from m_client 150 Document* m_document; 151 152 HTMLMediaElement* m_mediaElement; 153 AtomicString m_kind; 154 AtomicString m_label; 155 AtomicString m_language; 156 AtomicString m_id; 157 AtomicString m_mode; 158 TextTrackClient* m_client; 159 TextTrackType m_trackType; 160 ReadinessState m_readinessState; 161 int m_trackIndex; 162 int m_renderedTrackIndex; 163 bool m_hasBeenConfigured; 164 }; 165 166 } // namespace WebCore 167 168 #endif 169