1/* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2012, 2013, 2014 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 are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Redistributions in binary form must reproduce the above 12 * copyright notice, this list of conditions and the following disclaimer 13 * in the documentation and/or other materials provided with the 14 * distribution. 15 * * Neither the name of Google Inc. nor the names of its 16 * contributors may be used to endorse or promote products derived from 17 * this software without specific prior written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#ifndef TextTrackCue_h 33#define TextTrackCue_h 34 35#if ENABLE(VIDEO_TRACK) 36 37#include "EventTarget.h" 38#include "HTMLElement.h" 39#include <wtf/RefCounted.h> 40 41namespace WebCore { 42 43class TextTrack; 44 45class TextTrackCue : public RefCounted<TextTrackCue>, public EventTargetWithInlineData { 46public: 47 static PassRefPtr<TextTrackCue> create(ScriptExecutionContext&, double start, double end, const String& content); 48 49 static const AtomicString& cueShadowPseudoId() 50 { 51 DEPRECATED_DEFINE_STATIC_LOCAL(const AtomicString, cue, ("cue", AtomicString::ConstructFromLiteral)); 52 return cue; 53 } 54 55 virtual ~TextTrackCue(); 56 57 TextTrack* track() const; 58 void setTrack(TextTrack*); 59 60 const String& id() const { return m_id; } 61 void setId(const String&); 62 63 double startTime() const { return m_startTime; } 64 void setStartTime(double, ExceptionCode&); 65 66 double endTime() const { return m_endTime; } 67 void setEndTime(double, ExceptionCode&); 68 69 bool pauseOnExit() const { return m_pauseOnExit; } 70 void setPauseOnExit(bool); 71 72 int cueIndex(); 73 void invalidateCueIndex(); 74 75 using EventTarget::dispatchEvent; 76 virtual bool dispatchEvent(PassRefPtr<Event>) override; 77 78 bool isActive(); 79 virtual void setIsActive(bool); 80 81 virtual EventTargetInterface eventTargetInterface() const override final { return TextTrackCueEventTargetInterfaceType; } 82 virtual ScriptExecutionContext* scriptExecutionContext() const override final { return &m_scriptExecutionContext; } 83 84 virtual bool isOrderedBefore(const TextTrackCue*) const; 85 virtual bool isPositionedAbove(const TextTrackCue* cue) const { return isOrderedBefore(cue); } 86 87 bool hasEquivalentStartTime(const TextTrackCue&) const; 88 89 enum CueType { 90 Data, 91 Generic, 92 WebVTT 93 }; 94 virtual CueType cueType() const = 0; 95 virtual bool isRenderable() const { return false; } 96 97 enum CueMatchRules { 98 MatchAllFields, 99 IgnoreDuration, 100 }; 101 virtual bool isEqual(const TextTrackCue&, CueMatchRules) const; 102 virtual bool cueContentsMatch(const TextTrackCue&) const; 103 virtual bool doesExtendCue(const TextTrackCue&) const; 104 105 void willChange(); 106 virtual void didChange(); 107 108 DEFINE_ATTRIBUTE_EVENT_LISTENER(enter); 109 DEFINE_ATTRIBUTE_EVENT_LISTENER(exit); 110 111 using RefCounted<TextTrackCue>::ref; 112 using RefCounted<TextTrackCue>::deref; 113 114protected: 115 TextTrackCue(ScriptExecutionContext&, double start, double end); 116 117 Document& ownerDocument() { return toDocument(m_scriptExecutionContext); } 118 119private: 120 121 virtual void refEventTarget() override final { ref(); } 122 virtual void derefEventTarget() override final { deref(); } 123 124 String m_id; 125 double m_startTime; 126 double m_endTime; 127 int m_cueIndex; 128 int m_processingCueChanges; 129 130 TextTrack* m_track; 131 132 ScriptExecutionContext& m_scriptExecutionContext; 133 134 bool m_isActive : 1; 135 bool m_pauseOnExit : 1; 136}; 137 138} // namespace WebCore 139 140#endif 141#endif 142