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

Unified Diff: Source/core/layout/LayoutMediaControls.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
« no previous file with comments | « Source/core/html/TimeRangesTest.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/layout/LayoutMediaControls.cpp
diff --git a/Source/core/layout/LayoutMediaControls.cpp b/Source/core/layout/LayoutMediaControls.cpp
index 4c1a2c4faa321772a3456c4801fb9f5e4ec918e5..f3c51a6c9502044bc9060ba05048fd4618bae1ce 100644
--- a/Source/core/layout/LayoutMediaControls.cpp
+++ b/Source/core/layout/LayoutMediaControls.cpp
@@ -207,24 +207,31 @@ static bool paintMediaSlider(LayoutObject* object, const PaintInfo& paintInfo, c
// Draw the buffered range. Since the element may have multiple buffered ranges and it'd be
// distracting/'busy' to show all of them, show only the buffered range containing the current play head.
RefPtrWillBeRawPtr<TimeRanges> bufferedTimeRanges = mediaElement->buffered();
- float duration = mediaElement->duration();
- float currentTime = mediaElement->currentTime();
- if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan(currentTime))
+ double duration = mediaElement->duration();
+ double currentTime = mediaElement->currentTime();
+ if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan(currentTime)
+ || bufferedTimeRanges->length() == 0)
return true;
- for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) {
- float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION);
- float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION);
- if (std::isnan(start) || std::isnan(end) || start > currentTime || end < currentTime)
philipj_slow 2015/03/06 03:16:17 Could we fix the whole problem by tweaking this to
landell 2015/03/06 13:49:06 I can look at such a solution. Don't know if the s
- continue;
- int startPosition = int(start * rect.width() / duration);
- int currentPosition = int(currentTime * rect.width() / duration);
- int endPosition = int(end * rect.width() / duration);
+ unsigned nearestIdx = bufferedTimeRanges->nearestRange(currentTime);
philipj_slow 2015/03/06 03:16:17 So I was thinking that we could have a getter for
landell 2015/03/06 13:49:06 I agree. To me the problem is that the TimeRanges
+ double start = bufferedTimeRanges->start(nearestIdx, ASSERT_NO_EXCEPTION);
+ double end = bufferedTimeRanges->end(nearestIdx, ASSERT_NO_EXCEPTION);
+ if (std::isnan(start) || std::isnan(end)) {
+ return true;
+ }
+
+ int startPosition = int(start * rect.width() / duration);
+ int currentPosition = int(currentTime * rect.width() / duration);
+ int endPosition = int(end * rect.width() / duration);
- // Add half the thumb width proportionally adjusted to the current painting position.
- int thumbCenter = mediaSliderThumbWidth / 2;
- int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width());
- currentPosition += addWidth;
+ // Add half the thumb width proportionally adjusted to the current painting position.
+ int thumbCenter = mediaSliderThumbWidth / 2;
+ int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width());
+ currentPosition += addWidth;
+
+ // Only paint ranges that will intersect with the slider thumb
philipj_slow 2015/03/06 03:16:17 I see no explicit delta, so I guess the resolution
landell 2015/03/06 13:49:06 My thinking was that it made sense to make the del
+ if (currentPosition <= endPosition + thumbCenter
+ || currentPosition >= startPosition - thumbCenter) {
// Draw white-ish highlight before current time.
Color startColor = Color(195, 195, 195);
@@ -238,8 +245,6 @@ static bool paintMediaSlider(LayoutObject* object, const PaintInfo& paintInfo, c
if (endPosition > currentPosition)
paintSliderRangeHighlight(rect, style, context, currentPosition, endPosition, startColor, endColor);
-
- return true;
}
return true;
« no previous file with comments | « Source/core/html/TimeRangesTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698