2 This file is part of the KDE libraries
4 Copyright (C) 1997 Martin Jones (mjones@kde.org)
5 (C) 1997 Torben Weis (weis@kde.org)
6 (C) 1998 Waldo Bastian (bastian@kde.org)
7 (C) 1999 Lars Knoll (knoll@kde.org)
8 Copyright (C) 2004, 2005, 2006 Apple Computer, Inc.
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public
12 License as published by the Free Software Foundation; either
13 version 2 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
20 You should have received a copy of the GNU Library General Public License
21 along with this library; see the file COPYING.LIB. If not, write to
22 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 Boston, MA 02111-1307, USA.
25 //----------------------------------------------------------------------------
27 // KDE HTML Widget -- HTML Parser
32 #include "HTMLDocument.h"
36 class DocumentFragment;
39 class HTMLFormElement;
40 class HTMLHeadElement;
46 * The parser for html. It receives a stream of tokens from the HTMLTokenizer, and
47 * builds up the Document structure form it.
52 HTMLParser(Document*);
53 HTMLParser(DocumentFragment*);
54 virtual ~HTMLParser();
57 * parses one token delivered by the tokenizer
59 PassRefPtr<Node> parseToken(Token*);
62 * tokenizer says it's not going to be sending us any more tokens
71 bool skipMode() const { return !discard_until.isNull(); }
72 bool noSpaces() const { return !inBody; }
73 bool selectMode() const { return inSelect; }
75 HTMLDocument *doc() const { return static_cast<HTMLDocument *>(document); }
78 void setCurrent(Node* newCurrent);
79 void setSkipMode(const QualifiedName& qName) { discard_until = qName.localName(); }
83 PassRefPtr<Node> getNode(Token*);
84 bool bodyCreateErrorCheck(Token*, RefPtr<Node>&);
85 bool canvasCreateErrorCheck(Token*, RefPtr<Node>&);
86 bool commentCreateErrorCheck(Token*, RefPtr<Node>&);
87 bool ddCreateErrorCheck(Token*, RefPtr<Node>&);
88 bool dtCreateErrorCheck(Token*, RefPtr<Node>&);
89 bool formCreateErrorCheck(Token*, RefPtr<Node>&);
90 bool framesetCreateErrorCheck(Token*, RefPtr<Node>&);
91 bool headCreateErrorCheck(Token*, RefPtr<Node>&);
92 bool iframeCreateErrorCheck(Token*, RefPtr<Node>&);
93 bool isindexCreateErrorCheck(Token*, RefPtr<Node>&);
94 bool mapCreateErrorCheck(Token*, RefPtr<Node>&);
95 bool nestedCreateErrorCheck(Token*, RefPtr<Node>&);
96 bool nestedStyleCreateErrorCheck(Token*, RefPtr<Node>&);
97 bool noembedCreateErrorCheck(Token*, RefPtr<Node>&);
98 bool noframesCreateErrorCheck(Token*, RefPtr<Node>&);
99 bool nolayerCreateErrorCheck(Token*, RefPtr<Node>&);
100 bool noscriptCreateErrorCheck(Token*, RefPtr<Node>&);
101 bool selectCreateErrorCheck(Token*, RefPtr<Node>&);
102 bool tableCellCreateErrorCheck(Token*, RefPtr<Node>&);
103 bool tableSectionCreateErrorCheck(Token*, RefPtr<Node>&);
104 bool textCreateErrorCheck(Token*, RefPtr<Node>&);
106 void processCloseTag(Token *);
108 bool insertNode(Node *n, bool flat = false);
109 bool handleError(Node* n, bool flat, const AtomicString& localName, int tagPriority);
111 // The currently active element (the one new elements will be added to). Can be a DocumentFragment, a Document or an Element.
114 bool currentIsReferenced;
116 HTMLStackElem *blockStack;
118 void pushBlock(const AtomicString& tagName, int _level);
119 void popBlock(const AtomicString& tagName);
120 void popBlock(const QualifiedName& qName) { return popBlock(qName.localName()); } // Convenience function for readability.
121 void popOneBlock(bool delBlock = true);
122 void popInlineBlocks();
128 bool isResidualStyleTag(const AtomicString& tagName);
129 bool isAffectedByResidualStyle(const AtomicString& tagName);
130 void handleResidualStyleCloseTagAcrossBlocks(HTMLStackElem* elem);
131 void reopenResidualStyleTags(HTMLStackElem* elem, Node* malformedTableParent);
133 bool allowNestedRedundantTag(const AtomicString& tagName);
135 static bool isHeaderTag(const AtomicString& tagName);
136 void popNestedHeaderTag();
138 bool isInline(Node* node) const;
141 * currently active form
143 HTMLFormElement *form;
151 * the head element. Needed for crappy html which defines <base> after </head>
153 HTMLHeadElement *head;
156 * a possible <isindex> element in the head. Compatibility hack for
157 * html from the stone age
159 RefPtr<Node> isindex;
160 Node* handleIsindex(Token*);
163 * inserts the stupid isIndex element.
174 * tells the parser to discard all tags, until it reaches the one specified
176 AtomicString discard_until;
180 int inStrayTableContent;
185 #endif // HTMLPARSER_H