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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 128 } |
129 | 129 |
130 bool TextTrack::isVisualKind() const { | 130 bool TextTrack::isVisualKind() const { |
131 return kind() == subtitlesKeyword() || kind() == captionsKeyword(); | 131 return kind() == subtitlesKeyword() || kind() == captionsKeyword(); |
132 } | 132 } |
133 | 133 |
134 void TextTrack::setMode(const AtomicString& mode) { | 134 void TextTrack::setMode(const AtomicString& mode) { |
135 DCHECK(mode == disabledKeyword() || mode == hiddenKeyword() || | 135 DCHECK(mode == disabledKeyword() || mode == hiddenKeyword() || |
136 mode == showingKeyword()); | 136 mode == showingKeyword()); |
137 | 137 |
138 // On setting, if the new value isn't equal to what the attribute would curren
tly | 138 // On setting, if the new value isn't equal to what the attribute would |
139 // return, the new value must be processed as follows ... | 139 // currently return, the new value must be processed as follows ... |
140 if (m_mode == mode) | 140 if (m_mode == mode) |
141 return; | 141 return; |
142 | 142 |
143 if (m_cues && cueTimeline()) { | 143 if (m_cues && cueTimeline()) { |
144 // If mode changes to disabled, remove this track's cues from the client | 144 // If mode changes to disabled, remove this track's cues from the client |
145 // because they will no longer be accessible from the cues() function. | 145 // because they will no longer be accessible from the cues() function. |
146 if (mode == disabledKeyword()) | 146 if (mode == disabledKeyword()) |
147 cueTimeline()->removeCues(this, m_cues.get()); | 147 cueTimeline()->removeCues(this, m_cues.get()); |
148 else if (mode != showingKeyword()) | 148 else if (mode != showingKeyword()) |
149 cueTimeline()->hideCues(this, m_cues.get()); | 149 cueTimeline()->hideCues(this, m_cues.get()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 newCue->setTrack(this); | 191 newCue->setTrack(this); |
192 cues->add(newCue); | 192 cues->add(newCue); |
193 } | 193 } |
194 | 194 |
195 if (cueTimeline() && mode() != disabledKeyword()) | 195 if (cueTimeline() && mode() != disabledKeyword()) |
196 cueTimeline()->addCues(this, cues); | 196 cueTimeline()->addCues(this, cues); |
197 } | 197 } |
198 | 198 |
199 TextTrackCueList* TextTrack::activeCues() { | 199 TextTrackCueList* TextTrack::activeCues() { |
200 // 4.8.10.12.5 If the text track mode ... is not the text track disabled mode, | 200 // 4.8.10.12.5 If the text track mode ... is not the text track disabled mode, |
201 // then the activeCues attribute must return a live TextTrackCueList object ..
. | 201 // then the activeCues attribute must return a live TextTrackCueList object |
202 // ... whose active flag was set when the script started, in text track cue | 202 // ... whose active flag was set when the script started, in text track cue |
203 // order. Otherwise, it must return null. When an object is returned, the | 203 // order. Otherwise, it must return null. When an object is returned, the same |
204 // same object must be returned each time. | 204 // object must be returned each time. |
205 // http://www.whatwg.org/specs/web-apps/current-work/#dom-texttrack-activecues | 205 // http://www.whatwg.org/specs/web-apps/current-work/#dom-texttrack-activecues |
206 if (!m_cues || m_mode == disabledKeyword()) | 206 if (!m_cues || m_mode == disabledKeyword()) |
207 return nullptr; | 207 return nullptr; |
208 | 208 |
209 if (!m_activeCues) | 209 if (!m_activeCues) |
210 m_activeCues = TextTrackCueList::create(); | 210 m_activeCues = TextTrackCueList::create(); |
211 | 211 |
212 m_cues->collectActiveCues(*m_activeCues); | 212 m_cues->collectActiveCues(*m_activeCues); |
213 return m_activeCues; | 213 return m_activeCues; |
214 } | 214 } |
215 | 215 |
216 void TextTrack::addCue(TextTrackCue* cue) { | 216 void TextTrack::addCue(TextTrackCue* cue) { |
217 DCHECK(cue); | 217 DCHECK(cue); |
218 | 218 |
219 // TODO(93143): Add spec-compliant behavior for negative time values. | 219 // TODO(93143): Add spec-compliant behavior for negative time values. |
220 if (std::isnan(cue->startTime()) || std::isnan(cue->endTime()) || | 220 if (std::isnan(cue->startTime()) || std::isnan(cue->endTime()) || |
221 cue->startTime() < 0 || cue->endTime() < 0) | 221 cue->startTime() < 0 || cue->endTime() < 0) |
222 return; | 222 return; |
223 | 223 |
224 // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-
addcue | 224 // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-
addcue |
225 | 225 |
226 // The addCue(cue) method of TextTrack objects, when invoked, must run the fol
lowing steps: | 226 // The addCue(cue) method of TextTrack objects, when invoked, must run the |
| 227 // following steps: |
227 | 228 |
228 // (Steps 1 and 2 - pertaining to association of rendering rules - are not imp
lemented.) | 229 // (Steps 1 and 2 - pertaining to association of rendering rules - are not |
| 230 // implemented.) |
229 | 231 |
230 // 3. If the given cue is in a text track list of cues, then remove cue | 232 // 3. If the given cue is in a text track list of cues, then remove cue |
231 // from that text track list of cues. | 233 // from that text track list of cues. |
232 if (TextTrack* cueTrack = cue->track()) | 234 if (TextTrack* cueTrack = cue->track()) |
233 cueTrack->removeCue(cue, ASSERT_NO_EXCEPTION); | 235 cueTrack->removeCue(cue, ASSERT_NO_EXCEPTION); |
234 | 236 |
235 // 4. Add cue to the method's TextTrack object's text track's text track list
of cues. | 237 // 4. Add cue to the method's TextTrack object's text track's text track list |
| 238 // of cues. |
236 cue->setTrack(this); | 239 cue->setTrack(this); |
237 ensureTextTrackCueList()->add(cue); | 240 ensureTextTrackCueList()->add(cue); |
238 | 241 |
239 if (cueTimeline() && m_mode != disabledKeyword()) | 242 if (cueTimeline() && m_mode != disabledKeyword()) |
240 cueTimeline()->addCue(this, cue); | 243 cueTimeline()->addCue(this, cue); |
241 } | 244 } |
242 | 245 |
243 void TextTrack::removeCue(TextTrackCue* cue, ExceptionState& exceptionState) { | 246 void TextTrack::removeCue(TextTrackCue* cue, ExceptionState& exceptionState) { |
244 DCHECK(cue); | 247 DCHECK(cue); |
245 | 248 |
246 // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-
removecue | 249 // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-texttrack-
removecue |
247 | 250 |
248 // The removeCue(cue) method of TextTrack objects, when invoked, must run the
following steps: | 251 // The removeCue(cue) method of TextTrack objects, when invoked, must run the |
| 252 // following steps: |
249 | 253 |
250 // 1. If the given cue is not currently listed in the method's TextTrack | 254 // 1. If the given cue is not currently listed in the method's TextTrack |
251 // object's text track's text track list of cues, then throw a NotFoundError e
xception. | 255 // object's text track's text track list of cues, then throw a NotFoundError |
| 256 // exception. |
252 if (cue->track() != this) { | 257 if (cue->track() != this) { |
253 exceptionState.throwDOMException( | 258 exceptionState.throwDOMException( |
254 NotFoundError, | 259 NotFoundError, |
255 "The specified cue is not listed in the TextTrack's list of cues."); | 260 "The specified cue is not listed in the TextTrack's list of cues."); |
256 return; | 261 return; |
257 } | 262 } |
258 | 263 |
259 // cue->track() == this implies that cue is in this track's list of cues, | 264 // cue->track() == this implies that cue is in this track's list of cues, |
260 // so this track should have a list of cues and the cue being removed | 265 // so this track should have a list of cues and the cue being removed |
261 // should be in it. | 266 // should be in it. |
262 DCHECK(m_cues); | 267 DCHECK(m_cues); |
263 | 268 |
264 // 2. Remove cue from the method's TextTrack object's text track's text track
list of cues. | 269 // 2. Remove cue from the method's TextTrack object's text track's text track |
| 270 // list of cues. |
265 bool wasRemoved = m_cues->remove(cue); | 271 bool wasRemoved = m_cues->remove(cue); |
266 DCHECK(wasRemoved); | 272 DCHECK(wasRemoved); |
267 | 273 |
268 // If the cue is active, a timeline needs to be available. | 274 // If the cue is active, a timeline needs to be available. |
269 DCHECK(!cue->isActive() || cueTimeline()); | 275 DCHECK(!cue->isActive() || cueTimeline()); |
270 | 276 |
271 cue->setTrack(0); | 277 cue->setTrack(0); |
272 | 278 |
273 if (cueTimeline()) | 279 if (cueTimeline()) |
274 cueTimeline()->removeCue(this, cue); | 280 cueTimeline()->removeCue(this, cue); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 if (!m_regions || !m_regions->remove(region)) { | 345 if (!m_regions || !m_regions->remove(region)) { |
340 exceptionState.throwDOMException(InvalidStateError, | 346 exceptionState.throwDOMException(InvalidStateError, |
341 "Failed to remove the specified region."); | 347 "Failed to remove the specified region."); |
342 return; | 348 return; |
343 } | 349 } |
344 | 350 |
345 region->setTrack(0); | 351 region->setTrack(0); |
346 } | 352 } |
347 | 353 |
348 void TextTrack::cueWillChange(TextTrackCue* cue) { | 354 void TextTrack::cueWillChange(TextTrackCue* cue) { |
349 // The cue may need to be repositioned in the media element's interval tree, m
ay need to | 355 // The cue may need to be repositioned in the media element's interval tree, |
350 // be re-rendered, etc, so remove it before the modification... | 356 // may need to be re-rendered, etc, so remove it before the modification... |
351 if (cueTimeline()) | 357 if (cueTimeline()) |
352 cueTimeline()->removeCue(this, cue); | 358 cueTimeline()->removeCue(this, cue); |
353 } | 359 } |
354 | 360 |
355 void TextTrack::cueDidChange(TextTrackCue* cue) { | 361 void TextTrack::cueDidChange(TextTrackCue* cue) { |
356 // This method is called through cue->track(), which should imply that this | 362 // This method is called through cue->track(), which should imply that this |
357 // track has a list of cues. | 363 // track has a list of cues. |
358 DCHECK(m_cues && cue->track() == this); | 364 DCHECK(m_cues && cue->track() == this); |
359 | 365 |
360 // Make sure the TextTrackCueList order is up to date. | 366 // Make sure the TextTrackCueList order is up to date. |
(...skipping 25 matching lines...) Expand all Loading... |
386 void TextTrack::invalidateTrackIndex() { | 392 void TextTrack::invalidateTrackIndex() { |
387 m_trackIndex = invalidTrackIndex; | 393 m_trackIndex = invalidTrackIndex; |
388 m_renderedTrackIndex = invalidTrackIndex; | 394 m_renderedTrackIndex = invalidTrackIndex; |
389 } | 395 } |
390 | 396 |
391 bool TextTrack::isRendered() const { | 397 bool TextTrack::isRendered() const { |
392 return m_mode == showingKeyword() && isVisualKind(); | 398 return m_mode == showingKeyword() && isVisualKind(); |
393 } | 399 } |
394 | 400 |
395 bool TextTrack::canBeRendered() const { | 401 bool TextTrack::canBeRendered() const { |
396 // A track can be displayed when it's of kind captions or subtitles and hasn't
failed to load. | 402 // A track can be displayed when it's of kind captions or subtitles and hasn't |
| 403 // failed to load. |
397 return getReadinessState() != FailedToLoad && isVisualKind(); | 404 return getReadinessState() != FailedToLoad && isVisualKind(); |
398 } | 405 } |
399 | 406 |
400 TextTrackCueList* TextTrack::ensureTextTrackCueList() { | 407 TextTrackCueList* TextTrack::ensureTextTrackCueList() { |
401 if (!m_cues) | 408 if (!m_cues) |
402 m_cues = TextTrackCueList::create(); | 409 m_cues = TextTrackCueList::create(); |
403 | 410 |
404 return m_cues.get(); | 411 return m_cues.get(); |
405 } | 412 } |
406 | 413 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 visitor->trace(m_regions); | 448 visitor->trace(m_regions); |
442 visitor->trace(m_trackList); | 449 visitor->trace(m_trackList); |
443 TrackBase::trace(visitor); | 450 TrackBase::trace(visitor); |
444 EventTargetWithInlineData::trace(visitor); | 451 EventTargetWithInlineData::trace(visitor); |
445 } | 452 } |
446 | 453 |
447 DEFINE_TRACE_WRAPPERS(TextTrack) { | 454 DEFINE_TRACE_WRAPPERS(TextTrack) { |
448 visitor->traceWrappers(m_cues); | 455 visitor->traceWrappers(m_cues); |
449 } | 456 } |
450 } // namespace blink | 457 } // namespace blink |
OLD | NEW |