OLD | NEW |
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 Loading... |
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) |
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()) |
129 { | 130 { |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 236 |
236 m_panel = panel; | 237 m_panel = panel; |
237 enclosure->appendChild(panel); | 238 enclosure->appendChild(panel); |
238 | 239 |
239 m_enclosure = enclosure; | 240 m_enclosure = enclosure; |
240 appendChild(enclosure); | 241 appendChild(enclosure); |
241 | 242 |
242 MediaControlTextTrackListElement* textTrackList = MediaControlTextTrackListE
lement::create(*this); | 243 MediaControlTextTrackListElement* textTrackList = MediaControlTextTrackListE
lement::create(*this); |
243 m_textTrackList = textTrackList; | 244 m_textTrackList = textTrackList; |
244 appendChild(textTrackList); | 245 appendChild(textTrackList); |
| 246 |
| 247 MediaControlOverflowMenuButtonElement* overflowMenu = MediaControlOverflowMe
nuButtonElement::create(*this); |
| 248 m_overflowMenu = overflowMenu; |
| 249 panel->appendChild(overflowMenu); |
| 250 |
| 251 MediaControlOverflowMenuListElement* overflowList = MediaControlOverflowMenu
ListElement::create(*this); |
| 252 m_overflowList = overflowList; |
| 253 appendChild(overflowList); |
| 254 |
| 255 // The order in which we append elements to the overflow list does matter. |
| 256 m_overflowList->appendChild(m_muteButton->createOverflowElement(*this, Media
ControlMuteButtonElement::create(*this))); |
| 257 m_overflowList->appendChild(m_castButton->createOverflowElement(*this, Media
ControlCastButtonElement::create(*this, false))); |
| 258 m_overflowList->appendChild(m_toggleClosedCaptionsButton->createOverflowElem
ent(*this, MediaControlToggleClosedCaptionsButtonElement::create(*this))); |
| 259 m_overflowList->appendChild(m_fullscreenButton->createOverflowElement(*this,
MediaControlFullscreenButtonElement::create(*this))); |
| 260 m_overflowList->appendChild(m_playButton->createOverflowElement(*this, Media
ControlPlayButtonElement::create(*this))); |
245 } | 261 } |
246 | 262 |
247 void MediaControls::reset() | 263 void MediaControls::reset() |
248 { | 264 { |
249 EventDispatchForbiddenScope::AllowUserAgentEvents allowEventsInShadow; | 265 EventDispatchForbiddenScope::AllowUserAgentEvents allowEventsInShadow; |
250 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); | 266 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); |
251 BatchedControlUpdate batch(this); | 267 BatchedControlUpdate batch(this); |
252 | 268 |
253 m_allowHiddenVolumeControls = useNewUi; | 269 m_allowHiddenVolumeControls = useNewUi; |
254 | 270 |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 { | 697 { |
682 // Hide all controls that don't fit, and show the ones that do. | 698 // 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 | 699 // 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. | 700 // won't benefit from that anwyay, we just do it here like JS will. |
685 | 701 |
686 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) | 702 if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) |
687 return; | 703 return; |
688 | 704 |
689 // Controls that we'll hide / show, in order of decreasing priority. | 705 // Controls that we'll hide / show, in order of decreasing priority. |
690 MediaControlElement* elements[] = { | 706 MediaControlElement* elements[] = { |
691 // Exclude m_playButton; we handle it specially. | 707 // Exclude m_overflowMenu; we handle it specially. |
| 708 m_playButton.get(), |
692 m_fullscreenButton.get(), | 709 m_fullscreenButton.get(), |
693 m_toggleClosedCaptionsButton.get(), | 710 m_toggleClosedCaptionsButton.get(), |
694 m_timeline.get(), | 711 m_timeline.get(), |
695 m_currentTimeDisplay.get(), | 712 m_currentTimeDisplay.get(), |
696 m_volumeSlider.get(), | 713 m_volumeSlider.get(), |
697 m_castButton.get(), | 714 m_castButton.get(), |
698 m_muteButton.get(), | 715 m_muteButton.get(), |
699 m_durationDisplay.get(), | 716 m_durationDisplay.get(), |
700 }; | 717 }; |
701 | 718 |
702 int usedWidth = 0; | 719 int usedWidth = 0; |
703 | 720 |
704 // Assume that all controls require 48px, unless we can get the computed | 721 // Assume that all controls require 48px, unless we can get the computed |
705 // style for the play button. Since the play button is always shown, it | 722 // style for the play button. Since the play button or overflow is always |
706 // should be available the first time we're called after layout. This will | 723 // shown, one of the two buttons should be available the first time we're |
| 724 // called after layout. This will |
707 // also be the first time we have m_panelWidth!=0, so it won't matter if | 725 // also be the first time we have m_panelWidth!=0, so it won't matter if |
708 // we get this wrong before that. | 726 // we get this wrong before that. |
709 int minimumWidth = 48; | 727 int minimumWidth = 48; |
710 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) { | 728 if (m_playButton->layoutObject() && m_playButton->layoutObject()->style()) { |
711 const ComputedStyle* style = m_playButton->layoutObject()->style(); | 729 const ComputedStyle* style = m_playButton->layoutObject()->style(); |
712 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); | 730 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); |
713 } | 731 } else if (m_overflowMenu->layoutObject() && m_overflowMenu->layoutObject()-
>style()) { |
714 | 732 const ComputedStyle* style = m_overflowMenu->layoutObject()->style(); |
715 // Special-case the play button; it always fits. | 733 minimumWidth = ceil(style->width().pixels() / style->effectiveZoom()); |
716 if (m_playButton->isWanted()) { | |
717 m_playButton->setDoesFit(true); | |
718 usedWidth += minimumWidth; | |
719 } | 734 } |
720 | 735 |
721 if (!m_panelWidth) { | 736 if (!m_panelWidth) { |
722 // No layout yet -- hide everything, then make them show up later. | 737 // No layout yet -- hide everything, then make them show up later. |
723 // This prevents the wrong controls from being shown briefly | 738 // This prevents the wrong controls from being shown briefly |
724 // immediately after the first layout and paint, but before we have | 739 // immediately after the first layout and paint, but before we have |
725 // a chance to revise them. | 740 // a chance to revise them. |
726 for (MediaControlElement* element : elements) { | 741 for (MediaControlElement* element : elements) { |
727 if (element) | 742 if (element) |
728 element->setDoesFit(false); | 743 element->setDoesFit(false); |
729 } | 744 } |
730 return; | 745 return; |
731 } | 746 } |
732 | 747 |
| 748 // Insert an overflow menu. However, if we see that the overflow menu |
| 749 // doesn't end up containing at least two elements, we will not display it |
| 750 // but instead make place for the first element that was dropped. |
| 751 m_overflowMenu->setDoesFit(true); |
| 752 m_overflowMenu->setIsWanted(true); |
| 753 usedWidth = minimumWidth; |
| 754 |
| 755 std::list<MediaControlElement*> overflowElements; |
| 756 MediaControlElement* firstDisplacedElement = nullptr; |
733 // For each control that fits, enable it in order of decreasing priority. | 757 // For each control that fits, enable it in order of decreasing priority. |
734 bool droppedCastButton = false; | 758 bool droppedCastButton = false; |
735 for (MediaControlElement* element : elements) { | 759 for (MediaControlElement* element : elements) { |
736 if (!element) | 760 if (!element) |
737 continue; | 761 continue; |
738 | 762 element->shouldShowButtonInOverflowMenu(false); |
739 if (element->isWanted()) { | 763 if (element->isWanted()) { |
740 if (usedWidth + minimumWidth <= m_panelWidth) { | 764 if (usedWidth + minimumWidth <= m_panelWidth) { |
741 element->setDoesFit(true); | 765 element->setDoesFit(true); |
742 usedWidth += minimumWidth; | 766 usedWidth += minimumWidth; |
743 } else { | 767 } else { |
744 element->setDoesFit(false); | 768 element->setDoesFit(false); |
745 if (element == m_castButton.get()) | 769 if (element == m_castButton.get()) |
746 droppedCastButton = true; | 770 droppedCastButton = true; |
| 771 element->shouldShowButtonInOverflowMenu(true); |
| 772 if (element->hasOverflowButton()) |
| 773 overflowElements.push_front(element); |
| 774 // We want a way to access the first media element that was |
| 775 // removed. If we don't end up needing an overflow menu, we can |
| 776 // use the space the overflow menu would have taken up to |
| 777 // instead display that media element. |
| 778 if (!element->hasOverflowButton() && !firstDisplacedElement) |
| 779 firstDisplacedElement = element; |
747 } | 780 } |
748 } | 781 } |
749 } | 782 } |
750 | 783 |
| 784 // If we don't have at least two overflow elements, we will not show the |
| 785 // overflow menu. |
| 786 if (overflowElements.empty()) { |
| 787 m_overflowMenu->setIsWanted(false); |
| 788 if (firstDisplacedElement) |
| 789 firstDisplacedElement->setDoesFit(true); |
| 790 } else if (overflowElements.size() == 1) { |
| 791 m_overflowMenu->setIsWanted(false); |
| 792 overflowElements.front()->setDoesFit(true); |
| 793 } |
| 794 |
751 // Special case for cast: if we want a cast button but dropped it, then | 795 // Special case for cast: if we want a cast button but dropped it, then |
752 // show the overlay cast button instead. | 796 // show the overlay cast button instead. |
753 if (m_castButton->isWanted()) { | 797 if (m_castButton->isWanted()) { |
754 if (droppedCastButton) | 798 if (droppedCastButton) |
755 m_overlayCastButton->tryShowOverlay(); | 799 m_overlayCastButton->tryShowOverlay(); |
756 else | 800 else |
757 m_overlayCastButton->setIsWanted(false); | 801 m_overlayCastButton->setIsWanted(false); |
758 } | 802 } |
759 } | 803 } |
760 | 804 |
(...skipping 16 matching lines...) Expand all Loading... |
777 void MediaControls::networkStateChanged() | 821 void MediaControls::networkStateChanged() |
778 { | 822 { |
779 invalidate(m_playButton); | 823 invalidate(m_playButton); |
780 invalidate(m_overlayPlayButton); | 824 invalidate(m_overlayPlayButton); |
781 invalidate(m_muteButton); | 825 invalidate(m_muteButton); |
782 invalidate(m_fullscreenButton); | 826 invalidate(m_fullscreenButton); |
783 invalidate(m_timeline); | 827 invalidate(m_timeline); |
784 invalidate(m_volumeSlider); | 828 invalidate(m_volumeSlider); |
785 } | 829 } |
786 | 830 |
| 831 bool MediaControls::overflowMenuVisible() |
| 832 { |
| 833 return m_overflowList->isWanted(); |
| 834 } |
| 835 |
| 836 void MediaControls::toggleOverflowMenu() |
| 837 { |
| 838 m_overflowList->setIsWanted(!m_overflowList->isWanted()); |
| 839 } |
| 840 |
787 DEFINE_TRACE(MediaControls) | 841 DEFINE_TRACE(MediaControls) |
788 { | 842 { |
789 visitor->trace(m_mediaElement); | 843 visitor->trace(m_mediaElement); |
790 visitor->trace(m_panel); | 844 visitor->trace(m_panel); |
791 visitor->trace(m_overlayPlayButton); | 845 visitor->trace(m_overlayPlayButton); |
792 visitor->trace(m_overlayEnclosure); | 846 visitor->trace(m_overlayEnclosure); |
793 visitor->trace(m_playButton); | 847 visitor->trace(m_playButton); |
794 visitor->trace(m_currentTimeDisplay); | 848 visitor->trace(m_currentTimeDisplay); |
795 visitor->trace(m_timeline); | 849 visitor->trace(m_timeline); |
796 visitor->trace(m_muteButton); | 850 visitor->trace(m_muteButton); |
797 visitor->trace(m_volumeSlider); | 851 visitor->trace(m_volumeSlider); |
798 visitor->trace(m_toggleClosedCaptionsButton); | 852 visitor->trace(m_toggleClosedCaptionsButton); |
799 visitor->trace(m_fullscreenButton); | 853 visitor->trace(m_fullscreenButton); |
800 visitor->trace(m_durationDisplay); | 854 visitor->trace(m_durationDisplay); |
801 visitor->trace(m_enclosure); | 855 visitor->trace(m_enclosure); |
802 visitor->trace(m_textTrackList); | 856 visitor->trace(m_textTrackList); |
| 857 visitor->trace(m_overflowMenu); |
| 858 visitor->trace(m_overflowList); |
803 visitor->trace(m_castButton); | 859 visitor->trace(m_castButton); |
804 visitor->trace(m_overlayCastButton); | 860 visitor->trace(m_overlayCastButton); |
805 HTMLDivElement::trace(visitor); | 861 HTMLDivElement::trace(visitor); |
806 } | 862 } |
807 | 863 |
808 } // namespace blink | 864 } // namespace blink |
OLD | NEW |