HTMLConstructionSite.h [plain text]
#pragma once
#include "FragmentScriptingPermission.h"
#include "HTMLElementStack.h"
#include "HTMLFormattingElementList.h"
#include <wtf/Noncopyable.h>
#include <wtf/RefPtr.h>
#include <wtf/SetForScope.h>
#include <wtf/Vector.h>
namespace WebCore {
struct HTMLConstructionSiteTask {
enum Operation {
Insert,
InsertAlreadyParsedChild,
Reparent,
TakeAllChildrenAndReparent,
};
explicit HTMLConstructionSiteTask(Operation op)
: operation(op)
, selfClosing(false)
{
}
ContainerNode* oldParent()
{
return downcast<ContainerNode>(child.get());
}
Operation operation;
RefPtr<ContainerNode> parent;
RefPtr<Node> nextChild;
RefPtr<Node> child;
bool selfClosing;
};
}
namespace WTF {
template<> struct VectorTraits<WebCore::HTMLConstructionSiteTask> : SimpleClassVectorTraits { };
}
namespace WebCore {
enum WhitespaceMode {
AllWhitespace,
NotAllWhitespace,
WhitespaceUnknown
};
class AtomicHTMLToken;
struct CustomElementConstructionData;
class Document;
class Element;
class HTMLFormElement;
class JSCustomElementInterface;
class HTMLConstructionSite {
WTF_MAKE_NONCOPYABLE(HTMLConstructionSite);
public:
HTMLConstructionSite(Document&, ParserContentPolicy, unsigned maximumDOMTreeDepth);
HTMLConstructionSite(DocumentFragment&, ParserContentPolicy, unsigned maximumDOMTreeDepth);
~HTMLConstructionSite();
void executeQueuedTasks();
void setDefaultCompatibilityMode();
void finishedParsing();
void insertDoctype(AtomicHTMLToken&&);
void insertComment(AtomicHTMLToken&&);
void insertCommentOnDocument(AtomicHTMLToken&&);
void insertCommentOnHTMLHtmlElement(AtomicHTMLToken&&);
void insertHTMLElement(AtomicHTMLToken&&);
std::unique_ptr<CustomElementConstructionData> insertHTMLElementOrFindCustomElementInterface(AtomicHTMLToken&&);
void insertCustomElement(Ref<Element>&&, const AtomicString& localName, Vector<Attribute>&&);
void insertSelfClosingHTMLElement(AtomicHTMLToken&&);
void insertFormattingElement(AtomicHTMLToken&&);
void insertHTMLHeadElement(AtomicHTMLToken&&);
void insertHTMLBodyElement(AtomicHTMLToken&&);
void insertHTMLFormElement(AtomicHTMLToken&&, bool isDemoted = false);
void insertScriptElement(AtomicHTMLToken&&);
void insertTextNode(const String&, WhitespaceMode = WhitespaceUnknown);
void insertForeignElement(AtomicHTMLToken&&, const AtomicString& namespaceURI);
void insertHTMLHtmlStartTagBeforeHTML(AtomicHTMLToken&&);
void insertHTMLHtmlStartTagInBody(AtomicHTMLToken&&);
void insertHTMLBodyStartTagInBody(AtomicHTMLToken&&);
void reparent(HTMLElementStack::ElementRecord& newParent, HTMLElementStack::ElementRecord& child);
void insertAlreadyParsedChild(HTMLStackItem& newParent, HTMLElementStack::ElementRecord& child);
void takeAllChildrenAndReparent(HTMLStackItem& newParent, HTMLElementStack::ElementRecord& oldParent);
Ref<HTMLStackItem> createElementFromSavedToken(HTMLStackItem&);
bool shouldFosterParent() const;
void fosterParent(Ref<Node>&&);
Optional<unsigned> indexOfFirstUnopenFormattingElement() const;
void reconstructTheActiveFormattingElements();
void generateImpliedEndTags();
void generateImpliedEndTagsWithExclusion(const AtomicString& tagName);
bool inQuirksMode() { return m_inQuirksMode; }
bool isEmpty() const { return !m_openElements.stackDepth(); }
Element& currentElement() const { return m_openElements.top(); }
ContainerNode& currentNode() const { return m_openElements.topNode(); }
HTMLStackItem& currentStackItem() const { return m_openElements.topStackItem(); }
HTMLStackItem* oneBelowTop() const { return m_openElements.oneBelowTop(); }
Document& ownerDocumentForCurrentNode();
HTMLElementStack& openElements() const { return m_openElements; }
HTMLFormattingElementList& activeFormattingElements() const { return m_activeFormattingElements; }
bool currentIsRootNode() { return &m_openElements.topNode() == &m_openElements.rootNode(); }
Element& head() const { return m_head->element(); }
HTMLStackItem* headStackItem() const { return m_head.get(); }
void setForm(HTMLFormElement*);
HTMLFormElement* form() const { return m_form.get(); }
RefPtr<HTMLFormElement> takeForm();
ParserContentPolicy parserContentPolicy() { return m_parserContentPolicy; }
#if ENABLE(TELEPHONE_NUMBER_DETECTION)
bool isTelephoneNumberParsingEnabled() { return m_document.isTelephoneNumberParsingEnabled(); }
#endif
class RedirectToFosterParentGuard {
WTF_MAKE_NONCOPYABLE(RedirectToFosterParentGuard);
public:
explicit RedirectToFosterParentGuard(HTMLConstructionSite& tree)
: m_redirectAttachToFosterParentChange(tree.m_redirectAttachToFosterParent, true)
{ }
private:
SetForScope<bool> m_redirectAttachToFosterParentChange;
};
static bool isFormattingTag(const AtomicString&);
private:
typedef Vector<HTMLConstructionSiteTask, 1> TaskQueue;
void setCompatibilityMode(DocumentCompatibilityMode);
void setCompatibilityModeFromDoctype(const String& name, const String& publicId, const String& systemId);
void attachLater(ContainerNode& parent, Ref<Node>&& child, bool selfClosing = false);
void findFosterSite(HTMLConstructionSiteTask&);
RefPtr<Element> createHTMLElementOrFindCustomElementInterface(AtomicHTMLToken&, JSCustomElementInterface**);
Ref<Element> createHTMLElement(AtomicHTMLToken&);
Ref<Element> createElement(AtomicHTMLToken&, const AtomicString& namespaceURI);
void mergeAttributesFromTokenIntoElement(AtomicHTMLToken&&, Element&);
void dispatchDocumentElementAvailableIfNeeded();
Document& m_document;
ContainerNode& m_attachmentRoot;
RefPtr<HTMLStackItem> m_head;
RefPtr<HTMLFormElement> m_form;
mutable HTMLElementStack m_openElements;
mutable HTMLFormattingElementList m_activeFormattingElements;
TaskQueue m_taskQueue;
ParserContentPolicy m_parserContentPolicy;
bool m_isParsingFragment;
bool m_redirectAttachToFosterParent;
unsigned m_maximumDOMTreeDepth;
bool m_inQuirksMode;
};
}