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 for (size_t i = 0; i < cues->length(); ++i) | 29 for (size_t i = 0; i < cues->length(); ++i) |
30 addCueInternal(cues->item(i)); | 30 addCueInternal(cues->anonymousIndexedGetter(i)); |
31 updateActiveCues(mediaElement().currentTime()); | 31 updateActiveCues(mediaElement().currentTime()); |
32 } | 32 } |
33 | 33 |
34 void CueTimeline::addCue(TextTrack* track, PassRefPtrWillBeRawPtr<TextTrackCue>
cue) | 34 void CueTimeline::addCue(TextTrack* track, PassRefPtrWillBeRawPtr<TextTrackCue>
cue) |
35 { | 35 { |
36 ASSERT(track->mode() != TextTrack::disabledKeyword()); | 36 ASSERT(track->mode() != TextTrack::disabledKeyword()); |
37 addCueInternal(cue); | 37 addCueInternal(cue); |
38 updateActiveCues(mediaElement().currentTime()); | 38 updateActiveCues(mediaElement().currentTime()); |
39 } | 39 } |
40 | 40 |
41 void CueTimeline::addCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue> cue) | 41 void CueTimeline::addCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue> cue) |
42 { | 42 { |
43 // Negative duration cues need be treated in the interval tree as | 43 // Negative duration cues need be treated in the interval tree as |
44 // zero-length cues. | 44 // zero-length cues. |
45 double endTime = std::max(cue->startTime(), cue->endTime()); | 45 double endTime = std::max(cue->startTime(), cue->endTime()); |
46 | 46 |
47 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); | 47 CueInterval interval = m_cueTree.createInterval(cue->startTime(), endTime, c
ue.get()); |
48 if (!m_cueTree.contains(interval)) | 48 if (!m_cueTree.contains(interval)) |
49 m_cueTree.add(interval); | 49 m_cueTree.add(interval); |
50 } | 50 } |
51 | 51 |
52 void CueTimeline::removeCues(TextTrack*, const TextTrackCueList* cues) | 52 void CueTimeline::removeCues(TextTrack*, const TextTrackCueList* cues) |
53 { | 53 { |
54 for (size_t i = 0; i < cues->length(); ++i) | 54 for (size_t i = 0; i < cues->length(); ++i) |
55 removeCueInternal(cues->item(i)); | 55 removeCueInternal(cues->anonymousIndexedGetter(i)); |
56 updateActiveCues(mediaElement().currentTime()); | 56 updateActiveCues(mediaElement().currentTime()); |
57 } | 57 } |
58 | 58 |
59 void CueTimeline::removeCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue> cue
) | 59 void CueTimeline::removeCue(TextTrack*, PassRefPtrWillBeRawPtr<TextTrackCue> cue
) |
60 { | 60 { |
61 removeCueInternal(cue); | 61 removeCueInternal(cue); |
62 updateActiveCues(mediaElement().currentTime()); | 62 updateActiveCues(mediaElement().currentTime()); |
63 } | 63 } |
64 | 64 |
65 void CueTimeline::removeCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue> cue) | 65 void CueTimeline::removeCueInternal(PassRefPtrWillBeRawPtr<TextTrackCue> cue) |
(...skipping 13 matching lines...) Expand all Loading... |
79 // 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 |
80 // TextTrack might also be destructed, notifying the region of the cue | 80 // TextTrack might also be destructed, notifying the region of the cue |
81 // removal shouldn't be done. | 81 // removal shouldn't be done. |
82 cue->removeDisplayTree(TextTrackCue::DontNotifyRegion); | 82 cue->removeDisplayTree(TextTrackCue::DontNotifyRegion); |
83 } | 83 } |
84 } | 84 } |
85 | 85 |
86 void CueTimeline::hideCues(TextTrack*, const TextTrackCueList* cues) | 86 void CueTimeline::hideCues(TextTrack*, const TextTrackCueList* cues) |
87 { | 87 { |
88 for (size_t i = 0; i < cues->length(); ++i) | 88 for (size_t i = 0; i < cues->length(); ++i) |
89 cues->item(i)->removeDisplayTree(); | 89 cues->anonymousIndexedGetter(i)->removeDisplayTree(); |
90 } | 90 } |
91 | 91 |
92 static bool trackIndexCompare(TextTrack* a, TextTrack* b) | 92 static bool trackIndexCompare(TextTrack* a, TextTrack* b) |
93 { | 93 { |
94 return a->trackIndex() - b->trackIndex() < 0; | 94 return a->trackIndex() - b->trackIndex() < 0; |
95 } | 95 } |
96 | 96 |
97 static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a, const
std::pair<double, TextTrackCue*>& b) | 97 static bool eventTimeCueCompare(const std::pair<double, TextTrackCue*>& a, const
std::pair<double, TextTrackCue*>& b) |
98 { | 98 { |
99 // 12 - Sort the tasks in events in ascending time order (tasks with earlier | 99 // 12 - Sort the tasks in events in ascending time order (tasks with earlier |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
359 if (!m_ignoreUpdate) | 359 if (!m_ignoreUpdate) |
360 updateActiveCues(mediaElement().currentTime()); | 360 updateActiveCues(mediaElement().currentTime()); |
361 } | 361 } |
362 | 362 |
363 DEFINE_TRACE(CueTimeline) | 363 DEFINE_TRACE(CueTimeline) |
364 { | 364 { |
365 visitor->trace(m_mediaElement); | 365 visitor->trace(m_mediaElement); |
366 } | 366 } |
367 | 367 |
368 } // namespace blink | 368 } // namespace blink |
OLD | NEW |