#include "config.h"
#include "HTMLDocument.h"
#include "CSSPropertyNames.h"
#include "CookieJar.h"
#include "DocumentLoader.h"
#include "DocumentType.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 "HTMLNames.h"
#include "InspectorInstrumentation.h"
#include "KURL.h"
#include "Page.h"
#include "ScriptController.h"
#include "Settings.h"
#include "StyleResolver.h"
#include <wtf/text/CString.h>
namespace WebCore {
using namespace HTMLNames;
#if PLATFORM(IOS)
HTMLDocument::HTMLDocument(Frame* frame, const KURL& url, DocumentClassFlags documentClasses, bool isSynthesized)
: Document(frame, url, documentClasses | HTMLDocumentClass, isSynthesized)
#else
HTMLDocument::HTMLDocument(Frame* frame, const KURL& url, DocumentClassFlags documentClasses)
: Document(frame, url, documentClasses | HTMLDocumentClass)
#endif
{
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;
}
String HTMLDocument::dir()
{
HTMLElement* b = body();
if (!b)
return String();
return b->getAttribute(dirAttr);
}
void HTMLDocument::setDir(const String& 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);
}
Element* HTMLDocument::activeElement()
{
if (Element* element = treeScope()->focusedElement())
return element;
return body();
}
bool HTMLDocument::hasFocus()
{
Page* page = this->page();
if (!page)
return false;
if (!page->focusController()->isActive())
return false;
if (Frame* focusedFrame = page->focusController()->focusedFrame()) {
if (focusedFrame->tree()->isDescendantOf(frame()))
return true;
}
return false;
}
String HTMLDocument::bgColor()
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (!bodyElement)
return String();
return bodyElement->bgColor();
}
void HTMLDocument::setBgColor(const String& value)
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (bodyElement)
bodyElement->setBgColor(value);
}
String HTMLDocument::fgColor()
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (!bodyElement)
return String();
return bodyElement->text();
}
void HTMLDocument::setFgColor(const String& value)
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (bodyElement)
bodyElement->setText(value);
}
String HTMLDocument::alinkColor()
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (!bodyElement)
return String();
return bodyElement->aLink();
}
void HTMLDocument::setAlinkColor(const String& value)
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (bodyElement) {
if (bodyElement->aLink() != value)
bodyElement->setALink(value);
}
}
String HTMLDocument::linkColor()
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (!bodyElement)
return String();
return bodyElement->link();
}
void HTMLDocument::setLinkColor(const String& value)
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (bodyElement) {
if (bodyElement->link() != value)
bodyElement->setLink(value);
}
}
String HTMLDocument::vlinkColor()
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (!bodyElement)
return String();
return bodyElement->vLink();
}
void HTMLDocument::setVlinkColor(const String& value)
{
HTMLElement* b = body();
HTMLBodyElement* bodyElement = (b && b->hasTagName(bodyTag)) ? static_cast<HTMLBodyElement*>(b) : 0;
if (bodyElement) {
if (bodyElement->vLink() != value)
bodyElement->setVLink(value);
}
}
void HTMLDocument::captureEvents()
{
}
void HTMLDocument::releaseEvents()
{
}
PassRefPtr<DocumentParser> HTMLDocument::createParser()
{
bool reportErrors = InspectorInstrumentation::collectingHTMLParseErrors(this->page());
return HTMLDocumentParser::create(this, reportErrors);
}
PassRefPtr<Element> HTMLDocument::createElement(const AtomicString& name, ExceptionCode& ec)
{
if (!isValidName(name)) {
ec = INVALID_CHARACTER_ERR;
return 0;
}
return HTMLElementFactory::createHTMLElement(QualifiedName(nullAtom, name.lower(), xhtmlNamespaceURI), this, 0, false);
}
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;
}
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
{
HTMLElement* bodyElement = body();
return bodyElement && bodyElement->hasTagName(framesetTag);
}
}