#ifndef HTMLParser_h
#define HTMLParser_h
#include "QualifiedName.h"
#include <wtf/Forward.h>
#include <wtf/RefPtr.h>
#include "HTMLParserErrorCodes.h"
namespace WebCore {
class Document;
class DocumentFragment;
class HTMLDocument;
class HTMLFormElement;
class HTMLHeadElement;
class HTMLMapElement;
class Node;
class Token;
struct HTMLStackElem;
class HTMLParser : Noncopyable {
public:
HTMLParser(HTMLDocument*, bool reportErrors);
HTMLParser(DocumentFragment*);
virtual ~HTMLParser();
PassRefPtr<Node> parseToken(Token*);
void finished();
void reset();
bool skipMode() const { return !m_skipModeTag.isNull(); }
bool isHandlingResidualStyleAcrossBlocks() const { return m_handlingResidualStyleAcrossBlocks; }
private:
void setCurrent(Node*);
void derefCurrent();
void setSkipMode(const QualifiedName& qName) { m_skipModeTag = qName.localName(); }
PassRefPtr<Node> getNode(Token*);
bool bodyCreateErrorCheck(Token*, RefPtr<Node>&);
bool canvasCreateErrorCheck(Token*, RefPtr<Node>&);
bool commentCreateErrorCheck(Token*, RefPtr<Node>&);
bool ddCreateErrorCheck(Token*, RefPtr<Node>&);
bool dtCreateErrorCheck(Token*, RefPtr<Node>&);
bool formCreateErrorCheck(Token*, RefPtr<Node>&);
bool framesetCreateErrorCheck(Token*, RefPtr<Node>&);
bool headCreateErrorCheck(Token*, RefPtr<Node>&);
bool iframeCreateErrorCheck(Token*, RefPtr<Node>&);
bool isindexCreateErrorCheck(Token*, RefPtr<Node>&);
bool mapCreateErrorCheck(Token*, RefPtr<Node>&);
bool nestedCreateErrorCheck(Token*, RefPtr<Node>&);
bool nestedStyleCreateErrorCheck(Token*, RefPtr<Node>&);
bool noembedCreateErrorCheck(Token*, RefPtr<Node>&);
bool noframesCreateErrorCheck(Token*, RefPtr<Node>&);
bool nolayerCreateErrorCheck(Token*, RefPtr<Node>&);
bool noscriptCreateErrorCheck(Token*, RefPtr<Node>&);
bool selectCreateErrorCheck(Token*, RefPtr<Node>&);
bool tableCellCreateErrorCheck(Token*, RefPtr<Node>&);
bool tableSectionCreateErrorCheck(Token*, RefPtr<Node>&);
bool textCreateErrorCheck(Token*, RefPtr<Node>&);
void processCloseTag(Token*);
bool insertNode(Node*, bool flat = false);
bool handleError(Node*, bool flat, const AtomicString& localName, int tagPriority);
void pushBlock(const AtomicString& tagName, int level);
void popBlock(const AtomicString& tagName, bool reportErrors = false);
void popBlock(const QualifiedName& qName, bool reportErrors = false) { return popBlock(qName.localName(), reportErrors); } void popOneBlock();
void moveOneBlockToStack(HTMLStackElem*& head);
inline HTMLStackElem* popOneBlockCommon();
void popInlineBlocks();
void freeBlock();
void createHead();
static bool isResidualStyleTag(const AtomicString& tagName);
static bool isAffectedByResidualStyle(const AtomicString& tagName);
void handleResidualStyleCloseTagAcrossBlocks(HTMLStackElem*);
void reopenResidualStyleTags(HTMLStackElem*, Node* malformedTableParent);
bool allowNestedRedundantTag(const AtomicString& tagName);
static bool isHeaderTag(const AtomicString& tagName);
void popNestedHeaderTag();
bool isInline(Node*) const;
void startBody(); PassRefPtr<Node> handleIsindex(Token*);
void reportError(HTMLParserErrorCode errorCode, const AtomicString* tagName1 = 0, const AtomicString* tagName2 = 0, bool closeTags = false)
{ if (!m_reportErrors) return; reportErrorToConsole(errorCode, tagName1, tagName2, closeTags); }
void reportErrorToConsole(HTMLParserErrorCode, const AtomicString* tagName1, const AtomicString* tagName2, bool closeTags);
Document* document;
Node* current;
bool didRefCurrent;
HTMLStackElem* blockStack;
RefPtr<HTMLFormElement> m_currentFormElement; RefPtr<HTMLMapElement> m_currentMapElement; HTMLHeadElement* head; RefPtr<Node> m_isindexElement;
bool inBody;
bool haveContent;
bool haveFrameSet;
AtomicString m_skipModeTag;
bool m_isParsingFragment;
bool m_reportErrors;
bool m_handlingResidualStyleAcrossBlocks;
int inStrayTableContent;
};
}
#endif // HTMLParser_h