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

Side by Side Diff: third_party/WebKit/Source/core/html/shadow/MediaControls.cpp

Issue 2280123002: Fix under-invalidation of media buffered ranges (Closed)
Patch Set: Conditionally invalidate Created 4 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 unified diff | Download patch
« no previous file with comments | « third_party/WebKit/Source/core/html/shadow/MediaControls.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2011, 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2011, 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "core/html/shadow/MediaControls.h" 27 #include "core/html/shadow/MediaControls.h"
28 28
29 #include "bindings/core/v8/ExceptionStatePlaceholder.h" 29 #include "bindings/core/v8/ExceptionStatePlaceholder.h"
30 #include "core/dom/ClientRect.h" 30 #include "core/dom/ClientRect.h"
31 #include "core/dom/Fullscreen.h" 31 #include "core/dom/Fullscreen.h"
32 #include "core/events/MouseEvent.h" 32 #include "core/events/MouseEvent.h"
33 #include "core/frame/Settings.h" 33 #include "core/frame/Settings.h"
34 #include "core/html/HTMLMediaElement.h" 34 #include "core/html/HTMLMediaElement.h"
35 #include "core/html/TimeRanges.h"
35 #include "core/html/track/TextTrackContainer.h" 36 #include "core/html/track/TextTrackContainer.h"
36 #include "core/layout/LayoutTheme.h" 37 #include "core/layout/LayoutTheme.h"
37 #include "platform/EventDispatchForbiddenScope.h" 38 #include "platform/EventDispatchForbiddenScope.h"
38 39
39 namespace blink { 40 namespace blink {
40 41
41 // If you change this value, then also update the corresponding value in 42 // If you change this value, then also update the corresponding value in
42 // LayoutTests/media/media-controls.js. 43 // LayoutTests/media/media-controls.js.
43 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; 44 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3;
44 45
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 , m_textTrackList(nullptr) 120 , m_textTrackList(nullptr)
120 , m_castButton(nullptr) 121 , m_castButton(nullptr)
121 , m_fullScreenButton(nullptr) 122 , m_fullScreenButton(nullptr)
122 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) 123 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired )
123 , m_hideTimerBehaviorFlags(IgnoreNone) 124 , m_hideTimerBehaviorFlags(IgnoreNone)
124 , m_isMouseOverControls(false) 125 , m_isMouseOverControls(false)
125 , m_isPausedForScrubbing(false) 126 , m_isPausedForScrubbing(false)
126 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired ) 127 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired )
127 , m_panelWidth(0) 128 , m_panelWidth(0)
128 , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnab led()) 129 , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnab led())
130 , m_bufferedRangesPaintInvalidationTimer(this, &MediaControls::bufferedRange sPaintInvalidationTimerFired)
129 { 131 {
130 } 132 }
131 133
132 MediaControls* MediaControls::create(HTMLMediaElement& mediaElement) 134 MediaControls* MediaControls::create(HTMLMediaElement& mediaElement)
133 { 135 {
134 MediaControls* controls = new MediaControls(mediaElement); 136 MediaControls* controls = new MediaControls(mediaElement);
135 controls->setShadowPseudoId(AtomicString("-webkit-media-controls")); 137 controls->setShadowPseudoId(AtomicString("-webkit-media-controls"));
136 controls->initializeControls(); 138 controls->initializeControls();
137 return controls; 139 return controls;
138 } 140 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 270
269 // If the player has entered an error state, force it into the paused state. 271 // If the player has entered an error state, force it into the paused state.
270 if (mediaElement().error()) 272 if (mediaElement().error())
271 mediaElement().pause(); 273 mediaElement().pause();
272 274
273 updatePlayState(); 275 updatePlayState();
274 276
275 updateCurrentTimeDisplay(); 277 updateCurrentTimeDisplay();
276 278
277 m_timeline->setDuration(duration); 279 m_timeline->setDuration(duration);
278 m_timeline->setPosition(mediaElement().currentTime()); 280 updateTimelinePosition();
279 281
280 updateVolume(); 282 updateVolume();
281 283
282 refreshClosedCaptionsButtonVisibility(); 284 refreshClosedCaptionsButtonVisibility();
283 285
284 m_fullScreenButton->setIsWanted(shouldShowFullscreenButton(mediaElement())); 286 m_fullScreenButton->setIsWanted(shouldShowFullscreenButton(mediaElement()));
285 287
286 refreshCastButtonVisibilityWithoutUpdate(); 288 refreshCastButtonVisibilityWithoutUpdate();
287 } 289 }
288 290
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 void MediaControls::playbackStarted() 356 void MediaControls::playbackStarted()
355 { 357 {
356 BatchedControlUpdate batch(this); 358 BatchedControlUpdate batch(this);
357 359
358 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) { 360 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) {
359 m_currentTimeDisplay->setIsWanted(true); 361 m_currentTimeDisplay->setIsWanted(true);
360 m_durationDisplay->setIsWanted(false); 362 m_durationDisplay->setIsWanted(false);
361 } 363 }
362 364
363 updatePlayState(); 365 updatePlayState();
364 m_timeline->setPosition(mediaElement().currentTime()); 366 updateTimelinePosition();
365 updateCurrentTimeDisplay(); 367 updateCurrentTimeDisplay();
366 368
367 startHideMediaControlsTimer(); 369 startHideMediaControlsTimer();
368 } 370 }
369 371
370 void MediaControls::playbackProgressed() 372 void MediaControls::playbackProgressed()
371 { 373 {
372 m_timeline->setPosition(mediaElement().currentTime()); 374 updateTimelinePosition();
373 updateCurrentTimeDisplay(); 375 updateCurrentTimeDisplay();
374 376
375 if (shouldHideMediaControls()) 377 if (shouldHideMediaControls())
376 makeTransparent(); 378 makeTransparent();
377 } 379 }
378 380
379 void MediaControls::playbackStopped() 381 void MediaControls::playbackStopped()
380 { 382 {
381 updatePlayState(); 383 updatePlayState();
382 m_timeline->setPosition(mediaElement().currentTime()); 384 updateTimelinePosition();
383 updateCurrentTimeDisplay(); 385 updateCurrentTimeDisplay();
384 makeOpaque(); 386 makeOpaque();
385 387
386 stopHideMediaControlsTimer(); 388 stopHideMediaControlsTimer();
387 } 389 }
388 390
389 void MediaControls::updatePlayState() 391 void MediaControls::updatePlayState()
390 { 392 {
391 if (m_isPausedForScrubbing) 393 if (m_isPausedForScrubbing)
392 return; 394 return;
393 395
394 if (m_overlayPlayButton) 396 if (m_overlayPlayButton)
395 m_overlayPlayButton->updateDisplayType(); 397 m_overlayPlayButton->updateDisplayType();
396 m_playButton->updateDisplayType(); 398 m_playButton->updateDisplayType();
399
400 startOrStopBufferedRangesPaintInvalidationTimer();
397 } 401 }
398 402
399 void MediaControls::beginScrubbing() 403 void MediaControls::beginScrubbing()
400 { 404 {
401 if (!mediaElement().paused()) { 405 if (!mediaElement().paused()) {
402 m_isPausedForScrubbing = true; 406 m_isPausedForScrubbing = true;
403 mediaElement().pause(); 407 mediaElement().pause();
404 } 408 }
405 } 409 }
406 410
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 } 779 }
776 780
777 void MediaControls::networkStateChanged() 781 void MediaControls::networkStateChanged()
778 { 782 {
779 invalidate(m_playButton); 783 invalidate(m_playButton);
780 invalidate(m_overlayPlayButton); 784 invalidate(m_overlayPlayButton);
781 invalidate(m_muteButton); 785 invalidate(m_muteButton);
782 invalidate(m_fullScreenButton); 786 invalidate(m_fullScreenButton);
783 invalidate(m_timeline); 787 invalidate(m_timeline);
784 invalidate(m_volumeSlider); 788 invalidate(m_volumeSlider);
789
790 startOrStopBufferedRangesPaintInvalidationTimer();
791 }
792
793 void MediaControls::startOrStopBufferedRangesPaintInvalidationTimer()
794 {
795 if (m_mediaElement->getNetworkState() == HTMLMediaElement::kNetworkLoading & & m_mediaElement->paused()) {
796 updateBufferedRanges();
797 // Start timer to invalidate m_timeline to repaint the buffered ranges w hen the media is
798 // loading in paused state. In play state, m_timeline will be invalidate d on play progresses.
799 if (!m_bufferedRangesPaintInvalidationTimer.isActive())
800 m_bufferedRangesPaintInvalidationTimer.startRepeating(0.5, BLINK_FRO M_HERE);
801 } else {
802 m_bufferedRangesPaintInvalidationTimer.stop();
803 }
804 }
805
806 void MediaControls::updateTimelinePosition()
807 {
808 m_timeline->setPosition(mediaElement().currentTime());
809 // Synchronize buffered ranges when the current time changes.
810 updateBufferedRanges();
811 };
812
813 void MediaControls::updateBufferedRanges()
814 {
815 TimeRanges* newBufferedRanges = m_mediaElement->buffered();
816 if (!m_lastBufferedRanges) {
817 if (!newBufferedRanges->length())
818 return;
819 } else if (*m_lastBufferedRanges != *newBufferedRanges) {
820 return;
821 }
822
823 // Invalidate the timeline to repaint the buffered ranges.
824 invalidate(m_timeline);
825 m_lastBufferedRanges = newBufferedRanges->copy();
826 }
827
828 void MediaControls::bufferedRangesPaintInvalidationTimerFired(TimerBase*)
829 {
830 updateBufferedRanges();
785 } 831 }
786 832
787 DEFINE_TRACE(MediaControls) 833 DEFINE_TRACE(MediaControls)
788 { 834 {
789 visitor->trace(m_mediaElement); 835 visitor->trace(m_mediaElement);
790 visitor->trace(m_panel); 836 visitor->trace(m_panel);
791 visitor->trace(m_overlayPlayButton); 837 visitor->trace(m_overlayPlayButton);
792 visitor->trace(m_overlayEnclosure); 838 visitor->trace(m_overlayEnclosure);
793 visitor->trace(m_playButton); 839 visitor->trace(m_playButton);
794 visitor->trace(m_currentTimeDisplay); 840 visitor->trace(m_currentTimeDisplay);
795 visitor->trace(m_timeline); 841 visitor->trace(m_timeline);
796 visitor->trace(m_muteButton); 842 visitor->trace(m_muteButton);
797 visitor->trace(m_volumeSlider); 843 visitor->trace(m_volumeSlider);
798 visitor->trace(m_toggleClosedCaptionsButton); 844 visitor->trace(m_toggleClosedCaptionsButton);
799 visitor->trace(m_fullScreenButton); 845 visitor->trace(m_fullScreenButton);
800 visitor->trace(m_durationDisplay); 846 visitor->trace(m_durationDisplay);
801 visitor->trace(m_enclosure); 847 visitor->trace(m_enclosure);
802 visitor->trace(m_textTrackList); 848 visitor->trace(m_textTrackList);
803 visitor->trace(m_castButton); 849 visitor->trace(m_castButton);
804 visitor->trace(m_overlayCastButton); 850 visitor->trace(m_overlayCastButton);
851 visitor->trace(m_lastBufferedRanges);
805 HTMLDivElement::trace(visitor); 852 HTMLDivElement::trace(visitor);
806 } 853 }
807 854
808 } // namespace blink 855 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/html/shadow/MediaControls.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698