HTMLConstructionSite.h [plain text]
#ifndef HTMLConstructionSite_h
#define HTMLConstructionSite_h
#include "FragmentScriptingPermission.h"
#include "HTMLElementStack.h"
#include "HTMLFormattingElementList.h"
#include "NotImplemented.h"
#include <wtf/Noncopyable.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
struct HTMLConstructionSiteTask {
HTMLConstructionSiteTask()
: selfClosing(false)
{
}
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;
class Document;
class Element;
class HTMLFormElement;
class HTMLConstructionSite {
WTF_MAKE_NONCOPYABLE(HTMLConstructionSite);
public:
HTMLConstructionSite(Document*, ParserContentPolicy, unsigned maximumDOMTreeDepth);
HTMLConstructionSite(DocumentFragment*, ParserContentPolicy, unsigned maximumDOMTreeDepth);
~HTMLConstructionSite();
void detach();
void executeQueuedTasks();
void setDefaultCompatibilityMode();
void finishedParsing();
void insertDoctype(AtomicHTMLToken*);
void insertComment(AtomicHTMLToken*);
void insertCommentOnDocument(AtomicHTMLToken*);
void insertCommentOnHTMLHtmlElement(AtomicHTMLToken*);
void insertHTMLElement(AtomicHTMLToken*);
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*);
PassRefPtr<HTMLStackItem> createElementFromSavedToken(HTMLStackItem*);
bool shouldFosterParent() const;
void fosterParent(PassRefPtr<Node>);
bool indexOfFirstUnopenFormattingElement(unsigned& firstUnopenElementIndex) const;
void reconstructTheActiveFormattingElements();
void generateImpliedEndTags();
void generateImpliedEndTagsWithExclusion(const AtomicString& tagName);
bool inQuirksMode();
bool isEmpty() const { return !m_openElements.stackDepth(); }
HTMLElementStack::ElementRecord* currentElementRecord() const { return m_openElements.topRecord(); }
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(); }
PassRefPtr<HTMLFormElement> takeForm();
ParserContentPolicy parserContentPolicy() { return m_parserContentPolicy; }
#if PLATFORM(IOS)
bool isTelephoneNumberParsingEnabled() { return m_document->isTelephoneNumberParsingEnabled(); }
#endif
class RedirectToFosterParentGuard {
WTF_MAKE_NONCOPYABLE(RedirectToFosterParentGuard);
public:
RedirectToFosterParentGuard(HTMLConstructionSite& tree)
: m_tree(tree)
, m_wasRedirectingBefore(tree.m_redirectAttachToFosterParent)
{
m_tree.m_redirectAttachToFosterParent = true;
}
~RedirectToFosterParentGuard()
{
m_tree.m_redirectAttachToFosterParent = m_wasRedirectingBefore;
}
private:
HTMLConstructionSite& m_tree;
bool m_wasRedirectingBefore;
};
private:
typedef Vector<HTMLConstructionSiteTask, 1> AttachmentQueue;
void setCompatibilityMode(Document::CompatibilityMode);
void setCompatibilityModeFromDoctype(const String& name, const String& publicId, const String& systemId);
void attachLater(ContainerNode* parent, PassRefPtr<Node> child, bool selfClosing = false);
void findFosterSite(HTMLConstructionSiteTask&);
PassRefPtr<Element> createHTMLElement(AtomicHTMLToken*);
PassRefPtr<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;
AttachmentQueue m_attachmentQueue;
ParserContentPolicy m_parserContentPolicy;
bool m_isParsingFragment;
bool m_redirectAttachToFosterParent;
unsigned m_maximumDOMTreeDepth;
bool m_inQuirksMode;
};
}
#endif