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

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

Issue 982553002: Paint buffered range closest to the current play position (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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 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);

Powered by Google App Engine
This is Rietveld 408576698