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

Unified Diff: Source/core/html/shadow/MediaControls.cpp

Issue 1156993013: New media playback UI. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed tests (thanks, trybots!) and duration display. Created 5 years, 6 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 side-by-side diff with in-line comments
Download patch
Index: Source/core/html/shadow/MediaControls.cpp
diff --git a/Source/core/html/shadow/MediaControls.cpp b/Source/core/html/shadow/MediaControls.cpp
index 43d22a4cf8f2bc617013e90ffb0185038d8b74aa..d805b62582d38a9194ff147dd8139a77cb75074c 100644
--- a/Source/core/html/shadow/MediaControls.cpp
+++ b/Source/core/html/shadow/MediaControls.cpp
@@ -89,9 +89,9 @@ PassRefPtrWillBeRawPtr<MediaControls> MediaControls::create(HTMLMediaElement& me
// \-MediaControlPanelEnclosureElement (-webkit-media-controls-enclosure)
// \-MediaControlPanelElement (-webkit-media-controls-panel)
// +-MediaControlPlayButtonElement (-webkit-media-controls-play-button)
-// +-MediaControlTimelineElement (-webkit-media-controls-timeline)
// +-MediaControlCurrentTimeDisplayElement (-webkit-media-controls-current-time-display)
// +-MediaControlTimeRemainingDisplayElement (-webkit-media-controls-time-remaining-display)
+// +-MediaControlTimelineElement (-webkit-media-controls-timeline)
// +-MediaControlMuteButtonElement (-webkit-media-controls-mute-button)
// +-MediaControlVolumeSliderElement (-webkit-media-controls-volume-slider)
// +-MediaControlToggleClosedCaptionsButtonElement (-webkit-media-controls-toggle-closed-captions-button)
@@ -125,24 +125,41 @@ void MediaControls::initializeControls()
RefPtrWillBeRawPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement::create(*this);
m_timeline = timeline.get();
- panel->appendChild(timeline.release());
+ // In old UX, timeline is before the time / duration text.
+ if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
+ panel->appendChild(timeline.release());
+ // else we will attach it later.
RefPtrWillBeRawPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaControlCurrentTimeDisplayElement::create(*this);
m_currentTimeDisplay = currentTimeDisplay.get();
- m_currentTimeDisplay->hide();
+ if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
+ m_currentTimeDisplay->hide();
+
panel->appendChild(currentTimeDisplay.release());
RefPtrWillBeRawPtr<MediaControlTimeRemainingDisplayElement> durationDisplay = MediaControlTimeRemainingDisplayElement::create(*this);
m_durationDisplay = durationDisplay.get();
panel->appendChild(durationDisplay.release());
+ // In new UX, timeline is after the time / duration text.
+ if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
+ panel->appendChild(timeline.release());
+
RefPtrWillBeRawPtr<MediaControlMuteButtonElement> muteButton = MediaControlMuteButtonElement::create(*this);
m_muteButton = muteButton.get();
panel->appendChild(muteButton.release());
+#if OS(ANDROID)
DaleCurtis 2015/06/11 00:54:29 Seems like this should be more a function of viewp
liberato (no reviews please) 2015/06/11 01:06:52 it's part of the spec -- hide this on android, sin
+ if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
+ m_muteButton->hide();
+#endif
RefPtrWillBeRawPtr<MediaControlVolumeSliderElement> slider = MediaControlVolumeSliderElement::create(*this);
m_volumeSlider = slider.get();
panel->appendChild(slider.release());
+#if OS(ANDROID)
+ if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
+ m_volumeSlider->hide();
+#endif
RefPtrWillBeRawPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(*this);
m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get();
@@ -169,6 +186,17 @@ void MediaControls::reset()
m_durationDisplay->setInnerText(LayoutTheme::theme().formatMediaControlsTime(duration), ASSERT_NO_EXCEPTION);
m_durationDisplay->setCurrentValue(duration);
+ if (RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) {
+ // Show everything that we might hide.
+ // If we don't have a duration, then hide it.
+ if (std::isfinite(duration))
+ m_durationDisplay->show();
+ else
+ m_durationDisplay->hide();
+ m_currentTimeDisplay->show();
+ m_timeline->show();
+ }
+
updatePlayState();
updateCurrentTimeDisplay();
@@ -176,10 +204,19 @@ void MediaControls::reset()
m_timeline->setDuration(duration);
m_timeline->setPosition(mediaElement().currentTime());
- if (!mediaElement().hasAudio())
+ if (!mediaElement().hasAudio()) {
m_volumeSlider->hide();
- else
+ } else {
+#if OS(ANDROID)
+ // New UI always hides the volume slider on Android.
+ if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
+ m_volumeSlider->show();
+ else
+ m_volumeSlider->hide();
+#else
m_volumeSlider->show();
+#endif
+ }
updateVolume();
refreshClosedCaptionsButtonVisibility();
@@ -190,6 +227,7 @@ void MediaControls::reset()
m_fullScreenButton->hide();
refreshCastButtonVisibility();
+ hideControlsForSpace();
makeOpaque();
}
@@ -257,8 +295,10 @@ bool MediaControls::shouldHideMediaControls(unsigned behaviorFlags) const
void MediaControls::playbackStarted()
{
- m_currentTimeDisplay->show();
- m_durationDisplay->hide();
+ if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled()) {
+ m_currentTimeDisplay->show();
+ m_durationDisplay->hide();
+ }
updatePlayState();
m_timeline->setPosition(mediaElement().currentTime());
@@ -319,7 +359,7 @@ void MediaControls::updateCurrentTimeDisplay()
double duration = mediaElement().duration();
// After seek, hide duration display and show current time.
- if (now > 0) {
+ if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled() && now > 0) {
m_currentTimeDisplay->show();
m_durationDisplay->hide();
}
@@ -399,6 +439,8 @@ void MediaControls::refreshCastButtonVisibility()
m_castButton->hide();
m_overlayCastButton->hide();
}
+
+ hideControlsForSpace();
}
void MediaControls::showOverlayCastButton()
@@ -519,6 +561,48 @@ bool MediaControls::containsRelatedTarget(Event* event)
return contains(relatedTarget->toNode());
}
+void MediaControls::hideControlsForSpace()
+{
+ // Hide all controls that don't fit.
+ // The order, in order of decreasing droppiness:
+ // Volume, time, seek bar, cast.
+
+ // In the old UI, don't do this.
+ if (!RuntimeEnabledFeatures::newMediaPlaybackUiEnabled())
+ return;
+
+ int panelWidth = m_panel->clientWidth();
+ if (panelWidth == 0)
+ return;
+
+ // we should just memorize the requirements of each.
+ // cases: Vol Time Slider Cast
+ // Time Slider Cast
+ // Vol Time Slider
+ // Time Slider
+
+ // The cast button is the only variable. If it's shown, then subtract it
+ // from the available space. Note that because we don't re-show the other
+ // controls, this is stable.
+ if (m_castButton->isShown())
+ panelWidth -= 48;
+
+ // TODO(liberato): get confirmation from spec on these values.
+ if (panelWidth < 350)
+ m_volumeSlider->hide();
+
+ if (panelWidth < 300) {
+ m_currentTimeDisplay->hide();
+ m_durationDisplay->hide();
+ }
+
+ if (panelWidth < 200)
+ m_timeline->hide();
+
+ if (panelWidth < 150)
+ m_castButton->hide();
+}
+
DEFINE_TRACE(MediaControls)
{
visitor->trace(m_mediaElement);

Powered by Google App Engine
This is Rietveld 408576698