Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
| diff --git a/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp b/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
| index 8c0f1083541509794c61c292e4bc9b1401602d05..0309e76b2985a0415a3fe7fb52b6aa8bc7aad9fd 100644 |
| --- a/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
| +++ b/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
| @@ -32,6 +32,7 @@ |
| #include "core/events/MouseEvent.h" |
| #include "core/frame/Settings.h" |
| #include "core/html/HTMLMediaElement.h" |
| +#include "core/html/TimeRanges.h" |
| #include "core/html/track/TextTrackContainer.h" |
| #include "core/layout/LayoutTheme.h" |
| #include "platform/EventDispatchForbiddenScope.h" |
| @@ -126,6 +127,7 @@ MediaControls::MediaControls(HTMLMediaElement& mediaElement) |
| , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired) |
| , m_panelWidth(0) |
| , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) |
| + , m_bufferedRangesPaintInvalidationTimer(this, &MediaControls::bufferedRangesPaintInvalidationTimerFired) |
| { |
| } |
| @@ -275,7 +277,7 @@ void MediaControls::reset() |
| updateCurrentTimeDisplay(); |
| m_timeline->setDuration(duration); |
| - m_timeline->setPosition(mediaElement().currentTime()); |
| + updateTimelinePosition(); |
| updateVolume(); |
| @@ -361,7 +363,7 @@ void MediaControls::playbackStarted() |
| } |
| updatePlayState(); |
| - m_timeline->setPosition(mediaElement().currentTime()); |
| + updateTimelinePosition(); |
| updateCurrentTimeDisplay(); |
| startHideMediaControlsTimer(); |
| @@ -369,7 +371,7 @@ void MediaControls::playbackStarted() |
| void MediaControls::playbackProgressed() |
| { |
| - m_timeline->setPosition(mediaElement().currentTime()); |
| + updateTimelinePosition(); |
| updateCurrentTimeDisplay(); |
| if (shouldHideMediaControls()) |
| @@ -379,7 +381,7 @@ void MediaControls::playbackProgressed() |
| void MediaControls::playbackStopped() |
| { |
| updatePlayState(); |
| - m_timeline->setPosition(mediaElement().currentTime()); |
| + updateTimelinePosition(); |
| updateCurrentTimeDisplay(); |
| makeOpaque(); |
| @@ -774,6 +776,8 @@ void MediaControls::invalidate(Element* element) |
| layoutObject->setShouldDoFullPaintInvalidation(); |
| } |
| +static const double kBufferedRangesPaintInvalidationInterval = 0.5; |
| + |
| void MediaControls::networkStateChanged() |
| { |
| invalidate(m_playButton); |
| @@ -782,6 +786,40 @@ void MediaControls::networkStateChanged() |
| invalidate(m_fullScreenButton); |
| invalidate(m_timeline); |
| invalidate(m_volumeSlider); |
| + |
| + updateBufferedRanges(); |
| + if (m_mediaElement->getNetworkState() == HTMLMediaElement::kNetworkLoading) { |
| + if (!m_bufferedRangesPaintInvalidationTimer.isActive()) |
| + m_bufferedRangesPaintInvalidationTimer.startRepeating(kBufferedRangesPaintInvalidationInterval, BLINK_FROM_HERE); |
| + } else { |
| + m_bufferedRangesPaintInvalidationTimer.stop(); |
| + } |
| +} |
| + |
| +void MediaControls::updateTimelinePosition() |
| +{ |
| + m_timeline->setPosition(mediaElement().currentTime()); |
| + // Synchronize buffered ranges when the current time change. |
| + updateBufferedRanges(); |
| +} |
| + |
| +void MediaControls::updateBufferedRanges() |
| +{ |
| + TimeRanges* newBuffered = m_mediaElement->buffered(); |
| + if (!m_bufferedRangesForPainting) { |
| + if (!newBuffered->length()) |
| + return; |
| + } else if (*m_bufferedRangesForPainting == *newBuffered) { |
|
liberato (no reviews please)
2016/08/29 15:25:34
might one just unconditionally invalidate the time
Xianzhu
2016/08/29 18:04:14
Good question. It's unlikely to save invalidations
|
| + return; |
| + } |
| + |
| + m_bufferedRangesForPainting = newBuffered; |
| + invalidate(m_timeline); |
| +} |
| + |
| +void MediaControls::bufferedRangesPaintInvalidationTimerFired(TimerBase*) |
| +{ |
| + updateBufferedRanges(); |
| } |
| DEFINE_TRACE(MediaControls) |
| @@ -802,6 +840,7 @@ DEFINE_TRACE(MediaControls) |
| visitor->trace(m_textTrackList); |
| visitor->trace(m_castButton); |
| visitor->trace(m_overlayCastButton); |
| + visitor->trace(m_bufferedRangesForPainting); |
| HTMLDivElement::trace(visitor); |
| } |