Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / core / html / track / TextTrackCue.cpp
blob56320a9b2b0c64b2ba8bb5acbf5e8594afa6d639
1 /*
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
7 * met:
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.
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.
32 #include "config.h"
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"
41 namespace blink {
43 static const unsigned invalidCueIndex = UINT_MAX;
45 TextTrackCue::TextTrackCue(double start, double end)
46 : m_startTime(start)
47 , m_endTime(end)
48 , m_track(nullptr)
49 , m_cueIndex(invalidCueIndex)
50 , m_isActive(false)
51 , m_pauseOnExit(false)
55 void TextTrackCue::cueWillChange()
57 if (m_track)
58 m_track->cueWillChange(this);
61 void TextTrackCue::cueDidChange()
63 if (m_track)
64 m_track->cueDidChange(this);
67 TextTrack* TextTrackCue::track() const
69 return m_track;
72 void TextTrackCue::setTrack(TextTrack* track)
74 m_track = track;
77 Node* TextTrackCue::owner() const
79 return m_track ? m_track->owner() : 0;
82 void TextTrackCue::setId(const AtomicString& id)
84 if (m_id == id)
85 return;
87 cueWillChange();
88 m_id = id;
89 cueDidChange();
92 void TextTrackCue::setStartTime(double value)
94 // TODO(93143): Add spec-compliant behavior for negative time values.
95 if (m_startTime == value || value < 0)
96 return;
98 cueWillChange();
99 m_startTime = value;
100 cueDidChange();
103 void TextTrackCue::setEndTime(double value)
105 // TODO(93143): Add spec-compliant behavior for negative time values.
106 if (m_endTime == value || value < 0)
107 return;
109 cueWillChange();
110 m_endTime = value;
111 cueDidChange();
114 void TextTrackCue::setPauseOnExit(bool value)
116 if (m_pauseOnExit == value)
117 return;
119 cueWillChange();
120 m_pauseOnExit = value;
121 cueDidChange();
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();
137 return m_cueIndex;
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())
144 return false;
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);
160 } // namespace blink