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

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

Issue 2477203002: Media Controls: delegate 'volumechange' and 'focusin' handling to an EventListener. (Closed)
Patch Set: add comment 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) 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/shadow/MediaControlsMediaEventListener.h"
35 #include "core/html/shadow/MediaControlsWindowEventListener.h" 36 #include "core/html/shadow/MediaControlsWindowEventListener.h"
36 #include "core/html/track/TextTrackContainer.h" 37 #include "core/html/track/TextTrackContainer.h"
37 #include "core/html/track/TextTrackList.h" 38 #include "core/html/track/TextTrackList.h"
38 #include "core/layout/LayoutObject.h" 39 #include "core/layout/LayoutObject.h"
39 #include "core/layout/LayoutTheme.h" 40 #include "core/layout/LayoutTheme.h"
40 #include "platform/EventDispatchForbiddenScope.h" 41 #include "platform/EventDispatchForbiddenScope.h"
41 42
42 namespace blink { 43 namespace blink {
43 44
44 // If you change this value, then also update the corresponding value in 45 // If you change this value, then also update the corresponding value in
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 m_currentTimeDisplay(nullptr), 116 m_currentTimeDisplay(nullptr),
116 m_durationDisplay(nullptr), 117 m_durationDisplay(nullptr),
117 m_muteButton(nullptr), 118 m_muteButton(nullptr),
118 m_volumeSlider(nullptr), 119 m_volumeSlider(nullptr),
119 m_toggleClosedCaptionsButton(nullptr), 120 m_toggleClosedCaptionsButton(nullptr),
120 m_textTrackList(nullptr), 121 m_textTrackList(nullptr),
121 m_overflowList(nullptr), 122 m_overflowList(nullptr),
122 m_castButton(nullptr), 123 m_castButton(nullptr),
123 m_fullscreenButton(nullptr), 124 m_fullscreenButton(nullptr),
124 m_downloadButton(nullptr), 125 m_downloadButton(nullptr),
126 m_mediaEventListener(new MediaControlsMediaEventListener(this)),
125 m_windowEventListener(MediaControlsWindowEventListener::create( 127 m_windowEventListener(MediaControlsWindowEventListener::create(
126 this, 128 this,
127 WTF::bind(&MediaControls::hideAllMenus, wrapWeakPersistent(this)))), 129 WTF::bind(&MediaControls::hideAllMenus, wrapWeakPersistent(this)))),
128 m_hideMediaControlsTimer(this, 130 m_hideMediaControlsTimer(this,
129 &MediaControls::hideMediaControlsTimerFired), 131 &MediaControls::hideMediaControlsTimerFired),
130 m_hideTimerBehaviorFlags(IgnoreNone), 132 m_hideTimerBehaviorFlags(IgnoreNone),
131 m_isMouseOverControls(false), 133 m_isMouseOverControls(false),
132 m_isPausedForScrubbing(false), 134 m_isPausedForScrubbing(false),
133 m_panelWidthChangedTimer(this, 135 m_panelWidthChangedTimer(this,
134 &MediaControls::panelWidthChangedTimerFired), 136 &MediaControls::panelWidthChangedTimerFired),
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 if (mediaElement().error()) 331 if (mediaElement().error())
330 mediaElement().pause(); 332 mediaElement().pause();
331 333
332 updatePlayState(); 334 updatePlayState();
333 335
334 updateCurrentTimeDisplay(); 336 updateCurrentTimeDisplay();
335 337
336 m_timeline->setDuration(duration); 338 m_timeline->setDuration(duration);
337 m_timeline->setPosition(mediaElement().currentTime()); 339 m_timeline->setPosition(mediaElement().currentTime());
338 340
339 updateVolume(); 341 onVolumeChange();
340 342
341 refreshClosedCaptionsButtonVisibility(); 343 refreshClosedCaptionsButtonVisibility();
342 344
343 m_fullscreenButton->setIsWanted(shouldShowFullscreenButton(mediaElement())); 345 m_fullscreenButton->setIsWanted(shouldShowFullscreenButton(mediaElement()));
344 346
345 refreshCastButtonVisibilityWithoutUpdate(); 347 refreshCastButtonVisibilityWithoutUpdate();
346 348
347 m_downloadButton->setIsWanted( 349 m_downloadButton->setIsWanted(
348 m_downloadButton->shouldDisplayDownloadButton()); 350 m_downloadButton->shouldDisplayDownloadButton());
349 } 351 }
350 352
351 LayoutObject* MediaControls::layoutObjectForTextTrackLayout() { 353 LayoutObject* MediaControls::layoutObjectForTextTrackLayout() {
352 return m_panel->layoutObject(); 354 return m_panel->layoutObject();
353 } 355 }
354 356
355 void MediaControls::show() { 357 void MediaControls::show() {
356 makeOpaque(); 358 makeOpaque();
357 m_panel->setIsWanted(true); 359 m_panel->setIsWanted(true);
358 m_panel->setIsDisplayed(true); 360 m_panel->setIsDisplayed(true);
359 if (m_overlayPlayButton) 361 if (m_overlayPlayButton)
360 m_overlayPlayButton->updateDisplayType(); 362 m_overlayPlayButton->updateDisplayType();
361 } 363 }
362 364
363 void MediaControls::mediaElementFocused() {
364 if (mediaElement().shouldShowControls()) {
365 show();
366 resetHideMediaControlsTimer();
367 }
368 }
369
370 void MediaControls::hide() { 365 void MediaControls::hide() {
371 m_panel->setIsWanted(false); 366 m_panel->setIsWanted(false);
372 m_panel->setIsDisplayed(false); 367 m_panel->setIsDisplayed(false);
373 if (m_overlayPlayButton) 368 if (m_overlayPlayButton)
374 m_overlayPlayButton->setIsWanted(false); 369 m_overlayPlayButton->setIsWanted(false);
375 } 370 }
376 371
377 bool MediaControls::isVisible() const { 372 bool MediaControls::isVisible() const {
378 return m_panel->isOpaque(); 373 return m_panel->isOpaque();
379 } 374 }
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 double now = mediaElement().currentTime(); 473 double now = mediaElement().currentTime();
479 double duration = mediaElement().duration(); 474 double duration = mediaElement().duration();
480 475
481 // Allow the theme to format the time. 476 // Allow the theme to format the time.
482 m_currentTimeDisplay->setInnerText( 477 m_currentTimeDisplay->setInnerText(
483 LayoutTheme::theme().formatMediaControlsCurrentTime(now, duration), 478 LayoutTheme::theme().formatMediaControlsCurrentTime(now, duration),
484 IGNORE_EXCEPTION); 479 IGNORE_EXCEPTION);
485 m_currentTimeDisplay->setCurrentValue(now); 480 m_currentTimeDisplay->setCurrentValue(now);
486 } 481 }
487 482
488 void MediaControls::updateVolume() {
489 m_muteButton->updateDisplayType();
490 // Invalidate the mute button because it paints differently according to
491 // volume.
492 invalidate(m_muteButton);
493
494 if (mediaElement().muted())
495 m_volumeSlider->setVolume(0);
496 else
497 m_volumeSlider->setVolume(mediaElement().volume());
498
499 // Update the visibility of our audio elements.
500 // We never want the volume slider if there's no audio.
501 // If there is audio, then we want it unless we prefer to hide it.
502 BatchedControlUpdate batch(this);
503 m_volumeSlider->setIsWanted(mediaElement().hasAudio() &&
504 !preferHiddenVolumeControls(document()));
505
506 // If there is no audio track, then hide the mute button.
507 m_muteButton->setIsWanted(mediaElement().hasAudio());
508
509 // Invalidate the volume slider because it paints differently according to
510 // volume.
511 invalidate(m_volumeSlider);
512 }
513
514 void MediaControls::changedClosedCaptionsVisibility() { 483 void MediaControls::changedClosedCaptionsVisibility() {
515 m_toggleClosedCaptionsButton->updateDisplayType(); 484 m_toggleClosedCaptionsButton->updateDisplayType();
516 } 485 }
517 486
518 void MediaControls::refreshClosedCaptionsButtonVisibility() { 487 void MediaControls::refreshClosedCaptionsButtonVisibility() {
519 m_toggleClosedCaptionsButton->setIsWanted(mediaElement().hasClosedCaptions()); 488 m_toggleClosedCaptionsButton->setIsWanted(mediaElement().hasClosedCaptions());
520 BatchedControlUpdate batch(this); 489 BatchedControlUpdate batch(this);
521 } 490 }
522 491
523 void MediaControls::toggleTextTrackList() { 492 void MediaControls::toggleTextTrackList() {
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 689
721 bool MediaControls::containsRelatedTarget(Event* event) { 690 bool MediaControls::containsRelatedTarget(Event* event) {
722 if (!event->isMouseEvent()) 691 if (!event->isMouseEvent())
723 return false; 692 return false;
724 EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget(); 693 EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget();
725 if (!relatedTarget) 694 if (!relatedTarget)
726 return false; 695 return false;
727 return contains(relatedTarget->toNode()); 696 return contains(relatedTarget->toNode());
728 } 697 }
729 698
699 void MediaControls::onVolumeChange() {
700 m_muteButton->updateDisplayType();
701 m_volumeSlider->setVolume(mediaElement().muted() ? 0
702 : mediaElement().volume());
703
704 // Update visibility of volume controls.
705 // TODO(mlamouri): it should not be part of the volumechange handling because
706 // it is using audio availability as input.
707 BatchedControlUpdate batch(this);
708 m_volumeSlider->setIsWanted(mediaElement().hasAudio() &&
709 !preferHiddenVolumeControls(document()));
710 m_muteButton->setIsWanted(mediaElement().hasAudio());
711 }
712
713 void MediaControls::onFocusIn() {
714 if (!mediaElement().shouldShowControls())
715 return;
716
717 show();
718 resetHideMediaControlsTimer();
719 }
720
730 void MediaControls::notifyPanelWidthChanged(const LayoutUnit& newWidth) { 721 void MediaControls::notifyPanelWidthChanged(const LayoutUnit& newWidth) {
731 // Don't bother to do any work if this matches the most recent panel 722 // Don't bother to do any work if this matches the most recent panel
732 // width, since we're called after layout. 723 // width, since we're called after layout.
733 // Note that this code permits a bad frame on resize, since it is 724 // Note that this code permits a bad frame on resize, since it is
734 // run after the relayout / paint happens. It would be great to improve 725 // run after the relayout / paint happens. It would be great to improve
735 // this, but it would be even greater to move this code entirely to 726 // this, but it would be even greater to move this code entirely to
736 // JS and fix it there. 727 // JS and fix it there.
737 m_panelWidth = newWidth.toInt(); 728 m_panelWidth = newWidth.toInt();
738 729
739 // Adjust for effective zoom. 730 // Adjust for effective zoom.
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 visitor->trace(m_toggleClosedCaptionsButton); 902 visitor->trace(m_toggleClosedCaptionsButton);
912 visitor->trace(m_fullscreenButton); 903 visitor->trace(m_fullscreenButton);
913 visitor->trace(m_downloadButton); 904 visitor->trace(m_downloadButton);
914 visitor->trace(m_durationDisplay); 905 visitor->trace(m_durationDisplay);
915 visitor->trace(m_enclosure); 906 visitor->trace(m_enclosure);
916 visitor->trace(m_textTrackList); 907 visitor->trace(m_textTrackList);
917 visitor->trace(m_overflowMenu); 908 visitor->trace(m_overflowMenu);
918 visitor->trace(m_overflowList); 909 visitor->trace(m_overflowList);
919 visitor->trace(m_castButton); 910 visitor->trace(m_castButton);
920 visitor->trace(m_overlayCastButton); 911 visitor->trace(m_overlayCastButton);
912 visitor->trace(m_mediaEventListener);
921 visitor->trace(m_windowEventListener); 913 visitor->trace(m_windowEventListener);
922 HTMLDivElement::trace(visitor); 914 HTMLDivElement::trace(visitor);
923 } 915 }
924 916
925 } // namespace blink 917 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698