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

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

Issue 2243473002: Adding overflow menu to media player (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 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
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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 , m_enclosure(nullptr) 110 , m_enclosure(nullptr)
111 , m_panel(nullptr) 111 , m_panel(nullptr)
112 , m_playButton(nullptr) 112 , m_playButton(nullptr)
113 , m_timeline(nullptr) 113 , m_timeline(nullptr)
114 , m_currentTimeDisplay(nullptr) 114 , m_currentTimeDisplay(nullptr)
115 , m_durationDisplay(nullptr) 115 , m_durationDisplay(nullptr)
116 , m_muteButton(nullptr) 116 , m_muteButton(nullptr)
117 , m_volumeSlider(nullptr) 117 , m_volumeSlider(nullptr)
118 , m_toggleClosedCaptionsButton(nullptr) 118 , m_toggleClosedCaptionsButton(nullptr)
119 , m_textTrackList(nullptr) 119 , m_textTrackList(nullptr)
120 , m_overflowList(nullptr)
121 , m_muteOverflowButton(nullptr)
122 , m_castOverflowButton(nullptr)
123 , m_ClosedCaptionsOverflowButton(nullptr)
124 , m_fullscreenOverflowButton(nullptr)
120 , m_castButton(nullptr) 125 , m_castButton(nullptr)
121 , m_fullScreenButton(nullptr) 126 , m_fullScreenButton(nullptr)
122 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) 127 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired )
123 , m_hideTimerBehaviorFlags(IgnoreNone) 128 , m_hideTimerBehaviorFlags(IgnoreNone)
124 , m_isMouseOverControls(false) 129 , m_isMouseOverControls(false)
125 , m_isPausedForScrubbing(false) 130 , m_isPausedForScrubbing(false)
126 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired ) 131 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired )
127 , m_panelWidth(0) 132 , m_panelWidth(0)
128 , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnab led()) 133 , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnab led())
129 { 134 {
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 240
236 m_panel = panel; 241 m_panel = panel;
237 enclosure->appendChild(panel); 242 enclosure->appendChild(panel);
238 243
239 m_enclosure = enclosure; 244 m_enclosure = enclosure;
240 appendChild(enclosure); 245 appendChild(enclosure);
241 246
242 MediaControlTextTrackListElement* textTrackList = MediaControlTextTrackListE lement::create(*this); 247 MediaControlTextTrackListElement* textTrackList = MediaControlTextTrackListE lement::create(*this);
243 m_textTrackList = textTrackList; 248 m_textTrackList = textTrackList;
244 appendChild(textTrackList); 249 appendChild(textTrackList);
250
251 MediaControlOverflowMenu* overflowMenu = MediaControlOverflowMenu::create(*t his);
252 m_overflowMenu = overflowMenu;
253 panel->appendChild(overflowMenu);
254
255 MediaControlOverflowMenuListElement* overflowList = MediaControlOverflowMenu ListElement::create(*this);
256 m_overflowList = overflowList;
257 appendChild(overflowList);
258
259 m_muteOverflowButton = MediaControlMuteButtonElement::create(*this);
260 m_castOverflowButton = MediaControlCastButtonElement::create(*this, false);
261 m_ClosedCaptionsOverflowButton = MediaControlToggleClosedCaptionsButtonEleme nt::create(*this);
262 m_fullscreenOverflowButton = MediaControlFullscreenButtonElement::create(*th is);
263
264 m_muteOverflowButton->setShadowPseudoId(AtomicString("-internal-media-contro ls-overflow-menu-list-item-element"));
265 m_castOverflowButton->setShadowPseudoId(AtomicString("-internal-media-contro ls-overflow-menu-list-item-element"));
266 m_ClosedCaptionsOverflowButton->setShadowPseudoId(AtomicString("-internal-me dia-controls-overflow-menu-list-item-element"));
267 m_fullscreenOverflowButton->setShadowPseudoId(AtomicString("-internal-media- controls-overflow-menu-list-item-element"));
whywhat 2016/08/19 23:56:55 do we have these elements in the media element's d
kdsilva 2016/08/24 05:33:27 liberato@, Anton mentioned you might have recommen
liberato (no reviews please) 2016/08/24 16:44:22 i've had bad luck doing anything too complicated i
245 } 268 }
246 269
247 void MediaControls::reset() 270 void MediaControls::reset()
248 { 271 {
249 EventDispatchForbiddenScope::AllowUserAgentEvents allowEventsInShadow; 272 EventDispatchForbiddenScope::AllowUserAgentEvents allowEventsInShadow;
250 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); 273 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled();
251 BatchedControlUpdate batch(this); 274 BatchedControlUpdate batch(this);
252 275
253 m_allowHiddenVolumeControls = useNewUi; 276 m_allowHiddenVolumeControls = useNewUi;
254 277
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 } 449 }
427 450
428 // Allow the theme to format the time. 451 // Allow the theme to format the time.
429 m_currentTimeDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsC urrentTime(now, duration), IGNORE_EXCEPTION); 452 m_currentTimeDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsC urrentTime(now, duration), IGNORE_EXCEPTION);
430 m_currentTimeDisplay->setCurrentValue(now); 453 m_currentTimeDisplay->setCurrentValue(now);
431 } 454 }
432 455
433 void MediaControls::updateVolume() 456 void MediaControls::updateVolume()
434 { 457 {
435 m_muteButton->updateDisplayType(); 458 m_muteButton->updateDisplayType();
459 m_muteOverflowButton->updateDisplayType();
460
436 // Invalidate the mute button because it paints differently according to vol ume. 461 // Invalidate the mute button because it paints differently according to vol ume.
437 invalidate(m_muteButton); 462 invalidate(m_muteButton);
438 463
439 if (mediaElement().muted()) 464 if (mediaElement().muted())
440 m_volumeSlider->setVolume(0); 465 m_volumeSlider->setVolume(0);
441 else 466 else
442 m_volumeSlider->setVolume(mediaElement().volume()); 467 m_volumeSlider->setVolume(mediaElement().volume());
443 468
444 // Update the visibility of our audio elements. 469 // Update the visibility of our audio elements.
445 // We never want the volume slider if there's no audio. 470 // We never want the volume slider if there's no audio.
(...skipping 13 matching lines...) Expand all
459 m_muteButton->setIsWanted(mediaElement().hasAudio()); 484 m_muteButton->setIsWanted(mediaElement().hasAudio());
460 } 485 }
461 486
462 // Invalidate the volume slider because it paints differently according to v olume. 487 // Invalidate the volume slider because it paints differently according to v olume.
463 invalidate(m_volumeSlider); 488 invalidate(m_volumeSlider);
464 } 489 }
465 490
466 void MediaControls::changedClosedCaptionsVisibility() 491 void MediaControls::changedClosedCaptionsVisibility()
467 { 492 {
468 m_toggleClosedCaptionsButton->updateDisplayType(); 493 m_toggleClosedCaptionsButton->updateDisplayType();
494 m_ClosedCaptionsOverflowButton->updateDisplayType();
469 } 495 }
470 496
471 void MediaControls::refreshClosedCaptionsButtonVisibility() 497 void MediaControls::refreshClosedCaptionsButtonVisibility()
472 { 498 {
473 m_toggleClosedCaptionsButton->setIsWanted(mediaElement().hasClosedCaptions() ); 499 m_toggleClosedCaptionsButton->setIsWanted(mediaElement().hasClosedCaptions() );
474 BatchedControlUpdate batch(this); 500 BatchedControlUpdate batch(this);
475 } 501 }
476 502
477 void MediaControls::toggleTextTrackList() 503 void MediaControls::toggleTextTrackList()
478 { 504 {
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 // Hide all controls that don't fit, and show the ones that do. 708 // Hide all controls that don't fit, and show the ones that do.
683 // This might be better suited for a layout, but since JS media controls 709 // This might be better suited for a layout, but since JS media controls
684 // won't benefit from that anwyay, we just do it here like JS will. 710 // won't benefit from that anwyay, we just do it here like JS will.
685 711
686 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) 712 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
687 return; 713 return;
688 714
689 // Controls that we'll hide / show, in order of decreasing priority. 715 // Controls that we'll hide / show, in order of decreasing priority.
690 MediaControlElement* elements[] = { 716 MediaControlElement* elements[] = {
691 // Exclude m_playButton; we handle it specially. 717 // Exclude m_playButton; we handle it specially.
718 m_fullScreenButton.get(),
692 m_toggleClosedCaptionsButton.get(), 719 m_toggleClosedCaptionsButton.get(),
whywhat 2016/08/19 23:56:55 I thought this was fixed by another cl? Do you nee
kdsilva 2016/08/24 05:33:26 Done.
693 m_fullScreenButton.get(),
694 m_timeline.get(), 720 m_timeline.get(),
695 m_currentTimeDisplay.get(), 721 m_currentTimeDisplay.get(),
696 m_volumeSlider.get(), 722 m_volumeSlider.get(),
697 m_castButton.get(), 723 m_castButton.get(),
698 m_muteButton.get(), 724 m_muteButton.get(),
699 m_durationDisplay.get(), 725 m_durationDisplay.get(),
700 }; 726 };
701 727
702 int usedWidth = 0; 728 int usedWidth = 0;
703 729
(...skipping 19 matching lines...) Expand all
723 // This prevents the wrong controls from being shown briefly 749 // This prevents the wrong controls from being shown briefly
724 // immediately after the first layout and paint, but before we have 750 // immediately after the first layout and paint, but before we have
725 // a chance to revise them. 751 // a chance to revise them.
726 for (MediaControlElement* element : elements) { 752 for (MediaControlElement* element : elements) {
727 if (element) 753 if (element)
728 element->setDoesFit(false); 754 element->setDoesFit(false);
729 } 755 }
730 return; 756 return;
731 } 757 }
732 758
759 // Controls that don't fit within the media player that could be included
760 // in an overflow menu.
761 std::set<MediaControlElementType> overflowControls;
762
733 // For each control that fits, enable it in order of decreasing priority. 763 // For each control that fits, enable it in order of decreasing priority.
734 bool droppedCastButton = false; 764 bool droppedCastButton = false;
735 for (MediaControlElement* element : elements) { 765 for (MediaControlElement* element : elements) {
736 if (!element) 766 if (!element)
737 continue; 767 continue;
738 768
739 if (element->isWanted()) { 769 if (element->isWanted()) {
740 if (usedWidth + minimumWidth <= m_panelWidth) { 770 if (usedWidth + minimumWidth <= m_panelWidth) {
741 element->setDoesFit(true); 771 element->setDoesFit(true);
742 usedWidth += minimumWidth; 772 usedWidth += minimumWidth;
743 } else { 773 } else {
744 element->setDoesFit(false); 774 element->setDoesFit(false);
745 if (element == m_castButton.get()) 775 if (element == m_castButton.get())
746 droppedCastButton = true; 776 droppedCastButton = true;
777 overflowControls.insert(element->displayType());
747 } 778 }
748 } 779 }
749 } 780 }
750 781
782 // We display an overflow menu only when we have at least two items
783 // within it.
784 if (overflowControls.size() >= 2 && !mediaElement().isFullscreen()) {
whywhat 2016/08/19 23:56:55 2 is a magic constant (which is not 0 or 1). pleas
kdsilva 2016/08/24 05:33:26 Done.
785 m_overflowList->setOverflowMenuControls(overflowControls);
786 m_overflowMenu->setIsWanted(true);
787 } else {
788 m_overflowMenu->setIsWanted(false);
789 m_overflowList->setVisible(false);
790 }
791
751 // Special case for cast: if we want a cast button but dropped it, then 792 // Special case for cast: if we want a cast button but dropped it, then
752 // show the overlay cast button instead. 793 // show the overlay cast button instead.
753 if (m_castButton->isWanted()) { 794 if (m_castButton->isWanted()) {
754 if (droppedCastButton) 795 if (droppedCastButton)
755 m_overlayCastButton->tryShowOverlay(); 796 m_overlayCastButton->tryShowOverlay();
756 else 797 else
757 m_overlayCastButton->setIsWanted(false); 798 m_overlayCastButton->setIsWanted(false);
758 } 799 }
759 } 800 }
760 801
(...skipping 16 matching lines...) Expand all
777 void MediaControls::networkStateChanged() 818 void MediaControls::networkStateChanged()
778 { 819 {
779 invalidate(m_playButton); 820 invalidate(m_playButton);
780 invalidate(m_overlayPlayButton); 821 invalidate(m_overlayPlayButton);
781 invalidate(m_muteButton); 822 invalidate(m_muteButton);
782 invalidate(m_fullScreenButton); 823 invalidate(m_fullScreenButton);
783 invalidate(m_timeline); 824 invalidate(m_timeline);
784 invalidate(m_volumeSlider); 825 invalidate(m_volumeSlider);
785 } 826 }
786 827
828 bool MediaControls::overflowMenuVisible()
829 {
830 return m_overflowList->isWanted();
831 }
832
833 void MediaControls::toggleOverflowMenu()
834 {
835 m_overflowList->setVisible(!m_overflowList->isWanted());
836 }
837
838 std::vector<MediaControlInputElement*> MediaControls::getOverflowMenuButtons()
839 {
840 std::vector<MediaControlInputElement*> controlsListOverflow = { m_muteOverfl owButton, m_ClosedCaptionsOverflowButton, m_castOverflowButton, m_fullscreenOver flowButton };
whywhat 2016/08/19 23:56:55 creating a new vector and passing it around seems
kdsilva 2016/08/24 05:33:27 Done. I made controlsListOverflow a private member
841 return controlsListOverflow;
842 }
843
787 DEFINE_TRACE(MediaControls) 844 DEFINE_TRACE(MediaControls)
788 { 845 {
789 visitor->trace(m_mediaElement); 846 visitor->trace(m_mediaElement);
790 visitor->trace(m_panel); 847 visitor->trace(m_panel);
791 visitor->trace(m_overlayPlayButton); 848 visitor->trace(m_overlayPlayButton);
792 visitor->trace(m_overlayEnclosure); 849 visitor->trace(m_overlayEnclosure);
793 visitor->trace(m_playButton); 850 visitor->trace(m_playButton);
794 visitor->trace(m_currentTimeDisplay); 851 visitor->trace(m_currentTimeDisplay);
795 visitor->trace(m_timeline); 852 visitor->trace(m_timeline);
796 visitor->trace(m_muteButton); 853 visitor->trace(m_muteButton);
797 visitor->trace(m_volumeSlider); 854 visitor->trace(m_volumeSlider);
798 visitor->trace(m_toggleClosedCaptionsButton); 855 visitor->trace(m_toggleClosedCaptionsButton);
799 visitor->trace(m_fullScreenButton); 856 visitor->trace(m_fullScreenButton);
800 visitor->trace(m_durationDisplay); 857 visitor->trace(m_durationDisplay);
801 visitor->trace(m_enclosure); 858 visitor->trace(m_enclosure);
802 visitor->trace(m_textTrackList); 859 visitor->trace(m_textTrackList);
860 visitor->trace(m_overflowMenu);
861 visitor->trace(m_overflowList);
862 visitor->trace(m_muteOverflowButton);
863 visitor->trace(m_castOverflowButton);
864 visitor->trace(m_ClosedCaptionsOverflowButton);
865 visitor->trace(m_fullscreenOverflowButton);
803 visitor->trace(m_castButton); 866 visitor->trace(m_castButton);
804 visitor->trace(m_overlayCastButton); 867 visitor->trace(m_overlayCastButton);
805 HTMLDivElement::trace(visitor); 868 HTMLDivElement::trace(visitor);
806 } 869 }
807 870
808 } // namespace blink 871 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698