Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
| diff --git a/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp b/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
| index 8c0f1083541509794c61c292e4bc9b1401602d05..f501e4d62a91071a0a8e52c92f0d0ee3f34b080a 100644 |
| --- a/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
| +++ b/third_party/WebKit/Source/core/html/shadow/MediaControls.cpp |
| @@ -42,6 +42,9 @@ namespace blink { |
| // LayoutTests/media/media-controls.js. |
| static const double timeWithoutMouseMovementBeforeHidingMediaControls = 3; |
| +// We only want to show the overflow menu if it contains at least two buttons |
| +static const int minOverflowMenuControlElementsNum = 2; |
| + |
| static bool shouldShowFullscreenButton(const HTMLMediaElement& mediaElement) |
| { |
| // Unconditionally allow the user to exit fullscreen if we are in it |
| @@ -117,6 +120,7 @@ MediaControls::MediaControls(HTMLMediaElement& mediaElement) |
| , m_volumeSlider(nullptr) |
| , m_toggleClosedCaptionsButton(nullptr) |
| , m_textTrackList(nullptr) |
| + , m_overflowList(nullptr) |
| , m_castButton(nullptr) |
| , m_fullScreenButton(nullptr) |
| , m_hideMediaControlsTimer(this, &MediaControls::hideMediaControlsTimerFired) |
| @@ -242,6 +246,20 @@ void MediaControls::initializeControls() |
| MediaControlTextTrackListElement* textTrackList = MediaControlTextTrackListElement::create(*this); |
| m_textTrackList = textTrackList; |
| appendChild(textTrackList); |
| + |
| + MediaControlOverflowMenuButtonElement* overflowMenu = MediaControlOverflowMenuButtonElement::create(*this); |
| + m_overflowMenu = overflowMenu; |
| + panel->appendChild(overflowMenu); |
| + |
| + MediaControlOverflowMenuListElement* overflowList = MediaControlOverflowMenuListElement::create(*this); |
| + m_overflowList = overflowList; |
| + appendChild(overflowList); |
| + |
| + // The order in which we append elements to the overflow list does matter. |
| + m_overflowList->appendChild(m_muteButton->createOverflowElement(*this, MediaControlMuteButtonElement::create(*this))); |
| + m_overflowList->appendChild(m_castButton->createOverflowElement(*this, MediaControlCastButtonElement::create(*this, false))); |
| + m_overflowList->appendChild(m_toggleClosedCaptionsButton->createOverflowElement(*this, MediaControlToggleClosedCaptionsButtonElement::create(*this))); |
| + m_overflowList->appendChild(m_fullScreenButton->createOverflowElement(*this, MediaControlFullscreenButtonElement::create(*this))); |
| } |
| void MediaControls::reset() |
| @@ -433,6 +451,7 @@ void MediaControls::updateCurrentTimeDisplay() |
| void MediaControls::updateVolume() |
| { |
| m_muteButton->updateDisplayType(); |
| + |
|
mlamouri (slow - plz ping)
2016/09/01 18:29:15
nit: remove this unless it was intentional?
kdsilva
2016/09/05 14:39:35
Done.
|
| // Invalidate the mute button because it paints differently according to volume. |
| invalidate(m_muteButton); |
| @@ -730,6 +749,7 @@ void MediaControls::computeWhichControlsFit() |
| return; |
| } |
| + int numOverflowElements = 0; |
| // For each control that fits, enable it in order of decreasing priority. |
| bool droppedCastButton = false; |
| for (MediaControlElement* element : elements) { |
| @@ -740,14 +760,29 @@ void MediaControls::computeWhichControlsFit() |
| if (usedWidth + minimumWidth <= m_panelWidth) { |
| element->setDoesFit(true); |
| usedWidth += minimumWidth; |
| + element->shouldShowButtonInOverflowMenu(false); |
| } else { |
| element->setDoesFit(false); |
| if (element == m_castButton.get()) |
| droppedCastButton = true; |
| + element->shouldShowButtonInOverflowMenu(true); |
| + if (element->hasOverflowButton()) |
| + numOverflowElements++; |
| } |
| + } else { |
| + element->shouldShowButtonInOverflowMenu(false); |
|
mlamouri (slow - plz ping)
2016/09/01 18:29:15
Shouldn't that be set when `isWanted()` is set to
kdsilva
2016/09/05 14:39:35
Done.
|
| } |
| } |
| + // We display an overflow menu only when we have at least two items |
| + // within it. |
| + if (numOverflowElements >= minOverflowMenuControlElementsNum) { |
| + m_overflowMenu->setIsWanted(true); |
|
mlamouri (slow - plz ping)
2016/09/01 18:29:15
I'm confused. How do we know that m_overflowMenu w
kdsilva
2016/09/05 14:39:35
Hmm, I lost that logic when changing the implement
|
| + } else { |
| + m_overflowMenu->setIsWanted(false); |
| + m_overflowList->showOverflowMenu(false); |
| + } |
| + |
| // Special case for cast: if we want a cast button but dropped it, then |
| // show the overlay cast button instead. |
| if (m_castButton->isWanted()) { |
| @@ -784,6 +819,16 @@ void MediaControls::networkStateChanged() |
| invalidate(m_volumeSlider); |
| } |
| +bool MediaControls::overflowMenuVisible() |
| +{ |
| + return m_overflowList->isWanted(); |
| +} |
| + |
| +void MediaControls::toggleOverflowMenu() |
| +{ |
| + m_overflowList->showOverflowMenu(!m_overflowList->isWanted()); |
| +} |
| + |
| DEFINE_TRACE(MediaControls) |
| { |
| visitor->trace(m_mediaElement); |
| @@ -800,6 +845,8 @@ DEFINE_TRACE(MediaControls) |
| visitor->trace(m_durationDisplay); |
| visitor->trace(m_enclosure); |
| visitor->trace(m_textTrackList); |
| + visitor->trace(m_overflowMenu); |
| + visitor->trace(m_overflowList); |
| visitor->trace(m_castButton); |
| visitor->trace(m_overlayCastButton); |
| HTMLDivElement::trace(visitor); |