#include "config.h"
#include "HTMLDocument.h"
#include "CSSPropertyNames.h"
#include "CookieJar.h"
#include "DocumentLoader.h"
#include "DocumentType.h"
#include "ElementChildIterator.h"
#include "ExceptionCode.h"
#include "FocusController.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "FrameTree.h"
#include "FrameView.h"
#include "HashTools.h"
#include "HTMLDocumentParser.h"
#include "HTMLBodyElement.h"
#include "HTMLElementFactory.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLFrameSetElement.h"
#include "HTMLHtmlElement.h"
#include "HTMLNames.h"
#include "JSDOMBinding.h"
#include "Page.h"
#include "ScriptController.h"
#include "Settings.h"
#include "StyleResolver.h"
#include <wtf/text/CString.h>
namespace WebCore {
using namespace HTMLNames;
HTMLDocument::HTMLDocument(Frame* frame, const URL& url, DocumentClassFlags documentClasses, unsigned constructionFlags)
: Document(frame, url, documentClasses | HTMLDocumentClass, constructionFlags)
{
clearXMLVersion();
}
HTMLDocument::~HTMLDocument()
{
}
int HTMLDocument::width()
{
updateLayoutIgnorePendingStylesheets();
FrameView* frameView = view();
return frameView ? frameView->contentsWidth() : 0;
}
int HTMLDocument::height()
{
updateLayoutIgnorePendingStylesheets();
FrameView* frameView = view();
return frameView ? frameView->contentsHeight() : 0;
}
const AtomicString& HTMLDocument::dir() const
{
auto* documentElement = this->documentElement();
if (!is<HTMLHtmlElement>(documentElement))
return nullAtom;
return downcast<HTMLHtmlElement>(*documentElement).dir();
}
void HTMLDocument::setDir(const AtomicString& value)
{
auto* documentElement = this->documentElement();
if (is<HTMLHtmlElement>(documentElement))
downcast<HTMLHtmlElement>(*documentElement).setDir(value);
}
String HTMLDocument::designMode() const
{
return inDesignMode() ? ASCIILiteral("on") : ASCIILiteral("off");
}
void HTMLDocument::setDesignMode(const String& value)
{
InheritedBool mode;
if (equalLettersIgnoringASCIICase(value, "on"))
mode = on;
else if (equalLettersIgnoringASCIICase(value, "off"))
mode = off;
else
mode = inherit;
Document::setDesignMode(mode);
}
const AtomicString& HTMLDocument::bgColor() const
{
auto* bodyElement = body();
if (!bodyElement)
return emptyAtom;
return bodyElement->attributeWithoutSynchronization(bgcolorAttr);
}
void HTMLDocument::setBgColor(const String& value)
{
if (auto* bodyElement = body())
bodyElement->setAttributeWithoutSynchronization(bgcolorAttr, value);
}
const AtomicString& HTMLDocument::fgColor() const
{
auto* bodyElement = body();
if (!bodyElement)
return emptyAtom;
return bodyElement->attributeWithoutSynchronization(textAttr);
}
void HTMLDocument::setFgColor(const String& value)
{
if (auto* bodyElement = body())
bodyElement->setAttributeWithoutSynchronization(textAttr, value);
}
const AtomicString& HTMLDocument::alinkColor() const
{
auto* bodyElement = body();
if (!bodyElement)
return emptyAtom;
return bodyElement->attributeWithoutSynchronization(alinkAttr);
}
void HTMLDocument::setAlinkColor(const String& value)
{
if (auto* bodyElement = body())
bodyElement->setAttributeWithoutSynchronization(alinkAttr, value);
}
const AtomicString& HTMLDocument::linkColor() const
{
auto* bodyElement = body();
if (!bodyElement)
return emptyAtom;
return bodyElement->attributeWithoutSynchronization(linkAttr);
}
void HTMLDocument::setLinkColor(const String& value)
{
if (auto* bodyElement = body())
bodyElement->setAttributeWithoutSynchronization(linkAttr, value);
}
const AtomicString& HTMLDocument::vlinkColor() const
{
auto* bodyElement = body();
if (!bodyElement)
return emptyAtom;
return bodyElement->attributeWithoutSynchronization(vlinkAttr);
}
void HTMLDocument::setVlinkColor(const String& value)
{
if (auto* bodyElement = body())
bodyElement->setAttributeWithoutSynchronization(vlinkAttr, value);
}
void HTMLDocument::captureEvents()
{
}
void HTMLDocument::releaseEvents()
{
}
Ref<DocumentParser> HTMLDocument::createParser()
{
return HTMLDocumentParser::create(*this);
}
static void addLocalNameToSet(HashSet<AtomicStringImpl*>* set, const QualifiedName& qName)
{
set->add(qName.localName().impl());
}
static HashSet<AtomicStringImpl*>* createHtmlCaseInsensitiveAttributesSet()
{
HashSet<AtomicStringImpl*>* attrSet = new HashSet<AtomicStringImpl*>;
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;
}
void HTMLDocument::addDocumentNamedItem(const AtomicStringImpl& name, Element& item)
{
m_documentNamedItem.add(name, item, *this);
addImpureProperty(AtomicString(const_cast<AtomicStringImpl*>(&name)));
}
void HTMLDocument::removeDocumentNamedItem(const AtomicStringImpl& name, Element& item)
{
m_documentNamedItem.remove(name, item);
}
void HTMLDocument::addWindowNamedItem(const AtomicStringImpl& name, Element& item)
{
m_windowNamedItem.add(name, item, *this);
}
void HTMLDocument::removeWindowNamedItem(const AtomicStringImpl& name, Element& item)
{
m_windowNamedItem.remove(name, item);
}
bool HTMLDocument::isCaseSensitiveAttribute(const QualifiedName& attributeName)
{
static HashSet<AtomicStringImpl*>* htmlCaseInsensitiveAttributesSet = createHtmlCaseInsensitiveAttributesSet();
bool isPossibleHTMLAttr = !attributeName.hasPrefix() && (attributeName.namespaceURI() == nullAtom);
return !isPossibleHTMLAttr || !htmlCaseInsensitiveAttributesSet->contains(attributeName.localName().impl());
}
void HTMLDocument::clear()
{
}
bool HTMLDocument::isFrameSet() const
{
if (!documentElement())
return false;
return !!childrenOfType<HTMLFrameSetElement>(*documentElement()).first();
}
Ref<Document> HTMLDocument::cloneDocumentWithoutChildren() const
{
return create(nullptr, url());
}
}