diff options
author | Allan Sandfeld Jensen <allan.jensen@digia.com> | 2013-09-13 12:51:20 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 20:50:05 +0200 |
commit | d441d6f39bb846989d95bcf5caf387b42414718d (patch) | |
tree | e367e64a75991c554930278175d403c072de6bb8 /Source/WebCore/html/TimeRanges.cpp | |
parent | 0060b2994c07842f4c59de64b5e3e430525c4b90 (diff) | |
download | qtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz |
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit.
Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/WebCore/html/TimeRanges.cpp')
-rw-r--r-- | Source/WebCore/html/TimeRanges.cpp | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/Source/WebCore/html/TimeRanges.cpp b/Source/WebCore/html/TimeRanges.cpp index d68ea0371..cf8e20fc2 100644 --- a/Source/WebCore/html/TimeRanges.cpp +++ b/Source/WebCore/html/TimeRanges.cpp @@ -28,12 +28,13 @@ #include "TimeRanges.h" #include "ExceptionCode.h" +#include "ExceptionCodePlaceholder.h" #include <math.h> using namespace WebCore; using namespace std; -TimeRanges::TimeRanges(float start, float end) +TimeRanges::TimeRanges(double start, double end) { add(start, end); } @@ -52,19 +53,19 @@ PassRefPtr<TimeRanges> TimeRanges::copy() const void TimeRanges::invert() { RefPtr<TimeRanges> inverted = TimeRanges::create(); - float posInf = std::numeric_limits<float>::infinity(); - float negInf = -std::numeric_limits<float>::infinity(); + double posInf = std::numeric_limits<double>::infinity(); + double negInf = -std::numeric_limits<double>::infinity(); if (!m_ranges.size()) inverted->add(negInf, posInf); else { - if (float start = m_ranges.first().m_start != negInf) + if (double start = m_ranges.first().m_start != negInf) inverted->add(negInf, start); for (size_t index = 0; index + 1 < m_ranges.size(); ++index) inverted->add(m_ranges[index].m_end, m_ranges[index + 1].m_start); - if (float end = m_ranges.last().m_end != posInf) + if (double end = m_ranges.last().m_end != posInf) inverted->add(end, posInf); } @@ -94,7 +95,7 @@ void TimeRanges::unionWith(const TimeRanges* other) m_ranges.swap(unioned->m_ranges); } -float TimeRanges::start(unsigned index, ExceptionCode& ec) const +double TimeRanges::start(unsigned index, ExceptionCode& ec) const { if (index >= length()) { ec = INDEX_SIZE_ERR; @@ -103,7 +104,7 @@ float TimeRanges::start(unsigned index, ExceptionCode& ec) const return m_ranges[index].m_start; } -float TimeRanges::end(unsigned index, ExceptionCode& ec) const +double TimeRanges::end(unsigned index, ExceptionCode& ec) const { if (index >= length()) { ec = INDEX_SIZE_ERR; @@ -112,7 +113,7 @@ float TimeRanges::end(unsigned index, ExceptionCode& ec) const return m_ranges[index].m_end; } -void TimeRanges::add(float start, float end) +void TimeRanges::add(double start, double end) { ASSERT(start <= end); unsigned int overlappingArcIndex; @@ -155,30 +156,41 @@ void TimeRanges::add(float start, float end) m_ranges.insert(overlappingArcIndex, addedRange); } -bool TimeRanges::contain(float time) const -{ - ExceptionCode unused; +bool TimeRanges::contain(double time) const +{ for (unsigned n = 0; n < length(); n++) { - if (time >= start(n, unused) && time <= end(n, unused)) + if (time >= start(n, IGNORE_EXCEPTION) && time <= end(n, IGNORE_EXCEPTION)) return true; } return false; } -float TimeRanges::nearest(float time) const -{ - ExceptionCode unused; - float closest = 0; +double TimeRanges::nearest(double time) const +{ + double closestDelta = std::numeric_limits<double>::infinity(); + double closestTime = 0; unsigned count = length(); for (unsigned ndx = 0; ndx < count; ndx++) { - float startTime = start(ndx, unused); - float endTime = end(ndx, unused); + double startTime = start(ndx, IGNORE_EXCEPTION); + double endTime = end(ndx, IGNORE_EXCEPTION); if (time >= startTime && time <= endTime) return time; - if (fabs(startTime - time) < closest) - closest = fabsf(startTime - time); - else if (fabs(endTime - time) < closest) - closest = fabsf(endTime - time); + if (fabs(startTime - time) < closestDelta) { + closestTime = startTime; + closestDelta = fabsf(startTime - time); + } + if (fabs(endTime - time) < closestDelta) { + closestTime = endTime; + closestDelta = fabsf(endTime - time); + } } - return closest; + return closestTime; +} + +double TimeRanges::totalDuration() const +{ + double total = 0; + for (unsigned n = 0; n < length(); n++) + total += fabs(end(n, IGNORE_EXCEPTION) - start(n, IGNORE_EXCEPTION)); + return total; } |