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

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

Issue 2477203002: Media Controls: delegate 'volumechange' and 'focusin' handling to an EventListener. (Closed)
Patch Set: Created 4 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights 2 * Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights
3 * reserved. 3 * 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 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 startProgressEventTimer(); 1083 startProgressEventTimer();
1084 1084
1085 // Reset display mode to force a recalculation of what to show because we are 1085 // Reset display mode to force a recalculation of what to show because we are
1086 // resetting the player. 1086 // resetting the player.
1087 setDisplayMode(Unknown); 1087 setDisplayMode(Unknown);
1088 1088
1089 setPlayerPreload(); 1089 setPlayerPreload();
1090 1090
1091 if (fastHasAttribute(mutedAttr)) 1091 if (fastHasAttribute(mutedAttr))
1092 m_muted = true; 1092 m_muted = true;
1093 updateVolume();
mlamouri (slow - plz ping) 2016/11/07 00:26:05 FYI, I couldn't find what that was for. I did some
foolip 2016/11/08 10:28:29 https://chromium.googlesource.com/chromium/src/+/1
mlamouri (slow - plz ping) 2016/11/11 05:29:17 I've added a test for this. It sounds fine. Let me
foolip 2016/11/11 09:50:20 Do you know why it works? It could be kind of acci
mlamouri (slow - plz ping) 2016/11/13 06:15:11 That's because when readyState is changed, HTMLMed
foolip 2016/11/14 16:07:37 OK, since there's no volumechange event for this I
1094 1093
1095 DCHECK(!m_mediaSource); 1094 DCHECK(!m_mediaSource);
1096 1095
1097 bool attemptLoad = true; 1096 bool attemptLoad = true;
1098 1097
1099 m_mediaSource = HTMLMediaSource::lookup(url.getString()); 1098 m_mediaSource = HTMLMediaSource::lookup(url.getString());
1100 if (m_mediaSource && !m_mediaSource->attachToElement(this)) { 1099 if (m_mediaSource && !m_mediaSource->attachToElement(this)) {
1101 // Forget our reference to the MediaSource, so we leave it alone 1100 // Forget our reference to the MediaSource, so we leave it alone
1102 // while processing remainder of load failure. 1101 // while processing remainder of load failure.
1103 m_mediaSource = nullptr; 1102 m_mediaSource = nullptr;
(...skipping 1308 matching lines...) Expand 10 before | Expand all | Expand 10 after
2412 if (vol < 0.0f || vol > 1.0f) { 2411 if (vol < 0.0f || vol > 1.0f) {
2413 exceptionState.throwDOMException( 2412 exceptionState.throwDOMException(
2414 IndexSizeError, 2413 IndexSizeError,
2415 ExceptionMessages::indexOutsideRange( 2414 ExceptionMessages::indexOutsideRange(
2416 "volume", vol, 0.0, ExceptionMessages::InclusiveBound, 1.0, 2415 "volume", vol, 0.0, ExceptionMessages::InclusiveBound, 1.0,
2417 ExceptionMessages::InclusiveBound)); 2416 ExceptionMessages::InclusiveBound));
2418 return; 2417 return;
2419 } 2418 }
2420 2419
2421 m_volume = vol; 2420 m_volume = vol;
2422 updateVolume(); 2421
2422 if (webMediaPlayer())
2423 webMediaPlayer()->setVolume(effectiveMediaVolume());
2423 scheduleEvent(EventTypeNames::volumechange); 2424 scheduleEvent(EventTypeNames::volumechange);
2424 } 2425 }
2425 2426
2426 bool HTMLMediaElement::muted() const { 2427 bool HTMLMediaElement::muted() const {
2427 return m_muted; 2428 return m_muted;
2428 } 2429 }
2429 2430
2430 void HTMLMediaElement::setMuted(bool muted) { 2431 void HTMLMediaElement::setMuted(bool muted) {
2431 BLINK_MEDIA_LOG << "setMuted(" << (void*)this << ", " << boolString(muted) 2432 BLINK_MEDIA_LOG << "setMuted(" << (void*)this << ", " << boolString(muted)
2432 << ")"; 2433 << ")";
(...skipping 21 matching lines...) Expand all
2454 m_autoplayUmaHelper->recordAutoplayUnmuteStatus( 2455 m_autoplayUmaHelper->recordAutoplayUnmuteStatus(
2455 AutoplayUnmuteActionStatus::Failure); 2456 AutoplayUnmuteActionStatus::Failure);
2456 } else { 2457 } else {
2457 m_autoplayUmaHelper->recordAutoplayUnmuteStatus( 2458 m_autoplayUmaHelper->recordAutoplayUnmuteStatus(
2458 AutoplayUnmuteActionStatus::Success); 2459 AutoplayUnmuteActionStatus::Success);
2459 } 2460 }
2460 } 2461 }
2461 2462
2462 // This is called after the volumechange event to make sure isAutoplayingMuted 2463 // This is called after the volumechange event to make sure isAutoplayingMuted
2463 // returns the right value when webMediaPlayer receives the volume update. 2464 // returns the right value when webMediaPlayer receives the volume update.
2464 updateVolume(); 2465 if (webMediaPlayer())
2466 webMediaPlayer()->setVolume(effectiveMediaVolume());
2465 2467
2466 // If an element was a candidate for autoplay muted but not visible, it will 2468 // If an element was a candidate for autoplay muted but not visible, it will
2467 // have a visibility observer ready to start its playback. 2469 // have a visibility observer ready to start its playback.
2468 if (wasPendingAutoplayMuted) { 2470 if (wasPendingAutoplayMuted) {
2469 m_autoplayVisibilityObserver->stop(); 2471 m_autoplayVisibilityObserver->stop();
2470 m_autoplayVisibilityObserver = nullptr; 2472 m_autoplayVisibilityObserver = nullptr;
2471 } 2473 }
2472 } 2474 }
2473 2475
2474 void HTMLMediaElement::updateVolume() {
2475 if (webMediaPlayer())
2476 webMediaPlayer()->setVolume(effectiveMediaVolume());
2477
2478 if (mediaControls())
2479 mediaControls()->updateVolume();
2480 }
2481
2482 double HTMLMediaElement::effectiveMediaVolume() const { 2476 double HTMLMediaElement::effectiveMediaVolume() const {
2483 if (m_muted) 2477 if (m_muted)
2484 return 0; 2478 return 0;
2485 2479
2486 return m_volume; 2480 return m_volume;
2487 } 2481 }
2488 2482
2489 // The spec says to fire periodic timeupdate events (those sent while playing) 2483 // The spec says to fire periodic timeupdate events (those sent while playing)
2490 // every "15 to 250ms", we choose the slowest frequency 2484 // every "15 to 250ms", we choose the slowest frequency
2491 static const double maxTimeupdateEventFrequency = 0.25; 2485 static const double maxTimeupdateEventFrequency = 0.25;
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
3320 << ", isPlaying = " << boolString(isPlaying); 3314 << ", isPlaying = " << boolString(isPlaying);
3321 3315
3322 if (shouldBePlaying) { 3316 if (shouldBePlaying) {
3323 setDisplayMode(Video); 3317 setDisplayMode(Video);
3324 3318
3325 if (!isPlaying) { 3319 if (!isPlaying) {
3326 // Set rate, muted before calling play in case they were set before the 3320 // Set rate, muted before calling play in case they were set before the
3327 // media engine was setup. The media engine should just stash the rate 3321 // media engine was setup. The media engine should just stash the rate
3328 // and muted values since it isn't already playing. 3322 // and muted values since it isn't already playing.
3329 webMediaPlayer()->setRate(playbackRate()); 3323 webMediaPlayer()->setRate(playbackRate());
3330 updateVolume(); 3324 webMediaPlayer()->setVolume(effectiveMediaVolume());
3331 webMediaPlayer()->play(); 3325 webMediaPlayer()->play();
3332 m_autoplayHelper->playbackStarted(); 3326 m_autoplayHelper->playbackStarted();
3333 } 3327 }
3334 3328
3335 if (mediaControls()) 3329 if (mediaControls())
3336 mediaControls()->playbackStarted(); 3330 mediaControls()->playbackStarted();
3337 startPlaybackProgressTimer(); 3331 startPlaybackProgressTimer();
3338 m_playing = true; 3332 m_playing = true;
3339 3333
3340 } else { // Should not be playing right now 3334 } else { // Should not be playing right now
(...skipping 453 matching lines...) Expand 10 before | Expand all | Expand 10 after
3794 3788
3795 void HTMLMediaElement::mediaSourceOpened(WebMediaSource* webMediaSource) { 3789 void HTMLMediaElement::mediaSourceOpened(WebMediaSource* webMediaSource) {
3796 setShouldDelayLoadEvent(false); 3790 setShouldDelayLoadEvent(false);
3797 m_mediaSource->setWebMediaSourceAndOpen(wrapUnique(webMediaSource)); 3791 m_mediaSource->setWebMediaSourceAndOpen(wrapUnique(webMediaSource));
3798 } 3792 }
3799 3793
3800 bool HTMLMediaElement::isInteractiveContent() const { 3794 bool HTMLMediaElement::isInteractiveContent() const {
3801 return fastHasAttribute(controlsAttr); 3795 return fastHasAttribute(controlsAttr);
3802 } 3796 }
3803 3797
3804 void HTMLMediaElement::defaultEventHandler(Event* event) {
3805 if (event->type() == EventTypeNames::focusin) {
3806 if (mediaControls())
3807 mediaControls()->mediaElementFocused();
3808 }
3809 HTMLElement::defaultEventHandler(event);
3810 }
3811
3812 DEFINE_TRACE(HTMLMediaElement) { 3798 DEFINE_TRACE(HTMLMediaElement) {
3813 visitor->trace(m_playedTimeRanges); 3799 visitor->trace(m_playedTimeRanges);
3814 visitor->trace(m_asyncEventQueue); 3800 visitor->trace(m_asyncEventQueue);
3815 visitor->trace(m_error); 3801 visitor->trace(m_error);
3816 visitor->trace(m_currentSourceNode); 3802 visitor->trace(m_currentSourceNode);
3817 visitor->trace(m_nextChildNodeToConsider); 3803 visitor->trace(m_nextChildNodeToConsider);
3818 visitor->trace(m_mediaSource); 3804 visitor->trace(m_mediaSource);
3819 visitor->trace(m_audioTracks); 3805 visitor->trace(m_audioTracks);
3820 visitor->trace(m_videoTracks); 3806 visitor->trace(m_videoTracks);
3821 visitor->trace(m_cueTimeline); 3807 visitor->trace(m_cueTimeline);
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
4178 4164
4179 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect() 4165 IntRect HTMLMediaElement::AutoplayHelperClientImpl::absoluteBoundingBoxRect()
4180 const { 4166 const {
4181 IntRect result; 4167 IntRect result;
4182 if (LayoutObject* object = m_element->layoutObject()) 4168 if (LayoutObject* object = m_element->layoutObject())
4183 result = object->absoluteBoundingBoxRect(); 4169 result = object->absoluteBoundingBoxRect();
4184 return result; 4170 return result;
4185 } 4171 }
4186 4172
4187 } // namespace blink 4173 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698