#ifndef HTMLPARSER_H
#define HTMLPARSER_H
#include "HTMLDocument.h"
#include "HTMLParserErrorCodes.h"
namespace WebCore {
class DocumentFragment;
class FrameView;
class HTMLElement;
class HTMLFormElement;
class HTMLHeadElement;
class HTMLMapElement;
class HTMLStackElem;
class Token;
class HTMLParser
{
public:
HTMLParser(Document*, bool);
HTMLParser(DocumentFragment*);
virtual ~HTMLParser();
PassRefPtr<Node> parseToken(Token*);
void finished();
void reset();
bool skipMode() const { return !discard_until.isNull(); }
bool noSpaces() const { return !inBody; }
bool selectMode() const { return inSelect; }
HTMLDocument *doc() const { return static_cast<HTMLDocument *>(document); }
private:
void setCurrent(Node* newCurrent);
void setSkipMode(const QualifiedName& qName) { discard_until = qName.localName(); }
Document* document;
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 *n, bool flat = false);
bool handleError(Node* n, bool flat, const AtomicString& localName, int tagPriority);
Node* current;
bool currentIsReferenced;
HTMLStackElem *blockStack;
void pushBlock(const AtomicString& tagName, int _level);
void popBlock(const AtomicString& tagName, bool reportErrors = false);
void popBlock(const QualifiedName& qName) { return popBlock(qName.localName()); } void popOneBlock(bool delBlock = true);
void popInlineBlocks();
void freeBlock();
void createHead();
bool isResidualStyleTag(const AtomicString& tagName);
bool isAffectedByResidualStyle(const AtomicString& tagName);
void handleResidualStyleCloseTagAcrossBlocks(HTMLStackElem* elem);
void reopenResidualStyleTags(HTMLStackElem* elem, Node* malformedTableParent);
bool allowNestedRedundantTag(const AtomicString& tagName);
static bool isHeaderTag(const AtomicString& tagName);
void popNestedHeaderTag();
bool isInline(Node* node) const;
Node *parseTelephoneNumbers(Node *inputNode);
Text *parseNextPhoneNumber(Text *inputText);
HTMLFormElement *form;
HTMLMapElement *map;
HTMLHeadElement *head;
RefPtr<Node> isindex;
Node* handleIsindex(Token*);
void startBody();
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);
bool inBody;
bool haveContent;
bool haveFrameSet;
bool end;
bool inSelect;
AtomicString discard_until;
bool headLoaded;
bool m_fragment;
bool m_reportErrors;
int inStrayTableContent;
};
}
#endif // HTMLPARSER_H