Chromium Code Reviews| 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 24 matching lines...) Expand all Loading... | |
| 35 #include "core/html/track/TextTrackContainer.h" | 35 #include "core/html/track/TextTrackContainer.h" |
| 36 #include "core/layout/LayoutTheme.h" | 36 #include "core/layout/LayoutTheme.h" |
| 37 #include "platform/EventDispatchForbiddenScope.h" | 37 #include "platform/EventDispatchForbiddenScope.h" |
| 38 | 38 |
| 39 namespace blink { | 39 namespace blink { |
| 40 | 40 |
| 41 // If you change this value, then also update the corresponding value in | 41 // If you change this value, then also update the corresponding value in |
| 42 // LayoutTests/media/media-controls.js. | 42 // LayoutTests/media/media-controls.js. |
| 43 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; | 43 static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; |
| 44 | 44 |
| 45 // We only want to show the overflow menu if it contains at least two buttons | |
| 46 static const int minOverflowMenuControlElementsNum = 2; | |
| 47 | |
| 45 static bool shouldShowFullscreenButton(const HTMLMediaElement& mediaElement) | 48 static bool shouldShowFullscreenButton(const HTMLMediaElement& mediaElement) |
| 46 { | 49 { |
| 47 // Unconditionally allow the user to exit fullscreen if we are in it | 50 // Unconditionally allow the user to exit fullscreen if we are in it |
| 48 // now. Especially on android, when we might not yet know if | 51 // now. Especially on android, when we might not yet know if |
| 49 // fullscreen is supported, we sometimes guess incorrectly and show | 52 // fullscreen is supported, we sometimes guess incorrectly and show |
| 50 // the button earlier, and we don't want to remove it here if the | 53 // the button earlier, and we don't want to remove it here if the |
| 51 // user chose to enter fullscreen. crbug.com/500732 . | 54 // user chose to enter fullscreen. crbug.com/500732 . |
| 52 if (mediaElement.isFullscreen()) | 55 if (mediaElement.isFullscreen()) |
| 53 return true; | 56 return true; |
| 54 | 57 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 , m_enclosure(nullptr) | 113 , m_enclosure(nullptr) |
| 111 , m_panel(nullptr) | 114 , m_panel(nullptr) |
| 112 , m_playButton(nullptr) | 115 , m_playButton(nullptr) |
| 113 , m_timeline(nullptr) | 116 , m_timeline(nullptr) |
| 114 , m_currentTimeDisplay(nullptr) | 117 , m_currentTimeDisplay(nullptr) |
| 115 , m_durationDisplay(nullptr) | 118 , m_durationDisplay(nullptr) |
| 116 , m_muteButton(nullptr) | 119 , m_muteButton(nullptr) |
| 117 , m_volumeSlider(nullptr) | 120 , m_volumeSlider(nullptr) |
| 118 , m_toggleClosedCaptionsButton(nullptr) | 121 , m_toggleClosedCaptionsButton(nullptr) |
| 119 , m_textTrackList(nullptr) | 122 , m_textTrackList(nullptr) |
| 123 , m_overflowList(nullptr) | |
| 120 , m_castButton(nullptr) | 124 , m_castButton(nullptr) |
| 121 , m_fullScreenButton(nullptr) | 125 , m_fullScreenButton(nullptr) |
| 122 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) | 126 , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired ) |
| 123 , m_hideTimerBehaviorFlags(IgnoreNone) | 127 , m_hideTimerBehaviorFlags(IgnoreNone) |
| 124 , m_isMouseOverControls(false) | 128 , m_isMouseOverControls(false) |
| 125 , m_isPausedForScrubbing(false) | 129 , m_isPausedForScrubbing(false) |
| 126 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired ) | 130 , m_panelWidthChangedTimer(this, &MediaControls::panelWidthChangedTimerFired ) |
| 127 , m_panelWidth(0) | 131 , m_panelWidth(0) |
| 128 , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnab led()) | 132 , m_allowHiddenVolumeControls(RuntimeEnabledFeatures::newMediaPlaybackUiEnab led()) |
| 129 { | 133 { |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 235 | 239 |
| 236 m_panel = panel; | 240 m_panel = panel; |
| 237 enclosure->appendChild(panel); | 241 enclosure->appendChild(panel); |
| 238 | 242 |
| 239 m_enclosure = enclosure; | 243 m_enclosure = enclosure; |
| 240 appendChild(enclosure); | 244 appendChild(enclosure); |
| 241 | 245 |
| 242 MediaControlTextTrackListElement* textTrackList = MediaControlTextTrackListE lement::create(*this); | 246 MediaControlTextTrackListElement* textTrackList = MediaControlTextTrackListE lement::create(*this); |
| 243 m_textTrackList = textTrackList; | 247 m_textTrackList = textTrackList; |
| 244 appendChild(textTrackList); | 248 appendChild(textTrackList); |
| 249 | |
| 250 MediaControlOverflowMenuButtonElement* overflowMenu = MediaControlOverflowMe nuButtonElement::create(*this); | |
| 251 m_overflowMenu = overflowMenu; | |
| 252 panel->appendChild(overflowMenu); | |
| 253 | |
| 254 MediaControlOverflowMenuListElement* overflowList = MediaControlOverflowMenu ListElement::create(*this); | |
| 255 m_overflowList = overflowList; | |
| 256 appendChild(overflowList); | |
| 257 | |
| 258 std::vector<MediaControlInputElement*> buttons = { m_toggleClosedCaptionsBut ton, | |
|
kdsilva
2016/08/27 14:20:50
Ideally here, we’d iterate through all of the chil
liberato (no reviews please)
2016/08/30 16:42:06
please see the comment by fs in https://codereview
| |
| 259 m_fullScreenButton, m_muteButton, m_castButton }; | |
| 260 | |
| 261 for (MediaControlInputElement* elem : buttons) { | |
| 262 m_overflowList->appendChild(elem->initOverflowButton(*this)); | |
| 263 } | |
| 245 } | 264 } |
| 246 | 265 |
| 247 void MediaControls::reset() | 266 void MediaControls::reset() |
| 248 { | 267 { |
| 249 EventDispatchForbiddenScope::AllowUserAgentEvents allowEventsInShadow; | 268 EventDispatchForbiddenScope::AllowUserAgentEvents allowEventsInShadow; |
| 250 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); | 269 const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled(); |
| 251 BatchedControlUpdate batch(this); | 270 BatchedControlUpdate batch(this); |
| 252 | 271 |
| 253 m_allowHiddenVolumeControls = useNewUi; | 272 m_allowHiddenVolumeControls = useNewUi; |
| 254 | 273 |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 } | 445 } |
| 427 | 446 |
| 428 // Allow the theme to format the time. | 447 // Allow the theme to format the time. |
| 429 m_currentTimeDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsC urrentTime(now, duration), IGNORE_EXCEPTION); | 448 m_currentTimeDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsC urrentTime(now, duration), IGNORE_EXCEPTION); |
| 430 m_currentTimeDisplay->setCurrentValue(now); | 449 m_currentTimeDisplay->setCurrentValue(now); |
| 431 } | 450 } |
| 432 | 451 |
| 433 void MediaControls::updateVolume() | 452 void MediaControls::updateVolume() |
| 434 { | 453 { |
| 435 m_muteButton->updateDisplayType(); | 454 m_muteButton->updateDisplayType(); |
| 455 | |
| 436 // Invalidate the mute button because it paints differently according to vol ume. | 456 // Invalidate the mute button because it paints differently according to vol ume. |
| 437 invalidate(m_muteButton); | 457 invalidate(m_muteButton); |
| 438 | 458 |
| 439 if (mediaElement().muted()) | 459 if (mediaElement().muted()) |
| 440 m_volumeSlider->setVolume(0); | 460 m_volumeSlider->setVolume(0); |
| 441 else | 461 else |
| 442 m_volumeSlider->setVolume(mediaElement().volume()); | 462 m_volumeSlider->setVolume(mediaElement().volume()); |
| 443 | 463 |
| 444 // Update the visibility of our audio elements. | 464 // Update the visibility of our audio elements. |
| 445 // We never want the volume slider if there's no audio. | 465 // We never want the volume slider if there's no audio. |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 723 // This prevents the wrong controls from being shown briefly | 743 // This prevents the wrong controls from being shown briefly |
| 724 // immediately after the first layout and paint, but before we have | 744 // immediately after the first layout and paint, but before we have |
| 725 // a chance to revise them. | 745 // a chance to revise them. |
| 726 for (MediaControlElement* element : elements) { | 746 for (MediaControlElement* element : elements) { |
| 727 if (element) | 747 if (element) |
| 728 element->setDoesFit(false); | 748 element->setDoesFit(false); |
| 729 } | 749 } |
| 730 return; | 750 return; |
| 731 } | 751 } |
| 732 | 752 |
| 753 int numOverflowElements = 0; | |
| 733 // For each control that fits, enable it in order of decreasing priority. | 754 // For each control that fits, enable it in order of decreasing priority. |
| 734 bool droppedCastButton = false; | 755 bool droppedCastButton = false; |
| 735 for (MediaControlElement* element : elements) { | 756 for (MediaControlElement* element : elements) { |
| 736 if (!element) | 757 if (!element) |
| 737 continue; | 758 continue; |
| 738 | 759 |
| 739 if (element->isWanted()) { | 760 if (element->isWanted()) { |
| 740 if (usedWidth + minimumWidth <= m_panelWidth) { | 761 if (usedWidth + minimumWidth <= m_panelWidth) { |
| 741 element->setDoesFit(true); | 762 element->setDoesFit(true); |
| 742 usedWidth += minimumWidth; | 763 usedWidth += minimumWidth; |
| 764 element->shouldShowButtonInOverflowMenu(false); | |
| 743 } else { | 765 } else { |
| 744 element->setDoesFit(false); | 766 element->setDoesFit(false); |
| 745 if (element == m_castButton.get()) | 767 if (element == m_castButton.get()) |
| 746 droppedCastButton = true; | 768 droppedCastButton = true; |
| 769 element->shouldShowButtonInOverflowMenu(true); | |
| 770 if (element->hasOverflowButton()) | |
| 771 numOverflowElements++; | |
| 747 } | 772 } |
| 748 } | 773 } |
| 749 } | 774 } |
| 750 | 775 |
| 776 // We display an overflow menu only when we have at least two items | |
| 777 // within it. | |
| 778 if (numOverflowElements >= minOverflowMenuControlElementsNum) { | |
| 779 m_overflowMenu->setIsWanted(true); | |
| 780 } else { | |
| 781 m_overflowMenu->setIsWanted(false); | |
| 782 m_overflowList->showOverflowMenu(false); | |
| 783 } | |
| 784 | |
| 751 // Special case for cast: if we want a cast button but dropped it, then | 785 // Special case for cast: if we want a cast button but dropped it, then |
| 752 // show the overlay cast button instead. | 786 // show the overlay cast button instead. |
| 753 if (m_castButton->isWanted()) { | 787 if (m_castButton->isWanted()) { |
| 754 if (droppedCastButton) | 788 if (droppedCastButton) |
| 755 m_overlayCastButton->tryShowOverlay(); | 789 m_overlayCastButton->tryShowOverlay(); |
| 756 else | 790 else |
| 757 m_overlayCastButton->setIsWanted(false); | 791 m_overlayCastButton->setIsWanted(false); |
| 758 } | 792 } |
| 759 } | 793 } |
| 760 | 794 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 777 void MediaControls::networkStateChanged() | 811 void MediaControls::networkStateChanged() |
| 778 { | 812 { |
| 779 invalidate(m_playButton); | 813 invalidate(m_playButton); |
| 780 invalidate(m_overlayPlayButton); | 814 invalidate(m_overlayPlayButton); |
| 781 invalidate(m_muteButton); | 815 invalidate(m_muteButton); |
| 782 invalidate(m_fullScreenButton); | 816 invalidate(m_fullScreenButton); |
| 783 invalidate(m_timeline); | 817 invalidate(m_timeline); |
| 784 invalidate(m_volumeSlider); | 818 invalidate(m_volumeSlider); |
| 785 } | 819 } |
| 786 | 820 |
| 821 bool MediaControls::overflowMenuVisible() | |
| 822 { | |
| 823 return m_overflowList->isWanted(); | |
| 824 } | |
| 825 | |
| 826 void MediaControls::toggleOverflowMenu() | |
| 827 { | |
| 828 m_overflowList->showOverflowMenu(!m_overflowList->isWanted()); | |
| 829 } | |
| 830 | |
| 787 DEFINE_TRACE(MediaControls) | 831 DEFINE_TRACE(MediaControls) |
| 788 { | 832 { |
| 789 visitor->trace(m_mediaElement); | 833 visitor->trace(m_mediaElement); |
| 790 visitor->trace(m_panel); | 834 visitor->trace(m_panel); |
| 791 visitor->trace(m_overlayPlayButton); | 835 visitor->trace(m_overlayPlayButton); |
| 792 visitor->trace(m_overlayEnclosure); | 836 visitor->trace(m_overlayEnclosure); |
| 793 visitor->trace(m_playButton); | 837 visitor->trace(m_playButton); |
| 794 visitor->trace(m_currentTimeDisplay); | 838 visitor->trace(m_currentTimeDisplay); |
| 795 visitor->trace(m_timeline); | 839 visitor->trace(m_timeline); |
| 796 visitor->trace(m_muteButton); | 840 visitor->trace(m_muteButton); |
| 797 visitor->trace(m_volumeSlider); | 841 visitor->trace(m_volumeSlider); |
| 798 visitor->trace(m_toggleClosedCaptionsButton); | 842 visitor->trace(m_toggleClosedCaptionsButton); |
| 799 visitor->trace(m_fullScreenButton); | 843 visitor->trace(m_fullScreenButton); |
| 800 visitor->trace(m_durationDisplay); | 844 visitor->trace(m_durationDisplay); |
| 801 visitor->trace(m_enclosure); | 845 visitor->trace(m_enclosure); |
| 802 visitor->trace(m_textTrackList); | 846 visitor->trace(m_textTrackList); |
| 847 visitor->trace(m_overflowMenu); | |
| 848 visitor->trace(m_overflowList); | |
| 803 visitor->trace(m_castButton); | 849 visitor->trace(m_castButton); |
| 804 visitor->trace(m_overlayCastButton); | 850 visitor->trace(m_overlayCastButton); |
| 805 HTMLDivElement::trace(visitor); | 851 HTMLDivElement::trace(visitor); |
| 806 } | 852 } |
| 807 | 853 |
| 808 } // namespace blink | 854 } // namespace blink |
| OLD | NEW |