2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "HTMLMediaElement.h"
31 #include "csshelper.h"
32 #include "CSSPropertyNames.h"
33 #include "CSSValueKeywords.h"
34 #include "EventNames.h"
35 #include "ExceptionCode.h"
36 #include "HTMLDocument.h"
37 #include "HTMLNames.h"
38 #include "HTMLSourceElement.h"
39 #include "HTMLVideoElement.h"
41 #include "MediaError.h"
42 #include "MediaList.h"
43 #include "MediaQueryEvaluator.h"
44 #include "MIMETypeRegistry.h"
46 #include "RenderVideo.h"
47 #include "SystemTime.h"
48 #include "TimeRanges.h"
49 #include "VoidCallback.h"
55 using namespace EventNames;
56 using namespace HTMLNames;
58 HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* doc)
59 : HTMLElement(tagName, doc)
60 , m_loadTimer(this, &HTMLMediaElement::loadTimerFired)
61 , m_asyncEventTimer(this, &HTMLMediaElement::asyncEventTimerFired)
62 , m_progressEventTimer(this, &HTMLMediaElement::progressEventTimerFired)
63 , m_defaultPlaybackRate(1.0f)
64 , m_networkState(EMPTY)
65 , m_readyState(DATA_UNAVAILABLE)
67 , m_loadedFirstFrame(false)
69 , m_wasPlayingBeforeMovingToPageCache(false)
73 , m_previousProgress(0)
74 , m_previousProgressTime(numeric_limits<double>::max())
75 , m_sentStalledEvent(false)
77 , m_loadNestingLevel(0)
78 , m_terminateLoadBelowNestingLevel(0)
81 document()->registerForCacheCallbacks(this);
84 HTMLMediaElement::~HTMLMediaElement()
86 document()->unregisterForCacheCallbacks(this);
88 for (HashMap<float, CallbackVector*>::iterator it = m_cuePoints.begin(); it != m_cuePoints.end(); ++it)
92 bool HTMLMediaElement::checkDTD(const Node* newChild)
94 return newChild->hasTagName(sourceTag) || HTMLElement::checkDTD(newChild);
97 void HTMLMediaElement::attributeChanged(Attribute* attr, bool preserveDecls)
99 HTMLElement::attributeChanged(attr, preserveDecls);
101 const QualifiedName& attrName = attr->name();
102 if (attrName == srcAttr) {
104 // change to src attribute triggers load()
105 if (inDocument() && m_networkState == EMPTY)
110 void HTMLMediaElement::insertedIntoDocument()
112 HTMLElement::insertedIntoDocument();
113 if (!src().isEmpty())
117 void HTMLMediaElement::removedFromDocument()
121 HTMLElement::removedFromDocument();
124 void HTMLMediaElement::scheduleLoad()
126 m_loadTimer.startOneShot(0);
129 void HTMLMediaElement::initAndDispatchProgressEvent(const AtomicString& eventName)
131 bool totalKnown = m_movie && m_movie->totalBytesKnown();
132 unsigned loaded = m_movie ? m_movie->bytesLoaded() : 0;
133 unsigned total = m_movie ? m_movie->totalBytes() : 0;
134 dispatchProgressEvent(eventName, totalKnown, loaded, total);
137 void HTMLMediaElement::dispatchEventAsync(const AtomicString& eventName)
139 m_asyncEventsToDispatch.add(eventName);
140 if (!m_asyncEventTimer.isActive())
141 m_asyncEventTimer.startOneShot(0);
144 void HTMLMediaElement::loadTimerFired(Timer<HTMLMediaElement>*)
150 void HTMLMediaElement::asyncEventTimerFired(Timer<HTMLMediaElement>*)
152 HashSet<String>::const_iterator end = m_asyncEventsToDispatch.end();
153 for (HashSet<String>::const_iterator it = m_asyncEventsToDispatch.begin(); it != end; ++it)
154 dispatchHTMLEvent(*it, false, true);
155 m_asyncEventsToDispatch.clear();
158 String serializeTimeOffset(float time)
160 String timeString = String::number(time);
161 // FIXME serialize time offset values properly (format not specified yet)
162 timeString.append("s");
166 float parseTimeOffset(String timeString, bool* ok = 0)
168 if (timeString.endsWith("s"))
169 timeString = timeString.left(timeString.length() - 1);
170 // FIXME parse time offset values (format not specified yet)
171 float val = (float)timeString.toDouble(ok);
175 float HTMLMediaElement::getTimeOffsetAttribute(const QualifiedName& name, float valueOnError) const
178 String timeString = getAttribute(name);
179 float result = parseTimeOffset(timeString, &ok);
185 void HTMLMediaElement::setTimeOffsetAttribute(const QualifiedName& name, float value)
187 setAttribute(name, serializeTimeOffset(value));
190 PassRefPtr<MediaError> HTMLMediaElement::error() const
195 String HTMLMediaElement::src() const
197 return document()->completeURL(getAttribute(srcAttr));
200 void HTMLMediaElement::HTMLMediaElement::setSrc(const String& url)
202 setAttribute(srcAttr, url);
205 String HTMLMediaElement::currentSrc() const
210 HTMLMediaElement::NetworkState HTMLMediaElement::networkState() const
212 return m_networkState;
215 float HTMLMediaElement::bufferingRate()
219 return m_bufferingRate;
220 //return m_movie->dataRate();
223 void HTMLMediaElement::load(ExceptionCode& ec)
227 // 3.14.9.4. Loading the media resource
229 // if an event generated during load() ends up re-entering load(), terminate previous instances
230 m_loadNestingLevel++;
231 m_terminateLoadBelowNestingLevel = m_loadNestingLevel;
233 m_progressEventTimer.stop();
234 m_sentStalledEvent = false;
242 m_error = new MediaError(MediaError::MEDIA_ERR_ABORTED);
243 initAndDispatchProgressEvent(abortEvent);
244 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
250 m_loadedFirstFrame = false;
251 m_autoplaying = true;
254 setPlaybackRate(defaultPlaybackRate(), ec);
257 if (networkState() != EMPTY) {
258 m_networkState = EMPTY;
259 m_readyState = DATA_UNAVAILABLE;
265 dispatchHTMLEvent(emptiedEvent, false, true);
266 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
271 mediaSrc = pickMedia();
272 if (mediaSrc.isEmpty()) {
273 ec = INVALID_STATE_ERR;
278 m_networkState = LOADING;
281 m_currentSrc = mediaSrc;
285 dispatchProgressEvent(beginEvent, false, 0, 0); // progress event draft calls this loadstart
286 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
291 m_movie = new Movie(this);
292 m_movie->setVolume(m_volume);
293 m_movie->setMuted(m_muted);
294 for (HashMap<float, CallbackVector*>::iterator it = m_cuePoints.begin(); it != m_cuePoints.end(); ++it)
295 m_movie->addCuePoint(it->first);
296 m_movie->load(m_currentSrc);
297 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
301 renderer()->updateFromElement();
302 m_movie->setVisible(true);
306 m_previousProgressTime = WebCore::currentTime();
307 m_previousProgress = 0;
309 // 350ms is not magic, it is in the spec!
310 m_progressEventTimer.startRepeating(0.350);
312 ASSERT(m_loadNestingLevel);
313 m_loadNestingLevel--;
317 void HTMLMediaElement::movieNetworkStateChanged(Movie*)
319 if (!m_begun || m_networkState == EMPTY)
322 m_terminateLoadBelowNestingLevel = m_loadNestingLevel;
324 Movie::NetworkState state = m_movie->networkState();
326 // 3.14.9.4. Loading the media resource
328 if (state == Movie::LoadFailed) {
331 // FIXME better error handling
332 m_error = new MediaError(MediaError::MEDIA_ERR_NETWORK);
334 m_progressEventTimer.stop();
337 initAndDispatchProgressEvent(errorEvent);
338 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
341 m_networkState = EMPTY;
344 static_cast<HTMLVideoElement*>(this)->updatePosterImage();
346 dispatchHTMLEvent(emptiedEvent, false, true);
350 if (state >= Movie::Loading && m_networkState < LOADING)
351 m_networkState = LOADING;
353 if (state >= Movie::LoadedMetaData && m_networkState < LOADED_METADATA) {
354 m_movie->seek(effectiveStart());
355 m_movie->setEndTime(currentLoop() == loopCount() - 1 ? effectiveEnd() : effectiveLoopEnd());
356 m_networkState = LOADED_METADATA;
358 dispatchHTMLEvent(durationchangeEvent, false, true);
359 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
362 dispatchHTMLEvent(loadedmetadataEvent, false, true);
363 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
367 if (state >= Movie::LoadedFirstFrame && m_networkState < LOADED_FIRST_FRAME) {
368 m_networkState = LOADED_FIRST_FRAME;
370 setReadyState(CAN_SHOW_CURRENT_FRAME);
373 static_cast<HTMLVideoElement*>(this)->updatePosterImage();
375 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
378 m_loadedFirstFrame = true;
380 ASSERT(!renderer()->isImage());
381 static_cast<RenderVideo*>(renderer())->videoSizeChanged();
384 dispatchHTMLEvent(loadedfirstframeEvent, false, true);
385 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
388 dispatchHTMLEvent(canshowcurrentframeEvent, false, true);
389 if (m_loadNestingLevel < m_terminateLoadBelowNestingLevel)
394 if (state == Movie::Loaded && m_networkState < LOADED) {
396 m_networkState = LOADED;
397 m_progressEventTimer.stop();
399 initAndDispatchProgressEvent(loadEvent);
403 void HTMLMediaElement::movieReadyStateChanged(Movie*)
405 Movie::ReadyState state = m_movie->readyState();
406 setReadyState((ReadyState)state);
409 void HTMLMediaElement::setReadyState(ReadyState state)
411 // 3.14.9.6. The ready states
412 if (m_readyState == state)
415 bool wasActivelyPlaying = activelyPlaying();
416 m_readyState = state;
418 if (networkState() == EMPTY)
421 if (state == DATA_UNAVAILABLE) {
422 dispatchHTMLEvent(dataunavailableEvent, false, true);
423 if (wasActivelyPlaying) {
424 dispatchHTMLEvent(timeupdateEvent, false, true);
425 dispatchHTMLEvent(waitingEvent, false, true);
427 } else if (state == CAN_SHOW_CURRENT_FRAME) {
428 if (m_loadedFirstFrame)
429 dispatchHTMLEvent(canshowcurrentframeEvent, false, true);
430 if (wasActivelyPlaying) {
431 dispatchHTMLEvent(timeupdateEvent, false, true);
432 dispatchHTMLEvent(waitingEvent, false, true);
434 } else if (state == CAN_PLAY) {
435 dispatchHTMLEvent(canplayEvent, false, true);
436 } else if (state == CAN_PLAY_THROUGH) {
437 dispatchHTMLEvent(canplaythroughEvent, false, true);
438 if (m_autoplaying && paused() && autoplay()) {
440 dispatchHTMLEvent(playEvent, false, true);
445 void HTMLMediaElement::progressEventTimerFired(Timer<HTMLMediaElement>*)
448 unsigned progress = m_movie->bytesLoaded();
449 double time = WebCore::currentTime();
450 double timedelta = time - m_previousProgressTime;
452 m_bufferingRate = (float)(0.8 * m_bufferingRate + 0.2 * ((float)(progress - m_previousProgress)) / timedelta);
454 if (progress == m_previousProgress) {
455 if (timedelta > 3.0 && !m_sentStalledEvent) {
457 initAndDispatchProgressEvent(stalledEvent);
458 m_sentStalledEvent = true;
461 initAndDispatchProgressEvent(progressEvent);
462 m_previousProgress = progress;
463 m_previousProgressTime = time;
464 m_sentStalledEvent = false;
468 void HTMLMediaElement::seek(float time, ExceptionCode& ec)
472 if (networkState() < LOADED_METADATA) {
473 ec = INVALID_STATE_ERR;
479 if (currentLoop() == 0)
480 minTime = effectiveStart();
482 minTime = effectiveLoopStart();
485 float maxTime = currentLoop() == loopCount() - 1 ? effectiveEnd() : effectiveLoopEnd();
488 time = min(time, maxTime);
491 time = max(time, minTime);
494 RefPtr<TimeRanges> seekableRanges = seekable();
495 if (!seekableRanges->contain(time)) {
503 m_movie->setEndTime(maxTime);
507 // The seeking DOM attribute is implicitly set to true
510 dispatchHTMLEvent(timeupdateEvent, false, true);
513 // As soon as the user agent has established whether or not the media data for the new playback position is available,
514 // and, if it is, decoded enough data to play back that position, the seeking DOM attribute must be set to false.
517 HTMLMediaElement::ReadyState HTMLMediaElement::readyState() const
522 bool HTMLMediaElement::seeking() const
526 RefPtr<TimeRanges> seekableRanges = seekable();
527 return m_movie->seeking() && seekableRanges->contain(currentTime());
531 float HTMLMediaElement::currentTime() const
533 return m_movie ? m_movie->currentTime() : 0;
536 void HTMLMediaElement::setCurrentTime(float time, ExceptionCode& ec)
541 float HTMLMediaElement::duration() const
543 return m_movie ? m_movie->duration() : 0;
546 bool HTMLMediaElement::paused() const
548 return m_movie ? m_movie->paused() : true;
551 float HTMLMediaElement::defaultPlaybackRate() const
553 return m_defaultPlaybackRate;
556 void HTMLMediaElement::setDefaultPlaybackRate(float rate, ExceptionCode& ec)
559 ec = NOT_SUPPORTED_ERR;
562 if (m_defaultPlaybackRate != rate) {
563 m_defaultPlaybackRate = rate;
564 dispatchEventAsync(ratechangeEvent);
568 float HTMLMediaElement::playbackRate() const
570 return m_movie ? m_movie->rate() : 0;
573 void HTMLMediaElement::setPlaybackRate(float rate, ExceptionCode& ec)
576 ec = NOT_SUPPORTED_ERR;
579 if (m_movie && m_movie->rate() != rate) {
580 m_movie->setRate(rate);
581 dispatchEventAsync(ratechangeEvent);
585 bool HTMLMediaElement::ended()
587 return networkState() >= LOADED_METADATA && currentTime() >= effectiveEnd() && currentLoop() == loopCount() - 1;
590 bool HTMLMediaElement::autoplay() const
592 return hasAttribute(autoplayAttr);
595 void HTMLMediaElement::setAutoplay(bool b)
597 setBooleanAttribute(autoplayAttr, b);
600 void HTMLMediaElement::play(ExceptionCode& ec)
602 // 3.14.9.7. Playing the media resource
603 if (!m_movie || networkState() == EMPTY) {
608 if (endedPlayback()) {
610 seek(effectiveStart(), ec);
614 setPlaybackRate(defaultPlaybackRate(), ec);
618 m_autoplaying = false;
620 if (m_movie->paused()) {
621 dispatchHTMLEvent(playEvent, false, true);
626 void HTMLMediaElement::pause(ExceptionCode& ec)
628 // 3.14.9.7. Playing the media resource
629 if (!m_movie || networkState() == EMPTY) {
633 m_autoplaying = false;
635 if (!m_movie->paused()) {
636 dispatchHTMLEvent(pauseEvent, false, true);
641 unsigned HTMLMediaElement::loopCount() const
643 String val = getAttribute(loopcountAttr);
644 int count = val.toInt();
645 return max(count, 1);
648 void HTMLMediaElement::setLoopCount(unsigned count, ExceptionCode& ec)
654 setAttribute(loopcountAttr, String::number(count));
658 float HTMLMediaElement::start() const
660 return getTimeOffsetAttribute(startAttr, 0);
663 void HTMLMediaElement::setStart(float time)
665 setTimeOffsetAttribute(startAttr, time);
669 float HTMLMediaElement::end() const
671 return getTimeOffsetAttribute(endAttr, std::numeric_limits<float>::infinity());
674 void HTMLMediaElement::setEnd(float time)
676 setTimeOffsetAttribute(endAttr, time);
680 float HTMLMediaElement::loopStart() const
682 return getTimeOffsetAttribute(loopstartAttr, 0);
685 void HTMLMediaElement::setLoopStart(float time)
687 setTimeOffsetAttribute(loopstartAttr, time);
691 float HTMLMediaElement::loopEnd() const
693 return getTimeOffsetAttribute(loopendAttr, std::numeric_limits<float>::infinity());
696 void HTMLMediaElement::setLoopEnd(float time)
698 setTimeOffsetAttribute(loopendAttr, time);
702 unsigned HTMLMediaElement::currentLoop() const
704 return m_currentLoop;
707 void HTMLMediaElement::setCurrentLoop(unsigned currentLoop)
709 m_currentLoop = currentLoop;
712 bool HTMLMediaElement::controls() const
714 return hasAttribute(controlsAttr);
717 void HTMLMediaElement::setControls(bool b)
719 setBooleanAttribute(controlsAttr, b);
722 float HTMLMediaElement::volume() const
727 void HTMLMediaElement::setVolume(float vol, ExceptionCode& ec)
729 if (vol < 0.0f || vol > 1.0f) {
734 if (m_volume != vol) {
736 dispatchEventAsync(volumechangeEvent);
739 m_movie->setVolume(vol);
743 bool HTMLMediaElement::muted() const
748 void HTMLMediaElement::setMuted(bool muted)
750 if (m_muted != muted) {
752 dispatchEventAsync(volumechangeEvent);
754 m_movie->setMuted(muted);
758 String HTMLMediaElement::pickMedia()
760 // 3.14.9.2. Location of the media resource
761 String mediaSrc = getAttribute(srcAttr);
762 if (mediaSrc.isEmpty()) {
763 for (Node* n = firstChild(); n; n = n->nextSibling()) {
764 if (n->hasTagName(sourceTag)) {
765 HTMLSourceElement* source = static_cast<HTMLSourceElement*>(n);
766 if (!source->hasAttribute(srcAttr))
768 if (source->hasAttribute(mediaAttr)) {
769 MediaQueryEvaluator screenEval("screen", document()->page(), renderer() ? renderer()->style() : 0);
770 RefPtr<MediaList> media = new MediaList((CSSStyleSheet*)0, source->media(), true);
771 if (!screenEval.eval(media.get()))
774 if (source->hasAttribute(typeAttr)) {
775 String type = source->type();
776 if (!MIMETypeRegistry::isSupportedMovieMIMEType(type))
779 mediaSrc = source->src();
784 if (!mediaSrc.isEmpty())
785 mediaSrc = document()->completeURL(mediaSrc);
789 void HTMLMediaElement::checkIfSeekNeeded()
791 // 3.14.9.5. Offsets into the media resource
793 if (loopCount() - 1 < m_currentLoop)
794 m_currentLoop = loopCount() - 1;
797 if (networkState() <= LOADING)
802 float time = currentTime();
803 if (!m_currentLoop && time < effectiveStart())
804 seek(effectiveStart(), ec);
807 if (m_currentLoop && time < effectiveLoopStart())
808 seek(effectiveLoopStart(), ec);
811 if (m_currentLoop < loopCount() - 1 && time > effectiveLoopEnd()) {
812 seek(effectiveLoopStart(), ec);
817 if (m_currentLoop == loopCount() - 1 && time > effectiveEnd())
818 seek(effectiveEnd(), ec);
821 void HTMLMediaElement::movieVolumeChanged(Movie*)
825 if (m_movie->volume() != m_volume || m_movie->muted() != m_muted) {
826 m_volume = m_movie->volume();
827 m_muted = m_movie->muted();
828 dispatchEventAsync(volumechangeEvent);
832 void HTMLMediaElement::movieDidEnd(Movie*)
834 if (m_currentLoop < loopCount() - 1 && currentTime() >= effectiveLoopEnd()) {
835 m_movie->seek(effectiveLoopStart());
837 m_movie->setEndTime(m_currentLoop == loopCount() - 1 ? effectiveEnd() : effectiveLoopEnd());
840 dispatchHTMLEvent(timeupdateEvent, false, true);
843 if (m_currentLoop == loopCount() - 1 && currentTime() >= effectiveEnd()) {
844 dispatchHTMLEvent(timeupdateEvent, false, true);
845 dispatchHTMLEvent(endedEvent, false, true);
849 void HTMLMediaElement::movieCuePointReached(Movie*, float cueTime)
851 CallbackVector* callbackVector = m_cuePoints.get(cueTime);
854 for (unsigned n = 0; n < callbackVector->size(); n++) {
855 CallbackEntry ce = (*callbackVector)[n];
863 dispatchHTMLEvent(timeupdateEvent, false, true);
865 for (unsigned n = 0; n < callbackVector->size(); n++) {
866 CallbackEntry ce = (*callbackVector)[n];
867 if (ce.m_voidCallback)
868 ce.m_voidCallback->execute(document()->frame());
872 void HTMLMediaElement::addCuePoint(float time, VoidCallback* voidCallback, bool pause)
874 if (time < 0 || !isfinite(time))
876 CallbackVector* callbackVector = m_cuePoints.get(time);
877 if (!callbackVector) {
878 callbackVector = new CallbackVector;
879 m_cuePoints.add(time, callbackVector);
881 callbackVector->append(CallbackEntry(voidCallback, pause));
884 m_movie->addCuePoint(time);
887 void HTMLMediaElement::removeCuePoint(float time, VoidCallback* callback)
889 if (time < 0 || !isfinite(time))
891 CallbackVector* callbackVector = m_cuePoints.get(time);
892 if (callbackVector) {
893 for (unsigned n = 0; n < callbackVector->size(); n++) {
894 if (*(*callbackVector)[n].m_voidCallback == *callback) {
895 callbackVector->remove(n);
899 if (!callbackVector->size()) {
900 delete callbackVector;
901 m_cuePoints.remove(time);
903 m_movie->removeCuePoint(time);
908 PassRefPtr<TimeRanges> HTMLMediaElement::buffered() const
910 // FIXME real ranges support
911 if (!m_movie || !m_movie->maxTimeBuffered())
912 return new TimeRanges;
913 return new TimeRanges(0, m_movie->maxTimeBuffered());
916 PassRefPtr<TimeRanges> HTMLMediaElement::played() const
918 // FIXME track played
919 return new TimeRanges;
922 PassRefPtr<TimeRanges> HTMLMediaElement::seekable() const
924 // FIXME real ranges support
925 if (!m_movie || !m_movie->maxTimeSeekable())
926 return new TimeRanges;
927 return new TimeRanges(0, m_movie->maxTimeSeekable());
930 float HTMLMediaElement::effectiveStart() const
934 return min(start(), m_movie->duration());
937 float HTMLMediaElement::effectiveEnd() const
941 return min(max(end(), max(start(), loopStart())), m_movie->duration());
944 float HTMLMediaElement::effectiveLoopStart() const
948 return min(loopStart(), m_movie->duration());
951 float HTMLMediaElement::effectiveLoopEnd() const
955 return min(max(start(), max(loopStart(), loopEnd())), m_movie->duration());
958 bool HTMLMediaElement::activelyPlaying() const
960 return !paused() && readyState() >= CAN_PLAY && !endedPlayback(); // && !stoppedDueToErrors() && !pausedForUserInteraction();
963 bool HTMLMediaElement::endedPlayback() const
965 return networkState() >= LOADED_METADATA && currentTime() >= effectiveEnd() && currentLoop() == loopCount() - 1;
968 void HTMLMediaElement::willSaveToCache()
970 // 3.14.9.4. Loading the media resource
974 m_movie->cancelLoad();
975 m_error = new MediaError(MediaError::MEDIA_ERR_ABORTED);
977 initAndDispatchProgressEvent(abortEvent);
978 if (m_networkState >= LOADING) {
979 m_networkState = EMPTY;
980 dispatchHTMLEvent(emptiedEvent, false, true);
985 m_wasPlayingBeforeMovingToPageCache = !paused();
986 if (m_wasPlayingBeforeMovingToPageCache)
989 m_movie->setVisible(false);
992 void HTMLMediaElement::didRestoreFromCache()
995 if (m_wasPlayingBeforeMovingToPageCache)
998 m_movie->setVisible(true);