| 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" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 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 ASSERT(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, PassRefPtrWillBeRawPtr<TextTrackCue>
cue) | 33 void CueTimeline::addCue(TextTrack* track, RawPtr<TextTrackCue> cue) |
| 34 { | 34 { |
| 35 ASSERT(track->mode() != TextTrack::disabledKeyword()); | 35 ASSERT(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(PassRefPtrWillBeRawPtr<TextTrackCue> cue) | 40 void CueTimeline::addCueInternal(RawPtr<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 |
| 46 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); | 46 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); |
| 47 if (!m_cueTree.contains(interval)) | 47 if (!m_cueTree.contains(interval)) |
| 48 m_cueTree.add(interval); | 48 m_cueTree.add(interval); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void CueTimeline::removeCues(TextTrack*, const TextTrackCueList* cues) | 51 void CueTimeline::removeCues(TextTrack*, const TextTrackCueList* cues) |
| 52 { | 52 { |
| 53 for (size_t i = 0; i < cues->length(); ++i) | 53 for (size_t i = 0; i < cues->length(); ++i) |
| 54 removeCueInternal(cues->anonymousIndexedGetter(i)); | 54 removeCueInternal(cues->anonymousIndexedGetter(i)); |
| 55 updateActiveCues(mediaElement().currentTime()); | 55 updateActiveCues(mediaElement().currentTime()); |
| 56 } | 56 } |
| 57 | 57 |
| 58 void CueTimeline::removeCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue> cue
) | 58 void CueTimeline::removeCue(TextTrack*, RawPtr<TextTrackCue> cue) |
| 59 { | 59 { |
| 60 removeCueInternal(cue); | 60 removeCueInternal(cue); |
| 61 updateActiveCues(mediaElement().currentTime()); | 61 updateActiveCues(mediaElement().currentTime()); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void CueTimeline::removeCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue> cue) | 64 void CueTimeline::removeCueInternal(RawPtr<TextTrackCue> cue) |
| 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.get()); | 70 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); |
| 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) { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 105 // track order. | 105 // track order. |
| 106 if (a.second->track() != b.second->track()) | 106 if (a.second->track() != b.second->track()) |
| 107 return trackIndexCompare(a.second->track(), b.second->track()); | 107 return trackIndexCompare(a.second->track(), b.second->track()); |
| 108 | 108 |
| 109 // 12 - Further sort tasks in events that have the same time by the | 109 // 12 - Further sort tasks in events that have the same time by the |
| 110 // relative text track cue order of the text track cues associated | 110 // relative text track cue order of the text track cues associated |
| 111 // with these tasks. | 111 // with these tasks. |
| 112 return a.second->cueIndex() < b.second->cueIndex(); | 112 return a.second->cueIndex() < b.second->cueIndex(); |
| 113 } | 113 } |
| 114 | 114 |
| 115 static PassRefPtrWillBeRawPtr<Event> createEventWithTarget(const AtomicString& e
ventName, PassRefPtrWillBeRawPtr<EventTarget> eventTarget) | 115 static RawPtr<Event> createEventWithTarget(const AtomicString& eventName, RawPtr
<EventTarget> eventTarget) |
| 116 { | 116 { |
| 117 RefPtrWillBeRawPtr<Event> event = Event::create(eventName); | 117 RawPtr<Event> event = Event::create(eventName); |
| 118 event->setTarget(eventTarget); | 118 event->setTarget(eventTarget); |
| 119 return event.release(); | 119 return event.release(); |
| 120 } | 120 } |
| 121 | 121 |
| 122 void CueTimeline::updateActiveCues(double movieTime) | 122 void CueTimeline::updateActiveCues(double movieTime) |
| 123 { | 123 { |
| 124 // 4.8.10.8 Playing the media resource | 124 // 4.8.10.8 Playing the media resource |
| 125 | 125 |
| 126 // If the current playback position changes while the steps are running, | 126 // If the current playback position changes while the steps are running, |
| 127 // then the user agent must wait for the steps to complete, and then must | 127 // then the user agent must wait for the steps to complete, and then must |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 if (!m_ignoreUpdate) | 358 if (!m_ignoreUpdate) |
| 359 updateActiveCues(mediaElement().currentTime()); | 359 updateActiveCues(mediaElement().currentTime()); |
| 360 } | 360 } |
| 361 | 361 |
| 362 DEFINE_TRACE(CueTimeline) | 362 DEFINE_TRACE(CueTimeline) |
| 363 { | 363 { |
| 364 visitor->trace(m_mediaElement); | 364 visitor->trace(m_mediaElement); |
| 365 } | 365 } |
| 366 | 366 |
| 367 } // namespace blink | 367 } // namespace blink |
| OLD | NEW |