HTMLScriptElement.cpp [plain text]
#include "config.h"
#include "HTMLScriptElement.h"
#include "Attribute.h"
#include "Document.h"
#include "Event.h"
#include "EventNames.h"
#include "HTMLNames.h"
#include "ScriptEventListener.h"
#include "Text.h"
namespace WebCore {
using namespace HTMLNames;
inline HTMLScriptElement::HTMLScriptElement(const QualifiedName& tagName, Document* document, bool wasInsertedByParser, bool alreadyStarted)
: HTMLElement(tagName, document)
, ScriptElement(this, wasInsertedByParser, alreadyStarted)
{
ASSERT(hasTagName(scriptTag));
}
PassRefPtr<HTMLScriptElement> HTMLScriptElement::create(const QualifiedName& tagName, Document* document, bool wasInsertedByParser)
{
return adoptRef(new HTMLScriptElement(tagName, document, wasInsertedByParser, false));
}
bool HTMLScriptElement::isURLAttribute(Attribute* attr) const
{
return attr->name() == srcAttr || HTMLElement::isURLAttribute(attr);
}
void HTMLScriptElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
HTMLElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
ScriptElement::childrenChanged();
}
void HTMLScriptElement::parseAttribute(Attribute* attr)
{
const QualifiedName& attrName = attr->name();
if (attrName == srcAttr)
handleSourceAttribute(attr->value());
else if (attr->name() == asyncAttr)
handleAsyncAttribute();
else if (attrName == onloadAttr)
setAttributeEventListener(eventNames().loadEvent, createAttributeEventListener(this, attr));
else if (attrName == onbeforeloadAttr)
setAttributeEventListener(eventNames().beforeloadEvent, createAttributeEventListener(this, attr));
else
HTMLElement::parseAttribute(attr);
}
Node::InsertionNotificationRequest HTMLScriptElement::insertedInto(Node* insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
ScriptElement::insertedInto(insertionPoint);
return InsertionDone;
}
void HTMLScriptElement::setText(const String &value)
{
RefPtr<Node> protectFromMutationEvents(this);
ExceptionCode ec = 0;
int numChildren = childNodeCount();
if (numChildren == 1 && firstChild()->isTextNode()) {
toText(firstChild())->setData(value, ec);
return;
}
if (numChildren > 0)
removeChildren();
appendChild(document()->createTextNode(value.impl()), ec);
}
void HTMLScriptElement::setAsync(bool async)
{
setBooleanAttribute(asyncAttr, async);
handleAsyncAttribute();
}
bool HTMLScriptElement::async() const
{
return fastHasAttribute(asyncAttr) || forceAsync();
}
KURL HTMLScriptElement::src() const
{
return document()->completeURL(sourceAttributeValue());
}
void HTMLScriptElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
{
HTMLElement::addSubresourceAttributeURLs(urls);
addSubresourceURL(urls, src());
}
String HTMLScriptElement::sourceAttributeValue() const
{
return getAttribute(srcAttr).string();
}
String HTMLScriptElement::charsetAttributeValue() const
{
return getAttribute(charsetAttr).string();
}
String HTMLScriptElement::typeAttributeValue() const
{
return getAttribute(typeAttr).string();
}
String HTMLScriptElement::languageAttributeValue() const
{
return getAttribute(languageAttr).string();
}
String HTMLScriptElement::forAttributeValue() const
{
return getAttribute(forAttr).string();
}
String HTMLScriptElement::eventAttributeValue() const
{
return getAttribute(eventAttr).string();
}
bool HTMLScriptElement::asyncAttributeValue() const
{
return fastHasAttribute(asyncAttr);
}
bool HTMLScriptElement::deferAttributeValue() const
{
return fastHasAttribute(deferAttr);
}
bool HTMLScriptElement::hasSourceAttribute() const
{
return fastHasAttribute(srcAttr);
}
void HTMLScriptElement::dispatchLoadEvent()
{
ASSERT(!haveFiredLoadEvent());
setHaveFiredLoadEvent(true);
dispatchEvent(Event::create(eventNames().loadEvent, false, false));
}
PassRefPtr<Element> HTMLScriptElement::cloneElementWithoutAttributesAndChildren()
{
return adoptRef(new HTMLScriptElement(tagQName(), document(), false, alreadyStarted()));
}
}