Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(616)

Unified Diff: Source/core/html/TimeRanges.cpp

Issue 562493003: Allow seeks to zero on streaming sources. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/html/TimeRanges.cpp
diff --git a/Source/core/html/TimeRanges.cpp b/Source/core/html/TimeRanges.cpp
index 943eb93468f6899f8510f24fee18dce0a1abbc79..9c6456794a74e4559cb6126af4c4de43ac8174d4 100644
--- a/Source/core/html/TimeRanges.cpp
+++ b/Source/core/html/TimeRanges.cpp
@@ -184,19 +184,29 @@ bool TimeRanges::contain(double time) const
double TimeRanges::nearest(double time) const
{
- double closest = 0;
unsigned count = length();
+ double 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 (time >= startTime && time <= endTime)
return time;
- if (fabs(startTime - time) < closest)
- closest = fabs(startTime - time);
- else if (fabs(endTime - time) < closest)
- closest = fabs(endTime - time);
+ if (time < startTime) {
+ double delta = startTime - time;
+ if (delta < bestDelta) {
+ bestMatch = startTime;
+ bestDelta = delta;
+ }
+ } else if (time > endTime) {
+ double delta = time - endTime;
+ if (delta < bestDelta) {
+ bestMatch = endTime;
+ bestDelta = delta;
+ }
+ }
}
- return closest;
+ return bestMatch;
}
void TimeRanges::trace(Visitor* visitor)

Powered by Google App Engine
This is Rietveld 408576698