diff options
Diffstat (limited to 'WebCore/html/HTMLMediaElement.cpp')
-rw-r--r-- | WebCore/html/HTMLMediaElement.cpp | 134 |
1 files changed, 97 insertions, 37 deletions
diff --git a/WebCore/html/HTMLMediaElement.cpp b/WebCore/html/HTMLMediaElement.cpp index 729aceb..30f762a 100644 --- a/WebCore/html/HTMLMediaElement.cpp +++ b/WebCore/html/HTMLMediaElement.cpp @@ -117,6 +117,7 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* doc) , m_pausedInternal(false) , m_sendProgressEvents(true) , m_isFullscreen(false) + , m_closedCaptionsVisible(false) #if ENABLE(PLUGIN_PROXY_FOR_VIDEO) , m_needWidgetUpdate(false) #endif @@ -213,6 +214,10 @@ void HTMLMediaElement::parseMappedAttribute(MappedAttribute* attr) setAttributeEventListener(eventNames().volumechangeEvent, createAttributeEventListener(this, attr)); else if (attrName == onwaitingAttr) setAttributeEventListener(eventNames().waitingEvent, createAttributeEventListener(this, attr)); + else if (attrName == onwebkitbeginfullscreenAttr) + setAttributeEventListener(eventNames().webkitbeginfullscreenEvent, createAttributeEventListener(this, attr)); + else if (attrName == onwebkitendfullscreenAttr) + setAttributeEventListener(eventNames().webkitendfullscreenEvent, createAttributeEventListener(this, attr)); else HTMLElement::parseMappedAttribute(attr); } @@ -292,24 +297,6 @@ void HTMLMediaElement::scheduleNextSourceChild() m_loadTimer.startOneShot(0); } -void HTMLMediaElement::scheduleProgressEvent(const AtomicString& eventName) -{ - if (!m_sendProgressEvents) - return; - - // FIXME: don't schedule timeupdate or progress events unless there are registered listeners - - bool totalKnown = m_player && m_player->totalBytesKnown(); - unsigned loaded = m_player ? m_player->bytesLoaded() : 0; - unsigned total = m_player ? m_player->totalBytes() : 0; - - RefPtr<ProgressEvent> evt = ProgressEvent::create(eventName, totalKnown, loaded, total); - enqueueEvent(evt); - - if (renderer()) - renderer()->updateFromElement(); -} - void HTMLMediaElement::scheduleEvent(const AtomicString& eventName) { enqueueEvent(Event::create(eventName, false, true)); @@ -478,6 +465,7 @@ void HTMLMediaElement::loadInternal() m_autoplaying = true; m_playedTimeRanges = TimeRanges::create(); m_lastSeekTime = 0; + m_closedCaptionsVisible = false; // 6 setPlaybackRate(defaultPlaybackRate()); @@ -523,7 +511,7 @@ void HTMLMediaElement::selectMediaResource() m_networkState = NETWORK_LOADING; // 5 - scheduleProgressEvent(eventNames().loadstartEvent); + scheduleEvent(eventNames().loadstartEvent); // 6 - If the media element has a src attribute, then run these substeps ContentType contentType(""); @@ -582,11 +570,10 @@ void HTMLMediaElement::loadResource(const KURL& initialURL, ContentType& content startProgressEventTimer(); #if !ENABLE(PLUGIN_PROXY_FOR_VIDEO) - m_player.clear(); - m_player.set(new MediaPlayer(this)); + m_player = MediaPlayer::create(this); #else if (!m_player) - m_player.set(new MediaPlayer(this)); + m_player = MediaPlayer::create(this); #endif m_player->setPreservesPitch(m_webkitPreservesPitch); @@ -647,7 +634,7 @@ void HTMLMediaElement::noneSupported() // 7 - Queue a task to fire a progress event called error at the media element, in // the context of the fetching process that was used to try to obtain the media // resource in the resource fetch algorithm. - scheduleProgressEvent(eventNames().errorEvent); + scheduleEvent(eventNames().errorEvent); // 8 - Set the element's delaying-the-load-event flag to false. This stops delaying the load event. m_delayingTheLoadEvent = false; @@ -672,7 +659,7 @@ void HTMLMediaElement::mediaEngineError(PassRefPtr<MediaError> err) // 3 - Queue a task to fire a progress event called error at the media element, in // the context of the fetching process started by this instance of this algorithm. - scheduleProgressEvent(eventNames().errorEvent); + scheduleEvent(eventNames().errorEvent); // 4 - Set the element's networkState attribute to the NETWORK_EMPTY value and queue a // task to fire a simple event called emptied at the element. @@ -739,7 +726,7 @@ void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state) if (state == MediaPlayer::Idle) { if (m_networkState > NETWORK_IDLE) { stopPeriodicTimers(); - scheduleProgressEvent(eventNames().suspendEvent); + scheduleEvent(eventNames().suspendEvent); } m_networkState = NETWORK_IDLE; } @@ -759,7 +746,7 @@ void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state) // Schedule one last progress event so we guarantee that at least one is fired // for files that load very quickly. - scheduleProgressEvent(eventNames().progressEvent); + scheduleEvent(eventNames().progressEvent); // Check to see if readyState changes need to be dealt with before sending the // 'load' event so we report 'canplaythrough' first. This is necessary because a @@ -768,7 +755,7 @@ void HTMLMediaElement::setNetworkState(MediaPlayer::NetworkState state) if (static_cast<ReadyState>(currentState) != m_readyState) setReadyState(currentState); - scheduleProgressEvent(eventNames().loadEvent); + scheduleEvent(eventNames().loadEvent); } } } @@ -885,14 +872,16 @@ void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*) if (progress == m_previousProgress) { if (timedelta > 3.0 && !m_sentStalledEvent) { - scheduleProgressEvent(eventNames().stalledEvent); + scheduleEvent(eventNames().stalledEvent); m_sentStalledEvent = true; } } else { - scheduleProgressEvent(eventNames().progressEvent); + scheduleEvent(eventNames().progressEvent); m_previousProgress = progress; m_previousProgressTime = time; m_sentStalledEvent = false; + if (renderer()) + renderer()->updateFromElement(); } } @@ -1652,7 +1641,7 @@ void HTMLMediaElement::userCancelledLoad() // 3 - Queue a task to fire a progress event called abort at the media element, in the context // of the fetching process started by this instance of this algorithm. - scheduleProgressEvent(eventNames().abortEvent); + scheduleEvent(eventNames().abortEvent); // 5 - If the media element's readyState attribute has a value equal to HAVE_NOTHING, set the // element's networkState attribute to the NETWORK_EMPTY value and queue a task to fire a @@ -1784,7 +1773,7 @@ void HTMLMediaElement::finishParsingChildren() { HTMLElement::finishParsingChildren(); if (!m_player) - m_player.set(new MediaPlayer(this)); + m_player = MediaPlayer::create(this); document()->updateStyleIfNeeded(); if (m_needWidgetUpdate && renderer()) @@ -1796,25 +1785,96 @@ void HTMLMediaElement::finishParsingChildren() void HTMLMediaElement::enterFullscreen() { ASSERT(!m_isFullscreen); - if (!renderer()) - return; - if (document() && document()->page()) + if (document() && document()->page()) { document()->page()->chrome()->client()->enterFullscreenForNode(this); - m_isFullscreen = true; + scheduleEvent(eventNames().webkitbeginfullscreenEvent); + m_isFullscreen = true; + } } void HTMLMediaElement::exitFullscreen() { ASSERT(m_isFullscreen); - if (document() && document()->page()) + if (document() && document()->page()) { document()->page()->chrome()->client()->exitFullscreenForNode(this); + scheduleEvent(eventNames().webkitendfullscreenEvent); + } m_isFullscreen = false; } PlatformMedia HTMLMediaElement::platformMedia() const { return m_player ? m_player->platformMedia() : NoPlatformMedia; -} +} + +void HTMLMediaElement::webkitEnterFullScreen(ExceptionCode& ec) +{ + if (m_isFullscreen) + return; + + // Generate an exception if this isn't called in response to a user gesture, or if the + // element does not support fullscreen. + if (!processingUserGesture() || !supportsFullscreen()) { + ec = INVALID_STATE_ERR; + return; + } + + enterFullscreen(); +} + +void HTMLMediaElement::webkitExitFullScreen() +{ + if (m_isFullscreen) + exitFullscreen(); +} + +bool HTMLMediaElement::webkitSupportsFullscreen() +{ + return supportsFullscreen(); +} + +bool HTMLMediaElement::webkitDisplayingFullscreen() +{ + return m_isFullscreen; +} + +bool HTMLMediaElement::hasClosedCaptions() const +{ + return m_player && m_player->hasClosedCaptions(); +} + +bool HTMLMediaElement::closedCaptionsVisible() const +{ + return m_closedCaptionsVisible; +} + +void HTMLMediaElement::setClosedCaptionsVisible(bool closedCaptionVisible) +{ + if (!m_player ||!hasClosedCaptions()) + return; + + m_closedCaptionsVisible = closedCaptionVisible; + m_player->setClosedCaptionsVisible(closedCaptionVisible); + if (renderer()) + renderer()->updateFromElement(); +} + +void HTMLMediaElement::setWebkitClosedCaptionsVisible(bool visible) +{ + setClosedCaptionsVisible(visible); +} + +bool HTMLMediaElement::webkitClosedCaptionsVisible() const +{ + return closedCaptionsVisible(); +} + + +bool HTMLMediaElement::webkitHasClosedCaptions() const +{ + return hasClosedCaptions(); +} + } #endif |