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 "config.h" | 5 #include "config.h" |
6 #include "core/html/track/CueTimeline.h" | 6 #include "core/html/track/CueTimeline.h" |
7 | 7 |
8 #include "core/events/Event.h" | 8 #include "core/events/Event.h" |
9 #include "core/html/HTMLMediaElement.h" | 9 #include "core/html/HTMLMediaElement.h" |
10 #include "core/html/HTMLTrackElement.h" | 10 #include "core/html/HTMLTrackElement.h" |
11 #include "core/html/track/LoadableTextTrack.h" | 11 #include "core/html/track/LoadableTextTrack.h" |
12 #include "core/html/track/TextTrack.h" | 12 #include "core/html/track/TextTrack.h" |
13 #include "core/html/track/TextTrackCue.h" | 13 #include "core/html/track/TextTrackCue.h" |
14 #include "core/html/track/TextTrackCueList.h" | 14 #include "core/html/track/TextTrackCueList.h" |
15 #include "wtf/NonCopyingSort.h" | 15 #include "wtf/NonCopyingSort.h" |
16 | 16 |
17 namespace blink { | 17 namespace blink { |
18 | 18 |
19 CueTimeline::CueTimeline(HTMLMediaElement& mediaElement) | 19 CueTimeline::CueTimeline(HTMLMediaElement& mediaElement) |
20 : m_mediaElement(&mediaElement) | 20 : m_mediaElement(&mediaElement) |
21 , m_lastUpdateTime(-1) | 21 , m_lastUpdateTime(-1) |
22 , m_ignoreUpdate(0) | 22 , m_ignoreUpdate(0) |
23 { | 23 { |
24 } | 24 } |
25 | 25 |
26 void CueTimeline::addCues(TextTrack* track, const TextTrackCueList* cues) | 26 void CueTimeline::addCues(TextTrack* track, const TextTrackCueList* cues) |
27 { | 27 { |
28 ASSERT(track->mode() != TextTrack::disabledKeyword()); | 28 ASSERT(track->mode() != TextTrack::disabledKeyword()); |
29 | |
30 TrackDisplayUpdateScope scope(*this); | |
31 for (size_t i = 0; i < cues->length(); ++i) | 29 for (size_t i = 0; i < cues->length(); ++i) |
32 addCue(cues->item(i)->track(), cues->item(i)); | 30 addCueInternal(cues->item(i)); |
| 31 updateActiveCues(mediaElement().currentTime()); |
33 } | 32 } |
34 | 33 |
35 void CueTimeline::addCue(TextTrack* track, PassRefPtrWillBeRawPtr<TextTrackCue>
cue) | 34 void CueTimeline::addCue(TextTrack* track, PassRefPtrWillBeRawPtr<TextTrackCue>
cue) |
36 { | 35 { |
37 ASSERT(track->mode() != TextTrack::disabledKeyword()); | 36 ASSERT(track->mode() != TextTrack::disabledKeyword()); |
| 37 addCueInternal(cue); |
| 38 updateActiveCues(mediaElement().currentTime()); |
| 39 } |
38 | 40 |
| 41 void CueTimeline::addCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue> cue) |
| 42 { |
39 // Negative duration cues need be treated in the interval tree as | 43 // Negative duration cues need be treated in the interval tree as |
40 // zero-length cues. | 44 // zero-length cues. |
41 double endTime = std::max(cue->startTime(), cue->endTime()); | 45 double endTime = std::max(cue->startTime(), cue->endTime()); |
42 | 46 |
43 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); | 47 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); |
44 if (!m_cueTree.contains(interval)) | 48 if (!m_cueTree.contains(interval)) |
45 m_cueTree.add(interval); | 49 m_cueTree.add(interval); |
46 updateActiveCues(mediaElement().currentTime()); | |
47 } | 50 } |
48 | 51 |
49 void CueTimeline::removeCues(TextTrack*, const TextTrackCueList* cues) | 52 void CueTimeline::removeCues(TextTrack*, const TextTrackCueList* cues) |
50 { | 53 { |
51 TrackDisplayUpdateScope scope(*this); | |
52 for (size_t i = 0; i < cues->length(); ++i) | 54 for (size_t i = 0; i < cues->length(); ++i) |
53 removeCue(cues->item(i)->track(), cues->item(i)); | 55 removeCueInternal(cues->item(i)); |
| 56 updateActiveCues(mediaElement().currentTime()); |
54 } | 57 } |
55 | 58 |
56 void CueTimeline::removeCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue> cue
) | 59 void CueTimeline::removeCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue> cue
) |
57 { | 60 { |
| 61 removeCueInternal(cue); |
| 62 updateActiveCues(mediaElement().currentTime()); |
| 63 } |
| 64 |
| 65 void CueTimeline::removeCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue> cue) |
| 66 { |
58 // Negative duration cues need to be treated in the interval tree as | 67 // Negative duration cues need to be treated in the interval tree as |
59 // zero-length cues. | 68 // zero-length cues. |
60 double endTime = std::max(cue->startTime(), cue->endTime()); | 69 double endTime = std::max(cue->startTime(), cue->endTime()); |
61 | 70 |
62 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); | 71 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); |
63 m_cueTree.remove(interval); | 72 m_cueTree.remove(interval); |
64 | 73 |
65 size_t index = m_currentlyActiveCues.find(interval); | 74 size_t index = m_currentlyActiveCues.find(interval); |
66 if (index != kNotFound) { | 75 if (index != kNotFound) { |
67 ASSERT(cue->isActive()); | 76 ASSERT(cue->isActive()); |
68 m_currentlyActiveCues.remove(index); | 77 m_currentlyActiveCues.remove(index); |
69 cue->setIsActive(false); | 78 cue->setIsActive(false); |
70 // Since the cue will be removed from the media element and likely the | 79 // Since the cue will be removed from the media element and likely the |
71 // TextTrack might also be destructed, notifying the region of the cue | 80 // TextTrack might also be destructed, notifying the region of the cue |
72 // removal shouldn't be done. | 81 // removal shouldn't be done. |
73 cue->removeDisplayTree(TextTrackCue::DontNotifyRegion); | 82 cue->removeDisplayTree(TextTrackCue::DontNotifyRegion); |
74 } | 83 } |
75 updateActiveCues(mediaElement().currentTime()); | |
76 } | 84 } |
77 | 85 |
78 static bool trackIndexCompare(TextTrack* a, TextTrack* b) | 86 static bool trackIndexCompare(TextTrack* a, TextTrack* b) |
79 { | 87 { |
80 return a->trackIndex() - b->trackIndex() < 0; | 88 return a->trackIndex() - b->trackIndex() < 0; |
81 } | 89 } |
82 | 90 |
83 static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a, const
std::pair<double, TextTrackCue*>& b) | 91 static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a, const
std::pair<double, TextTrackCue*>& b) |
84 { | 92 { |
85 // 12 - Sort the tasks in events in ascending time order (tasks with earlier | 93 // 12 - Sort the tasks in events in ascending time order (tasks with earlier |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 if (!m_ignoreUpdate && mediaElement().inActiveDocument()) | 341 if (!m_ignoreUpdate && mediaElement().inActiveDocument()) |
334 updateActiveCues(mediaElement().currentTime()); | 342 updateActiveCues(mediaElement().currentTime()); |
335 } | 343 } |
336 | 344 |
337 DEFINE_TRACE(CueTimeline) | 345 DEFINE_TRACE(CueTimeline) |
338 { | 346 { |
339 visitor->trace(m_mediaElement); | 347 visitor->trace(m_mediaElement); |
340 } | 348 } |
341 | 349 |
342 } // namespace blink | 350 } // namespace blink |
OLD | NEW |