#ifndef HTMLParser_h
#define HTMLParser_h
#include "QualifiedName.h"
#include <wtf/Forward.h>
#include <wtf/OwnPtr.h>
#include <wtf/RefPtr.h>
#include "HTMLParserErrorCodes.h"
#include "MappedAttributeEntry.h"
#include "Text.h"
namespace WebCore {
class DoctypeToken;
class Document;
class DocumentFragment;
class HTMLDocument;
class HTMLFormElement;
class HTMLHeadElement;
class HTMLMapElement;
class HTMLParserQuirks;
class Node;
struct HTMLStackElem;
struct Token;
class HTMLParser : public Noncopyable {
public:
HTMLParser(HTMLDocument*, bool reportErrors);
HTMLParser(DocumentFragment*, FragmentScriptingPermission = FragmentScriptingAllowed);
virtual ~HTMLParser();
PassRefPtr<Node> parseToken(Token*);
void parseDoctypeToken(DoctypeToken*);
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 nestedPCloserCreateErrorCheck(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 pCloserCreateErrorCheck(Token*, RefPtr<Node>&);
bool pCloserStrictCreateErrorCheck(Token*, RefPtr<Node>&);
bool rpCreateErrorCheck(Token*, RefPtr<Node>&);
bool rtCreateErrorCheck(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*);
void limitDepth(int tagPriority);
bool insertNodeAfterLimitDepth(Node*, bool flat = false);
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 isHeadingTag(const AtomicString& tagName);
bool isInline(Node*) const;
void startBody(); PassRefPtr<Node> handleIsindex(Token*);
PassRefPtr<Node> parseTelephoneNumbers(Node *inputNode);
PassRefPtr<Text> parseNextPhoneNumber(Text *inputText);
void checkIfHasPElementInScope();
bool hasPElementInScope()
{
if (m_hasPElementInScope == Unknown)
checkIfHasPElementInScope();
return m_hasPElementInScope == InScope;
}
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* m_document;
Node* m_current;
bool m_didRefCurrent;
HTMLStackElem* m_blockStack;
size_t m_blocksInStack;
unsigned m_treeDepth;
enum ElementInScopeState { NotInScope, InScope, Unknown };
ElementInScopeState m_hasPElementInScope;
RefPtr<HTMLFormElement> m_currentFormElement; RefPtr<HTMLMapElement> m_currentMapElement; RefPtr<HTMLHeadElement> m_head; RefPtr<Node> m_isindexElement;
bool m_inBody;
bool m_haveContent;
bool m_haveFrameSet;
AtomicString m_skipModeTag;
bool m_isParsingFragment;
bool m_reportErrors;
bool m_handlingResidualStyleAcrossBlocks;
int m_inStrayTableContent;
FragmentScriptingPermission m_scriptingPermission;
OwnPtr<HTMLParserQuirks> m_parserQuirks;
};
#if defined(BUILDING_ON_LEOPARD) || defined(BUILDING_ON_TIGER)
bool shouldCreateImplicitHead(Document*);
#else
inline bool shouldCreateImplicitHead(Document*) { return true; }
#endif
bool parseToDoubleForNumberType(const String&, double*);
String serializeForNumberType(double);
}
#endif // HTMLParser_h