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

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

Issue 158333002: Merge MediaControlsChromium into MediaControls (2nd try) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: if OS(ANDRIOD) Created 6 years, 10 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
« no previous file with comments | « Source/core/html/shadow/MediaControls.h ('k') | Source/core/html/shadow/MediaControlsChromium.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/shadow/MediaControls.cpp
diff --git a/Source/core/html/shadow/MediaControls.cpp b/Source/core/html/shadow/MediaControls.cpp
index 357fea5dc236a61567265ad378edc17958dd7426..61661b4d7371a713d68069a8c8380e38e8d76d57 100644
--- a/Source/core/html/shadow/MediaControls.cpp
+++ b/Source/core/html/shadow/MediaControls.cpp
@@ -28,6 +28,9 @@
#include "core/html/shadow/MediaControls.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
+#if OS(ANDROID)
+#include "core/html/shadow/MediaControlsChromiumAndroid.h"
+#endif
namespace WebCore {
@@ -48,9 +51,101 @@ MediaControls::MediaControls(Document& document)
, m_hideFullscreenControlsTimer(this, &MediaControls::hideFullscreenControlsTimerFired)
, m_isFullscreen(false)
, m_isMouseOverControls(false)
+ , m_durationDisplay(0)
+ , m_enclosure(0)
{
}
+PassRefPtr<MediaControls> MediaControls::create(Document& document)
+{
+ if (!document.page())
+ return 0;
+
+ RefPtr<MediaControls> controls;
+#if OS(ANDROID)
+ controls = adoptRef(new MediaControlsChromiumAndroid(document));
+#else
+ controls = adoptRef(new MediaControls(document));
+#endif
+
+ if (controls->initializeControls(document))
+ return controls.release();
+
+ return 0;
+}
+
+bool MediaControls::initializeControls(Document& document)
+{
+ // Create an enclosing element for the panel so we can visually offset the controls correctly.
+ RefPtr<MediaControlPanelEnclosureElement> enclosure = MediaControlPanelEnclosureElement::create(document);
+
+ RefPtr<MediaControlPanelElement> panel = MediaControlPanelElement::create(document);
+
+ TrackExceptionState exceptionState;
+
+ RefPtr<MediaControlPlayButtonElement> playButton = MediaControlPlayButtonElement::create(document);
+ m_playButton = playButton.get();
+ panel->appendChild(playButton.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ RefPtr<MediaControlTimelineElement> timeline = MediaControlTimelineElement::create(document, this);
+ m_timeline = timeline.get();
+ panel->appendChild(timeline.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ RefPtr<MediaControlCurrentTimeDisplayElement> currentTimeDisplay = MediaControlCurrentTimeDisplayElement::create(document);
+ m_currentTimeDisplay = currentTimeDisplay.get();
+ m_currentTimeDisplay->hide();
+ panel->appendChild(currentTimeDisplay.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ RefPtr<MediaControlTimeRemainingDisplayElement> durationDisplay = MediaControlTimeRemainingDisplayElement::create(document);
+ m_durationDisplay = durationDisplay.get();
+ panel->appendChild(durationDisplay.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ RefPtr<MediaControlPanelMuteButtonElement> panelMuteButton = MediaControlPanelMuteButtonElement::create(document, this);
+ m_panelMuteButton = panelMuteButton.get();
+ panel->appendChild(panelMuteButton.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ RefPtr<MediaControlPanelVolumeSliderElement> slider = MediaControlPanelVolumeSliderElement::create(document);
+ m_volumeSlider = slider.get();
+ m_volumeSlider->setClearMutedOnUserInteraction(true);
+ panel->appendChild(slider.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ RefPtr<MediaControlToggleClosedCaptionsButtonElement> toggleClosedCaptionsButton = MediaControlToggleClosedCaptionsButtonElement::create(document, this);
+ m_toggleClosedCaptionsButton = toggleClosedCaptionsButton.get();
+ panel->appendChild(toggleClosedCaptionsButton.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ RefPtr<MediaControlFullscreenButtonElement> fullscreenButton = MediaControlFullscreenButtonElement::create(document);
+ m_fullScreenButton = fullscreenButton.get();
+ panel->appendChild(fullscreenButton.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ m_panel = panel.get();
+ enclosure->appendChild(panel.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ m_enclosure = enclosure.get();
+ appendChild(enclosure.release(), exceptionState);
+ if (exceptionState.hadException())
+ return false;
+
+ return true;
+}
+
void MediaControls::setMediaController(MediaControllerInterface* controller)
{
if (m_mediaController == controller)
@@ -75,6 +170,10 @@ void MediaControls::setMediaController(MediaControllerInterface* controller)
m_toggleClosedCaptionsButton->setMediaController(controller);
if (m_fullScreenButton)
m_fullScreenButton->setMediaController(controller);
+ if (m_durationDisplay)
+ m_durationDisplay->setMediaController(controller);
+ if (m_enclosure)
+ m_enclosure->setMediaController(controller);
}
void MediaControls::reset()
@@ -83,6 +182,10 @@ void MediaControls::reset()
if (!page)
return;
+ double duration = m_mediaController->duration();
+ m_durationDisplay->setInnerText(RenderTheme::theme().formatMediaControlsTime(duration), ASSERT_NO_EXCEPTION);
+ m_durationDisplay->setCurrentValue(duration);
+
m_playButton->updateDisplayType();
updateCurrentTimeDisplay();
@@ -151,6 +254,9 @@ void MediaControls::bufferingProgressed()
void MediaControls::playbackStarted()
{
+ m_currentTimeDisplay->show();
+ m_durationDisplay->hide();
+
m_playButton->updateDisplayType();
m_timeline->setPosition(m_mediaController->currentTime());
updateCurrentTimeDisplay();
@@ -178,6 +284,26 @@ void MediaControls::playbackStopped()
stopHideFullscreenControlsTimer();
}
+void MediaControls::updateCurrentTimeDisplay()
+{
+ double now = m_mediaController->currentTime();
+ double duration = m_mediaController->duration();
+
+ Page* page = document().page();
+ if (!page)
+ return;
+
+ // After seek, hide duration display and show current time.
+ if (now > 0) {
+ m_currentTimeDisplay->show();
+ m_durationDisplay->hide();
+ }
+
+ // Allow the theme to format the time.
+ m_currentTimeDisplay->setInnerText(RenderTheme::theme().formatMediaControlsCurrentTime(now, duration), IGNORE_EXCEPTION);
+ m_currentTimeDisplay->setCurrentValue(now);
+}
+
void MediaControls::showVolumeSlider()
{
if (!m_mediaController->hasAudio())
@@ -189,6 +315,11 @@ void MediaControls::showVolumeSlider()
void MediaControls::changedMute()
{
m_panelMuteButton->changedMute();
+
+ if (m_mediaController->muted())
+ m_volumeSlider->setVolume(0);
+ else
+ m_volumeSlider->setVolume(m_mediaController->volume());
}
void MediaControls::changedVolume()
@@ -329,8 +460,7 @@ void MediaControls::createTextTrackDisplay()
if (m_mediaController)
m_textDisplayContainer->setMediaController(m_mediaController);
- // Insert it before the first controller element so it always displays behind the controls.
- insertBefore(textDisplayContainer.release(), m_panel, IGNORE_EXCEPTION);
+ insertTextTrackContainer(textDisplayContainer.release());
}
void MediaControls::showTextTrackDisplay()
@@ -355,4 +485,10 @@ void MediaControls::updateTextTrackDisplay()
m_textDisplayContainer->updateDisplay();
}
+void MediaControls::insertTextTrackContainer(PassRefPtr<MediaControlTextTrackContainerElement> textTrackContainer)
+{
+ // Insert it before the first controller element so it always displays behind the controls.
+ insertBefore(textTrackContainer, m_enclosure);
+}
+
}
« no previous file with comments | « Source/core/html/shadow/MediaControls.h ('k') | Source/core/html/shadow/MediaControlsChromium.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698