This source file includes following definitions.
- m_transitionTimer
- create
- shadowPseudoId
- defaultEventHandler
- startTimer
- stopTimer
- transitionTimerFired
- makeOpaque
- makeTransparent
- setIsDisplayed
- create
- shadowPseudoId
- create
- shadowPseudoId
- create
- defaultEventHandler
- updateDisplayType
- shadowPseudoId
- create
- defaultEventHandler
- updateDisplayType
- shadowPseudoId
- create
- updateDisplayType
- shadowPseudoId
- create
- updateDisplayType
- defaultEventHandler
- shadowPseudoId
- create
- defaultEventHandler
- willRespondToMouseClickEvents
- setPosition
- setDuration
- shadowPseudoId
- create
- defaultEventHandler
- willRespondToMouseMoveEvents
- willRespondToMouseClickEvents
- setVolume
- shadowPseudoId
- create
- defaultEventHandler
- shadowPseudoId
- setIsFullscreen
- create
- getMediaControlTimeRemainingDisplayElementShadowPseudoId
- shadowPseudoId
- create
- getMediaControlCurrentTimeDisplayElementShadowPseudoId
- shadowPseudoId
- m_fontSize
- create
- createRenderer
- textTrackContainerElementShadowPseudoId
- shadowPseudoId
- updateDisplay
- updateSizes
#include "config.h"
#include "core/html/shadow/MediaControlElements.h"
#include "RuntimeEnabledFeatures.h"
#include "bindings/v8/ExceptionStatePlaceholder.h"
#include "core/dom/DOMTokenList.h"
#include "core/dom/FullscreenElementStack.h"
#include "core/dom/shadow/ShadowRoot.h"
#include "core/events/MouseEvent.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLVideoElement.h"
#include "core/html/MediaController.h"
#include "core/html/shadow/MediaControls.h"
#include "core/html/track/TextTrack.h"
#include "core/html/track/vtt/VTTRegionList.h"
#include "core/page/EventHandler.h"
#include "core/rendering/RenderMediaControlElements.h"
#include "core/rendering/RenderSlider.h"
#include "core/rendering/RenderTheme.h"
#include "core/rendering/RenderVideo.h"
namespace WebCore {
using namespace HTMLNames;
static const AtomicString& getMediaControlCurrentTimeDisplayElementShadowPseudoId();
static const AtomicString& getMediaControlTimeRemainingDisplayElementShadowPseudoId();
static const double fadeInDuration = 0.1;
static const double fadeOutDuration = 0.3;
MediaControlPanelElement::MediaControlPanelElement(MediaControls& mediaControls)
: MediaControlDivElement(mediaControls, MediaControlsPanel)
, m_isDisplayed(false)
, m_opaque(true)
, m_transitionTimer(this, &MediaControlPanelElement::transitionTimerFired)
{
}
PassRefPtr<MediaControlPanelElement> MediaControlPanelElement::create(MediaControls& mediaControls)
{
return adoptRef(new MediaControlPanelElement(mediaControls));
}
const AtomicString& MediaControlPanelElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-panel", AtomicString::ConstructFromLiteral));
return id;
}
void MediaControlPanelElement::defaultEventHandler(Event* event)
{
if (event->type() == EventTypeNames::click) {
event->setDefaultHandled();
return;
}
HTMLDivElement::defaultEventHandler(event);
}
void MediaControlPanelElement::startTimer()
{
stopTimer();
m_transitionTimer.startOneShot(fadeOutDuration, FROM_HERE);
}
void MediaControlPanelElement::stopTimer()
{
if (m_transitionTimer.isActive())
m_transitionTimer.stop();
}
void MediaControlPanelElement::transitionTimerFired(Timer<MediaControlPanelElement>*)
{
if (!m_opaque)
hide();
stopTimer();
}
void MediaControlPanelElement::makeOpaque()
{
if (m_opaque)
return;
setInlineStyleProperty(CSSPropertyTransitionProperty, CSSPropertyOpacity);
setInlineStyleProperty(CSSPropertyTransitionDuration, fadeInDuration, CSSPrimitiveValue::CSS_S);
setInlineStyleProperty(CSSPropertyOpacity, 1.0, CSSPrimitiveValue::CSS_NUMBER);
m_opaque = true;
if (m_isDisplayed)
show();
}
void MediaControlPanelElement::makeTransparent()
{
if (!m_opaque)
return;
setInlineStyleProperty(CSSPropertyTransitionProperty, CSSPropertyOpacity);
setInlineStyleProperty(CSSPropertyTransitionDuration, fadeOutDuration, CSSPrimitiveValue::CSS_S);
setInlineStyleProperty(CSSPropertyOpacity, 0.0, CSSPrimitiveValue::CSS_NUMBER);
m_opaque = false;
startTimer();
}
void MediaControlPanelElement::setIsDisplayed(bool isDisplayed)
{
m_isDisplayed = isDisplayed;
}
MediaControlPanelEnclosureElement::MediaControlPanelEnclosureElement(MediaControls& mediaControls)
: MediaControlDivElement(mediaControls, MediaControlsPanel)
{
}
PassRefPtr<MediaControlPanelEnclosureElement> MediaControlPanelEnclosureElement::create(MediaControls& mediaControls)
{
return adoptRef(new MediaControlPanelEnclosureElement(mediaControls));
}
const AtomicString& MediaControlPanelEnclosureElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-enclosure", AtomicString::ConstructFromLiteral));
return id;
}
MediaControlOverlayEnclosureElement::MediaControlOverlayEnclosureElement(MediaControls& mediaControls)
: MediaControlDivElement(mediaControls, MediaControlsPanel)
{
}
PassRefPtr<MediaControlOverlayEnclosureElement> MediaControlOverlayEnclosureElement::create(MediaControls& mediaControls)
{
return adoptRef(new MediaControlOverlayEnclosureElement(mediaControls));
}
const AtomicString& MediaControlOverlayEnclosureElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-overlay-enclosure", AtomicString::ConstructFromLiteral));
return id;
}
MediaControlMuteButtonElement::MediaControlMuteButtonElement(MediaControls& mediaControls)
: MediaControlInputElement(mediaControls, MediaMuteButton)
{
}
PassRefPtr<MediaControlMuteButtonElement> MediaControlMuteButtonElement::create(MediaControls& mediaControls)
{
RefPtr<MediaControlMuteButtonElement> button = adoptRef(new MediaControlMuteButtonElement(mediaControls));
button->ensureUserAgentShadowRoot();
button->setType("button");
return button.release();
}
void MediaControlMuteButtonElement::defaultEventHandler(Event* event)
{
if (event->type() == EventTypeNames::click) {
mediaElement().setMuted(!mediaElement().muted());
event->setDefaultHandled();
}
HTMLInputElement::defaultEventHandler(event);
}
void MediaControlMuteButtonElement::updateDisplayType()
{
setDisplayType(mediaElement().muted() ? MediaUnMuteButton : MediaMuteButton);
}
const AtomicString& MediaControlMuteButtonElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-mute-button", AtomicString::ConstructFromLiteral));
return id;
}
MediaControlPlayButtonElement::MediaControlPlayButtonElement(MediaControls& mediaControls)
: MediaControlInputElement(mediaControls, MediaPlayButton)
{
}
PassRefPtr<MediaControlPlayButtonElement> MediaControlPlayButtonElement::create(MediaControls& mediaControls)
{
RefPtr<MediaControlPlayButtonElement> button = adoptRef(new MediaControlPlayButtonElement(mediaControls));
button->ensureUserAgentShadowRoot();
button->setType("button");
return button.release();
}
void MediaControlPlayButtonElement::defaultEventHandler(Event* event)
{
if (event->type() == EventTypeNames::click) {
mediaElement().togglePlayState();
updateDisplayType();
event->setDefaultHandled();
}
HTMLInputElement::defaultEventHandler(event);
}
void MediaControlPlayButtonElement::updateDisplayType()
{
setDisplayType(mediaElement().togglePlayStateWillPlay() ? MediaPlayButton : MediaPauseButton);
}
const AtomicString& MediaControlPlayButtonElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-play-button", AtomicString::ConstructFromLiteral));
return id;
}
MediaControlOverlayPlayButtonElement::MediaControlOverlayPlayButtonElement(MediaControls& mediaControls)
: MediaControlInputElement(mediaControls, MediaOverlayPlayButton)
{
}
PassRefPtr<MediaControlOverlayPlayButtonElement> MediaControlOverlayPlayButtonElement::create(MediaControls& mediaControls)
{
RefPtr<MediaControlOverlayPlayButtonElement> button = adoptRef(new MediaControlOverlayPlayButtonElement(mediaControls));
button->ensureUserAgentShadowRoot();
button->setType("button");
return button.release();
}
void MediaControlOverlayPlayButtonElement::updateDisplayType()
{
if (mediaElement().togglePlayStateWillPlay()) {
show();
} else
hide();
}
const AtomicString& MediaControlOverlayPlayButtonElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-overlay-play-button", AtomicString::ConstructFromLiteral));
return id;
}
MediaControlToggleClosedCaptionsButtonElement::MediaControlToggleClosedCaptionsButtonElement(MediaControls& mediaControls)
: MediaControlInputElement(mediaControls, MediaShowClosedCaptionsButton)
{
}
PassRefPtr<MediaControlToggleClosedCaptionsButtonElement> MediaControlToggleClosedCaptionsButtonElement::create(MediaControls& mediaControls)
{
RefPtr<MediaControlToggleClosedCaptionsButtonElement> button = adoptRef(new MediaControlToggleClosedCaptionsButtonElement(mediaControls));
button->ensureUserAgentShadowRoot();
button->setType("button");
button->hide();
return button.release();
}
void MediaControlToggleClosedCaptionsButtonElement::updateDisplayType()
{
bool captionsVisible = mediaElement().closedCaptionsVisible();
setDisplayType(captionsVisible ? MediaHideClosedCaptionsButton : MediaShowClosedCaptionsButton);
setChecked(captionsVisible);
}
void MediaControlToggleClosedCaptionsButtonElement::defaultEventHandler(Event* event)
{
if (event->type() == EventTypeNames::click) {
mediaElement().setClosedCaptionsVisible(!mediaElement().closedCaptionsVisible());
setChecked(mediaElement().closedCaptionsVisible());
updateDisplayType();
event->setDefaultHandled();
}
HTMLInputElement::defaultEventHandler(event);
}
const AtomicString& MediaControlToggleClosedCaptionsButtonElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-toggle-closed-captions-button", AtomicString::ConstructFromLiteral));
return id;
}
MediaControlTimelineElement::MediaControlTimelineElement(MediaControls& mediaControls)
: MediaControlInputElement(mediaControls, MediaSlider)
{
}
PassRefPtr<MediaControlTimelineElement> MediaControlTimelineElement::create(MediaControls& mediaControls)
{
RefPtr<MediaControlTimelineElement> timeline = adoptRef(new MediaControlTimelineElement(mediaControls));
timeline->ensureUserAgentShadowRoot();
timeline->setType("range");
timeline->setAttribute(stepAttr, "any");
return timeline.release();
}
void MediaControlTimelineElement::defaultEventHandler(Event* event)
{
if (event->isMouseEvent() && toMouseEvent(event)->button() != LeftButton)
return;
if (!inDocument() || !document().isActive())
return;
if (event->type() == EventTypeNames::mousedown)
mediaControls().beginScrubbing();
if (event->type() == EventTypeNames::mouseup)
mediaControls().endScrubbing();
MediaControlInputElement::defaultEventHandler(event);
if (event->type() == EventTypeNames::mouseover || event->type() == EventTypeNames::mouseout || event->type() == EventTypeNames::mousemove)
return;
double time = value().toDouble();
if (event->type() == EventTypeNames::input) {
if (mediaElement().controller())
mediaElement().controller()->setCurrentTime(time, IGNORE_EXCEPTION);
else
mediaElement().setCurrentTime(time, IGNORE_EXCEPTION);
}
RenderSlider* slider = toRenderSlider(renderer());
if (slider && slider->inDragMode())
mediaControls().updateCurrentTimeDisplay();
}
bool MediaControlTimelineElement::willRespondToMouseClickEvents()
{
return inDocument() && document().isActive();
}
void MediaControlTimelineElement::setPosition(double currentTime)
{
setValue(String::number(currentTime));
}
void MediaControlTimelineElement::setDuration(double duration)
{
setFloatingPointAttribute(maxAttr, std::isfinite(duration) ? duration : 0);
}
const AtomicString& MediaControlTimelineElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-timeline", AtomicString::ConstructFromLiteral));
return id;
}
MediaControlVolumeSliderElement::MediaControlVolumeSliderElement(MediaControls& mediaControls)
: MediaControlInputElement(mediaControls, MediaVolumeSlider)
{
}
PassRefPtr<MediaControlVolumeSliderElement> MediaControlVolumeSliderElement::create(MediaControls& mediaControls)
{
RefPtr<MediaControlVolumeSliderElement> slider = adoptRef(new MediaControlVolumeSliderElement(mediaControls));
slider->ensureUserAgentShadowRoot();
slider->setType("range");
slider->setAttribute(stepAttr, "any");
slider->setAttribute(maxAttr, "1");
return slider.release();
}
void MediaControlVolumeSliderElement::defaultEventHandler(Event* event)
{
if (event->isMouseEvent() && toMouseEvent(event)->button() != LeftButton)
return;
if (!inDocument() || !document().isActive())
return;
MediaControlInputElement::defaultEventHandler(event);
if (event->type() == EventTypeNames::mouseover || event->type() == EventTypeNames::mouseout || event->type() == EventTypeNames::mousemove)
return;
double volume = value().toDouble();
mediaElement().setVolume(volume, ASSERT_NO_EXCEPTION);
mediaElement().setMuted(false);
}
bool MediaControlVolumeSliderElement::willRespondToMouseMoveEvents()
{
if (!inDocument() || !document().isActive())
return false;
return MediaControlInputElement::willRespondToMouseMoveEvents();
}
bool MediaControlVolumeSliderElement::willRespondToMouseClickEvents()
{
if (!inDocument() || !document().isActive())
return false;
return MediaControlInputElement::willRespondToMouseClickEvents();
}
void MediaControlVolumeSliderElement::setVolume(double volume)
{
if (value().toDouble() != volume)
setValue(String::number(volume));
}
const AtomicString& MediaControlVolumeSliderElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-volume-slider", AtomicString::ConstructFromLiteral));
return id;
}
MediaControlFullscreenButtonElement::MediaControlFullscreenButtonElement(MediaControls& mediaControls)
: MediaControlInputElement(mediaControls, MediaEnterFullscreenButton)
{
}
PassRefPtr<MediaControlFullscreenButtonElement> MediaControlFullscreenButtonElement::create(MediaControls& mediaControls)
{
RefPtr<MediaControlFullscreenButtonElement> button = adoptRef(new MediaControlFullscreenButtonElement(mediaControls));
button->ensureUserAgentShadowRoot();
button->setType("button");
button->hide();
return button.release();
}
void MediaControlFullscreenButtonElement::defaultEventHandler(Event* event)
{
if (event->type() == EventTypeNames::click) {
if (FullscreenElementStack::isActiveFullScreenElement(&mediaElement()))
FullscreenElementStack::from(document()).webkitCancelFullScreen();
else
FullscreenElementStack::from(document()).requestFullScreenForElement(&mediaElement(), 0, FullscreenElementStack::ExemptIFrameAllowFullScreenRequirement);
event->setDefaultHandled();
}
HTMLInputElement::defaultEventHandler(event);
}
const AtomicString& MediaControlFullscreenButtonElement::shadowPseudoId() const
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-fullscreen-button", AtomicString::ConstructFromLiteral));
return id;
}
void MediaControlFullscreenButtonElement::setIsFullscreen(bool isFullscreen)
{
setDisplayType(isFullscreen ? MediaExitFullscreenButton : MediaEnterFullscreenButton);
}
MediaControlTimeRemainingDisplayElement::MediaControlTimeRemainingDisplayElement(MediaControls& mediaControls)
: MediaControlTimeDisplayElement(mediaControls, MediaTimeRemainingDisplay)
{
}
PassRefPtr<MediaControlTimeRemainingDisplayElement> MediaControlTimeRemainingDisplayElement::create(MediaControls& mediaControls)
{
return adoptRef(new MediaControlTimeRemainingDisplayElement(mediaControls));
}
static const AtomicString& getMediaControlTimeRemainingDisplayElementShadowPseudoId()
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-time-remaining-display", AtomicString::ConstructFromLiteral));
return id;
}
const AtomicString& MediaControlTimeRemainingDisplayElement::shadowPseudoId() const
{
return getMediaControlTimeRemainingDisplayElementShadowPseudoId();
}
MediaControlCurrentTimeDisplayElement::MediaControlCurrentTimeDisplayElement(MediaControls& mediaControls)
: MediaControlTimeDisplayElement(mediaControls, MediaCurrentTimeDisplay)
{
}
PassRefPtr<MediaControlCurrentTimeDisplayElement> MediaControlCurrentTimeDisplayElement::create(MediaControls& mediaControls)
{
return adoptRef(new MediaControlCurrentTimeDisplayElement(mediaControls));
}
static const AtomicString& getMediaControlCurrentTimeDisplayElementShadowPseudoId()
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-controls-current-time-display", AtomicString::ConstructFromLiteral));
return id;
}
const AtomicString& MediaControlCurrentTimeDisplayElement::shadowPseudoId() const
{
return getMediaControlCurrentTimeDisplayElementShadowPseudoId();
}
MediaControlTextTrackContainerElement::MediaControlTextTrackContainerElement(MediaControls& mediaControls)
: MediaControlDivElement(mediaControls, MediaTextTrackDisplayContainer)
, m_fontSize(0)
{
}
PassRefPtr<MediaControlTextTrackContainerElement> MediaControlTextTrackContainerElement::create(MediaControls& mediaControls)
{
RefPtr<MediaControlTextTrackContainerElement> element = adoptRef(new MediaControlTextTrackContainerElement(mediaControls));
element->hide();
return element.release();
}
RenderObject* MediaControlTextTrackContainerElement::createRenderer(RenderStyle*)
{
return new RenderTextTrackContainerElement(this);
}
const AtomicString& MediaControlTextTrackContainerElement::textTrackContainerElementShadowPseudoId()
{
DEFINE_STATIC_LOCAL(AtomicString, id, ("-webkit-media-text-track-container", AtomicString::ConstructFromLiteral));
return id;
}
const AtomicString& MediaControlTextTrackContainerElement::shadowPseudoId() const
{
return textTrackContainerElementShadowPseudoId();
}
void MediaControlTextTrackContainerElement::updateDisplay()
{
if (!mediaElement().closedCaptionsVisible()) {
removeChildren();
return;
}
if (isHTMLAudioElement(mediaElement()))
return;
HTMLVideoElement& video = toHTMLVideoElement(mediaElement());
Vector<RefPtr<HTMLDivElement> > output;
CueList activeCues = video.currentlyActiveCues();
for (size_t i = 0; i < activeCues.size(); ++i) {
TextTrackCue* cue = activeCues[i].data();
ASSERT(cue->isActive());
if (!cue->track() || !cue->track()->isRendered() || !cue->isActive())
continue;
cue->updateDisplay(m_videoDisplaySize.size(), *this);
}
if (hasChildren())
show();
else
hide();
}
void MediaControlTextTrackContainerElement::updateSizes()
{
if (!document().isActive())
return;
IntRect videoBox;
if (!mediaElement().renderer() || !mediaElement().renderer()->isVideo())
return;
videoBox = toRenderVideo(mediaElement().renderer())->videoBox();
if (m_videoDisplaySize == videoBox)
return;
m_videoDisplaySize = videoBox;
float smallestDimension = std::min(m_videoDisplaySize.size().height(), m_videoDisplaySize.size().width());
float fontSize = smallestDimension * 0.05f;
if (fontSize != m_fontSize) {
m_fontSize = fontSize;
setInlineStyleProperty(CSSPropertyFontSize, fontSize, CSSPrimitiveValue::CSS_PX);
}
}
}