This source file includes following definitions.
- dir
- setDir
- designMode
- setDesignMode
- htmlBodyElement
- bodyAttributeValue
- setBodyAttribute
- bgColor
- setBgColor
- fgColor
- setFgColor
- alinkColor
- setAlinkColor
- linkColor
- setLinkColor
- vlinkColor
- setVlinkColor
- cloneDocumentWithoutChildren
- addItemToMap
- removeItemFromMap
- addNamedItem
- removeNamedItem
- addExtraNamedItem
- removeExtraNamedItem
- addLocalNameToSet
- createHtmlCaseInsensitiveAttributesSet
- isCaseSensitiveAttribute
- write
- writeln
#include "config.h"
#include "core/html/HTMLDocument.h"
#include "HTMLNames.h"
#include "bindings/v8/ScriptController.h"
#include "core/frame/DOMWindow.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLBodyElement.h"
#include "core/page/FocusController.h"
#include "core/page/FrameTree.h"
#include "core/page/Page.h"
#include "wtf/text/StringBuilder.h"
namespace WebCore {
using namespace HTMLNames;
HTMLDocument::HTMLDocument(const DocumentInit& initializer, DocumentClassFlags extendedDocumentClasses)
: Document(initializer, HTMLDocumentClass | extendedDocumentClasses)
{
ScriptWrappable::init(this);
clearXMLVersion();
}
HTMLDocument::~HTMLDocument()
{
}
const AtomicString& HTMLDocument::dir()
{
HTMLElement* b = body();
if (!b)
return nullAtom;
return b->getAttribute(dirAttr);
}
void HTMLDocument::setDir(const AtomicString& value)
{
HTMLElement* b = body();
if (b)
b->setAttribute(dirAttr, value);
}
String HTMLDocument::designMode() const
{
return inDesignMode() ? "on" : "off";
}
void HTMLDocument::setDesignMode(const String& value)
{
InheritedBool mode;
if (equalIgnoringCase(value, "on"))
mode = on;
else if (equalIgnoringCase(value, "off"))
mode = off;
else
mode = inherit;
Document::setDesignMode(mode);
}
HTMLBodyElement* HTMLDocument::htmlBodyElement() const
{
HTMLElement* body = this->body();
return isHTMLBodyElement(body) ? toHTMLBodyElement(body) : 0;
}
const AtomicString& HTMLDocument::bodyAttributeValue(const QualifiedName& name) const
{
if (HTMLBodyElement* body = htmlBodyElement())
return body->fastGetAttribute(name);
return nullAtom;
}
void HTMLDocument::setBodyAttribute(const QualifiedName& name, const AtomicString& value)
{
if (HTMLBodyElement* body = htmlBodyElement()) {
if (body->fastGetAttribute(name) != value)
body->setAttribute(name, value);
}
}
const AtomicString& HTMLDocument::bgColor() const
{
return bodyAttributeValue(bgcolorAttr);
}
void HTMLDocument::setBgColor(const AtomicString& value)
{
setBodyAttribute(bgcolorAttr, value);
}
const AtomicString& HTMLDocument::fgColor() const
{
return bodyAttributeValue(textAttr);
}
void HTMLDocument::setFgColor(const AtomicString& value)
{
setBodyAttribute(textAttr, value);
}
const AtomicString& HTMLDocument::alinkColor() const
{
return bodyAttributeValue(alinkAttr);
}
void HTMLDocument::setAlinkColor(const AtomicString& value)
{
setBodyAttribute(alinkAttr, value);
}
const AtomicString& HTMLDocument::linkColor() const
{
return bodyAttributeValue(linkAttr);
}
void HTMLDocument::setLinkColor(const AtomicString& value)
{
setBodyAttribute(linkAttr, value);
}
const AtomicString& HTMLDocument::vlinkColor() const
{
return bodyAttributeValue(vlinkAttr);
}
void HTMLDocument::setVlinkColor(const AtomicString& value)
{
setBodyAttribute(vlinkAttr, value);
}
PassRefPtr<Document> HTMLDocument::cloneDocumentWithoutChildren()
{
return create(DocumentInit(url()).withRegistrationContext(registrationContext()));
}
void HTMLDocument::addItemToMap(HashCountedSet<AtomicString>& map, const AtomicString& name)
{
if (name.isEmpty())
return;
map.add(name);
if (LocalFrame* f = frame())
f->script().namedItemAdded(this, name);
}
void HTMLDocument::removeItemFromMap(HashCountedSet<AtomicString>& map, const AtomicString& name)
{
if (name.isEmpty())
return;
map.remove(name);
if (LocalFrame* f = frame())
f->script().namedItemRemoved(this, name);
}
void HTMLDocument::addNamedItem(const AtomicString& name)
{
addItemToMap(m_namedItemCounts, name);
}
void HTMLDocument::removeNamedItem(const AtomicString& name)
{
removeItemFromMap(m_namedItemCounts, name);
}
void HTMLDocument::addExtraNamedItem(const AtomicString& name)
{
addItemToMap(m_extraNamedItemCounts, name);
}
void HTMLDocument::removeExtraNamedItem(const AtomicString& name)
{
removeItemFromMap(m_extraNamedItemCounts, name);
}
static void addLocalNameToSet(HashSet<StringImpl*>* set, const QualifiedName& qName)
{
set->add(qName.localName().impl());
}
static HashSet<StringImpl*>* createHtmlCaseInsensitiveAttributesSet()
{
HashSet<StringImpl*>* attrSet = new HashSet<StringImpl*>;
addLocalNameToSet(attrSet, accept_charsetAttr);
addLocalNameToSet(attrSet, acceptAttr);
addLocalNameToSet(attrSet, alignAttr);
addLocalNameToSet(attrSet, alinkAttr);
addLocalNameToSet(attrSet, axisAttr);
addLocalNameToSet(attrSet, bgcolorAttr);
addLocalNameToSet(attrSet, charsetAttr);
addLocalNameToSet(attrSet, checkedAttr);
addLocalNameToSet(attrSet, clearAttr);
addLocalNameToSet(attrSet, codetypeAttr);
addLocalNameToSet(attrSet, colorAttr);
addLocalNameToSet(attrSet, compactAttr);
addLocalNameToSet(attrSet, declareAttr);
addLocalNameToSet(attrSet, deferAttr);
addLocalNameToSet(attrSet, dirAttr);
addLocalNameToSet(attrSet, disabledAttr);
addLocalNameToSet(attrSet, enctypeAttr);
addLocalNameToSet(attrSet, faceAttr);
addLocalNameToSet(attrSet, frameAttr);
addLocalNameToSet(attrSet, hreflangAttr);
addLocalNameToSet(attrSet, http_equivAttr);
addLocalNameToSet(attrSet, langAttr);
addLocalNameToSet(attrSet, languageAttr);
addLocalNameToSet(attrSet, linkAttr);
addLocalNameToSet(attrSet, mediaAttr);
addLocalNameToSet(attrSet, methodAttr);
addLocalNameToSet(attrSet, multipleAttr);
addLocalNameToSet(attrSet, nohrefAttr);
addLocalNameToSet(attrSet, noresizeAttr);
addLocalNameToSet(attrSet, noshadeAttr);
addLocalNameToSet(attrSet, nowrapAttr);
addLocalNameToSet(attrSet, readonlyAttr);
addLocalNameToSet(attrSet, relAttr);
addLocalNameToSet(attrSet, revAttr);
addLocalNameToSet(attrSet, rulesAttr);
addLocalNameToSet(attrSet, scopeAttr);
addLocalNameToSet(attrSet, scrollingAttr);
addLocalNameToSet(attrSet, selectedAttr);
addLocalNameToSet(attrSet, shapeAttr);
addLocalNameToSet(attrSet, targetAttr);
addLocalNameToSet(attrSet, textAttr);
addLocalNameToSet(attrSet, typeAttr);
addLocalNameToSet(attrSet, valignAttr);
addLocalNameToSet(attrSet, valuetypeAttr);
addLocalNameToSet(attrSet, vlinkAttr);
return attrSet;
}
bool HTMLDocument::isCaseSensitiveAttribute(const QualifiedName& attributeName)
{
static HashSet<StringImpl*>* htmlCaseInsensitiveAttributesSet = createHtmlCaseInsensitiveAttributesSet();
bool isPossibleHTMLAttr = !attributeName.hasPrefix() && (attributeName.namespaceURI() == nullAtom);
return !isPossibleHTMLAttr || !htmlCaseInsensitiveAttributesSet->contains(attributeName.localName().impl());
}
void HTMLDocument::write(DOMWindow* callingWindow, const Vector<String>& text)
{
ASSERT(callingWindow);
StringBuilder builder;
for (size_t i = 0; i < text.size(); ++i)
builder.append(text[i]);
write(builder.toString(), callingWindow->document());
}
void HTMLDocument::writeln(DOMWindow* callingWindow, const Vector<String>& text)
{
ASSERT(callingWindow);
StringBuilder builder;
for (size_t i = 0; i < text.size(); ++i)
builder.append(text[i]);
writeln(builder.toString(), callingWindow->document());
}
}