1/* 2 * Copyright (C) 2007, 2008, 2010 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26#include "config.h" 27#if ENABLE(VIDEO) 28#include "HTMLSourceElement.h" 29 30#include "Event.h" 31#include "EventNames.h" 32#include "HTMLDocument.h" 33#include "HTMLMediaElement.h" 34#include "HTMLNames.h" 35#include "Logging.h" 36 37using namespace std; 38 39namespace WebCore { 40 41using namespace HTMLNames; 42 43inline HTMLSourceElement::HTMLSourceElement(const QualifiedName& tagName, Document* document) 44 : HTMLElement(tagName, document) 45 , m_errorEventTimer(this, &HTMLSourceElement::errorEventTimerFired) 46{ 47 LOG(Media, "HTMLSourceElement::HTMLSourceElement - %p", this); 48 ASSERT(hasTagName(sourceTag)); 49} 50 51PassRefPtr<HTMLSourceElement> HTMLSourceElement::create(const QualifiedName& tagName, Document* document) 52{ 53 return adoptRef(new HTMLSourceElement(tagName, document)); 54} 55 56Node::InsertionNotificationRequest HTMLSourceElement::insertedInto(ContainerNode* insertionPoint) 57{ 58 HTMLElement::insertedInto(insertionPoint); 59 Element* parent = parentElement(); 60 if (parent && parent->isMediaElement()) 61 static_cast<HTMLMediaElement*>(parentNode())->sourceWasAdded(this); 62 return InsertionDone; 63} 64 65void HTMLSourceElement::removedFrom(ContainerNode* removalRoot) 66{ 67 Element* parent = parentElement(); 68 if (!parent && removalRoot->isElementNode()) 69 parent = toElement(removalRoot); 70 if (parent && parent->isMediaElement()) 71 toMediaElement(parent)->sourceWasRemoved(this); 72 HTMLElement::removedFrom(removalRoot); 73} 74 75void HTMLSourceElement::setSrc(const String& url) 76{ 77 setAttribute(srcAttr, url); 78} 79 80String HTMLSourceElement::media() const 81{ 82 return getAttribute(mediaAttr); 83} 84 85void HTMLSourceElement::setMedia(const String& media) 86{ 87 setAttribute(mediaAttr, media); 88} 89 90String HTMLSourceElement::type() const 91{ 92 return getAttribute(typeAttr); 93} 94 95void HTMLSourceElement::setType(const String& type) 96{ 97 setAttribute(typeAttr, type); 98} 99 100void HTMLSourceElement::scheduleErrorEvent() 101{ 102 LOG(Media, "HTMLSourceElement::scheduleErrorEvent - %p", this); 103 if (m_errorEventTimer.isActive()) 104 return; 105 106 m_errorEventTimer.startOneShot(0); 107} 108 109void HTMLSourceElement::cancelPendingErrorEvent() 110{ 111 LOG(Media, "HTMLSourceElement::cancelPendingErrorEvent - %p", this); 112 m_errorEventTimer.stop(); 113} 114 115void HTMLSourceElement::errorEventTimerFired(Timer<HTMLSourceElement>*) 116{ 117 LOG(Media, "HTMLSourceElement::errorEventTimerFired - %p", this); 118 dispatchEvent(Event::create(eventNames().errorEvent, false, true)); 119} 120 121bool HTMLSourceElement::isURLAttribute(const Attribute& attribute) const 122{ 123 return attribute.name() == srcAttr || HTMLElement::isURLAttribute(attribute); 124} 125 126#if ENABLE(MICRODATA) 127String HTMLSourceElement::itemValueText() const 128{ 129 return getURLAttribute(srcAttr); 130} 131 132void HTMLSourceElement::setItemValueText(const String& value, ExceptionCode&) 133{ 134 setAttribute(srcAttr, value); 135} 136#endif 137 138} 139 140#endif 141