2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
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
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.
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.
33 #include "core/html/track/TextTrackCue.h"
35 #include "bindings/core/v8/ExceptionMessages.h"
36 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
37 #include "core/events/Event.h"
38 #include "core/html/track/TextTrack.h"
39 #include "core/html/track/TextTrackCueList.h"
43 static const unsigned invalidCueIndex
= UINT_MAX
;
45 TextTrackCue::TextTrackCue(double start
, double end
)
49 , m_cueIndex(invalidCueIndex
)
51 , m_pauseOnExit(false)
55 void TextTrackCue::cueWillChange()
58 m_track
->cueWillChange(this);
61 void TextTrackCue::cueDidChange()
64 m_track
->cueDidChange(this);
67 TextTrack
* TextTrackCue::track() const
72 void TextTrackCue::setTrack(TextTrack
* track
)
77 Node
* TextTrackCue::owner() const
79 return m_track
? m_track
->owner() : 0;
82 void TextTrackCue::setId(const AtomicString
& id
)
92 void TextTrackCue::setStartTime(double value
)
94 // TODO(93143): Add spec-compliant behavior for negative time values.
95 if (m_startTime
== value
|| value
< 0)
103 void TextTrackCue::setEndTime(double value
)
105 // TODO(93143): Add spec-compliant behavior for negative time values.
106 if (m_endTime
== value
|| value
< 0)
114 void TextTrackCue::setPauseOnExit(bool value
)
116 if (m_pauseOnExit
== value
)
120 m_pauseOnExit
= value
;
124 void TextTrackCue::invalidateCueIndex()
126 m_cueIndex
= invalidCueIndex
;
129 unsigned TextTrackCue::cueIndex()
131 // This method can only be called on cues while they are associated with
132 // a(n enabled) track (and hence that track's list of cues should exist.)
133 ASSERT(track() && track()->cues());
134 TextTrackCueList
* cueList
= track()->cues();
135 if (!cueList
->isCueIndexValid(m_cueIndex
))
136 cueList
->validateCueIndexes();
140 bool TextTrackCue::dispatchEventInternal(PassRefPtrWillBeRawPtr
<Event
> event
)
142 // When a TextTrack's mode is disabled: no cues are active, no events fired.
143 if (!track() || track()->mode() == TextTrack::disabledKeyword())
146 return EventTarget::dispatchEventInternal(event
);
149 const AtomicString
& TextTrackCue::interfaceName() const
151 return EventTargetNames::TextTrackCue
;
154 DEFINE_TRACE(TextTrackCue
)
156 visitor
->trace(m_track
);
157 RefCountedGarbageCollectedEventTargetWithInlineData
<TextTrackCue
>::trace(visitor
);