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 "Text.h"
#include <wtf/Ref.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, bool alreadyStarted)
{
return adoptRef(new HTMLScriptElement(tagName, document, wasInsertedByParser, alreadyStarted));
}
bool HTMLScriptElement::isURLAttribute(const Attribute& attribute) const
{
return attribute.name() == srcAttr || HTMLElement::isURLAttribute(attribute);
}
void HTMLScriptElement::childrenChanged(const ChildChange& change)
{
HTMLElement::childrenChanged(change);
ScriptElement::childrenChanged();
}
void HTMLScriptElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (name == srcAttr)
handleSourceAttribute(value);
else if (name == asyncAttr)
handleAsyncAttribute();
else if (name == onbeforeloadAttr)
setAttributeEventListener(eventNames().beforeloadEvent, name, value);
else
HTMLElement::parseAttribute(name, value);
}
Node::InsertionNotificationRequest HTMLScriptElement::insertedInto(ContainerNode& insertionPoint)
{
HTMLElement::insertedInto(insertionPoint);
return shouldNotifySubtreeInsertions(insertionPoint) ? InsertionShouldCallDidNotifySubtreeInsertions : InsertionDone;
}
void HTMLScriptElement::didNotifySubtreeInsertions(ContainerNode* node)
{
ScriptElement::didNotifySubtreeInsertions(node);
}
void HTMLScriptElement::setText(const String &value)
{
Ref<HTMLScriptElement> protectFromMutationEvents(*this);
int numChildren = childNodeCount();
if (numChildren == 1 && firstChild()->isTextNode()) {
toText(firstChild())->setData(value, IGNORE_EXCEPTION);
return;
}
if (numChildren > 0)
removeChildren();
appendChild(document().createTextNode(value.impl()), IGNORE_EXCEPTION);
}
void HTMLScriptElement::setAsync(bool async)
{
setBooleanAttribute(asyncAttr, async);
handleAsyncAttribute();
}
bool HTMLScriptElement::async() const
{
return fastHasAttribute(asyncAttr) || forceAsync();
}
URL HTMLScriptElement::src() const
{
return document().completeURL(sourceAttributeValue());
}
void HTMLScriptElement::addSubresourceAttributeURLs(ListHashSet<URL>& 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()));
}
}