| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/html/track/CueTimeline.h" | 5 #include "core/html/track/CueTimeline.h" |
| 6 | 6 |
| 7 #include "core/events/Event.h" | 7 #include "core/events/Event.h" |
| 8 #include "core/html/HTMLMediaElement.h" | 8 #include "core/html/HTMLMediaElement.h" |
| 9 #include "core/html/HTMLTrackElement.h" | 9 #include "core/html/HTMLTrackElement.h" |
| 10 #include "core/html/track/LoadableTextTrack.h" | 10 #include "core/html/track/LoadableTextTrack.h" |
| 11 #include "core/html/track/TextTrack.h" | 11 #include "core/html/track/TextTrack.h" |
| 12 #include "core/html/track/TextTrackCue.h" | 12 #include "core/html/track/TextTrackCue.h" |
| 13 #include "core/html/track/TextTrackCueList.h" | 13 #include "core/html/track/TextTrackCueList.h" |
| 14 #include "wtf/NonCopyingSort.h" | 14 #include "wtf/NonCopyingSort.h" |
| 15 | 15 |
| 16 namespace blink { | 16 namespace blink { |
| 17 | 17 |
| 18 CueTimeline::CueTimeline(HTMLMediaElement& mediaElement) | 18 CueTimeline::CueTimeline(HTMLMediaElement& mediaElement) |
| 19 : m_mediaElement(&mediaElement) | 19 : m_mediaElement(&mediaElement) |
| 20 , m_lastUpdateTime(-1) | 20 , m_lastUpdateTime(-1) |
| 21 , m_ignoreUpdate(0) | 21 , m_ignoreUpdate(0) |
| 22 { | 22 { |
| 23 } | 23 } |
| 24 | 24 |
| 25 void CueTimeline::addCues(TextTrack* track, const TextTrackCueList* cues) | 25 void CueTimeline::addCues(TextTrack* track, const TextTrackCueList* cues) |
| 26 { | 26 { |
| 27 ASSERT(track->mode() != TextTrack::disabledKeyword()); | 27 DCHECK_NE(track->mode(), TextTrack::disabledKeyword()); |
| 28 for (size_t i = 0; i < cues->length(); ++i) | 28 for (size_t i = 0; i < cues->length(); ++i) |
| 29 addCueInternal(cues->anonymousIndexedGetter(i)); | 29 addCueInternal(cues->anonymousIndexedGetter(i)); |
| 30 updateActiveCues(mediaElement().currentTime()); | 30 updateActiveCues(mediaElement().currentTime()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void CueTimeline::addCue(TextTrack* track, TextTrackCue* cue) | 33 void CueTimeline::addCue(TextTrack* track, TextTrackCue* cue) |
| 34 { | 34 { |
| 35 ASSERT(track->mode() != TextTrack::disabledKeyword()); | 35 DCHECK_NE(track->mode(), TextTrack::disabledKeyword()); |
| 36 addCueInternal(cue); | 36 addCueInternal(cue); |
| 37 updateActiveCues(mediaElement().currentTime()); | 37 updateActiveCues(mediaElement().currentTime()); |
| 38 } | 38 } |
| 39 | 39 |
| 40 void CueTimeline::addCueInternal(TextTrackCue* cue) | 40 void CueTimeline::addCueInternal(TextTrackCue* cue) |
| 41 { | 41 { |
| 42 // Negative duration cues need be treated in the interval tree as | 42 // Negative duration cues need be treated in the interval tree as |
| 43 // zero-length cues. | 43 // zero-length cues. |
| 44 double endTime = std::max(cue->startTime(), cue->endTime()); | 44 double endTime = std::max(cue->startTime(), cue->endTime()); |
| 45 | 45 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 65 { | 65 { |
| 66 // Negative duration cues need to be treated in the interval tree as | 66 // Negative duration cues need to be treated in the interval tree as |
| 67 // zero-length cues. | 67 // zero-length cues. |
| 68 double endTime = std::max(cue->startTime(), cue->endTime()); | 68 double endTime = std::max(cue->startTime(), cue->endTime()); |
| 69 | 69 |
| 70 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue); | 70 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue); |
| 71 m_cueTree.remove(interval); | 71 m_cueTree.remove(interval); |
| 72 | 72 |
| 73 size_t index = m_currentlyActiveCues.find(interval); | 73 size_t index = m_currentlyActiveCues.find(interval); |
| 74 if (index != kNotFound) { | 74 if (index != kNotFound) { |
| 75 ASSERT(cue->isActive()); | 75 DCHECK(cue->isActive()); |
| 76 m_currentlyActiveCues.remove(index); | 76 m_currentlyActiveCues.remove(index); |
| 77 cue->setIsActive(false); | 77 cue->setIsActive(false); |
| 78 // Since the cue will be removed from the media element and likely the | 78 // Since the cue will be removed from the media element and likely the |
| 79 // TextTrack might also be destructed, notifying the region of the cue | 79 // TextTrack might also be destructed, notifying the region of the cue |
| 80 // removal shouldn't be done. | 80 // removal shouldn't be done. |
| 81 cue->removeDisplayTree(TextTrackCue::DontNotifyRegion); | 81 cue->removeDisplayTree(TextTrackCue::DontNotifyRegion); |
| 82 } | 82 } |
| 83 } | 83 } |
| 84 | 84 |
| 85 void CueTimeline::hideCues(TextTrack*, const TextTrackCueList* cues) | 85 void CueTimeline::hideCues(TextTrack*, const TextTrackCueList* cues) |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 | 313 |
| 314 // 15 - For each text track in affected tracks, in the list order, queue a | 314 // 15 - For each text track in affected tracks, in the list order, queue a |
| 315 // task to fire a simple event named cuechange at the TextTrack object, and,
... | 315 // task to fire a simple event named cuechange at the TextTrack object, and,
... |
| 316 for (size_t i = 0; i < affectedTracks.size(); ++i) { | 316 for (size_t i = 0; i < affectedTracks.size(); ++i) { |
| 317 mediaElement.scheduleEvent(createEventWithTarget(EventTypeNames::cuechan
ge, affectedTracks[i].get())); | 317 mediaElement.scheduleEvent(createEventWithTarget(EventTypeNames::cuechan
ge, affectedTracks[i].get())); |
| 318 | 318 |
| 319 // ... if the text track has a corresponding track element, to then fire
a | 319 // ... if the text track has a corresponding track element, to then fire
a |
| 320 // simple event named cuechange at the track element as well. | 320 // simple event named cuechange at the track element as well. |
| 321 if (affectedTracks[i]->trackType() == TextTrack::TrackElement) { | 321 if (affectedTracks[i]->trackType() == TextTrack::TrackElement) { |
| 322 HTMLTrackElement* trackElement = static_cast<LoadableTextTrack*>(aff
ectedTracks[i].get())->trackElement(); | 322 HTMLTrackElement* trackElement = static_cast<LoadableTextTrack*>(aff
ectedTracks[i].get())->trackElement(); |
| 323 ASSERT(trackElement); | 323 DCHECK(trackElement); |
| 324 mediaElement.scheduleEvent(createEventWithTarget(EventTypeNames::cue
change, trackElement)); | 324 mediaElement.scheduleEvent(createEventWithTarget(EventTypeNames::cue
change, trackElement)); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| 328 // 16 - Set the text track cue active flag of all the cues in the current | 328 // 16 - Set the text track cue active flag of all the cues in the current |
| 329 // cues, and unset the text track cue active flag of all the cues in the | 329 // cues, and unset the text track cue active flag of all the cues in the |
| 330 // other cues. | 330 // other cues. |
| 331 for (size_t i = 0; i < currentCuesSize; ++i) | 331 for (size_t i = 0; i < currentCuesSize; ++i) |
| 332 currentCues[i].data()->setIsActive(true); | 332 currentCues[i].data()->setIsActive(true); |
| 333 | 333 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 344 mediaElement.updateTextTrackDisplay(); | 344 mediaElement.updateTextTrackDisplay(); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void CueTimeline::beginIgnoringUpdateRequests() | 347 void CueTimeline::beginIgnoringUpdateRequests() |
| 348 { | 348 { |
| 349 ++m_ignoreUpdate; | 349 ++m_ignoreUpdate; |
| 350 } | 350 } |
| 351 | 351 |
| 352 void CueTimeline::endIgnoringUpdateRequests() | 352 void CueTimeline::endIgnoringUpdateRequests() |
| 353 { | 353 { |
| 354 ASSERT(m_ignoreUpdate); | 354 DCHECK(m_ignoreUpdate); |
| 355 --m_ignoreUpdate; | 355 --m_ignoreUpdate; |
| 356 if (!m_ignoreUpdate) | 356 if (!m_ignoreUpdate) |
| 357 updateActiveCues(mediaElement().currentTime()); | 357 updateActiveCues(mediaElement().currentTime()); |
| 358 } | 358 } |
| 359 | 359 |
| 360 DEFINE_TRACE(CueTimeline) | 360 DEFINE_TRACE(CueTimeline) |
| 361 { | 361 { |
| 362 visitor->trace(m_mediaElement); | 362 visitor->trace(m_mediaElement); |
| 363 } | 363 } |
| 364 | 364 |
| 365 } // namespace blink | 365 } // namespace blink |
| OLD | NEW |