#ifndef HTMLTreeBuilder_h
#define HTMLTreeBuilder_h
#include "Element.h"
#include "FragmentScriptingPermission.h"
#include "HTMLConstructionSite.h"
#include "HTMLElementStack.h"
#include "HTMLFormattingElementList.h"
#include "HTMLTokenizer.h"
#include <wtf/Noncopyable.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
#include <wtf/text/StringBuilder.h>
#include <wtf/text/TextPosition.h>
#include <wtf/unicode/Unicode.h>
namespace WebCore {
class AtomicHTMLToken;
class Document;
class DocumentFragment;
class Frame;
class HTMLToken;
class HTMLDocument;
class Node;
class HTMLDocumentParser;
class HTMLTreeBuilder {
WTF_MAKE_NONCOPYABLE(HTMLTreeBuilder); WTF_MAKE_FAST_ALLOCATED;
public:
static PassOwnPtr<HTMLTreeBuilder> create(HTMLDocumentParser* parser, HTMLDocument* document, bool reportErrors, bool usePreHTML5ParserQuirks, unsigned maximumDOMTreeDepth)
{
return adoptPtr(new HTMLTreeBuilder(parser, document, reportErrors, usePreHTML5ParserQuirks, maximumDOMTreeDepth));
}
static PassOwnPtr<HTMLTreeBuilder> create(HTMLDocumentParser* parser, DocumentFragment* fragment, Element* contextElement, FragmentScriptingPermission scriptingPermission, bool usePreHTML5ParserQuirks, unsigned maximumDOMTreeDepth)
{
return adoptPtr(new HTMLTreeBuilder(parser, fragment, contextElement, scriptingPermission, usePreHTML5ParserQuirks, maximumDOMTreeDepth));
}
~HTMLTreeBuilder();
bool isParsingFragment() const { return !!m_fragmentContext.fragment(); }
void detach();
void setPaused(bool paused) { m_isPaused = paused; }
bool isPaused() const { return m_isPaused; }
void constructTreeFromToken(HTMLToken&);
void constructTreeFromAtomicToken(AtomicHTMLToken&);
PassRefPtr<Element> takeScriptToProcess(TextPosition& scriptStartPosition);
void finished();
void setShouldSkipLeadingNewline(bool shouldSkip) { m_shouldSkipLeadingNewline = shouldSkip; }
static bool scriptEnabled(Frame*);
static bool pluginsEnabled(Frame*);
private:
class ExternalCharacterTokenBuffer;
enum InsertionMode {
InitialMode,
BeforeHTMLMode,
BeforeHeadMode,
InHeadMode,
InHeadNoscriptMode,
AfterHeadMode,
InBodyMode,
TextMode,
InTableMode,
InTableTextMode,
InCaptionMode,
InColumnGroupMode,
InTableBodyMode,
InRowMode,
InCellMode,
InSelectMode,
InSelectInTableMode,
AfterBodyMode,
InFramesetMode,
AfterFramesetMode,
AfterAfterBodyMode,
AfterAfterFramesetMode,
};
HTMLTreeBuilder(HTMLDocumentParser*, HTMLDocument*, bool reportErrors, bool usePreHTML5ParserQuirks, unsigned maximumDOMTreeDepth);
HTMLTreeBuilder(HTMLDocumentParser*, DocumentFragment*, Element* contextElement, FragmentScriptingPermission, bool usePreHTML5ParserQuirks, unsigned maximumDOMTreeDepth);
void insertPhoneNumberLink(const String &);
void linkifyPhoneNumbers(const String&);
void processToken(AtomicHTMLToken&);
void processDoctypeToken(AtomicHTMLToken&);
void processStartTag(AtomicHTMLToken&);
void processEndTag(AtomicHTMLToken&);
void processComment(AtomicHTMLToken&);
void processCharacter(AtomicHTMLToken&);
void processEndOfFile(AtomicHTMLToken&);
bool processStartTagForInHead(AtomicHTMLToken&);
void processStartTagForInBody(AtomicHTMLToken&);
void processStartTagForInTable(AtomicHTMLToken&);
void processEndTagForInBody(AtomicHTMLToken&);
void processEndTagForInTable(AtomicHTMLToken&);
void processEndTagForInTableBody(AtomicHTMLToken&);
void processEndTagForInRow(AtomicHTMLToken&);
void processEndTagForInCell(AtomicHTMLToken&);
void processIsindexStartTagForInBody(AtomicHTMLToken&);
bool processBodyEndTagForInBody(AtomicHTMLToken&);
bool processTableEndTagForInTable();
bool processCaptionEndTagForInCaption();
bool processColgroupEndTagForInColumnGroup();
bool processTrEndTagForInRow();
void processAnyOtherEndTagForInBody(AtomicHTMLToken&);
void processCharacterBuffer(ExternalCharacterTokenBuffer&);
inline void processCharacterBufferForInBody(ExternalCharacterTokenBuffer&);
void processFakeStartTag(const QualifiedName&, const Vector<Attribute>& attributes = Vector<Attribute>());
void processFakeEndTag(const QualifiedName&);
void processFakeCharacters(const String&);
void processFakePEndTagIfPInButtonScope();
void processGenericRCDATAStartTag(AtomicHTMLToken&);
void processGenericRawTextStartTag(AtomicHTMLToken&);
void processScriptStartTag(AtomicHTMLToken&);
void defaultForInitial();
void defaultForBeforeHTML();
void defaultForBeforeHead();
void defaultForInHead();
void defaultForInHeadNoscript();
void defaultForAfterHead();
void defaultForInTableText();
inline bool shouldProcessTokenInForeignContent(AtomicHTMLToken&);
void processTokenInForeignContent(AtomicHTMLToken&);
Vector<Attribute> attributesForIsindexInput(AtomicHTMLToken&);
HTMLElementStack::ElementRecord* furthestBlockForFormattingElement(Element*);
void callTheAdoptionAgency(AtomicHTMLToken&);
void closeTheCell();
template <bool shouldClose(const ContainerNode*)>
void processCloseWhenNestedTag(AtomicHTMLToken&);
bool m_framesetOk;
void parseError(AtomicHTMLToken&);
InsertionMode insertionMode() const { return m_insertionMode; }
void setInsertionMode(InsertionMode mode) { m_insertionMode = mode; }
void resetInsertionModeAppropriately();
class FragmentParsingContext {
WTF_MAKE_NONCOPYABLE(FragmentParsingContext);
public:
FragmentParsingContext();
FragmentParsingContext(DocumentFragment*, Element* contextElement, FragmentScriptingPermission);
~FragmentParsingContext();
DocumentFragment* fragment() const { return m_fragment; }
Element* contextElement() const { ASSERT(m_fragment); return m_contextElement; }
FragmentScriptingPermission scriptingPermission() const { ASSERT(m_fragment); return m_scriptingPermission; }
private:
DocumentFragment* m_fragment;
Element* m_contextElement;
FragmentScriptingPermission m_scriptingPermission;
};
FragmentParsingContext m_fragmentContext;
Document* m_document;
HTMLConstructionSite m_tree;
bool m_reportErrors;
bool m_isPaused;
InsertionMode m_insertionMode;
InsertionMode m_originalInsertionMode;
StringBuilder m_pendingTableCharacters;
bool m_shouldSkipLeadingNewline;
HTMLDocumentParser* m_parser;
RefPtr<Element> m_scriptToProcess; TextPosition m_scriptToProcessStartPosition;
TextPosition m_lastScriptElementStartPosition;
bool m_usePreHTML5ParserQuirks;
};
}
#endif