| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2009, 2010 Apple 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 21 matching lines...) Expand all Loading... |
| 32 #include "core/dom/ExceptionCode.h" | 32 #include "core/dom/ExceptionCode.h" |
| 33 #include <math.h> | 33 #include <math.h> |
| 34 | 34 |
| 35 using namespace blink; | 35 using namespace blink; |
| 36 | 36 |
| 37 TimeRanges::TimeRanges(double start, double end) | 37 TimeRanges::TimeRanges(double start, double end) |
| 38 { | 38 { |
| 39 add(start, end); | 39 add(start, end); |
| 40 } | 40 } |
| 41 | 41 |
| 42 PassRefPtrWillBeRawPtr<TimeRanges> TimeRanges::create(const blink::WebTimeRanges
& webRanges) | 42 TimeRanges* TimeRanges::create(const blink::WebTimeRanges& webRanges) |
| 43 { | 43 { |
| 44 RefPtrWillBeRawPtr<TimeRanges> ranges = TimeRanges::create(); | 44 TimeRanges* ranges = TimeRanges::create(); |
| 45 | 45 |
| 46 unsigned size = webRanges.size(); | 46 unsigned size = webRanges.size(); |
| 47 for (unsigned i = 0; i < size; ++i) | 47 for (unsigned i = 0; i < size; ++i) |
| 48 ranges->add(webRanges[i].start, webRanges[i].end); | 48 ranges->add(webRanges[i].start, webRanges[i].end); |
| 49 | 49 |
| 50 return ranges.release(); | 50 return ranges; |
| 51 } | 51 } |
| 52 | 52 |
| 53 PassRefPtrWillBeRawPtr<TimeRanges> TimeRanges::copy() const | 53 TimeRanges* TimeRanges::copy() const |
| 54 { | 54 { |
| 55 RefPtrWillBeRawPtr<TimeRanges> newSession = TimeRanges::create(); | 55 TimeRanges* newSession = TimeRanges::create(); |
| 56 | 56 |
| 57 unsigned size = m_ranges.size(); | 57 unsigned size = m_ranges.size(); |
| 58 for (unsigned i = 0; i < size; i++) | 58 for (unsigned i = 0; i < size; i++) |
| 59 newSession->add(m_ranges[i].m_start, m_ranges[i].m_end); | 59 newSession->add(m_ranges[i].m_start, m_ranges[i].m_end); |
| 60 | 60 |
| 61 return newSession.release(); | 61 return newSession; |
| 62 } | 62 } |
| 63 | 63 |
| 64 void TimeRanges::invert() | 64 void TimeRanges::invert() |
| 65 { | 65 { |
| 66 RefPtrWillBeRawPtr<TimeRanges> inverted = TimeRanges::create(); | 66 TimeRanges* inverted = TimeRanges::create(); |
| 67 double posInf = std::numeric_limits<double>::infinity(); | 67 double posInf = std::numeric_limits<double>::infinity(); |
| 68 double negInf = -std::numeric_limits<double>::infinity(); | 68 double negInf = -std::numeric_limits<double>::infinity(); |
| 69 | 69 |
| 70 if (!m_ranges.size()) { | 70 if (!m_ranges.size()) { |
| 71 inverted->add(negInf, posInf); | 71 inverted->add(negInf, posInf); |
| 72 } else { | 72 } else { |
| 73 double start = m_ranges.first().m_start; | 73 double start = m_ranges.first().m_start; |
| 74 if (start != negInf) | 74 if (start != negInf) |
| 75 inverted->add(negInf, start); | 75 inverted->add(negInf, start); |
| 76 | 76 |
| 77 for (size_t index = 0; index + 1 < m_ranges.size(); ++index) | 77 for (size_t index = 0; index + 1 < m_ranges.size(); ++index) |
| 78 inverted->add(m_ranges[index].m_end, m_ranges[index + 1].m_start); | 78 inverted->add(m_ranges[index].m_end, m_ranges[index + 1].m_start); |
| 79 | 79 |
| 80 double end = m_ranges.last().m_end; | 80 double end = m_ranges.last().m_end; |
| 81 if (end != posInf) | 81 if (end != posInf) |
| 82 inverted->add(end, posInf); | 82 inverted->add(end, posInf); |
| 83 } | 83 } |
| 84 | 84 |
| 85 m_ranges.swap(inverted->m_ranges); | 85 m_ranges.swap(inverted->m_ranges); |
| 86 } | 86 } |
| 87 | 87 |
| 88 void TimeRanges::intersectWith(const TimeRanges* other) | 88 void TimeRanges::intersectWith(const TimeRanges* other) |
| 89 { | 89 { |
| 90 ASSERT(other); | 90 ASSERT(other); |
| 91 | 91 |
| 92 if (other == this) | 92 if (other == this) |
| 93 return; | 93 return; |
| 94 | 94 |
| 95 RefPtrWillBeRawPtr<TimeRanges> invertedOther = other->copy(); | 95 TimeRanges* invertedOther = other->copy(); |
| 96 invertedOther->invert(); | 96 invertedOther->invert(); |
| 97 | 97 |
| 98 invert(); | 98 invert(); |
| 99 unionWith(invertedOther.get()); | 99 unionWith(invertedOther); |
| 100 invert(); | 100 invert(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 void TimeRanges::unionWith(const TimeRanges* other) | 103 void TimeRanges::unionWith(const TimeRanges* other) |
| 104 { | 104 { |
| 105 ASSERT(other); | 105 ASSERT(other); |
| 106 RefPtrWillBeRawPtr<TimeRanges> unioned = copy(); | 106 TimeRanges* unioned = copy(); |
| 107 for (size_t index = 0; index < other->m_ranges.size(); ++index) { | 107 for (size_t index = 0; index < other->m_ranges.size(); ++index) { |
| 108 const Range& range = other->m_ranges[index]; | 108 const Range& range = other->m_ranges[index]; |
| 109 unioned->add(range.m_start, range.m_end); | 109 unioned->add(range.m_start, range.m_end); |
| 110 } | 110 } |
| 111 | 111 |
| 112 m_ranges.swap(unioned->m_ranges); | 112 m_ranges.swap(unioned->m_ranges); |
| 113 } | 113 } |
| 114 | 114 |
| 115 double TimeRanges::start(unsigned index, ExceptionState& exceptionState) const | 115 double TimeRanges::start(unsigned index, ExceptionState& exceptionState) const |
| 116 { | 116 { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 203 } |
| 204 | 204 |
| 205 if (delta < bestDelta || (delta == bestDelta | 205 if (delta < bestDelta || (delta == bestDelta |
| 206 && std::abs(currentPlaybackPosition - match) < std::abs(currentPlayb
ackPosition - bestMatch))) { | 206 && std::abs(currentPlaybackPosition - match) < std::abs(currentPlayb
ackPosition - bestMatch))) { |
| 207 bestDelta = delta; | 207 bestDelta = delta; |
| 208 bestMatch = match; | 208 bestMatch = match; |
| 209 } | 209 } |
| 210 } | 210 } |
| 211 return bestMatch; | 211 return bestMatch; |
| 212 } | 212 } |
| OLD | NEW |