| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 { | 60 { |
| 61 activeCues.clear(); | 61 activeCues.clear(); |
| 62 for (auto& cue : m_list) { | 62 for (auto& cue : m_list) { |
| 63 if (cue->isActive()) | 63 if (cue->isActive()) |
| 64 activeCues.add(cue); | 64 activeCues.add(cue); |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool TextTrackCueList::add(TextTrackCue* cue) | 68 bool TextTrackCueList::add(TextTrackCue* cue) |
| 69 { | 69 { |
| 70 ASSERT(cue->startTime() >= 0); | 70 DCHECK_GE(cue->startTime(), 0); |
| 71 ASSERT(cue->endTime() >= 0); | 71 DCHECK_GE(cue->endTime(), 0); |
| 72 | 72 |
| 73 // Maintain text track cue order: | 73 // Maintain text track cue order: |
| 74 // https://html.spec.whatwg.org/#text-track-cue-order | 74 // https://html.spec.whatwg.org/#text-track-cue-order |
| 75 size_t index = findInsertionIndex(cue); | 75 size_t index = findInsertionIndex(cue); |
| 76 | 76 |
| 77 // FIXME: The cue should not exist in the list in the first place. | 77 // FIXME: The cue should not exist in the list in the first place. |
| 78 if (!m_list.isEmpty() && (index > 0) && (m_list[index - 1].get() == cue)) | 78 if (!m_list.isEmpty() && (index > 0) && (m_list[index - 1].get() == cue)) |
| 79 return false; | 79 return false; |
| 80 | 80 |
| 81 m_list.insert(index, cue); | 81 m_list.insert(index, cue); |
| 82 invalidateCueIndex(index); | 82 invalidateCueIndex(index); |
| 83 return true; | 83 return true; |
| 84 } | 84 } |
| 85 | 85 |
| 86 static bool cueIsBefore(const TextTrackCue* cue, TextTrackCue* otherCue) | 86 static bool cueIsBefore(const TextTrackCue* cue, TextTrackCue* otherCue) |
| 87 { | 87 { |
| 88 if (cue->startTime() < otherCue->startTime()) | 88 if (cue->startTime() < otherCue->startTime()) |
| 89 return true; | 89 return true; |
| 90 | 90 |
| 91 return cue->startTime() == otherCue->startTime() && cue->endTime() > otherCu
e->endTime(); | 91 return cue->startTime() == otherCue->startTime() && cue->endTime() > otherCu
e->endTime(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 size_t TextTrackCueList::findInsertionIndex(const TextTrackCue* cueToInsert) con
st | 94 size_t TextTrackCueList::findInsertionIndex(const TextTrackCue* cueToInsert) con
st |
| 95 { | 95 { |
| 96 auto it = std::upper_bound(m_list.begin(), m_list.end(), cueToInsert, cueIsB
efore); | 96 auto it = std::upper_bound(m_list.begin(), m_list.end(), cueToInsert, cueIsB
efore); |
| 97 size_t index = safeCast<size_t>(it - m_list.begin()); | 97 size_t index = safeCast<size_t>(it - m_list.begin()); |
| 98 ASSERT_WITH_SECURITY_IMPLICATION(index <= m_list.size()); | 98 SECURITY_DCHECK(index <= m_list.size()); |
| 99 return index; | 99 return index; |
| 100 } | 100 } |
| 101 | 101 |
| 102 bool TextTrackCueList::remove(TextTrackCue* cue) | 102 bool TextTrackCueList::remove(TextTrackCue* cue) |
| 103 { | 103 { |
| 104 size_t index = m_list.find(cue); | 104 size_t index = m_list.find(cue); |
| 105 if (index == kNotFound) | 105 if (index == kNotFound) |
| 106 return false; | 106 return false; |
| 107 | 107 |
| 108 m_list.remove(index); | 108 m_list.remove(index); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 visitor->trace(m_list); | 149 visitor->trace(m_list); |
| 150 } | 150 } |
| 151 | 151 |
| 152 DEFINE_TRACE_WRAPPERS(TextTrackCueList) | 152 DEFINE_TRACE_WRAPPERS(TextTrackCueList) |
| 153 { | 153 { |
| 154 for (auto cue : m_list) { | 154 for (auto cue : m_list) { |
| 155 visitor->traceWrappers(cue); | 155 visitor->traceWrappers(cue); |
| 156 } | 156 } |
| 157 } | 157 } |
| 158 } // namespace blink | 158 } // namespace blink |
| OLD | NEW |