OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. | 3 * Copyright (C) 2011, 2012, 2013 Apple Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 18 matching lines...) Expand all Loading... |
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
30 */ | 30 */ |
31 | 31 |
32 #include "config.h" | 32 #include "config.h" |
33 #include "core/html/track/TextTrack.h" | 33 #include "core/html/track/TextTrack.h" |
34 | 34 |
35 #include "bindings/core/v8/ExceptionState.h" | 35 #include "bindings/core/v8/ExceptionState.h" |
36 #include "bindings/core/v8/ExceptionStatePlaceholder.h" | 36 #include "bindings/core/v8/ExceptionStatePlaceholder.h" |
37 #include "core/dom/ExceptionCode.h" | 37 #include "core/dom/ExceptionCode.h" |
38 #include "core/html/HTMLMediaElement.h" | 38 #include "core/html/HTMLMediaElement.h" |
| 39 #include "core/html/track/CueTimeline.h" |
39 #include "core/html/track/TextTrackCueList.h" | 40 #include "core/html/track/TextTrackCueList.h" |
40 #include "core/html/track/TextTrackList.h" | 41 #include "core/html/track/TextTrackList.h" |
41 #include "core/html/track/vtt/VTTRegion.h" | 42 #include "core/html/track/vtt/VTTRegion.h" |
42 #include "core/html/track/vtt/VTTRegionList.h" | 43 #include "core/html/track/vtt/VTTRegionList.h" |
43 #include "platform/RuntimeEnabledFeatures.h" | 44 #include "platform/RuntimeEnabledFeatures.h" |
44 | 45 |
45 namespace blink { | 46 namespace blink { |
46 | 47 |
47 static const int invalidTrackIndex = -1; | 48 static const int invalidTrackIndex = -1; |
48 | 49 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 if (value == chaptersKeyword()) | 137 if (value == chaptersKeyword()) |
137 return true; | 138 return true; |
138 if (value == metadataKeyword()) | 139 if (value == metadataKeyword()) |
139 return true; | 140 return true; |
140 | 141 |
141 return false; | 142 return false; |
142 } | 143 } |
143 | 144 |
144 void TextTrack::setTrackList(TextTrackList* trackList) | 145 void TextTrack::setTrackList(TextTrackList* trackList) |
145 { | 146 { |
146 if (!trackList && mediaElement() && m_cues) | 147 if (!trackList && cueTimeline() && m_cues) |
147 mediaElement()->textTrackRemoveCues(this, m_cues.get()); | 148 cueTimeline()->removeCues(this, m_cues.get()); |
148 | 149 |
149 m_trackList = trackList; | 150 m_trackList = trackList; |
150 invalidateTrackIndex(); | 151 invalidateTrackIndex(); |
151 } | 152 } |
152 | 153 |
153 void TextTrack::setKind(const AtomicString& newKind) | 154 void TextTrack::setKind(const AtomicString& newKind) |
154 { | 155 { |
155 AtomicString oldKind = kind(); | 156 AtomicString oldKind = kind(); |
156 TrackBase::setKind(newKind); | 157 TrackBase::setKind(newKind); |
157 | 158 |
158 if (mediaElement() && oldKind != kind()) | 159 if (mediaElement() && oldKind != kind()) |
159 mediaElement()->textTrackKindChanged(this); | 160 mediaElement()->textTrackKindChanged(this); |
160 } | 161 } |
161 | 162 |
162 void TextTrack::setMode(const AtomicString& mode) | 163 void TextTrack::setMode(const AtomicString& mode) |
163 { | 164 { |
164 ASSERT(mode == disabledKeyword() || mode == hiddenKeyword() || mode == showi
ngKeyword()); | 165 ASSERT(mode == disabledKeyword() || mode == hiddenKeyword() || mode == showi
ngKeyword()); |
165 | 166 |
166 // On setting, if the new value isn't equal to what the attribute would curr
ently | 167 // On setting, if the new value isn't equal to what the attribute would curr
ently |
167 // return, the new value must be processed as follows ... | 168 // return, the new value must be processed as follows ... |
168 if (m_mode == mode) | 169 if (m_mode == mode) |
169 return; | 170 return; |
170 | 171 |
171 // If mode changes to disabled, remove this track's cues from the client | 172 // If mode changes to disabled, remove this track's cues from the client |
172 // because they will no longer be accessible from the cues() function. | 173 // because they will no longer be accessible from the cues() function. |
173 if (mode == disabledKeyword() && mediaElement() && m_cues) | 174 if (mode == disabledKeyword() && cueTimeline() && m_cues) |
174 mediaElement()->textTrackRemoveCues(this, m_cues.get()); | 175 cueTimeline()->removeCues(this, m_cues.get()); |
175 | 176 |
176 if (mode != showingKeyword() && m_cues) | 177 if (mode != showingKeyword() && m_cues) |
177 for (size_t i = 0; i < m_cues->length(); ++i) | 178 for (size_t i = 0; i < m_cues->length(); ++i) |
178 m_cues->item(i)->removeDisplayTree(); | 179 m_cues->item(i)->removeDisplayTree(); |
179 | 180 |
180 m_mode = mode; | 181 m_mode = mode; |
181 | 182 |
182 if (mediaElement()) | 183 if (mediaElement()) |
183 mediaElement()->textTrackModeChanged(this); | 184 mediaElement()->textTrackModeChanged(this); |
184 } | 185 } |
185 | 186 |
186 TextTrackCueList* TextTrack::cues() | 187 TextTrackCueList* TextTrack::cues() |
187 { | 188 { |
188 // 4.8.10.12.5 If the text track mode ... is not the text track disabled mod
e, | 189 // 4.8.10.12.5 If the text track mode ... is not the text track disabled mod
e, |
189 // then the cues attribute must return a live TextTrackCueList object ... | 190 // then the cues attribute must return a live TextTrackCueList object ... |
190 // Otherwise, it must return null. When an object is returned, the | 191 // Otherwise, it must return null. When an object is returned, the |
191 // same object must be returned each time. | 192 // same object must be returned each time. |
192 // http://www.whatwg.org/specs/web-apps/current-work/#dom-texttrack-cues | 193 // http://www.whatwg.org/specs/web-apps/current-work/#dom-texttrack-cues |
193 if (m_mode != disabledKeyword()) | 194 if (m_mode != disabledKeyword()) |
194 return ensureTextTrackCueList(); | 195 return ensureTextTrackCueList(); |
195 return nullptr; | 196 return nullptr; |
196 } | 197 } |
197 | 198 |
198 void TextTrack::removeAllCues() | 199 void TextTrack::removeAllCues() |
199 { | 200 { |
200 if (!m_cues) | 201 if (!m_cues) |
201 return; | 202 return; |
202 | 203 |
203 if (mediaElement()) | 204 if (cueTimeline()) |
204 mediaElement()->textTrackRemoveCues(this, m_cues.get()); | 205 cueTimeline()->removeCues(this, m_cues.get()); |
205 | 206 |
206 for (size_t i = 0; i < m_cues->length(); ++i) | 207 for (size_t i = 0; i < m_cues->length(); ++i) |
207 m_cues->item(i)->setTrack(0); | 208 m_cues->item(i)->setTrack(0); |
208 | 209 |
209 m_cues = nullptr; | 210 m_cues = nullptr; |
210 } | 211 } |
211 | 212 |
212 TextTrackCueList* TextTrack::activeCues() const | 213 TextTrackCueList* TextTrack::activeCues() const |
213 { | 214 { |
214 // 4.8.10.12.5 If the text track mode ... is not the text track disabled mod
e, | 215 // 4.8.10.12.5 If the text track mode ... is not the text track disabled mod
e, |
(...skipping 25 matching lines...) Expand all Loading... |
240 // 1. If the given cue is in a text track list of cues, then remove cue from
that text track | 241 // 1. If the given cue is in a text track list of cues, then remove cue from
that text track |
241 // list of cues. | 242 // list of cues. |
242 TextTrack* cueTrack = cue->track(); | 243 TextTrack* cueTrack = cue->track(); |
243 if (cueTrack && cueTrack != this) | 244 if (cueTrack && cueTrack != this) |
244 cueTrack->removeCue(cue.get(), ASSERT_NO_EXCEPTION); | 245 cueTrack->removeCue(cue.get(), ASSERT_NO_EXCEPTION); |
245 | 246 |
246 // 2. Add cue to the method's TextTrack object's text track's text track lis
t of cues. | 247 // 2. Add cue to the method's TextTrack object's text track's text track lis
t of cues. |
247 cue->setTrack(this); | 248 cue->setTrack(this); |
248 ensureTextTrackCueList()->add(cue); | 249 ensureTextTrackCueList()->add(cue); |
249 | 250 |
250 if (mediaElement() && m_mode != disabledKeyword()) | 251 if (cueTimeline() && m_mode != disabledKeyword()) |
251 mediaElement()->textTrackAddCue(this, cue.get()); | 252 cueTimeline()->addCue(this, cue.get()); |
252 } | 253 } |
253 | 254 |
254 void TextTrack::removeCue(TextTrackCue* cue, ExceptionState& exceptionState) | 255 void TextTrack::removeCue(TextTrackCue* cue, ExceptionState& exceptionState) |
255 { | 256 { |
256 if (!cue) | 257 if (!cue) |
257 return; | 258 return; |
258 | 259 |
259 // 4.8.10.12.5 Text track API | 260 // 4.8.10.12.5 Text track API |
260 | 261 |
261 // The removeCue(cue) method of TextTrack objects, when invoked, must run th
e following steps: | 262 // The removeCue(cue) method of TextTrack objects, when invoked, must run th
e following steps: |
262 | 263 |
263 // 1. If the given cue is not currently listed in the method's TextTrack | 264 // 1. If the given cue is not currently listed in the method's TextTrack |
264 // object's text track's text track list of cues, then throw a NotFoundError
exception. | 265 // object's text track's text track list of cues, then throw a NotFoundError
exception. |
265 if (cue->track() != this) { | 266 if (cue->track() != this) { |
266 exceptionState.throwDOMException(NotFoundError, "The specified cue is no
t listed in the TextTrack's list of cues."); | 267 exceptionState.throwDOMException(NotFoundError, "The specified cue is no
t listed in the TextTrack's list of cues."); |
267 return; | 268 return; |
268 } | 269 } |
269 | 270 |
270 // 2. Remove cue from the method's TextTrack object's text track's text trac
k list of cues. | 271 // 2. Remove cue from the method's TextTrack object's text track's text trac
k list of cues. |
271 if (!m_cues || !m_cues->remove(cue)) { | 272 if (!m_cues || !m_cues->remove(cue)) { |
272 exceptionState.throwDOMException(InvalidStateError, "Failed to remove th
e specified cue."); | 273 exceptionState.throwDOMException(InvalidStateError, "Failed to remove th
e specified cue."); |
273 return; | 274 return; |
274 } | 275 } |
275 | 276 |
276 cue->setTrack(0); | 277 cue->setTrack(0); |
277 if (mediaElement()) | 278 if (cueTimeline()) |
278 mediaElement()->textTrackRemoveCue(this, cue); | 279 cueTimeline()->removeCue(this, cue); |
279 } | 280 } |
280 | 281 |
281 VTTRegionList* TextTrack::ensureVTTRegionList() | 282 VTTRegionList* TextTrack::ensureVTTRegionList() |
282 { | 283 { |
283 if (!m_regions) | 284 if (!m_regions) |
284 m_regions = VTTRegionList::create(); | 285 m_regions = VTTRegionList::create(); |
285 | 286 |
286 return m_regions.get(); | 287 return m_regions.get(); |
287 } | 288 } |
288 | 289 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 if (!m_regions || !m_regions->remove(region)) { | 345 if (!m_regions || !m_regions->remove(region)) { |
345 exceptionState.throwDOMException(InvalidStateError, "Failed to remove th
e specified region."); | 346 exceptionState.throwDOMException(InvalidStateError, "Failed to remove th
e specified region."); |
346 return; | 347 return; |
347 } | 348 } |
348 | 349 |
349 region->setTrack(0); | 350 region->setTrack(0); |
350 } | 351 } |
351 | 352 |
352 void TextTrack::cueWillChange(TextTrackCue* cue) | 353 void TextTrack::cueWillChange(TextTrackCue* cue) |
353 { | 354 { |
354 if (!mediaElement()) | 355 if (!cueTimeline()) |
355 return; | 356 return; |
356 | 357 |
357 // The cue may need to be repositioned in the media element's interval tree,
may need to | 358 // The cue may need to be repositioned in the media element's interval tree,
may need to |
358 // be re-rendered, etc, so remove it before the modification... | 359 // be re-rendered, etc, so remove it before the modification... |
359 mediaElement()->textTrackRemoveCue(this, cue); | 360 cueTimeline()->removeCue(this, cue); |
360 } | 361 } |
361 | 362 |
362 void TextTrack::cueDidChange(TextTrackCue* cue) | 363 void TextTrack::cueDidChange(TextTrackCue* cue) |
363 { | 364 { |
364 if (!mediaElement()) | 365 if (!cueTimeline()) |
365 return; | 366 return; |
366 | 367 |
367 // Make sure the TextTrackCueList order is up-to-date. | 368 // Make sure the TextTrackCueList order is up-to-date. |
368 ensureTextTrackCueList()->updateCueIndex(cue); | 369 ensureTextTrackCueList()->updateCueIndex(cue); |
369 | 370 |
370 // ... and add it back again if the track is enabled. | 371 // ... and add it back again if the track is enabled. |
371 if (m_mode == disabledKeyword()) | 372 if (m_mode == disabledKeyword()) |
372 return; | 373 return; |
373 | 374 |
374 mediaElement()->textTrackAddCue(this, cue); | 375 cueTimeline()->addCue(this, cue); |
375 } | 376 } |
376 | 377 |
377 int TextTrack::trackIndex() | 378 int TextTrack::trackIndex() |
378 { | 379 { |
379 ASSERT(m_trackList); | 380 ASSERT(m_trackList); |
380 | 381 |
381 if (m_trackIndex == invalidTrackIndex) | 382 if (m_trackIndex == invalidTrackIndex) |
382 m_trackIndex = m_trackList->getTrackIndex(this); | 383 m_trackIndex = m_trackList->getTrackIndex(this); |
383 | 384 |
384 return m_trackIndex; | 385 return m_trackIndex; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 { | 429 { |
429 HTMLMediaElement* owner = mediaElement(); | 430 HTMLMediaElement* owner = mediaElement(); |
430 return owner ? owner->executionContext() : 0; | 431 return owner ? owner->executionContext() : 0; |
431 } | 432 } |
432 | 433 |
433 HTMLMediaElement* TextTrack::mediaElement() const | 434 HTMLMediaElement* TextTrack::mediaElement() const |
434 { | 435 { |
435 return m_trackList ? m_trackList->owner() : 0; | 436 return m_trackList ? m_trackList->owner() : 0; |
436 } | 437 } |
437 | 438 |
| 439 CueTimeline* TextTrack::cueTimeline() const |
| 440 { |
| 441 return mediaElement() ? &mediaElement()->cueTimeline() : nullptr; |
| 442 } |
| 443 |
438 Node* TextTrack::owner() const | 444 Node* TextTrack::owner() const |
439 { | 445 { |
440 return mediaElement(); | 446 return mediaElement(); |
441 } | 447 } |
442 | 448 |
443 void TextTrack::trace(Visitor* visitor) | 449 void TextTrack::trace(Visitor* visitor) |
444 { | 450 { |
445 visitor->trace(m_cues); | 451 visitor->trace(m_cues); |
446 visitor->trace(m_regions); | 452 visitor->trace(m_regions); |
447 visitor->trace(m_trackList); | 453 visitor->trace(m_trackList); |
448 TrackBase::trace(visitor); | 454 TrackBase::trace(visitor); |
449 EventTargetWithInlineData::trace(visitor); | 455 EventTargetWithInlineData::trace(visitor); |
450 } | 456 } |
451 | 457 |
452 } // namespace blink | 458 } // namespace blink |
OLD | NEW |