Index: Source/core/html/TimeRanges.cpp |
diff --git a/Source/core/html/TimeRanges.cpp b/Source/core/html/TimeRanges.cpp |
index b41ff687be6ef94a79097aae11817ebe34a2e9c4..23d8cb1d533fa4a13046bf38c0950af82959a50b 100644 |
--- a/Source/core/html/TimeRanges.cpp |
+++ b/Source/core/html/TimeRanges.cpp |
@@ -211,6 +211,35 @@ double TimeRanges::nearest(double newPlaybackPosition, double currentPlaybackPos |
return bestMatch; |
} |
+unsigned TimeRanges::nearestRange(double position) const |
+{ |
+ unsigned count = length(); |
+ unsigned bestMatch = 0; |
+ double bestDelta = std::numeric_limits<double>::infinity(); |
+ for (unsigned ndx = 0; ndx < count; ++ndx) { |
+ double startTime = start(ndx, IGNORE_EXCEPTION); |
+ double endTime = end(ndx, IGNORE_EXCEPTION); |
+ if (position >= startTime && position <= endTime) { |
+ return ndx; |
+ } |
+ |
+ double delta; |
+ if (position < startTime) { |
+ delta = startTime - position; |
+ } else { |
+ delta = position - endTime; |
+ } |
+ |
+ // Prioritize later ranges |
+ if (delta <= bestDelta) { |
+ bestDelta = delta; |
+ bestMatch = ndx; |
+ } |
+ } |
+ |
+ return bestMatch; |
+} |
+ |
DEFINE_TRACE(TimeRanges) |
{ |
visitor->trace(m_ranges); |