| 1 | /* |
| 2 | * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 | * Copyright (C) 2012-2017 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 | #pragma once |
| 33 | |
| 34 | #if ENABLE(VIDEO_TRACK) |
| 35 | |
| 36 | #include "Document.h" |
| 37 | #include <wtf/JSONValues.h> |
| 38 | #include <wtf/MediaTime.h> |
| 39 | |
| 40 | namespace WebCore { |
| 41 | |
| 42 | class TextTrack; |
| 43 | |
| 44 | class TextTrackCue : public RefCounted<TextTrackCue>, public EventTargetWithInlineData { |
| 45 | WTF_MAKE_ISO_ALLOCATED(TextTrackCue); |
| 46 | public: |
| 47 | static const AtomicString& cueShadowPseudoId(); |
| 48 | |
| 49 | TextTrack* track() const; |
| 50 | void setTrack(TextTrack*); |
| 51 | |
| 52 | const String& id() const { return m_id; } |
| 53 | void setId(const String&); |
| 54 | |
| 55 | double startTime() const { return startMediaTime().toDouble(); } |
| 56 | void setStartTime(double); |
| 57 | |
| 58 | double endTime() const { return endMediaTime().toDouble(); } |
| 59 | void setEndTime(double); |
| 60 | |
| 61 | bool pauseOnExit() const { return m_pauseOnExit; } |
| 62 | void setPauseOnExit(bool); |
| 63 | |
| 64 | MediaTime startMediaTime() const { return m_startTime; } |
| 65 | void setStartTime(const MediaTime&); |
| 66 | |
| 67 | MediaTime endMediaTime() const { return m_endTime; } |
| 68 | void setEndTime(const MediaTime&); |
| 69 | |
| 70 | bool isActive(); |
| 71 | virtual void setIsActive(bool); |
| 72 | |
| 73 | virtual bool isOrderedBefore(const TextTrackCue*) const; |
| 74 | virtual bool isPositionedAbove(const TextTrackCue* cue) const { return isOrderedBefore(cue); } |
| 75 | |
| 76 | bool hasEquivalentStartTime(const TextTrackCue&) const; |
| 77 | |
| 78 | enum CueType { Data, Generic, WebVTT }; |
| 79 | virtual CueType cueType() const = 0; |
| 80 | virtual bool isRenderable() const { return false; } |
| 81 | |
| 82 | enum CueMatchRules { MatchAllFields, IgnoreDuration }; |
| 83 | virtual bool isEqual(const TextTrackCue&, CueMatchRules) const; |
| 84 | virtual bool doesExtendCue(const TextTrackCue&) const; |
| 85 | |
| 86 | void willChange(); |
| 87 | virtual void didChange(); |
| 88 | |
| 89 | String toJSONString() const; |
| 90 | String debugString() const; |
| 91 | |
| 92 | using RefCounted::ref; |
| 93 | using RefCounted::deref; |
| 94 | |
| 95 | protected: |
| 96 | TextTrackCue(ScriptExecutionContext&, const MediaTime& start, const MediaTime& end); |
| 97 | |
| 98 | Document& ownerDocument() { return downcast<Document>(m_scriptExecutionContext); } |
| 99 | |
| 100 | virtual void toJSON(JSON::Object&) const; |
| 101 | |
| 102 | private: |
| 103 | void refEventTarget() final { ref(); } |
| 104 | void derefEventTarget() final { deref(); } |
| 105 | |
| 106 | using EventTarget::dispatchEvent; |
| 107 | void dispatchEvent(Event&) final; |
| 108 | |
| 109 | EventTargetInterface eventTargetInterface() const final { return TextTrackCueEventTargetInterfaceType; } |
| 110 | ScriptExecutionContext* scriptExecutionContext() const final { return &m_scriptExecutionContext; } |
| 111 | |
| 112 | virtual bool cueContentsMatch(const TextTrackCue&) const; |
| 113 | |
| 114 | String m_id; |
| 115 | MediaTime m_startTime; |
| 116 | MediaTime m_endTime; |
| 117 | int m_processingCueChanges { 0 }; |
| 118 | |
| 119 | TextTrack* m_track { nullptr }; |
| 120 | |
| 121 | ScriptExecutionContext& m_scriptExecutionContext; |
| 122 | |
| 123 | bool m_isActive : 1; |
| 124 | bool m_pauseOnExit : 1; |
| 125 | }; |
| 126 | |
| 127 | } // namespace WebCore |
| 128 | |
| 129 | namespace WTF { |
| 130 | |
| 131 | template<typename> struct LogArgument; |
| 132 | |
| 133 | template<> struct LogArgument<WebCore::TextTrackCue> { |
| 134 | static String toString(const WebCore::TextTrackCue& cue) { return cue.toJSONString(); } |
| 135 | }; |
| 136 | |
| 137 | } |
| 138 | |
| 139 | #endif |
| 140 | |