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/events/EventTarget.h" 32 #include "core/html/track/TrackBase.h" 33 #include "platform/heap/Handle.h" 34 #include "wtf/text/WTFString.h" 35 36 namespace WebCore { 37 38 class Document; 39 class ExceptionState; 40 class HTMLMediaElement; 41 class TextTrack; 42 class TextTrackCue; 43 class TextTrackCueList; 44 class TextTrackList; 45 class VTTRegion; 46 class VTTRegionList; 47 48 class TextTrack : public TrackBase, public ScriptWrappable, public EventTargetWithInlineData { 49 REFCOUNTED_EVENT_TARGET(TrackBase); 50 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(TextTrack); 51 public: create(Document & document,const AtomicString & kind,const AtomicString & label,const AtomicString & language)52 static PassRefPtrWillBeRawPtr<TextTrack> create(Document& document, const AtomicString& kind, const AtomicString& label, const AtomicString& language) 53 { 54 return adoptRefWillBeRefCountedGarbageCollected(new TextTrack(document, kind, label, language, emptyAtom, AddTrack)); 55 } 56 virtual ~TextTrack(); 57 58 virtual void setTrackList(TextTrackList*); trackList()59 TextTrackList* trackList() { return m_trackList; } 60 61 virtual void setKind(const AtomicString&) OVERRIDE; 62 63 static const AtomicString& subtitlesKeyword(); 64 static const AtomicString& captionsKeyword(); 65 static const AtomicString& descriptionsKeyword(); 66 static const AtomicString& chaptersKeyword(); 67 static const AtomicString& metadataKeyword(); 68 static bool isValidKindKeyword(const AtomicString&); 69 70 static const AtomicString& disabledKeyword(); 71 static const AtomicString& hiddenKeyword(); 72 static const AtomicString& showingKeyword(); 73 mode()74 AtomicString mode() const { return m_mode; } 75 virtual void setMode(const AtomicString&); 76 77 enum ReadinessState { NotLoaded = 0, Loading = 1, Loaded = 2, FailedToLoad = 3 }; readinessState()78 ReadinessState readinessState() const { return m_readinessState; } setReadinessState(ReadinessState state)79 void setReadinessState(ReadinessState state) { m_readinessState = state; } 80 81 TextTrackCueList* cues(); 82 TextTrackCueList* activeCues() const; 83 84 HTMLMediaElement* mediaElement() const; 85 Node* owner() const; 86 87 void addCue(PassRefPtrWillBeRawPtr<TextTrackCue>); 88 void removeCue(TextTrackCue*, ExceptionState&); 89 90 VTTRegionList* regions(); 91 void addRegion(PassRefPtrWillBeRawPtr<VTTRegion>); 92 void removeRegion(VTTRegion*, ExceptionState&); 93 94 void cueWillChange(TextTrackCue*); 95 void cueDidChange(TextTrackCue*); 96 97 DEFINE_ATTRIBUTE_EVENT_LISTENER(cuechange); 98 99 enum TextTrackType { TrackElement, AddTrack, InBand }; trackType()100 TextTrackType trackType() const { return m_trackType; } 101 102 int trackIndex(); 103 void invalidateTrackIndex(); 104 105 bool isRendered(); 106 int trackIndexRelativeToRenderedTracks(); 107 hasBeenConfigured()108 bool hasBeenConfigured() const { return m_hasBeenConfigured; } setHasBeenConfigured(bool flag)109 void setHasBeenConfigured(bool flag) { m_hasBeenConfigured = flag; } 110 isDefault()111 virtual bool isDefault() const { return false; } setIsDefault(bool)112 virtual void setIsDefault(bool) { } 113 114 void removeAllCues(); 115 116 // EventTarget methods 117 virtual const AtomicString& interfaceName() const OVERRIDE; 118 virtual ExecutionContext* executionContext() const OVERRIDE; 119 120 virtual void trace(Visitor*) OVERRIDE; 121 122 protected: 123 TextTrack(Document&, const AtomicString& kind, const AtomicString& label, const AtomicString& language, const AtomicString& id, TextTrackType); 124 isValidKind(const AtomicString & kind)125 virtual bool isValidKind(const AtomicString& kind) const OVERRIDE { return isValidKindKeyword(kind); } defaultKind()126 virtual AtomicString defaultKind() const OVERRIDE { return subtitlesKeyword(); } 127 128 RefPtrWillBeMember<TextTrackCueList> m_cues; 129 130 private: 131 VTTRegionList* ensureVTTRegionList(); 132 RefPtrWillBeMember<VTTRegionList> m_regions; 133 134 TextTrackCueList* ensureTextTrackCueList(); 135 136 RawPtrWillBeMember<TextTrackList> m_trackList; 137 AtomicString m_mode; 138 TextTrackType m_trackType; 139 ReadinessState m_readinessState; 140 int m_trackIndex; 141 int m_renderedTrackIndex; 142 bool m_hasBeenConfigured; 143 }; 144 145 } // namespace WebCore 146 147 #endif 148